diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-08-31 16:17:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-31 16:17:04 +0000 |
commit | c39ea3c55fac807c0b98aabdf56c70dc8a49036c (patch) | |
tree | e282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/dialer/calldetails/CallDetailsActivity.java | |
parent | 68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff) | |
parent | 2ca4318cc1ee57dda907ba2069bd61d162b1baef (diff) |
Merge "Update Dialer source to latest internal Google revision."
Diffstat (limited to 'java/com/android/dialer/calldetails/CallDetailsActivity.java')
-rw-r--r-- | java/com/android/dialer/calldetails/CallDetailsActivity.java | 162 |
1 files changed, 150 insertions, 12 deletions
diff --git a/java/com/android/dialer/calldetails/CallDetailsActivity.java b/java/com/android/dialer/calldetails/CallDetailsActivity.java index 7eab951fa..569aaa5b5 100644 --- a/java/com/android/dialer/calldetails/CallDetailsActivity.java +++ b/java/com/android/dialer/calldetails/CallDetailsActivity.java @@ -23,38 +23,65 @@ import android.os.Bundle; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; 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 com.android.dialer.callcomposer.CallComposerContact; import com.android.dialer.calldetails.CallDetailsEntries.CallDetailsEntry; import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.AsyncTaskExecutors; +import com.android.dialer.dialercontact.DialerContact; +import com.android.dialer.enrichedcall.EnrichedCallComponent; +import com.android.dialer.enrichedcall.EnrichedCallManager.HistoricalDataChangedListener; +import com.android.dialer.enrichedcall.historyquery.proto.HistoryResult; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.logging.UiAction; +import com.android.dialer.performancereport.PerformanceReport; +import com.android.dialer.postcall.PostCall; import com.android.dialer.protos.ProtoParsers; +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 { +public class CallDetailsActivity extends AppCompatActivity + implements OnMenuItemClickListener, + CallDetailsFooterViewHolder.ReportCallIdListener, + HistoricalDataChangedListener { + public static final String EXTRA_PHONE_NUMBER = "phone_number"; + public static final String EXTRA_HAS_ENRICHED_CALL_DATA = "has_enriched_call_data"; private static final String EXTRA_CALL_DETAILS_ENTRIES = "call_details_entries"; private static final String EXTRA_CONTACT = "contact"; + private static final String EXTRA_CAN_REPORT_CALLER_ID = "can_report_caller_id"; private static final String TASK_DELETE = "task_delete"; - private List<CallDetailsEntry> entries; + private CallDetailsEntries entries; + private DialerContact contact; + private CallDetailsAdapter adapter; + + public static boolean isLaunchIntent(Intent intent) { + return intent.getComponent() != null + && CallDetailsActivity.class.getName().equals(intent.getComponent().getClassName()); + } public static Intent newInstance( - Context context, @NonNull CallDetailsEntries details, @NonNull CallComposerContact contact) { + Context context, + @NonNull CallDetailsEntries details, + @NonNull DialerContact contact, + boolean canReportCallerId) { Assert.isNotNull(details); Assert.isNotNull(contact); Intent intent = new Intent(context, CallDetailsActivity.class); ProtoParsers.put(intent, EXTRA_CONTACT, contact); ProtoParsers.put(intent, EXTRA_CALL_DETAILS_ENTRIES, details); + intent.putExtra(EXTRA_CAN_REPORT_CALLER_ID, canReportCallerId); return intent; } @@ -62,30 +89,65 @@ public class CallDetailsActivity extends AppCompatActivity implements OnMenuItem protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.call_details_activity); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + 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 -> { + PerformanceReport.recordClick(UiAction.Type.CLOSE_CALL_DETAIL_WITH_CANCEL_BUTTON); + finish(); + }); onHandleIntent(getIntent()); } @Override + protected void onResume() { + super.onResume(); + + // Some calls may not be recorded (eg. from quick contact), + // so we should restart recording after these calls. (Recorded call is stopped) + PostCall.restartPerformanceRecordingIfARecentCallExist(this); + if (!PerformanceReport.isRecording()) { + PerformanceReport.startRecording(); + } + + PostCall.promptUserForMessageIfNecessary(this, findViewById(R.id.recycler_view)); + + EnrichedCallComponent.get(this) + .getEnrichedCallManager() + .registerHistoricalDataChangedListener(this); + EnrichedCallComponent.get(this) + .getEnrichedCallManager() + .requestAllHistoricalData(contact.getNumber(), entries); + } + + @Override + protected void onPause() { + super.onPause(); + + EnrichedCallComponent.get(this) + .getEnrichedCallManager() + .unregisterHistoricalDataChangedListener(this); + } + + @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); onHandleIntent(intent); } private void onHandleIntent(Intent intent) { - CallComposerContact contact = - ProtoParsers.getTrusted(intent, EXTRA_CONTACT, CallComposerContact.getDefaultInstance()); + contact = ProtoParsers.getTrusted(intent, EXTRA_CONTACT, DialerContact.getDefaultInstance()); entries = ProtoParsers.getTrusted( - intent, EXTRA_CALL_DETAILS_ENTRIES, CallDetailsEntries.getDefaultInstance()) - .getEntriesList(); + intent, EXTRA_CALL_DETAILS_ENTRIES, CallDetailsEntries.getDefaultInstance()); + adapter = new CallDetailsAdapter(this, contact, entries.getEntriesList(), this); - RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); + RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(new CallDetailsAdapter(this, contact, entries)); + recyclerView.setAdapter(adapter); + PerformanceReport.logOnScrollStateChange(recyclerView); } @Override @@ -99,6 +161,73 @@ public class CallDetailsActivity extends AppCompatActivity implements OnMenuItem return false; } + @Override + public void onBackPressed() { + PerformanceReport.recordClick(UiAction.Type.PRESS_ANDROID_BACK_BUTTON); + super.onBackPressed(); + } + + @Override + public void reportCallId(String number) { + ReportDialogFragment.newInstance(number).show(getFragmentManager(), null); + } + + @Override + public boolean canReportCallerId(String number) { + return getIntent().getExtras().getBoolean(EXTRA_CAN_REPORT_CALLER_ID, false); + } + + @Override + public void onHistoricalDataChanged() { + Map<CallDetailsEntry, List<HistoryResult>> mappedResults = + getAllHistoricalData(contact.getNumber(), entries); + + adapter.updateCallDetailsEntries( + generateAndMapNewCallDetailsEntriesHistoryResults( + contact.getNumber(), entries, mappedResults) + .getEntriesList()); + } + + @NonNull + private Map<CallDetailsEntry, List<HistoryResult>> getAllHistoricalData( + @Nullable String number, @NonNull CallDetailsEntries entries) { + if (number == null) { + return Collections.emptyMap(); + } + + Map<CallDetailsEntry, List<HistoryResult>> historicalData = + EnrichedCallComponent.get(this) + .getEnrichedCallManager() + .getAllHistoricalData(number, entries); + if (historicalData == null) { + return Collections.emptyMap(); + } + return historicalData; + } + + private static CallDetailsEntries generateAndMapNewCallDetailsEntriesHistoryResults( + @Nullable String number, + @NonNull CallDetailsEntries callDetailsEntries, + @NonNull Map<CallDetailsEntry, List<HistoryResult>> mappedResults) { + if (number == null) { + return callDetailsEntries; + } + CallDetailsEntries.Builder mutableCallDetailsEntries = CallDetailsEntries.newBuilder(); + for (CallDetailsEntry entry : callDetailsEntries.getEntriesList()) { + CallDetailsEntry.Builder newEntry = CallDetailsEntry.newBuilder().mergeFrom(entry); + List<HistoryResult> results = mappedResults.get(entry); + if (results != null) { + newEntry.addAllHistoryResults(mappedResults.get(entry)); + LogUtil.v( + "CallLogAdapter.generateAndMapNewCallDetailsEntriesHistoryResults", + "mapped %d results", + newEntry.getHistoryResultsList().size()); + } + mutableCallDetailsEntries.addEntries(newEntry.build()); + } + return mutableCallDetailsEntries.build(); + } + /** Delete specified calls from the call log. */ private class DeleteCallsTask extends AsyncTask<Void, Void, Void> { @@ -106,7 +235,7 @@ public class CallDetailsActivity extends AppCompatActivity implements OnMenuItem DeleteCallsTask() { StringBuilder callIds = new StringBuilder(); - for (CallDetailsEntry entry : entries) { + for (CallDetailsEntry entry : entries.getEntriesList()) { if (callIds.length() != 0) { callIds.append(","); } @@ -124,6 +253,15 @@ public class CallDetailsActivity extends AppCompatActivity implements OnMenuItem @Override public void onPostExecute(Void result) { + Intent data = new Intent(); + data.putExtra(EXTRA_PHONE_NUMBER, contact.getNumber()); + for (CallDetailsEntry entry : entries.getEntriesList()) { + if (entry.getHistoryResultsCount() > 0) { + data.putExtra(EXTRA_HAS_ENRICHED_CALL_DATA, true); + break; + } + } + setResult(RESULT_OK, data); finish(); } } |