summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Faust <colefaust@google.com>2019-06-20 15:41:50 -0700
committerCole Faust <colefaust@google.com>2019-06-24 14:37:23 -0700
commitbe536fea8399fd2ef7f9c75a692f7bb9e7c9daaf (patch)
tree024e9f16d71161377c054f143322db5371d3d2fe
parentd4cd644f3189ee57700d89ec29db00485de48199 (diff)
downloadDialer-be536fea8399fd2ef7f9c75a692f7bb9e7c9daaf.tar.gz
Create a page for when you don't have any favorites
Fixes: 135639094 Test: Manually Change-Id: Idd5fc0bb121ff43a3c7485dd6227c6b6bfe27c9d
-rw-r--r--res/layout/favorite_fragment.xml55
-rw-r--r--res/values/dimens.xml2
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/android/car/dialer/ui/favorite/FavoriteFragment.java96
-rw-r--r--src/com/android/car/dialer/ui/favorite/FavoriteListFragment.java99
-rw-r--r--tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteListFragmentTest.java (renamed from tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java)6
6 files changed, 193 insertions, 67 deletions
diff --git a/res/layout/favorite_fragment.xml b/res/layout/favorite_fragment.xml
new file mode 100644
index 00000000..f21bc489
--- /dev/null
+++ b/res/layout/favorite_fragment.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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.
+ -->
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <fragment
+ android:id="@+id/favorite_list_fragment"
+ android:name="com.android.car.dialer.ui.favorite.FavoriteListFragment"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"/>
+
+ <LinearLayout
+ android:id="@+id/empty_page_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="@string/favorites_empty"
+ android:layout_marginBottom="@dimen/favorite_add_button_and_text_separation"/>
+
+ <TextView
+ android:id="@+id/add_favorite_button"
+ android:layout_width="wrap_content"
+ android:layout_height="@dimen/touch_target_size"
+ android:text="@string/add_favorite_button"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:background="@drawable/hero_button_background"
+ android:paddingStart="@dimen/favorite_add_button_padding"
+ android:paddingEnd="@dimen/favorite_add_button_padding"
+ android:gravity="center"/>
+
+ </LinearLayout>
+
+</FrameLayout> \ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 1e5ab955..222e11b3 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -87,6 +87,8 @@
<dimen name="favorite_card_space_horizontal">@*android:dimen/car_padding_3</dimen>
<dimen name="favorite_card_space_vertical">@*android:dimen/car_padding_4</dimen>
<dimen name="favorites_avatar_margin_bottom">@*android:dimen/car_padding_3</dimen>
+ <dimen name="favorite_add_button_and_text_separation">@*android:dimen/car_padding_5</dimen>
+ <dimen name="favorite_add_button_padding">@*android:dimen/car_padding_4</dimen>
<dimen name="call_fab_elevation">8dp</dimen>
<dimen name="bksp_button_width">@dimen/touch_target_size</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f6823d8f..554c5f9a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -79,6 +79,8 @@
<!-- Button to add start choosing a contact to add as a new favorite [CHAR_LIMIT=50] -->
<string name="add_favorite_button">Add a favorite</string>
+ <!-- Error message shown when on the favorites page without any favorites added [CHAR_LIMIT=80] -->
+ <string name="favorites_empty">You haven\'t added any favorites yet</string>
<!-- Keypad strings-->
<string name="one" translatable="false">1</string>
diff --git a/src/com/android/car/dialer/ui/favorite/FavoriteFragment.java b/src/com/android/car/dialer/ui/favorite/FavoriteFragment.java
index 617fc685..7e3573de 100644
--- a/src/com/android/car/dialer/ui/favorite/FavoriteFragment.java
+++ b/src/com/android/car/dialer/ui/favorite/FavoriteFragment.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2019 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.
@@ -16,84 +16,52 @@
package com.android.car.dialer.ui.favorite;
-import android.content.res.Resources;
-import android.graphics.Rect;
import android.os.Bundle;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Toast;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.lifecycle.LiveData;
+import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
-import androidx.recyclerview.widget.GridLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import com.android.car.dialer.R;
-import com.android.car.dialer.telecom.UiCallManager;
-import com.android.car.dialer.ui.common.DialerListBaseFragment;
-import com.android.car.dialer.ui.common.DialerUtils;
-import com.android.car.telephony.common.Contact;
+import com.android.car.dialer.ui.common.DialerBaseFragment;
-import java.util.List;
-
-/** Contains a list of favorite contacts. */
-public class FavoriteFragment extends DialerListBaseFragment {
- private static final String TAG = "CD.FavoriteFrag";
+/** Contains either the "You haven't added any favorites yet" screen, or FavoriteListFragment */
+public class FavoriteFragment extends DialerBaseFragment {
public static FavoriteFragment newInstance() {
return new FavoriteFragment();
}
@Override
- public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
- getRecyclerView().addItemDecoration(new ItemSpacingDecoration());
- getRecyclerView().setItemAnimator(null);
-
- FavoriteAdapter adapter = new FavoriteAdapter();
-
- FavoriteViewModel favoriteViewModel = ViewModelProviders.of(this).get(
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.favorite_fragment, container, false);
+ View emptyPage = view.findViewById(R.id.empty_page_container);
+ Fragment listFragment =
+ getChildFragmentManager().findFragmentById(R.id.favorite_list_fragment);
+
+ FavoriteViewModel favoriteViewModel = ViewModelProviders.of(getActivity()).get(
FavoriteViewModel.class);
- LiveData<List<Contact>> favoriteContacts = favoriteViewModel.getFavoriteContacts();
- adapter.setOnListItemClickedListener(this::onItemClicked);
- favoriteContacts.observe(this, adapter::setFavoriteContacts);
-
- getRecyclerView().setAdapter(adapter);
- }
-
- @NonNull
- @Override
- protected RecyclerView.LayoutManager createLayoutManager() {
- int numOfColumn = getContext().getResources().getInteger(
- R.integer.favorite_fragment_grid_column);
- return new GridLayoutManager(getContext(), numOfColumn);
- }
-
- private void onItemClicked(Contact contact) {
- DialerUtils.promptForPrimaryNumber(getContext(), contact, (phoneNumber, always) ->
- UiCallManager.get().placeCall(phoneNumber.getRawNumber()));
- }
-
- private class ItemSpacingDecoration extends RecyclerView.ItemDecoration {
-
- @Override
- public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
- @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
- super.getItemOffsets(outRect, view, parent, state);
- Resources resources = FavoriteFragment.this.getContext().getResources();
- int numColumns = resources.getInteger(R.integer.favorite_fragment_grid_column);
- int leftPadding =
- resources.getDimensionPixelOffset(R.dimen.favorite_card_space_horizontal);
- int topPadding =
- resources.getDimensionPixelOffset(R.dimen.favorite_card_space_vertical);
-
- if (parent.getChildAdapterPosition(view) % numColumns == 0) {
- leftPadding = 0;
- }
- if (parent.getChildAdapterPosition(view) < numColumns) {
- topPadding = 0;
+ favoriteViewModel.getFavoriteContacts().observe(this, contacts -> {
+ if (contacts == null || contacts.isEmpty()) {
+ emptyPage.setVisibility(View.VISIBLE);
+ getChildFragmentManager().beginTransaction()
+ .hide(listFragment)
+ .commit();
+ } else {
+ emptyPage.setVisibility(View.GONE);
+ getChildFragmentManager().beginTransaction()
+ .show(listFragment)
+ .commit();
}
+ });
+
+ emptyPage.findViewById(R.id.add_favorite_button).setOnClickListener(v ->
+ Toast.makeText(getContext(), "Not yet implemented", Toast.LENGTH_LONG).show());
- outRect.set(leftPadding, topPadding, 0, 0);
- }
+ return view;
}
}
diff --git a/src/com/android/car/dialer/ui/favorite/FavoriteListFragment.java b/src/com/android/car/dialer/ui/favorite/FavoriteListFragment.java
new file mode 100644
index 00000000..41583727
--- /dev/null
+++ b/src/com/android/car/dialer/ui/favorite/FavoriteListFragment.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2019 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.car.dialer.ui.favorite;
+
+import android.content.res.Resources;
+import android.graphics.Rect;
+import android.os.Bundle;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.ViewModelProviders;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.car.dialer.R;
+import com.android.car.dialer.telecom.UiCallManager;
+import com.android.car.dialer.ui.common.DialerListBaseFragment;
+import com.android.car.dialer.ui.common.DialerUtils;
+import com.android.car.telephony.common.Contact;
+
+import java.util.List;
+
+/** Contains a list of favorite contacts. */
+public class FavoriteListFragment extends DialerListBaseFragment {
+
+ /** Constructs a new FavoriteListFragment */
+ public static FavoriteListFragment newInstance() {
+ return new FavoriteListFragment();
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ getRecyclerView().addItemDecoration(new ItemSpacingDecoration());
+ getRecyclerView().setItemAnimator(null);
+
+ FavoriteAdapter adapter = new FavoriteAdapter();
+
+ FavoriteViewModel favoriteViewModel = ViewModelProviders.of(getActivity()).get(
+ FavoriteViewModel.class);
+ LiveData<List<Contact>> favoriteContacts = favoriteViewModel.getFavoriteContacts();
+ adapter.setOnListItemClickedListener(this::onItemClicked);
+ favoriteContacts.observe(this, adapter::setFavoriteContacts);
+
+ getRecyclerView().setAdapter(adapter);
+ }
+
+ @NonNull
+ @Override
+ protected RecyclerView.LayoutManager createLayoutManager() {
+ int numOfColumn = getContext().getResources().getInteger(
+ R.integer.favorite_fragment_grid_column);
+ return new GridLayoutManager(getContext(), numOfColumn);
+ }
+
+ private void onItemClicked(Contact contact) {
+ DialerUtils.promptForPrimaryNumber(getContext(), contact, (phoneNumber, always) ->
+ UiCallManager.get().placeCall(phoneNumber.getRawNumber()));
+ }
+
+ private class ItemSpacingDecoration extends RecyclerView.ItemDecoration {
+
+ @Override
+ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
+ @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
+ super.getItemOffsets(outRect, view, parent, state);
+ Resources resources = FavoriteListFragment.this.getContext().getResources();
+ int numColumns = resources.getInteger(R.integer.favorite_fragment_grid_column);
+ int leftPadding =
+ resources.getDimensionPixelOffset(R.dimen.favorite_card_space_horizontal);
+ int topPadding =
+ resources.getDimensionPixelOffset(R.dimen.favorite_card_space_vertical);
+
+ if (parent.getChildAdapterPosition(view) % numColumns == 0) {
+ leftPadding = 0;
+ }
+ if (parent.getChildAdapterPosition(view) < numColumns) {
+ topPadding = 0;
+ }
+
+ outRect.set(leftPadding, topPadding, 0, 0);
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java b/tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteListFragmentTest.java
index 80fd991a..260bb481 100644
--- a/tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java
+++ b/tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteListFragmentTest.java
@@ -49,10 +49,10 @@ import java.util.List;
@Config(shadows = {ShadowAndroidViewModelFactory.class})
@RunWith(CarDialerRobolectricTestRunner.class)
-public class FavoriteFragmentTest {
+public class FavoriteListFragmentTest {
private static final String RAW_NUMBER = "6502530000";
- private FavoriteFragment mFavoriteFragment;
+ private FavoriteListFragment mFavoriteFragment;
private FavoriteContactViewHolder mViewHolder;
@Mock
private UiCallManager mMockUiCallManager;
@@ -75,7 +75,7 @@ public class FavoriteFragmentTest {
ShadowAndroidViewModelFactory.add(FavoriteViewModel.class, mMockFavoriteViewModel);
when(mMockFavoriteViewModel.getFavoriteContacts()).thenReturn(favoriteContacts);
- mFavoriteFragment = FavoriteFragment.newInstance();
+ mFavoriteFragment = FavoriteListFragment.newInstance();
FragmentTestActivity fragmentTestActivity = Robolectric.buildActivity(
FragmentTestActivity.class).create().resume().get();
fragmentTestActivity.setFragment(mFavoriteFragment);