summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2018-05-04 12:51:59 -0700
committerCopybara-Service <copybara-piper@google.com>2018-05-09 16:46:36 -0700
commita583c2b50f4ebec902325567faf724080185b951 (patch)
tree09d663fd57d274be48db01e85f8ece538c94e081 /java
parentd3844742f236c5c6b838848d226ea9fbcaabab2e (diff)
Pass activity between new call log's adapter/view holder.
This avoids a cast and generally improves understandability. TEST=existing Test: existing PiperOrigin-RevId: 195457457 Change-Id: Ida9d3fc85bed8ff1e0f8064805e23fab00fdeddf
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/calllog/ui/NewCallLogAdapter.java24
-rw-r--r--java/com/android/dialer/calllog/ui/NewCallLogFragment.java7
-rw-r--r--java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java8
3 files changed, 25 insertions, 14 deletions
diff --git a/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java b/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java
index f373a7c69..7fd8132aa 100644
--- a/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java
+++ b/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java
@@ -15,6 +15,7 @@
*/
package com.android.dialer.calllog.ui;
+import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
@@ -72,7 +73,7 @@ final class NewCallLogAdapter extends RecyclerView.Adapter<ViewHolder> {
}
private final Clock clock;
- private final Context context;
+ private final Activity activity;
private final RealtimeRowProcessor realtimeRowProcessor;
private final PopCounts popCounts = new PopCounts();
private final SharedPreferences sharedPref;
@@ -93,12 +94,12 @@ final class NewCallLogAdapter extends RecyclerView.Adapter<ViewHolder> {
/** Position of the "Older" header. Null when it should not be displayed. */
@Nullable private Integer olderHeaderPosition;
- NewCallLogAdapter(Context context, Cursor cursor, Clock clock) {
- this.context = context;
+ NewCallLogAdapter(Activity activity, Cursor cursor, Clock clock) {
+ this.activity = activity;
this.cursor = cursor;
this.clock = clock;
- this.realtimeRowProcessor = CallLogUiComponent.get(context).realtimeRowProcessor();
- this.sharedPref = StorageComponent.get(context).unencryptedSharedPrefs();
+ this.realtimeRowProcessor = CallLogUiComponent.get(activity).realtimeRowProcessor();
+ this.sharedPref = StorageComponent.get(activity).unencryptedSharedPrefs();
this.onScrollListenerForRecordingDuoDisclosureFirstViewTime =
new OnScrollListenerForRecordingDuoDisclosureFirstViewTime(sharedPref, clock);
@@ -175,8 +176,8 @@ final class NewCallLogAdapter extends RecyclerView.Adapter<ViewHolder> {
// Don't show the Duo disclosure card if
// (1) Duo integration is not enabled on the device, or
// (2) Duo is not activated.
- Duo duo = DuoComponent.get(context).getDuo();
- if (!duo.isEnabled(context) || !duo.isActivated(context)) {
+ Duo duo = DuoComponent.get(activity).getDuo();
+ if (!duo.isEnabled(activity) || !duo.isActivated(activity)) {
return false;
}
@@ -218,7 +219,7 @@ final class NewCallLogAdapter extends RecyclerView.Adapter<ViewHolder> {
switch (viewType) {
case RowType.DUO_DISCLOSURE_CARD:
return new DuoDisclosureCardViewHolder(
- LayoutInflater.from(context)
+ LayoutInflater.from(activity)
.inflate(
R.layout.new_call_log_duo_disclosure_card,
viewGroup,
@@ -227,11 +228,12 @@ final class NewCallLogAdapter extends RecyclerView.Adapter<ViewHolder> {
case RowType.HEADER_YESTERDAY:
case RowType.HEADER_OLDER:
return new HeaderViewHolder(
- LayoutInflater.from(context)
+ LayoutInflater.from(activity)
.inflate(R.layout.new_call_log_header, viewGroup, /* attachToRoot = */ false));
case RowType.CALL_LOG_ENTRY:
return new NewCallLogViewHolder(
- LayoutInflater.from(context)
+ activity,
+ LayoutInflater.from(activity)
.inflate(R.layout.new_call_log_entry, viewGroup, /* attachToRoot = */ false),
clock,
realtimeRowProcessor,
@@ -249,7 +251,7 @@ final class NewCallLogAdapter extends RecyclerView.Adapter<ViewHolder> {
((DuoDisclosureCardViewHolder) viewHolder)
.setDismissListener(
unused -> {
- StorageComponent.get(context)
+ StorageComponent.get(activity)
.unencryptedSharedPrefs()
.edit()
.putBoolean(SHARED_PREF_KEY_DUO_DISCLOSURE_DISMISSED, true)
diff --git a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java
index 0f1c2510a..bc5750770 100644
--- a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java
+++ b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java
@@ -15,6 +15,7 @@
*/
package com.android.dialer.calllog.ui;
+import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
@@ -30,6 +31,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.android.dialer.calllog.CallLogComponent;
import com.android.dialer.calllog.RefreshAnnotatedCallLogReceiver;
+import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.DefaultFutureCallback;
import com.android.dialer.common.concurrent.ThreadUtil;
@@ -229,8 +231,11 @@ public final class NewCallLogFragment extends Fragment implements LoaderCallback
// TODO(zachh): Handle empty cursor by showing empty view.
if (recyclerView.getAdapter() == null) {
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ // Note: It's not clear if this callback can be invoked when there's no associated activity,
+ // but if crashes are observed here it may be possible to use getContext() instead.
+ Activity activity = Assert.isNotNull(getActivity());
recyclerView.setAdapter(
- new NewCallLogAdapter(getContext(), newCursor, System::currentTimeMillis));
+ new NewCallLogAdapter(activity, newCursor, System::currentTimeMillis));
} else {
((NewCallLogAdapter) recyclerView.getAdapter()).updateCursor(newCursor);
}
diff --git a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
index c02d80ede..5f3cd96c4 100644
--- a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
+++ b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java
@@ -72,9 +72,13 @@ final class NewCallLogViewHolder extends RecyclerView.ViewHolder {
private long currentRowId;
NewCallLogViewHolder(
- View view, Clock clock, RealtimeRowProcessor realtimeRowProcessor, PopCounts popCounts) {
+ Activity activity,
+ View view,
+ Clock clock,
+ RealtimeRowProcessor realtimeRowProcessor,
+ PopCounts popCounts) {
super(view);
- this.activity = (Activity) view.getContext();
+ this.activity = activity;
contactPhotoView = view.findViewById(R.id.contact_photo_view);
primaryTextView = view.findViewById(R.id.primary_text);
callCountTextView = view.findViewById(R.id.call_count);