1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.dialer.calldetails;
18 
19 import android.app.LoaderManager.LoaderCallbacks;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.Loader;
23 import android.database.Cursor;
24 import android.os.Bundle;
25 import com.android.dialer.CoalescedIds;
26 import com.android.dialer.calldetails.CallDetailsEntryViewHolder.CallDetailsEntryListener;
27 import com.android.dialer.calldetails.CallDetailsFooterViewHolder.DeleteCallDetailsListener;
28 import com.android.dialer.calldetails.CallDetailsFooterViewHolder.ReportCallIdListener;
29 import com.android.dialer.calldetails.CallDetailsHeaderViewHolder.CallDetailsHeaderListener;
30 import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog;
31 import com.android.dialer.common.Assert;
32 import com.android.dialer.enrichedcall.EnrichedCallComponent;
33 import com.android.dialer.protos.ProtoParsers;
34 
35 /**
36  * Displays the details of a specific call log entry.
37  *
38  * <p>This activity is for the new call log.
39  *
40  * <p>See {@link CallDetailsAdapterCommon} for logic shared between this activity and the one for
41  * the old call log.
42  */
43 public final class CallDetailsActivity extends CallDetailsActivityCommon {
44   public static final String EXTRA_COALESCED_CALL_LOG_IDS = "coalesced_call_log_ids";
45   public static final String EXTRA_HEADER_INFO = "header_info";
46 
47   private static final int CALL_DETAILS_LOADER_ID = 0;
48 
49   /** IDs of call log entries, used to retrieve them from the annotated call log. */
50   private CoalescedIds coalescedCallLogIds;
51 
52   /** Info to be shown in the header. */
53   private CallDetailsHeaderInfo headerInfo;
54 
55   /** Returns an {@link Intent} to launch this activity. */
newInstance( Context context, CoalescedIds coalescedAnnotatedCallLogIds, CallDetailsHeaderInfo callDetailsHeaderInfo, boolean canReportCallerId, boolean canSupportAssistedDialing)56   public static Intent newInstance(
57       Context context,
58       CoalescedIds coalescedAnnotatedCallLogIds,
59       CallDetailsHeaderInfo callDetailsHeaderInfo,
60       boolean canReportCallerId,
61       boolean canSupportAssistedDialing) {
62     Intent intent = new Intent(context, CallDetailsActivity.class);
63     ProtoParsers.put(
64         intent, EXTRA_COALESCED_CALL_LOG_IDS, Assert.isNotNull(coalescedAnnotatedCallLogIds));
65     ProtoParsers.put(intent, EXTRA_HEADER_INFO, Assert.isNotNull(callDetailsHeaderInfo));
66     intent.putExtra(EXTRA_CAN_REPORT_CALLER_ID, canReportCallerId);
67     intent.putExtra(EXTRA_CAN_SUPPORT_ASSISTED_DIALING, canSupportAssistedDialing);
68     return intent;
69   }
70 
71   @Override
handleIntent(Intent intent)72   protected void handleIntent(Intent intent) {
73     Assert.checkArgument(intent.hasExtra(EXTRA_COALESCED_CALL_LOG_IDS));
74     Assert.checkArgument(intent.hasExtra(EXTRA_HEADER_INFO));
75     Assert.checkArgument(intent.hasExtra(EXTRA_CAN_REPORT_CALLER_ID));
76     Assert.checkArgument(intent.hasExtra(EXTRA_CAN_SUPPORT_ASSISTED_DIALING));
77 
78     setCallDetailsEntries(CallDetailsEntries.getDefaultInstance());
79     coalescedCallLogIds =
80         ProtoParsers.getTrusted(
81             intent, EXTRA_COALESCED_CALL_LOG_IDS, CoalescedIds.getDefaultInstance());
82     headerInfo =
83         ProtoParsers.getTrusted(
84             intent, EXTRA_HEADER_INFO, CallDetailsHeaderInfo.getDefaultInstance());
85 
86     getLoaderManager()
87         .initLoader(
88             CALL_DETAILS_LOADER_ID, /* args = */ null, new CallDetailsLoaderCallbacks(this));
89   }
90 
91   @Override
createAdapter( CallDetailsEntryListener callDetailsEntryListener, CallDetailsHeaderListener callDetailsHeaderListener, ReportCallIdListener reportCallIdListener, DeleteCallDetailsListener deleteCallDetailsListener)92   protected CallDetailsAdapterCommon createAdapter(
93       CallDetailsEntryListener callDetailsEntryListener,
94       CallDetailsHeaderListener callDetailsHeaderListener,
95       ReportCallIdListener reportCallIdListener,
96       DeleteCallDetailsListener deleteCallDetailsListener) {
97     return new CallDetailsAdapter(
98         this,
99         headerInfo,
100         getCallDetailsEntries(),
101         callDetailsEntryListener,
102         callDetailsHeaderListener,
103         reportCallIdListener,
104         deleteCallDetailsListener);
105   }
106 
107   @Override
getNumber()108   protected String getNumber() {
109     return headerInfo.getDialerPhoneNumber().getNormalizedNumber();
110   }
111 
112   /**
113    * {@link LoaderCallbacks} for {@link CallDetailsCursorLoader}, which loads call detail entries
114    * from {@link AnnotatedCallLog}.
115    */
116   private static final class CallDetailsLoaderCallbacks implements LoaderCallbacks<Cursor> {
117     private final CallDetailsActivity activity;
118 
CallDetailsLoaderCallbacks(CallDetailsActivity callDetailsActivity)119     CallDetailsLoaderCallbacks(CallDetailsActivity callDetailsActivity) {
120       this.activity = callDetailsActivity;
121     }
122 
123     @Override
onCreateLoader(int id, Bundle args)124     public Loader<Cursor> onCreateLoader(int id, Bundle args) {
125       return new CallDetailsCursorLoader(activity, Assert.isNotNull(activity.coalescedCallLogIds));
126     }
127 
128     @Override
onLoadFinished(Loader<Cursor> loader, Cursor data)129     public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
130       updateCallDetailsEntries(CallDetailsCursorLoader.toCallDetailsEntries(activity, data));
131       activity.loadRttTranscriptAvailability();
132     }
133 
134     @Override
onLoaderReset(Loader<Cursor> loader)135     public void onLoaderReset(Loader<Cursor> loader) {
136       updateCallDetailsEntries(CallDetailsEntries.getDefaultInstance());
137     }
138 
updateCallDetailsEntries(CallDetailsEntries newEntries)139     private void updateCallDetailsEntries(CallDetailsEntries newEntries) {
140       activity.setCallDetailsEntries(newEntries);
141       EnrichedCallComponent.get(activity)
142           .getEnrichedCallManager()
143           .requestAllHistoricalData(activity.getNumber(), newEntries);
144     }
145   }
146 }
147