Skip to content

Commit

Permalink
Internal cleanup for the new UI's bottom sheet.
Browse files Browse the repository at this point in the history
Test: Existing tests
PiperOrigin-RevId: 187254014
Change-Id: I8a57b632d45e87ad075eb8bbb25180858e890f08
  • Loading branch information
linyuh authored and Copybara-Service committed Feb 28, 2018
1 parent 311c525 commit 4ef5116
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import com.android.dialer.common.concurrent.DialerExecutor.Worker;
import com.android.dialer.common.concurrent.DialerExecutorComponent;
import com.android.dialer.common.database.Selection;
import com.android.dialer.contactactions.ContactActionModule;
import com.android.dialer.historyitemactions.HistoryItemActionModule;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/** {@link ContactActionModule} for deleting a call log item in the new call log. */
public final class DeleteCallLogItemModule implements ContactActionModule {
/** {@link HistoryItemActionModule} for deleting a call log item in the new call log. */
public final class DeleteCallLogItemModule implements HistoryItemActionModule {
private static final String TAG = DeleteCallLogItemModule.class.getName();

private final Context context;
Expand Down
108 changes: 61 additions & 47 deletions java/com/android/dialer/calllog/ui/menu/Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,42 @@
import com.android.dialer.calllog.model.CoalescedRow;
import com.android.dialer.calllogutils.CallLogContactTypes;
import com.android.dialer.calllogutils.PhoneNumberDisplayUtil;
import com.android.dialer.contactactions.ContactActionModule;
import com.android.dialer.contactactions.DividerModule;
import com.android.dialer.contactactions.IntentModule;
import com.android.dialer.contactactions.SharedModules;
import com.android.dialer.dialercontact.DialerContact;
import com.android.dialer.historyitemactions.DividerModule;
import com.android.dialer.historyitemactions.HistoryItemActionModule;
import com.android.dialer.historyitemactions.IntentModule;
import com.android.dialer.historyitemactions.SharedModules;
import com.android.dialer.logging.ReportingLocation;
import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.telecom.TelecomUtil;
import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Configures the modules for the bottom sheet; these are the rows below the top row (primary
* action) in the bottom sheet.
*/
@SuppressWarnings("Guava")
final class Modules {

static List<ContactActionModule> fromRow(Context context, CoalescedRow row) {
static List<HistoryItemActionModule> fromRow(Context context, CoalescedRow row) {
// Conditionally add each module, which are items in the bottom sheet's menu.
List<ContactActionModule> modules = new ArrayList<>();
List<HistoryItemActionModule> modules = new ArrayList<>();

String normalizedNumber = row.number().getNormalizedNumber();
boolean canPlaceCalls =
PhoneNumberHelper.canPlaceCallsTo(normalizedNumber, row.numberPresentation());

if (canPlaceCalls) {
addModuleForCalls(context, modules, row, normalizedNumber);
SharedModules.maybeAddModuleForSendingTextMessage(
context, modules, normalizedNumber, row.numberAttributes().getIsBlocked());
modules.addAll(createModulesForCalls(context, row, normalizedNumber));
Optional<HistoryItemActionModule> moduleForSendingTextMessage =
SharedModules.createModuleForSendingTextMessage(
context, normalizedNumber, row.numberAttributes().getIsBlocked());
if (moduleForSendingTextMessage.isPresent()) {
modules.add(moduleForSendingTextMessage.get());
}
}

if (!modules.isEmpty()) {
Expand All @@ -65,45 +71,52 @@ static List<ContactActionModule> fromRow(Context context, CoalescedRow row) {
// TODO(zachh): Module for CallComposer.

if (canPlaceCalls) {
SharedModules.maybeAddModuleForAddingToContacts(
context,
modules,
row.number(),
row.numberAttributes().getName(),
row.numberAttributes().getLookupUri(),
row.numberAttributes().getIsBlocked(),
row.numberAttributes().getIsSpam());
SharedModules.addModulesHandlingBlockedOrSpamNumber(
context,
modules,
row.number().getNormalizedNumber(),
row.number().getCountryIso(),
row.callType(),
row.numberAttributes().getIsBlocked(),
row.numberAttributes().getIsSpam(),
ReportingLocation.Type.CALL_LOG_HISTORY);
SharedModules.maybeAddModuleForCopyingNumber(context, modules, normalizedNumber);
Optional<HistoryItemActionModule> moduleForAddingToContacts =
SharedModules.createModuleForAddingToContacts(
context,
row.number(),
row.numberAttributes().getName(),
row.numberAttributes().getLookupUri(),
row.numberAttributes().getIsBlocked(),
row.numberAttributes().getIsSpam());
if (moduleForAddingToContacts.isPresent()) {
modules.add(moduleForAddingToContacts.get());
}

modules.addAll(
SharedModules.createModulesHandlingBlockedOrSpamNumber(
context,
row.number().getNormalizedNumber(),
row.number().getCountryIso(),
row.callType(),
row.numberAttributes().getIsBlocked(),
row.numberAttributes().getIsSpam(),
ReportingLocation.Type.CALL_LOG_HISTORY));

Optional<HistoryItemActionModule> moduleForCopyingNumber =
SharedModules.createModuleForCopyingNumber(context, normalizedNumber);
if (moduleForCopyingNumber.isPresent()) {
modules.add(moduleForCopyingNumber.get());
}
}

// TODO(zachh): Revisit if DialerContact is the best thing to pass to CallDetails; could
// it use a ContactPrimaryActionInfo instead?
addModuleForAccessingCallDetails(context, modules, row);
// it use a HistoryItemPrimaryActionInfo instead?
modules.add(createModuleForAccessingCallDetails(context, row));

modules.add(new DeleteCallLogItemModule(context, row.coalescedIds()));

return modules;
}

private static void addModuleForCalls(
Context context,
List<ContactActionModule> modules,
CoalescedRow row,
String normalizedNumber) {
private static List<HistoryItemActionModule> createModulesForCalls(
Context context, CoalescedRow row, String normalizedNumber) {
// Don't add call options if a number is blocked.
if (row.numberAttributes().getIsBlocked()) {
return;
return Collections.emptyList();
}

List<HistoryItemActionModule> modules = new ArrayList<>();
PhoneAccountHandle phoneAccountHandle =
TelecomUtil.composePhoneAccountHandle(
row.phoneAccountComponentName(), row.phoneAccountId());
Expand All @@ -123,24 +136,25 @@ private static void addModuleForCalls(

// TODO(zachh): Also show video option if the call log entry is for an audio call but video
// capabilities are present?

return modules;
}

private static void addModuleForAccessingCallDetails(
Context context, List<ContactActionModule> modules, CoalescedRow row) {
private static HistoryItemActionModule createModuleForAccessingCallDetails(
Context context, CoalescedRow row) {
boolean canReportAsInvalidNumber = row.numberAttributes().getCanReportAsInvalidNumber();
boolean canSupportAssistedDialing = !TextUtils.isEmpty(row.numberAttributes().getLookupUri());

modules.add(
new IntentModule(
return new IntentModule(
context,
CallDetailsActivity.newInstance(
context,
CallDetailsActivity.newInstance(
context,
row.coalescedIds(),
createDialerContactFromRow(context, row),
canReportAsInvalidNumber,
canSupportAssistedDialing),
R.string.call_details_menu_label,
R.drawable.quantum_ic_info_outline_vd_theme_24));
row.coalescedIds(),
createDialerContactFromRow(context, row),
canReportAsInvalidNumber,
canSupportAssistedDialing),
R.string.call_details_menu_label,
R.drawable.quantum_ic_info_outline_vd_theme_24);
}

private static DialerContact createDialerContactFromRow(Context context, CoalescedRow row) {
Expand Down
4 changes: 2 additions & 2 deletions java/com/android/dialer/calllog/ui/menu/NewCallLogMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.android.dialer.calllog.CallLogComponent;
import com.android.dialer.calllog.model.CoalescedRow;
import com.android.dialer.common.concurrent.DefaultFutureCallback;
import com.android.dialer.contactactions.ContactActionBottomSheet;
import com.android.dialer.glidephotomanager.GlidePhotoManager;
import com.android.dialer.historyitemactions.HistoryItemActionBottomSheet;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;

Expand All @@ -34,7 +34,7 @@ public final class NewCallLogMenu {
public static View.OnClickListener createOnClickListener(
Context context, CoalescedRow row, GlidePhotoManager glidePhotoManager) {
return view -> {
ContactActionBottomSheet.show(
HistoryItemActionBottomSheet.show(
context,
PrimaryAction.fromRow(context, row),
Modules.fromRow(context, row),
Expand Down
6 changes: 3 additions & 3 deletions java/com/android/dialer/calllog/ui/menu/PrimaryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import com.android.dialer.calllogutils.CallLogEntryText;
import com.android.dialer.calllogutils.CallLogIntents;
import com.android.dialer.calllogutils.NumberAttributesConverter;
import com.android.dialer.contactactions.ContactPrimaryActionInfo;
import com.android.dialer.historyitemactions.HistoryItemPrimaryActionInfo;

/** Configures the primary action row (top row) for the bottom sheet. */
final class PrimaryAction {

static ContactPrimaryActionInfo fromRow(Context context, CoalescedRow row) {
static HistoryItemPrimaryActionInfo fromRow(Context context, CoalescedRow row) {
CharSequence primaryText = CallLogEntryText.buildPrimaryText(context, row);
return ContactPrimaryActionInfo.builder()
return HistoryItemPrimaryActionInfo.builder()
.setNumber(row.number())
.setPhotoInfo(
NumberAttributesConverter.toPhotoInfoBuilder(row.numberAttributes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
<manifest package="com.android.dialer.contactactions"/>
<manifest package="com.android.dialer.historyitemactions"/>
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

package com.android.dialer.contactactions;
package com.android.dialer.historyitemactions;

import com.android.dialer.common.Assert;

/**
* A module that inserts a grey line divider into {@link ContactActionModule}. Layout it provided in
* R.layout.divider_layout.xml
* A module that inserts a grey line divider into {@link HistoryItemActionModule}. Layout it
* provided in R.layout.divider_layout.xml
*/
public final class DividerModule implements ContactActionModule {
public final class DividerModule implements HistoryItemActionModule {

@Override
public int getStringId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.android.dialer.contactactions;
package com.android.dialer.historyitemactions;

import android.content.Context;
import android.os.Bundle;
Expand All @@ -32,37 +32,38 @@
import java.util.List;

/**
* {@link BottomSheetDialog} used for building a list of contact actions in a bottom sheet menu.
* {@link BottomSheetDialog} used to show a list of actions in a bottom sheet menu.
*
* <p>{@link #show(Context, ContactPrimaryActionInfo, List)} should be used to create and display
* the menu. Modules are built using {@link ContactActionModule} and some defaults are provided by
* {@link IntentModule} and {@link DividerModule}.
* <p>{@link #show(Context, HistoryItemPrimaryActionInfo, List, GlidePhotoManager)} should be used
* to create and display the menu. Modules are built using {@link HistoryItemActionModule} and some
* defaults are provided by {@link IntentModule} and {@link DividerModule}.
*/
public class ContactActionBottomSheet extends BottomSheetDialog implements OnClickListener {
public class HistoryItemActionBottomSheet extends BottomSheetDialog implements OnClickListener {

private final List<ContactActionModule> modules;
private final ContactPrimaryActionInfo contactPrimaryActionInfo;
private final List<HistoryItemActionModule> modules;
private final HistoryItemPrimaryActionInfo historyItemPrimaryActionInfo;
private final GlidePhotoManager glidePhotoManager;

private ContactActionBottomSheet(
private HistoryItemActionBottomSheet(
Context context,
ContactPrimaryActionInfo contactPrimaryActionInfo,
List<ContactActionModule> modules,
HistoryItemPrimaryActionInfo historyItemPrimaryActionInfo,
List<HistoryItemActionModule> modules,
GlidePhotoManager glidePhotoManager) {
super(context);
this.modules = modules;
this.contactPrimaryActionInfo = contactPrimaryActionInfo;
this.historyItemPrimaryActionInfo = historyItemPrimaryActionInfo;
this.glidePhotoManager = glidePhotoManager;
setContentView(LayoutInflater.from(context).inflate(R.layout.sheet_layout, null));
}

public static ContactActionBottomSheet show(
public static HistoryItemActionBottomSheet show(
Context context,
ContactPrimaryActionInfo contactPrimaryActionInfo,
List<ContactActionModule> modules,
HistoryItemPrimaryActionInfo historyItemPrimaryActionInfo,
List<HistoryItemActionModule> modules,
GlidePhotoManager glidePhotoManager) {
ContactActionBottomSheet sheet =
new ContactActionBottomSheet(context, contactPrimaryActionInfo, modules, glidePhotoManager);
HistoryItemActionBottomSheet sheet =
new HistoryItemActionBottomSheet(
context, historyItemPrimaryActionInfo, modules, glidePhotoManager);
sheet.show();
return sheet;
}
Expand All @@ -73,7 +74,7 @@ protected void onCreate(Bundle bundle) {
LinearLayout container = Assert.isNotNull(findViewById(R.id.action_container));
container.addView(getContactView(container));

for (ContactActionModule module : modules) {
for (HistoryItemActionModule module : modules) {
if (module instanceof DividerModule) {
container.addView(getDividerView(container));
} else {
Expand All @@ -88,22 +89,23 @@ private View getContactView(ViewGroup container) {

// TODO(zachh): The contact image should be badged with a video icon if it is for a video call.
glidePhotoManager.loadQuickContactBadge(
contactView.findViewById(R.id.quick_contact_photo), contactPrimaryActionInfo.photoInfo());
contactView.findViewById(R.id.quick_contact_photo),
historyItemPrimaryActionInfo.photoInfo());

TextView primaryTextView = contactView.findViewById(R.id.primary_text);
TextView secondaryTextView = contactView.findViewById(R.id.secondary_text);

primaryTextView.setText(contactPrimaryActionInfo.primaryText());
if (!TextUtils.isEmpty(contactPrimaryActionInfo.secondaryText())) {
secondaryTextView.setText(contactPrimaryActionInfo.secondaryText());
primaryTextView.setText(historyItemPrimaryActionInfo.primaryText());
if (!TextUtils.isEmpty(historyItemPrimaryActionInfo.secondaryText())) {
secondaryTextView.setText(historyItemPrimaryActionInfo.secondaryText());
} else {
secondaryTextView.setVisibility(View.GONE);
secondaryTextView.setText(null);
}
if (contactPrimaryActionInfo.intent() != null) {
if (historyItemPrimaryActionInfo.intent() != null) {
contactView.setOnClickListener(
(view) -> {
getContext().startActivity(contactPrimaryActionInfo.intent());
getContext().startActivity(historyItemPrimaryActionInfo.intent());
dismiss();
});
}
Expand All @@ -115,7 +117,7 @@ private View getDividerView(ViewGroup container) {
return inflater.inflate(R.layout.divider_layout, container, false);
}

private View getModuleView(ViewGroup container, ContactActionModule module) {
private View getModuleView(ViewGroup container, HistoryItemActionModule module) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View moduleView = inflater.inflate(R.layout.module_layout, container, false);
((TextView) moduleView.findViewById(R.id.module_text)).setText(module.getStringId());
Expand All @@ -128,7 +130,7 @@ private View getModuleView(ViewGroup container, ContactActionModule module) {

@Override
public void onClick(View view) {
if (((ContactActionModule) view.getTag()).onClick()) {
if (((HistoryItemActionModule) view.getTag()).onClick()) {
dismiss();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
* limitations under the License.
*/

package com.android.dialer.contactactions;
package com.android.dialer.historyitemactions;

import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;

/**
* Modules used to build {@link ContactActionBottomSheet}.
* Modules used to build {@link HistoryItemActionBottomSheet}.
*
* <p>Contacts as they relate to this class should be thought of as any entity that an action can be
* performed on like unknown/restricted contacts, along with saved and non-saved contacts.
* <p>A history item is one that is displayed in the call log or the voicemail fragment.
*/
public interface ContactActionModule {
public interface HistoryItemActionModule {

@StringRes
int getStringId();
Expand Down
Loading

0 comments on commit 4ef5116

Please sign in to comment.