diff options
author | linyuh <linyuh@google.com> | 2017-11-22 10:58:56 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-22 16:26:29 -0800 |
commit | 7ba72d2d5b4061cf55d5440d4434a660c9108d2e (patch) | |
tree | c2de078bec6bbc96654c1032d016cdb19ac004c0 /java/com/android/dialer/calldetails/CallDetailsActivity.java | |
parent | 1fb1c697a2b71ed629df76c4be129729f3cb6aea (diff) |
Allow deleting a call log entry in the call log UI and the call details UI.
In the call log UI, an entry can be deleted by selecting "delete" in its context menu.
In the call details UI, a "delete" button is added at the bottom.
The "delete" icon at the top right of the call details UI is removed.
Public-Origin-Change-Id: Iabe1310fb9a97a277cf482a3fd61ffccbec125fe
Signed-off-by: Linyu He <linyuh@google.com>
Author: Masafumi Miya <masafumi.miya@sony.com>
Bug: 38188896
Test: CallLogActivityIntegrationTest, CallDetailsActivityIntegrationTest
PiperOrigin-RevId: 176677167
Change-Id: I2e31cd112efdfb83393f5e68ce016dcf36ac4858
Diffstat (limited to 'java/com/android/dialer/calldetails/CallDetailsActivity.java')
-rw-r--r-- | java/com/android/dialer/calldetails/CallDetailsActivity.java | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/java/com/android/dialer/calldetails/CallDetailsActivity.java b/java/com/android/dialer/calldetails/CallDetailsActivity.java index 7a117a3f1..06b6a1040 100644 --- a/java/com/android/dialer/calldetails/CallDetailsActivity.java +++ b/java/com/android/dialer/calldetails/CallDetailsActivity.java @@ -16,6 +16,9 @@ package com.android.dialer.calldetails; +import android.Manifest.permission; +import android.annotation.SuppressLint; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -25,14 +28,14 @@ import android.provider.CallLog; import android.provider.CallLog.Calls; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.RequiresPermission; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.support.v7.widget.Toolbar.OnMenuItemClickListener; -import android.view.MenuItem; import android.widget.Toast; import com.android.dialer.calldetails.CallDetailsEntries.CallDetailsEntry; +import com.android.dialer.calldetails.CallDetailsFooterViewHolder.DeleteCallDetailsListener; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; import com.android.dialer.common.Assert; @@ -52,15 +55,16 @@ import com.android.dialer.performancereport.PerformanceReport; import com.android.dialer.postcall.PostCall; import com.android.dialer.precall.PreCall; import com.android.dialer.protos.ProtoParsers; +import java.lang.ref.WeakReference; import java.util.Collections; import java.util.List; import java.util.Map; /** Displays the details of a specific call log entry. */ public class CallDetailsActivity extends AppCompatActivity - implements OnMenuItemClickListener, - CallDetailsHeaderViewHolder.CallbackActionListener, + implements CallDetailsHeaderViewHolder.CallbackActionListener, CallDetailsFooterViewHolder.ReportCallIdListener, + DeleteCallDetailsListener, HistoricalDataChangedListener { public static final String EXTRA_PHONE_NUMBER = "phone_number"; @@ -102,8 +106,6 @@ public class CallDetailsActivity extends AppCompatActivity super.onCreate(savedInstanceState); setContentView(R.layout.call_details_activity); Toolbar toolbar = findViewById(R.id.toolbar); - toolbar.inflateMenu(R.menu.call_details_menu); - toolbar.setOnMenuItemClickListener(this); toolbar.setTitle(R.string.call_details); toolbar.setNavigationOnClickListener( v -> { @@ -160,7 +162,8 @@ public class CallDetailsActivity extends AppCompatActivity contact, entries.getEntriesList(), this /* callbackListener */, - this /* reportCallIdListener */); + this /* reportCallIdListener */, + this /* callDetailDeletionListener */); RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); @@ -169,17 +172,6 @@ public class CallDetailsActivity extends AppCompatActivity } @Override - public boolean onMenuItemClick(MenuItem item) { - if (item.getItemId() == R.id.call_detail_delete_menu_item) { - Logger.get(this).logImpression(DialerImpression.Type.USER_DELETED_CALL_LOG_ITEM); - AsyncTaskExecutors.createAsyncTaskExecutor().submit(TASK_DELETE, new DeleteCallsTask()); - item.setEnabled(false); - return true; - } - return false; - } - - @Override public void onBackPressed() { PerformanceReport.recordClick(UiAction.Type.PRESS_ANDROID_BACK_BUTTON); super.onBackPressed(); @@ -246,6 +238,12 @@ public class CallDetailsActivity extends AppCompatActivity PreCall.start(this, callIntentBuilder); } + @Override + public void delete() { + AsyncTaskExecutors.createAsyncTaskExecutor() + .submit(TASK_DELETE, new DeleteCallsTask(this, contact, entries)); + } + @NonNull private Map<CallDetailsEntry, List<HistoryResult>> getAllHistoricalData( @Nullable String number, @NonNull CallDetailsEntries entries) { @@ -287,13 +285,22 @@ public class CallDetailsActivity extends AppCompatActivity } /** Delete specified calls from the call log. */ - private class DeleteCallsTask extends AsyncTask<Void, Void, Void> { + private static class DeleteCallsTask extends AsyncTask<Void, Void, Void> { + // Use a weak reference to hold the Activity so that there is no memory leak. + private final WeakReference<Activity> activityWeakReference; + private final DialerContact contact; + private final CallDetailsEntries callDetailsEntries; private final String callIds; - DeleteCallsTask() { + DeleteCallsTask( + Activity activity, DialerContact contact, CallDetailsEntries callDetailsEntries) { + this.activityWeakReference = new WeakReference<>(activity); + this.contact = contact; + this.callDetailsEntries = callDetailsEntries; + StringBuilder callIds = new StringBuilder(); - for (CallDetailsEntry entry : entries.getEntriesList()) { + for (CallDetailsEntry entry : callDetailsEntries.getEntriesList()) { if (callIds.length() != 0) { callIds.append(","); } @@ -303,24 +310,43 @@ public class CallDetailsActivity extends AppCompatActivity } @Override + // Suppress the lint check here as the user will not be able to see call log entries if + // permission.WRITE_CALL_LOG is not granted. + @SuppressLint("MissingPermission") + @RequiresPermission(value = permission.WRITE_CALL_LOG) protected Void doInBackground(Void... params) { - getContentResolver() - .delete(Calls.CONTENT_URI, CallLog.Calls._ID + " IN (" + callIds + ")", null); + Activity activity = activityWeakReference.get(); + if (activity == null) { + return null; + } + + activity + .getContentResolver() + .delete( + Calls.CONTENT_URI, + CallLog.Calls._ID + " IN (" + callIds + ")" /* where */, + null /* selectionArgs */); return null; } @Override public void onPostExecute(Void result) { + Activity activity = activityWeakReference.get(); + if (activity == null) { + return; + } + Intent data = new Intent(); data.putExtra(EXTRA_PHONE_NUMBER, contact.getNumber()); - for (CallDetailsEntry entry : entries.getEntriesList()) { + for (CallDetailsEntry entry : callDetailsEntries.getEntriesList()) { if (entry.getHistoryResultsCount() > 0) { data.putExtra(EXTRA_HAS_ENRICHED_CALL_DATA, true); break; } } - setResult(RESULT_OK, data); - finish(); + + activity.setResult(RESULT_OK, data); + activity.finish(); } } } |