summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/speeddial
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2017-12-08 20:52:56 -0800
committerCopybara-Service <copybara-piper@google.com>2017-12-08 20:53:51 -0800
commit73b51d5771b31c932a589abc9bb0fe64c52fe102 (patch)
tree3845e7aad9e502bf5a91eb8705c8005f06990105 /java/com/android/dialer/speeddial
parent20ebcdca46e6be68050cd44087f0f768f5dae5c6 (diff)
Implemented adding a new favorites contact flow NUI.
This change consists of mainly 3 things: - Update contacts fragment to meet AddFavoriteActivity requirements - Implement AddFavoriteActivity - Passing the contact back to SpeedDialFragment Bug: 36841782 Test: SpeedDialIntegrationTest PiperOrigin-RevId: 178461265 Change-Id: Ib3a13eae311acf6ce10a94df4f2c95b9af120cff
Diffstat (limited to 'java/com/android/dialer/speeddial')
-rw-r--r--java/com/android/dialer/speeddial/AddFavoriteActivity.java109
-rw-r--r--java/com/android/dialer/speeddial/AndroidManifest.xml13
-rw-r--r--java/com/android/dialer/speeddial/SpeedDialCursor.java4
-rw-r--r--java/com/android/dialer/speeddial/SpeedDialFragment.java40
-rw-r--r--java/com/android/dialer/speeddial/res/layout/add_favorite_activity.xml21
-rw-r--r--java/com/android/dialer/speeddial/res/menu/add_favorite_menu.xml24
-rw-r--r--java/com/android/dialer/speeddial/res/values/strings.xml9
7 files changed, 188 insertions, 32 deletions
diff --git a/java/com/android/dialer/speeddial/AddFavoriteActivity.java b/java/com/android/dialer/speeddial/AddFavoriteActivity.java
new file mode 100644
index 000000000..eea6e840e
--- /dev/null
+++ b/java/com/android/dialer/speeddial/AddFavoriteActivity.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 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.speeddial;
+
+import android.content.ContentValues;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.support.annotation.Nullable;
+import android.support.annotation.WorkerThread;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.SearchView;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.ImageView;
+import com.android.dialer.common.Assert;
+import com.android.dialer.common.concurrent.DialerExecutorComponent;
+import com.android.dialer.contactsfragment.ContactsFragment;
+import com.android.dialer.contactsfragment.ContactsFragment.OnContactSelectedListener;
+
+/**
+ * Activity for selecting a single contact and adding it to favorites.
+ *
+ * <p>Contacts are displayed using {@link ContactsFragment}. Contacts are searchable via search bar
+ * in the toolbar. When a contact is selected, it's uri is passed back in the result data.
+ */
+public class AddFavoriteActivity extends AppCompatActivity implements OnContactSelectedListener {
+
+ private ContactsFragment contactsFragment;
+
+ @Override
+ protected void onCreate(@Nullable Bundle bundle) {
+ super.onCreate(bundle);
+ setContentView(R.layout.add_favorite_activity);
+ contactsFragment = ContactsFragment.newAddFavoritesInstance();
+ getFragmentManager()
+ .beginTransaction()
+ .add(R.id.add_favorite_container, contactsFragment, null)
+ .commit();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.add_favorite_menu, menu);
+
+ MenuItem searchItem = menu.findItem(R.id.action_search);
+ SearchView searchView = (SearchView) searchItem.getActionView();
+ searchView.setOnQueryTextListener(
+ new SearchView.OnQueryTextListener() {
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ if (!searchView.isIconified()) {
+ searchView.setIconified(true);
+ }
+ searchItem.collapseActionView();
+ return false;
+ }
+
+ @Override
+ public boolean onQueryTextChange(String s) {
+ contactsFragment.updateQuery(s);
+ return false;
+ }
+ });
+ return true;
+ }
+
+ @Override
+ public void onContactSelected(ImageView photo, Uri contactUri, long contactId) {
+ DialerExecutorComponent.get(this)
+ .dialerExecutorFactory()
+ .createUiTaskBuilder(
+ getFragmentManager(), "mark_contact_favorite", this::markContactStarred)
+ .onSuccess(output -> finish())
+ .onFailure(this::onContactStarredFailed)
+ .build()
+ .executeParallel(contactId);
+ }
+
+ @WorkerThread
+ private int markContactStarred(long contactId) {
+ // TODO(calderwoodra): For now, we will just mark contacts as starred. This means that contacts
+ // will only be able to exist once in favorites until we implement multiple contact avenues.
+ ContentValues contentValues = new ContentValues();
+ contentValues.put(Contacts.STARRED, 1);
+
+ String where = Contacts._ID + " = ?";
+ String[] selectionArgs = new String[] {Long.toString(contactId)};
+ return getContentResolver().update(Contacts.CONTENT_URI, contentValues, where, selectionArgs);
+ }
+
+ private void onContactStarredFailed(Throwable throwable) {
+ throw Assert.createAssertionFailException(throwable.getMessage());
+ }
+}
diff --git a/java/com/android/dialer/speeddial/AndroidManifest.xml b/java/com/android/dialer/speeddial/AndroidManifest.xml
index f4f0d82eb..99ab12c4b 100644
--- a/java/com/android/dialer/speeddial/AndroidManifest.xml
+++ b/java/com/android/dialer/speeddial/AndroidManifest.xml
@@ -13,4 +13,15 @@
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
-<manifest package="com.android.dialer.speeddial"/>
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.dialer.speeddial">
+
+ <application android:theme="@style/Theme.AppCompat">
+ <activity
+ android:name="com.android.dialer.speeddial.AddFavoriteActivity"
+ android:label="@string/add_favorite_activity_title"
+ android:exported="false"
+ android:theme="@style/DialtactsTheme"/>
+ </application>
+</manifest> \ No newline at end of file
diff --git a/java/com/android/dialer/speeddial/SpeedDialCursor.java b/java/com/android/dialer/speeddial/SpeedDialCursor.java
index 552fab175..1208daefd 100644
--- a/java/com/android/dialer/speeddial/SpeedDialCursor.java
+++ b/java/com/android/dialer/speeddial/SpeedDialCursor.java
@@ -64,10 +64,6 @@ final class SpeedDialCursor extends MergeCursor {
strequentCursor.moveToPosition(-1);
while (strequentCursor.moveToNext()) {
- if (strequentCursor.getInt(StrequentContactsCursorLoader.PHONE_IS_SUPER_PRIMARY) != 0) {
- continue;
- }
-
if (strequentCursor.getPosition() != 0) {
long contactId = strequentCursor.getLong(StrequentContactsCursorLoader.PHONE_CONTACT_ID);
int position = strequentCursor.getPosition();
diff --git a/java/com/android/dialer/speeddial/SpeedDialFragment.java b/java/com/android/dialer/speeddial/SpeedDialFragment.java
index 65e542cd4..08861dae9 100644
--- a/java/com/android/dialer/speeddial/SpeedDialFragment.java
+++ b/java/com/android/dialer/speeddial/SpeedDialFragment.java
@@ -18,10 +18,10 @@ package com.android.dialer.speeddial;
import android.app.Fragment;
import android.app.LoaderManager.LoaderCallbacks;
+import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
-import android.provider.ContactsContract.Contacts;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@@ -35,7 +35,16 @@ import com.android.dialer.speeddial.FavoritesViewHolder.FavoriteContactsListener
import com.android.dialer.speeddial.HeaderViewHolder.SpeedDialHeaderListener;
import com.android.dialer.speeddial.SuggestionViewHolder.SuggestedContactsListener;
-/** Favorites fragment. Contents TBD. TODO(calderwoodra) */
+/**
+ * Fragment for displaying:
+ *
+ * <ul>
+ * <li>Favorite/Starred contacts
+ * <li>Suggested contacts
+ * </ul>
+ *
+ * <p>Suggested contacts built from {@link android.provider.ContactsContract#STREQUENT_PHONE_ONLY}.
+ */
public class SpeedDialFragment extends Fragment {
private static final int STREQUENT_CONTACTS_LOADER_ID = 1;
@@ -73,16 +82,16 @@ public class SpeedDialFragment extends Fragment {
}
@Override
- public void onPause() {
- super.onPause();
- loaderCallback.unregisterContentObserver();
+ public void onResume() {
+ super.onResume();
+ getLoaderManager().restartLoader(STREQUENT_CONTACTS_LOADER_ID, null, loaderCallback);
}
- private static class SpeedDialFragmentHeaderListener implements SpeedDialHeaderListener {
+ private class SpeedDialFragmentHeaderListener implements SpeedDialHeaderListener {
@Override
public void onAddFavoriteClicked() {
- // TODO(calderwoodra): implement add favorite screen
+ startActivity(new Intent(getContext(), AddFavoriteActivity.class));
}
}
@@ -123,8 +132,6 @@ public class SpeedDialFragment extends Fragment {
*/
private class SpeedDialFragmentLoaderCallback implements LoaderCallbacks<Cursor> {
- private StrequentContactsCursorLoader cursorLoader;
-
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
if (id == STREQUENT_CONTACTS_LOADER_ID) {
@@ -135,24 +142,9 @@ public class SpeedDialFragment extends Fragment {
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
- cursorLoader = (StrequentContactsCursorLoader) loader;
- // Since the original cursor we queried against was modified and closed, we need to register a
- // new content observer in order to get updates on changes to our contacts.
- getContext()
- .getContentResolver()
- .registerContentObserver(
- Contacts.CONTENT_STREQUENT_URI,
- true /* notifyForDescendants*/,
- cursorLoader.getContentObserver());
adapter.setCursor((SpeedDialCursor) data);
}
- public void unregisterContentObserver() {
- getContext()
- .getContentResolver()
- .unregisterContentObserver(cursorLoader.getContentObserver());
- }
-
@Override
public void onLoaderReset(Loader<Cursor> loader) {
adapter.setCursor(null);
diff --git a/java/com/android/dialer/speeddial/res/layout/add_favorite_activity.xml b/java/com/android/dialer/speeddial/res/layout/add_favorite_activity.xml
new file mode 100644
index 000000000..4df2f29b4
--- /dev/null
+++ b/java/com/android/dialer/speeddial/res/layout/add_favorite_activity.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2017 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:id="@+id/add_favorite_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/> \ No newline at end of file
diff --git a/java/com/android/dialer/speeddial/res/menu/add_favorite_menu.xml b/java/com/android/dialer/speeddial/res/menu/add_favorite_menu.xml
new file mode 100644
index 000000000..b11c7f5d6
--- /dev/null
+++ b/java/com/android/dialer/speeddial/res/menu/add_favorite_menu.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2017 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
+ -->
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/action_search"
+ android:title="@android:string/search_go"
+ app:showAsAction="always"
+ app:actionViewClass="android.support.v7.widget.SearchView"/>
+</menu> \ No newline at end of file
diff --git a/java/com/android/dialer/speeddial/res/values/strings.xml b/java/com/android/dialer/speeddial/res/values/strings.xml
index f814ed6d4..d64d03575 100644
--- a/java/com/android/dialer/speeddial/res/values/strings.xml
+++ b/java/com/android/dialer/speeddial/res/values/strings.xml
@@ -15,12 +15,15 @@
~ limitations under the License
-->
<resources>
- <!-- header for a list of contacts that are the users favorites. -->
+ <!-- header for a list of contacts that are the users favorites. [CHAR LIMIT=30] -->
<string name="favorites_header">Favorites</string>
- <!-- header for a list of contacts that are suggestions for the user to place calls to -->
+ <!-- header for a list of contacts that are suggestions for the user to place calls to. [CHAR LIMIT=30] -->
<string name="suggestions_header">Suggestions</string>
- <!-- text for a button that prompts the user to add a contact to their favorites -->
+ <!-- text for a button that prompts the user to add a contact to their favorites. [CHAR LIMIT=12] -->
<string name="speed_dial_add_button_text">Add</string>
+
+ <!-- Title for screen prompting the user to select a contact to mark as a favorite. [CHAR LIMIT=NONE] -->
+ <string name="add_favorite_activity_title">Add Favorite</string>
</resources> \ No newline at end of file