summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/voicemail
diff options
context:
space:
mode:
authoruabdullah <uabdullah@google.com>2018-02-11 16:49:45 -0800
committerCopybara-Service <copybara-piper@google.com>2018-02-12 11:42:06 -0800
commitcdcda1a127c4841c2710c17f64a2f522c62cd512 (patch)
tree5addb70bf9c778c1617b20e700baf9bf67983c2b /java/com/android/dialer/voicemail
parentc9213fe63ee5727c55980f549ff10dac87f2e4f0 (diff)
Use UI Listeners for querying voicemail status table
Earlier we were using the legacy CallLogQueryHandler for querying the voicemail status table. However we should be using UI Listeners instead in NUI. This CL queries the voicemail status table and returns a list of voicemail status', which are then used to display the corresponding error messages. This CL also moved VoicemailStatus out of the legacy dialer/database and moves it to dialer/voicemailstatus and ensures that there are no dependencies on the legacy dialer/database in the NUI. Bug: 73139237 Test: Unit tests PiperOrigin-RevId: 185321023 Change-Id: Id16ea475b6a52da380fbf8b3590dc75cbcdc370e
Diffstat (limited to 'java/com/android/dialer/voicemail')
-rw-r--r--java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java41
-rw-r--r--java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java104
-rw-r--r--java/com/android/dialer/voicemail/listui/error/VoicemailStatus.java2
-rw-r--r--java/com/android/dialer/voicemail/listui/error/VoicemailStatusWorker.java2
4 files changed, 96 insertions, 53 deletions
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
index 05a3bc951..044d8df6d 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
@@ -25,7 +25,6 @@ import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
-import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
@@ -49,10 +48,9 @@ import com.android.dialer.voicemail.listui.error.VoicemailErrorMessage;
import com.android.dialer.voicemail.listui.error.VoicemailErrorMessageCreator;
import com.android.dialer.voicemail.listui.error.VoicemailStatus;
import com.android.dialer.voicemail.model.VoicemailEntry;
+import com.google.common.collect.ImmutableList;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
@@ -74,7 +72,6 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
}
private Cursor cursor;
- private Cursor voicemailStatusCursor;
private final Clock clock;
private final GlidePhotoManager glidePhotoManager;
@@ -880,6 +877,7 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
+ LogUtil.e("NewVoicemailAdapter.onError", "onError, what:%d, extra:%d", what, extra);
Assert.checkArgument(
mediaPlayer.getMediaPlayer().equals(mp),
"there should always only be one instance of the media player");
@@ -1009,36 +1007,24 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
}
}
- @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
- public void setVoicemailStatusCursor(Cursor voicemailStatusCursor) {
- this.voicemailStatusCursor = voicemailStatusCursor;
- }
+ /**
+ * Updates the voicemail alert message to reflect the state of the {@link VoicemailStatus} table.
+ * TODO(uabdullah): Handle ToS properly (a bug)
+ */
+ public void updateVoicemailAlertWithMostRecentStatus(
+ Context context, ImmutableList<VoicemailStatus> voicemailStatuses) {
- // TODO(uabdullah): Handle ToS properly
- public void updateAlert(Context context) {
- if (voicemailStatusCursor == null) {
- LogUtil.i("NewVoicemailAdapter.updateAlert", "status cursor was null");
+ if (voicemailStatuses.isEmpty()) {
+ LogUtil.i(
+ "NewVoicemailAdapter.updateVoicemailAlertWithMostRecentStatus",
+ "voicemailStatuses was empty");
return;
}
- LogUtil.i(
- "NewVoicemailAdapter.updateAlert",
- "status cursor size was " + voicemailStatusCursor.getCount());
-
- List<VoicemailStatus> statuses = new ArrayList<>();
-
- while (voicemailStatusCursor.moveToNext()) {
- VoicemailStatus status = new VoicemailStatus(context, voicemailStatusCursor);
- if (status.isActive()) {
- statuses.add(status);
- // TODO(uabdullah): addServiceStateListener
- }
- }
-
voicemailErrorMessage = null;
VoicemailErrorMessageCreator messageCreator = new VoicemailErrorMessageCreator();
- for (VoicemailStatus status : statuses) {
+ for (VoicemailStatus status : voicemailStatuses) {
voicemailErrorMessage = messageCreator.create(context, status, null);
if (voicemailErrorMessage != null) {
break;
@@ -1046,6 +1032,7 @@ final class NewVoicemailAdapter extends RecyclerView.Adapter<ViewHolder>
}
if (voicemailErrorMessage != null) {
+ LogUtil.i("NewVoicemailAdapter.updateVoicemailAlertWithMostRecentStatus", "showing alert");
voicemailAlertPosition = 0;
updateHeaderPositions();
notifyItemChanged(0);
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
index 45a544323..8b6fcbc07 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
@@ -16,8 +16,10 @@
package com.android.dialer.voicemail.listui;
+import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
+import android.provider.VoicemailContract.Status;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
@@ -35,10 +37,14 @@ import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.DialerExecutorComponent;
import com.android.dialer.common.concurrent.ThreadUtil;
import com.android.dialer.common.concurrent.UiListener;
-import com.android.dialer.database.CallLogQueryHandler;
-import com.android.dialer.database.CallLogQueryHandler.Listener;
import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent;
+import com.android.dialer.voicemail.listui.error.VoicemailStatus;
+import com.android.dialer.voicemailstatus.VoicemailStatusQuery;
+import com.android.voicemail.VoicemailComponent;
+import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
+import java.util.List;
// TODO(uabdullah): Register content observer for VoicemailContract.Status.CONTENT_URI in onStart
/** Fragment for Dialer Voicemail Tab. */
@@ -57,8 +63,9 @@ public final class NewVoicemailFragment extends Fragment
private UiListener<Void> refreshAnnotatedCallLogListener;
@Nullable private Runnable refreshAnnotatedCallLogRunnable;
+ private UiListener<ImmutableList<VoicemailStatus>> queryVoicemailStatusTableListener;
+
private RecyclerView recyclerView;
- private CallLogQueryHandler callLogQueryHandler;
public NewVoicemailFragment() {
LogUtil.enterBlock("NewVoicemailFragment.NewVoicemailFragment");
@@ -79,6 +86,13 @@ public final class NewVoicemailFragment extends Fragment
DialerExecutorComponent.get(getContext())
.createUiListener(
getActivity().getFragmentManager(), "NewVoicemailFragment.refreshAnnotatedCallLog");
+
+ queryVoicemailStatusTableListener =
+ DialerExecutorComponent.get(getContext())
+ .createUiListener(
+ getActivity().getFragmentManager(),
+ "NewVoicemailFragment.queryVoicemailStatusTable");
+
refreshAnnotatedCallLogWorker = component.getRefreshAnnotatedCallLogWorker();
}
@@ -192,31 +206,73 @@ public final class NewVoicemailFragment extends Fragment
((NewVoicemailAdapter) recyclerView.getAdapter()).updateCursor(data);
((NewVoicemailAdapter) recyclerView.getAdapter()).checkAndPlayVoicemail();
}
- callLogQueryHandler =
- new CallLogQueryHandler(
- getContext(), getContext().getContentResolver(), new NewVoicemailFragmentListener());
- callLogQueryHandler.fetchVoicemailStatus();
- }
- private final class NewVoicemailFragmentListener implements Listener {
-
- @Override
- public void onVoicemailStatusFetched(Cursor statusCursor) {
- LogUtil.enterBlock("NewVoicemailFragmentListener.onVoicemailStatusFetched");
- ((NewVoicemailAdapter) recyclerView.getAdapter()).setVoicemailStatusCursor(statusCursor);
- ((NewVoicemailAdapter) recyclerView.getAdapter()).updateAlert(getContext());
- }
+ queryAndUpdateVoicemailStatusAlert();
+ }
- @Override
- public void onVoicemailUnreadCountFetched(Cursor cursor) {}
+ private void queryAndUpdateVoicemailStatusAlert() {
+ queryVoicemailStatusTableListener.listen(
+ getContext(),
+ queryVoicemailStatus(getContext()),
+ this::updateVoicemailStatusAlert,
+ throwable -> {
+ throw new RuntimeException(throwable);
+ });
+ }
- @Override
- public void onMissedCallsUnreadCountFetched(Cursor cursor) {}
+ private ListenableFuture<ImmutableList<VoicemailStatus>> queryVoicemailStatus(Context context) {
+ return DialerExecutorComponent.get(context)
+ .backgroundExecutor()
+ .submit(
+ () -> {
+ StringBuilder where = new StringBuilder();
+ List<String> selectionArgs = new ArrayList<>();
+
+ VoicemailComponent.get(context)
+ .getVoicemailClient()
+ .appendOmtpVoicemailStatusSelectionClause(context, where, selectionArgs);
+
+ ImmutableList.Builder<VoicemailStatus> statuses = ImmutableList.builder();
+
+ try (Cursor cursor =
+ context
+ .getContentResolver()
+ .query(
+ Status.CONTENT_URI,
+ VoicemailStatusQuery.getProjection(),
+ where.toString(),
+ selectionArgs.toArray(new String[selectionArgs.size()]),
+ null)) {
+ if (cursor == null) {
+ LogUtil.e(
+ "NewVoicemailFragment.queryVoicemailStatus", "query failed. Null cursor.");
+ return statuses.build();
+ }
+
+ LogUtil.i(
+ "NewVoicemailFragment.queryVoicemailStatus",
+ "cursor size:%d ",
+ cursor.getCount());
+
+ while (cursor.moveToNext()) {
+ VoicemailStatus status = new VoicemailStatus(context, cursor);
+ if (status.isActive()) {
+ statuses.add(status);
+ // TODO(a bug): Handle Service State Listeners
+ }
+ }
+ }
+ LogUtil.i(
+ "NewVoicemailFragment.queryVoicemailStatus",
+ "query returned %d results",
+ statuses.build().size());
+ return statuses.build();
+ });
+ }
- @Override
- public boolean onCallsFetched(Cursor combinedCursor) {
- return false;
- }
+ private void updateVoicemailStatusAlert(ImmutableList<VoicemailStatus> voicemailStatuses) {
+ ((NewVoicemailAdapter) recyclerView.getAdapter())
+ .updateVoicemailAlertWithMostRecentStatus(getContext(), voicemailStatuses);
}
@Override
diff --git a/java/com/android/dialer/voicemail/listui/error/VoicemailStatus.java b/java/com/android/dialer/voicemail/listui/error/VoicemailStatus.java
index 3447f03df..9b7b7fd86 100644
--- a/java/com/android/dialer/voicemail/listui/error/VoicemailStatus.java
+++ b/java/com/android/dialer/voicemail/listui/error/VoicemailStatus.java
@@ -33,7 +33,7 @@ import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.android.dialer.common.LogUtil;
-import com.android.dialer.database.VoicemailStatusQuery;
+import com.android.dialer.voicemailstatus.VoicemailStatusQuery;
/** Structured data from {@link android.provider.VoicemailContract.Status} */
public class VoicemailStatus {
diff --git a/java/com/android/dialer/voicemail/listui/error/VoicemailStatusWorker.java b/java/com/android/dialer/voicemail/listui/error/VoicemailStatusWorker.java
index 20e46ee2d..df58d419f 100644
--- a/java/com/android/dialer/voicemail/listui/error/VoicemailStatusWorker.java
+++ b/java/com/android/dialer/voicemail/listui/error/VoicemailStatusWorker.java
@@ -23,8 +23,8 @@ import android.os.Build.VERSION_CODES;
import android.provider.VoicemailContract.Status;
import android.support.annotation.Nullable;
import com.android.dialer.common.concurrent.DialerExecutor.Worker;
-import com.android.dialer.database.VoicemailStatusQuery;
import com.android.dialer.telecom.TelecomUtil;
+import com.android.dialer.voicemailstatus.VoicemailStatusQuery;
import com.android.voicemail.VoicemailComponent;
import java.util.ArrayList;
import java.util.List;