summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/speeddial
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2018-05-17 16:36:28 -0700
committerCopybara-Service <copybara-piper@google.com>2018-05-17 17:32:22 -0700
commit47d9f4fb771e029d954d2857c86d650aed3bfd40 (patch)
treeb029185bbfd33a4f338c8f8f8488c4b41cd549f7 /java/com/android/dialer/speeddial
parent29b95403e0997f58e0030e638dcdaf209319f282 (diff)
Add empty content view for when the user has no contacts in favorites.
Bug: 79885614 Test: SpeedDialFragmentTest PiperOrigin-RevId: 197071565 Change-Id: I72df9feb44737e5f0fe42d26a77be7ffe57c1d09
Diffstat (limited to 'java/com/android/dialer/speeddial')
-rw-r--r--java/com/android/dialer/speeddial/SpeedDialFragment.java66
-rw-r--r--java/com/android/dialer/speeddial/res/values/strings.xml6
2 files changed, 59 insertions, 13 deletions
diff --git a/java/com/android/dialer/speeddial/SpeedDialFragment.java b/java/com/android/dialer/speeddial/SpeedDialFragment.java
index c118f9601..a645fb82b 100644
--- a/java/com/android/dialer/speeddial/SpeedDialFragment.java
+++ b/java/com/android/dialer/speeddial/SpeedDialFragment.java
@@ -137,11 +137,7 @@ public class SpeedDialFragment extends Fragment {
LogUtil.enterBlock("SpeedDialFragment.onCreateView");
View rootLayout = inflater.inflate(R.layout.fragment_speed_dial, container, false);
emptyContentView = rootLayout.findViewById(R.id.speed_dial_empty_content_view);
- emptyContentView.setActionLabel(R.string.speed_dial_turn_on_contacts_permission);
- emptyContentView.setDescription(R.string.speed_dial_contacts_permission_description);
emptyContentView.setImage(R.drawable.empty_speed_dial);
- emptyContentView.setActionClickedListener(
- new SpeedDialEmptyContentViewClickedListener(getContext(), this));
speedDialLoaderListener =
DialerExecutorComponent.get(getContext())
@@ -232,11 +228,8 @@ public class SpeedDialFragment extends Fragment {
return;
}
- if (!PermissionsUtil.hasContactsReadPermissions(getContext())) {
- emptyContentView.setVisibility(View.VISIBLE);
+ if (showContactsPermissionEmptyContentView()) {
return;
- } else {
- emptyContentView.setVisibility(View.GONE);
}
speedDialLoaderListener.listen(
@@ -274,20 +267,51 @@ public class SpeedDialFragment extends Fragment {
.speedDialUiItemMutator()
.insertDuoChannels(getContext(), speedDialUiItems));
adapter.notifyDataSetChanged();
+ maybeShowNoContactsEmptyContentView();
+
if (getActivity() != null) {
FragmentUtils.getParentUnsafe(this, HostInterface.class)
.setHasFrequents(adapter.hasFrequents());
}
}
+ /** Returns true if the empty content view was shown. */
+ private boolean showContactsPermissionEmptyContentView() {
+ if (PermissionsUtil.hasContactsReadPermissions(getContext())) {
+ emptyContentView.setVisibility(View.GONE);
+ return false;
+ }
+
+ emptyContentView.setVisibility(View.VISIBLE);
+ emptyContentView.setActionLabel(R.string.speed_dial_turn_on_contacts_permission);
+ emptyContentView.setDescription(R.string.speed_dial_contacts_permission_description);
+ emptyContentView.setActionClickedListener(
+ new SpeedDialContactPermissionEmptyViewListener(getContext(), this));
+ return true;
+ }
+
+ private void maybeShowNoContactsEmptyContentView() {
+ if (adapter.getItemCount() != 0) {
+ emptyContentView.setVisibility(View.GONE);
+ return;
+ }
+
+ emptyContentView.setVisibility(View.VISIBLE);
+ emptyContentView.setActionLabel(R.string.speed_dial_no_contacts_action_text);
+ emptyContentView.setDescription(R.string.speed_dial_no_contacts_description);
+ emptyContentView.setActionClickedListener(new SpeedDialNoContactsEmptyViewListener(this));
+ }
+
@Override
public void onStart() {
super.onStart();
PermissionsUtil.registerPermissionReceiver(
getActivity(), readContactsPermissionGrantedReceiver, Manifest.permission.READ_CONTACTS);
- getContext()
- .getContentResolver()
- .registerContentObserver(Contacts.CONTENT_STREQUENT_URI, true, strequentsContentObserver);
+ if (PermissionsUtil.hasContactsReadPermissions(getContext())) {
+ getContext()
+ .getContentResolver()
+ .registerContentObserver(Contacts.CONTENT_STREQUENT_URI, true, strequentsContentObserver);
+ }
}
@Override
@@ -559,13 +583,13 @@ public class SpeedDialFragment extends Fragment {
}
}
- private static final class SpeedDialEmptyContentViewClickedListener
+ private static final class SpeedDialContactPermissionEmptyViewListener
implements OnEmptyViewActionButtonClickedListener {
private final Context context;
private final Fragment fragment;
- private SpeedDialEmptyContentViewClickedListener(Context context, Fragment fragment) {
+ private SpeedDialContactPermissionEmptyViewListener(Context context, Fragment fragment) {
this.context = context;
this.fragment = fragment;
}
@@ -583,6 +607,22 @@ public class SpeedDialFragment extends Fragment {
}
}
+ private static final class SpeedDialNoContactsEmptyViewListener
+ implements OnEmptyViewActionButtonClickedListener {
+
+ private final Fragment fragment;
+
+ SpeedDialNoContactsEmptyViewListener(Fragment fragment) {
+ this.fragment = fragment;
+ }
+
+ @Override
+ public void onEmptyViewActionButtonClicked() {
+ Intent intent = new Intent(Intent.ACTION_PICK, Phone.CONTENT_URI);
+ fragment.startActivityForResult(intent, ActivityRequestCodes.SPEED_DIAL_ADD_FAVORITE);
+ }
+ }
+
/** Listener for when a SpeedDialUiItem is updated. */
private class UpdateSpeedDialAdapterListener {
diff --git a/java/com/android/dialer/speeddial/res/values/strings.xml b/java/com/android/dialer/speeddial/res/values/strings.xml
index 7f11119c7..7f8fed51f 100644
--- a/java/com/android/dialer/speeddial/res/values/strings.xml
+++ b/java/com/android/dialer/speeddial/res/values/strings.xml
@@ -65,4 +65,10 @@
<!-- The label of the button used to turn on a single permission [CHAR LIMIT=30]-->
<string name="speed_dial_turn_on_contacts_permission">Turn on</string>
+
+ <!-- [CHAR LIMIT=NONE] Shown when there are no contacts in the all contacts list. -->
+ <string name="speed_dial_no_contacts_description">You haven\'t added any favorites yet</string>
+
+ <!-- [CHAR LIMIT=NONE] Shown as an action when the all contacts list is empty -->
+ <string name="speed_dial_no_contacts_action_text">Add favorite</string>
</resources> \ No newline at end of file