summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/com/android/dialer/database/CallLogQueryHandler.java1
-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
-rw-r--r--java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java1
-rw-r--r--java/com/android/dialer/voicemailstatus/VoicemailStatusQuery.java (renamed from java/com/android/dialer/database/VoicemailStatusQuery.java)2
7 files changed, 98 insertions, 55 deletions
diff --git a/java/com/android/dialer/database/CallLogQueryHandler.java b/java/com/android/dialer/database/CallLogQueryHandler.java
index 1aa125184..92c49a09e 100644
--- a/java/com/android/dialer/database/CallLogQueryHandler.java
+++ b/java/com/android/dialer/database/CallLogQueryHandler.java
@@ -40,6 +40,7 @@ import com.android.dialer.compat.SdkVersionOverride;
import com.android.dialer.phonenumbercache.CallLogQuery;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.PermissionsUtil;
+import com.android.dialer.voicemailstatus.VoicemailStatusQuery;
import com.android.voicemail.VoicemailComponent;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
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;
diff --git a/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java b/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java
index 313fc1be1..16a8c7b69 100644
--- a/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java
+++ b/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java
@@ -18,7 +18,6 @@ package com.android.dialer.voicemailstatus;
import android.database.Cursor;
import android.provider.VoicemailContract.Status;
-import com.android.dialer.database.VoicemailStatusQuery;
/**
* Utility used by the call log UI to determine what user message, if any, related to voicemail
diff --git a/java/com/android/dialer/database/VoicemailStatusQuery.java b/java/com/android/dialer/voicemailstatus/VoicemailStatusQuery.java
index dbd88be1f..4a6e9f703 100644
--- a/java/com/android/dialer/database/VoicemailStatusQuery.java
+++ b/java/com/android/dialer/voicemailstatus/VoicemailStatusQuery.java
@@ -14,7 +14,7 @@
* limitations under the License
*/
-package com.android.dialer.database;
+package com.android.dialer.voicemailstatus;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;