diff options
author | Yorke Lee <yorkelee@google.com> | 2014-04-18 17:14:58 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2014-04-21 16:40:14 -0700 |
commit | 4cde566de5f54b6bdd305229c3134068cdde4bbd (patch) | |
tree | 2e7fee8434341791b109d43ab2155ffcd4c5d101 /src/com/android/dialer/list/ListsFragment.java | |
parent | 4b10dd4a659bec13d5415fcaf24d2b60453f4d7a (diff) |
Move call shortcut cards to their own list
This CL migrates the logic that queries for and displays call
shortcut cards to ListsFragment so that they can be displayed
above the main contacts viewpager.
* Add a ListView above the ViewPager in ListsFragment
* Implement CallLogQueryHandler.Listener and CallLogAdapter.CallFetcher
in ListsFragment, and delete that corresponding logic in
PhoneFavoritesFragment.
* Use animateLayoutChanges on the parent LinearLayout hosting shortcard
cards so that we don't have to handle animations ourselves when a card
is swiped away.
* Make the minimum set of changes to PhoneFavoritesMergedAdapter so that
only call shortcut cards are displayed (no more menu, teaser, etc).
More significant changes to actually delete unnecessary logic is upcoming
in a separate CL.
Bug: 13963734
Change-Id: I55cdc53a9311b1bb78422aab9d174e860596b997
Diffstat (limited to 'src/com/android/dialer/list/ListsFragment.java')
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 158 |
1 files changed, 148 insertions, 10 deletions
diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 513272741..3144b8698 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -1,19 +1,34 @@ package com.android.dialer.list; -import android.app.Activity; +import android.animation.LayoutTransition; import android.app.Fragment; import android.app.FragmentManager; +import android.app.LoaderManager; +import android.content.Context; +import android.content.CursorLoader; +import android.content.Loader; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.net.Uri; import android.os.Bundle; +import android.provider.CallLog; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.ListView; -import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; +import com.android.contacts.common.GeoUtil; +import com.android.dialer.DialtactsActivity; import com.android.dialer.R; +import com.android.dialer.calllog.CallLogAdapter; import com.android.dialer.calllog.CallLogFragment; +import com.android.dialer.calllog.CallLogQuery; import com.android.dialer.calllog.CallLogQueryHandler; +import com.android.dialer.calllog.ContactInfoHelper; +import com.android.dialerbind.ObjectFactory; /** * Fragment that is used as the main screen of the Dialer. @@ -23,7 +38,23 @@ import com.android.dialer.calllog.CallLogQueryHandler; * ViewPager containing the lists up above the shortcut cards and pin it against the top of the * screen. */ -public class ListsFragment extends Fragment { +public class ListsFragment extends Fragment implements CallLogQueryHandler.Listener, + CallLogAdapter.CallFetcher { + + private static final int TAB_INDEX_SPEED_DIAL = 0; + private static final int TAB_INDEX_RECENTS = 1; + private static final int TAB_INDEX_ALL_CONTACTS = 2; + + private static final int TAB_INDEX_COUNT = 3; + + // TODO: Replace with a date limit (e.g. 2 weeks) + private static final int MAX_ENTRIES = 20; + + private static final String KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE = + "key_last_dismissed_call_shortcut_date"; + + // Used with LoaderManager + private static int MISSED_CALL_LOADER = 1; private ViewPager mViewPager; private ViewPagerAdapter mViewPagerAdapter; @@ -31,16 +62,43 @@ public class ListsFragment extends Fragment { private CallLogFragment mRecentsFragment; private AllContactsFragment mAllContactsFragment; - private static final int TAB_INDEX_SPEED_DIAL = 0; - private static final int TAB_INDEX_RECENTS = 1; - private static final int TAB_INDEX_ALL_CONTACTS = 2; - private String[] mTabTitles; - private static final int TAB_INDEX_COUNT = 3; + private PhoneFavoriteMergedAdapter mMergedAdapter; + private CallLogAdapter mCallLogAdapter; + private CallLogQueryHandler mCallLogQueryHandler; - // TODO: Replace with a date limit (e.g. 2 weeks) - private static final int MAX_ENTRIES = 20; + /** + * Call shortcuts older than this date (persisted in shared preferences) will not show up in + * at the top of the screen + */ + private long mLastCallShortcutDate = 0; + + /** + * The date of the current call shortcut that is showing on screen. + */ + private long mCurrentCallShortcutDate = 0; + + private class MissedCallLogLoaderListener implements LoaderManager.LoaderCallbacks<Cursor> { + + @Override + public Loader<Cursor> onCreateLoader(int id, Bundle args) { + final Uri uri = CallLog.Calls.CONTENT_URI; + final String[] projection = new String[] {CallLog.Calls.TYPE}; + final String selection = CallLog.Calls.TYPE + " = " + CallLog.Calls.MISSED_TYPE + + " AND " + CallLog.Calls.IS_READ + " = 0"; + return new CursorLoader(getActivity(), uri, projection, selection, null, null); + } + + @Override + public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor data) { + mCallLogAdapter.setMissedCalls(data); + } + + @Override + public void onLoaderReset(Loader<Cursor> cursorLoader) { + } + } public class ViewPagerAdapter extends FragmentPagerAdapter { public ViewPagerAdapter(FragmentManager fm) { @@ -76,6 +134,45 @@ public class ListsFragment extends Fragment { } @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(), + this, 1); + final String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); + mCallLogAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this, + new ContactInfoHelper(getActivity(), currentCountryIso), false, false); + + mMergedAdapter = new PhoneFavoriteMergedAdapter(getActivity(), this, null, + mCallLogAdapter, null, null); + } + + @Override + public void onStart() { + super.onStart(); + getLoaderManager().initLoader(MISSED_CALL_LOADER, null, new MissedCallLogLoaderListener()); + } + + @Override + public void onResume() { + super.onResume(); + final SharedPreferences prefs = getActivity().getSharedPreferences( + DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE); + mLastCallShortcutDate = prefs.getLong(KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE, 0); + + fetchCalls(); + mCallLogAdapter.setLoading(true); + } + + @Override + public void onPause() { + // Wipe the cache to refresh the call shortcut item. This is not that expensive because + // it only contains one item. + mCallLogAdapter.invalidateCache(); + super.onPause(); + } + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View parentView = inflater.inflate(R.layout.lists_fragment, container, false); @@ -91,6 +188,47 @@ public class ListsFragment extends Fragment { ViewPagerTabs tabs = (ViewPagerTabs) parentView.findViewById(R.id.lists_pager_header); tabs.setViewPager(mViewPager); + + final ListView shortcutCardsListView = + (ListView) parentView.findViewById(R.id.shortcut_card_list); + shortcutCardsListView.setAdapter(mMergedAdapter); + + LayoutTransition transition = ((LinearLayout) parentView).getLayoutTransition(); + // Turns on animations for all types of layout changes so that they occur for + // height changes. + transition.enableTransitionType(LayoutTransition.CHANGING); return parentView; } + + @Override + public void onVoicemailStatusFetched(Cursor statusCursor) { + // no-op + } + + @Override + public void onCallsFetched(Cursor cursor) { + mCallLogAdapter.setLoading(false); + + // Save the date of the most recent call log item + if (cursor != null && cursor.moveToFirst()) { + mCurrentCallShortcutDate = cursor.getLong(CallLogQuery.DATE); + } + + mCallLogAdapter.changeCursor(cursor); + mMergedAdapter.notifyDataSetChanged(); + } + + @Override + public void fetchCalls() { + mCallLogQueryHandler.fetchCalls(CallLogQueryHandler.CALL_TYPE_ALL, mLastCallShortcutDate); + } + + public void dismissShortcut(View view) { + mLastCallShortcutDate = mCurrentCallShortcutDate; + final SharedPreferences prefs = view.getContext().getSharedPreferences( + DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE); + prefs.edit().putLong(KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE, mLastCallShortcutDate) + .apply(); + fetchCalls(); + } } |