From 5dd30438fd3e4384b57cef3c7606ec20fad9b50d Mon Sep 17 00:00:00 2001 From: zachh Date: Thu, 11 Jan 2018 13:43:45 -0800 Subject: Minor polish and bugfixes for new call log. -Reuse the adapter in NewCallLogFragment to maintain position in call log when returning from call details -Convert empty values to null when invoking ContactPhotoManager to make photos appear correctly in new call log bottom sheets -Added CallLogContactTypes to be shared between proper call log and bottom sheets -Fixed vertical alignment in bottom sheet when there was no secondary text -Added some verbose logging Test: unit and manual PiperOrigin-RevId: 181655715 Change-Id: I9c1a42ad8d529ee2327e15fcc1d32b7b83982014 --- .../phonelookup/PhoneLookupDataSource.java | 13 ++++++++ .../dialer/calllog/ui/NewCallLogAdapter.java | 20 +++++++++--- .../dialer/calllog/ui/NewCallLogFragment.java | 11 +++++-- .../dialer/calllog/ui/NewCallLogViewHolder.java | 12 +++---- .../dialer/calllog/ui/menu/PrimaryAction.java | 9 ++--- .../dialer/calllogutils/CallLogContactTypes.java | 38 ++++++++++++++++++++++ .../contactactions/ContactActionBottomSheet.java | 4 +-- .../contactactions/res/layout/contact_layout.xml | 17 +++++----- 8 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 java/com/android/dialer/calllogutils/CallLogContactTypes.java (limited to 'java') diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index 508191cde..dca992789 100644 --- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java +++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java @@ -141,6 +141,13 @@ public final class PhoneLookupDataSource */ @Override public ListenableFuture fill(Context appContext, CallLogMutations mutations) { + LogUtil.v( + "PhoneLookupDataSource.fill", + "processing mutations (inserts: %d, updates: %d, deletes: %d)", + mutations.getInserts().size(), + mutations.getUpdates().size(), + mutations.getDeletes().size()); + // Clear state saved since the last call to fill. This is necessary in case fill is called but // onSuccessfulFill is not called during a previous flow. phoneLookupHistoryRowsToUpdate.clear(); @@ -224,6 +231,12 @@ public final class PhoneLookupDataSource rowsToUpdateFuture, rowsToUpdate -> { updateMutations(rowsToUpdate, mutations); + LogUtil.v( + "PhoneLookupDataSource.fill", + "updated mutations (inserts: %d, updates: %d, deletes: %d)", + mutations.getInserts().size(), + mutations.getUpdates().size(), + mutations.getDeletes().size()); return null; }, lightweightExecutorService); diff --git a/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java b/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java index 6dd742be5..a4a67d712 100644 --- a/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java +++ b/java/com/android/dialer/calllog/ui/NewCallLogAdapter.java @@ -44,23 +44,35 @@ final class NewCallLogAdapter extends RecyclerView.Adapter { int CALL_LOG_ENTRY = 3; } - private final Cursor cursor; private final Clock clock; private final RealtimeRowProcessor realtimeRowProcessor; + private Cursor cursor; + /** Null when the "Today" header should not be displayed. */ - @Nullable private final Integer todayHeaderPosition; + @Nullable private Integer todayHeaderPosition; /** Null when the "Older" header should not be displayed. */ - @Nullable private final Integer olderHeaderPosition; + @Nullable private Integer olderHeaderPosition; NewCallLogAdapter(Context context, Cursor cursor, Clock clock) { this.cursor = cursor; this.clock = clock; this.realtimeRowProcessor = CallLogUiComponent.get(context).realtimeRowProcessor(); + setHeaderPositions(); + } + + void updateCursor(Cursor updatedCursor) { + this.cursor = updatedCursor; + + setHeaderPositions(); + notifyDataSetChanged(); + } + + private void setHeaderPositions() { // Calculate header adapter positions by reading cursor. long currentTimeMillis = clock.currentTimeMillis(); - if (cursor.moveToNext()) { + if (cursor.moveToFirst()) { long firstTimestamp = CoalescedAnnotatedCallLogCursorLoader.getTimestamp(cursor); if (CallLogDates.isSameDay(currentTimeMillis, firstTimestamp)) { this.todayHeaderPosition = 0; diff --git a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java index d0656a433..6db7c5d6c 100644 --- a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java +++ b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java @@ -174,10 +174,15 @@ public final class NewCallLogFragment extends Fragment LogUtil.w("NewCallLogFragment.onLoadFinished", "null cursor"); return; } + // TODO(zachh): Handle empty cursor by showing empty view. - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.setAdapter( - new NewCallLogAdapter(getContext(), newCursor, System::currentTimeMillis)); + if (recyclerView.getAdapter() == null) { + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter( + new NewCallLogAdapter(getContext(), newCursor, System::currentTimeMillis)); + } else { + ((NewCallLogAdapter) recyclerView.getAdapter()).updateCursor(newCursor); + } } @Override diff --git a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java index 5cceac989..7482efdea 100644 --- a/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java +++ b/java/com/android/dialer/calllog/ui/NewCallLogViewHolder.java @@ -21,12 +21,14 @@ import android.database.Cursor; import android.net.Uri; import android.provider.CallLog.Calls; import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; import android.view.View; import android.widget.ImageView; import android.widget.QuickContactBadge; import android.widget.TextView; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.calllog.ui.menu.NewCallLogMenu; +import com.android.dialer.calllogutils.CallLogContactTypes; import com.android.dialer.calllogutils.CallLogEntryText; import com.android.dialer.calllogutils.CallLogIntents; import com.android.dialer.calllogutils.CallTypeIconsView; @@ -34,7 +36,6 @@ import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutorComponent; import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.contactphoto.ContactPhotoManager; -import com.android.dialer.lettertile.LetterTileDrawable; import com.android.dialer.oem.MotorolaUtils; import com.android.dialer.time.Clock; import com.google.common.base.Optional; @@ -130,15 +131,14 @@ final class NewCallLogViewHolder extends RecyclerView.ViewHolder { } private void setPhoto(CoalescedRow row) { - // TODO(zachh): Set the contact type. ContactPhotoManager.getInstance(context) .loadDialerThumbnailOrPhoto( quickContactBadge, - row.lookupUri() == null ? null : Uri.parse(row.lookupUri()), + TextUtils.isEmpty(row.lookupUri()) ? null : Uri.parse(row.lookupUri()), row.photoId(), - row.photoUri() == null ? null : Uri.parse(row.photoUri()), - row.name(), - LetterTileDrawable.TYPE_DEFAULT); + TextUtils.isEmpty(row.photoUri()) ? null : Uri.parse(row.photoUri()), + CallLogEntryText.buildPrimaryText(context, row).toString(), + CallLogContactTypes.getContactType(row)); } private void setPrimaryCallTypes(CoalescedRow row) { diff --git a/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java b/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java index 404c41787..faedc8f62 100644 --- a/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java +++ b/java/com/android/dialer/calllog/ui/menu/PrimaryAction.java @@ -19,16 +19,17 @@ package com.android.dialer.calllog.ui.menu; import android.content.Context; import android.provider.CallLog.Calls; import com.android.dialer.calllog.model.CoalescedRow; +import com.android.dialer.calllogutils.CallLogContactTypes; import com.android.dialer.calllogutils.CallLogEntryText; import com.android.dialer.calllogutils.CallLogIntents; import com.android.dialer.contactactions.ContactPrimaryActionInfo; import com.android.dialer.contactactions.ContactPrimaryActionInfo.PhotoInfo; -import com.android.dialer.lettertile.LetterTileDrawable; /** Configures the primary action row (top row) for the bottom sheet. */ final class PrimaryAction { static ContactPrimaryActionInfo fromRow(Context context, CoalescedRow row) { + CharSequence primaryText = CallLogEntryText.buildPrimaryText(context, row); return ContactPrimaryActionInfo.builder() .setNumber(row.number()) .setPhotoInfo( @@ -37,10 +38,10 @@ final class PrimaryAction { .setPhotoUri(row.photoUri()) .setLookupUri(row.lookupUri()) .setIsVideo((row.features() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO) - .setContactType(LetterTileDrawable.TYPE_DEFAULT) // TODO(zachh): Use proper type. - .setDisplayName(row.name()) + .setContactType(CallLogContactTypes.getContactType(row)) + .setDisplayName(primaryText.toString()) .build()) - .setPrimaryText(CallLogEntryText.buildPrimaryText(context, row)) + .setPrimaryText(primaryText) .setSecondaryText(CallLogEntryText.buildSecondaryTextForBottomSheet(context, row)) .setIntent(CallLogIntents.getCallBackIntent(context, row)) .build(); diff --git a/java/com/android/dialer/calllogutils/CallLogContactTypes.java b/java/com/android/dialer/calllogutils/CallLogContactTypes.java new file mode 100644 index 000000000..01ae653b4 --- /dev/null +++ b/java/com/android/dialer/calllogutils/CallLogContactTypes.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.calllogutils; + +import com.android.dialer.calllog.model.CoalescedRow; +import com.android.dialer.lettertile.LetterTileDrawable; + +/** Determines the {@link LetterTileDrawable.ContactType} for a {@link CoalescedRow}. */ +public class CallLogContactTypes { + + /** Determines the {@link LetterTileDrawable.ContactType} for a {@link CoalescedRow}. */ + @LetterTileDrawable.ContactType + public static int getContactType(CoalescedRow row) { + // TODO(zachh): Set these fields correctly. + boolean isVoicemail = false; + boolean isSpam = false; + boolean isBusiness = false; + int numberPresentation = 0; + boolean isConference = false; + + return LetterTileDrawable.getContactTypeFromPrimitives( + isVoicemail, isSpam, isBusiness, numberPresentation, isConference); + } +} diff --git a/java/com/android/dialer/contactactions/ContactActionBottomSheet.java b/java/com/android/dialer/contactactions/ContactActionBottomSheet.java index f2f1d189b..7e216aaa1 100644 --- a/java/com/android/dialer/contactactions/ContactActionBottomSheet.java +++ b/java/com/android/dialer/contactactions/ContactActionBottomSheet.java @@ -89,9 +89,9 @@ public class ContactActionBottomSheet extends BottomSheetDialog implements OnCli ContactPhotoManager.getInstance(getContext()) .loadDialerThumbnailOrPhoto( contactView.findViewById(R.id.quick_contact_photo), - photoInfo.lookupUri() != null ? Uri.parse(photoInfo.lookupUri()) : null, + !TextUtils.isEmpty(photoInfo.lookupUri()) ? Uri.parse(photoInfo.lookupUri()) : null, photoInfo.photoId(), - photoInfo.photoUri() != null ? Uri.parse(photoInfo.photoUri()) : null, + !TextUtils.isEmpty(photoInfo.photoUri()) ? Uri.parse(photoInfo.photoUri()) : null, photoInfo.displayName(), photoInfo.contactType()); diff --git a/java/com/android/dialer/contactactions/res/layout/contact_layout.xml b/java/com/android/dialer/contactactions/res/layout/contact_layout.xml index 8ea05d4d6..4deef3e07 100644 --- a/java/com/android/dialer/contactactions/res/layout/contact_layout.xml +++ b/java/com/android/dialer/contactactions/res/layout/contact_layout.xml @@ -15,12 +15,13 @@ ~ limitations under the License --> + android:layout_marginEnd="8dp" + android:gravity="center_vertical" + android:orientation="horizontal"> + android:gravity="center_vertical" + android:orientation="vertical"> + android:layout_height="wrap_content"/> + android:layout_marginTop="2dp"/> \ No newline at end of file -- cgit v1.2.3