summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app/list
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/app/list')
-rw-r--r--java/com/android/dialer/app/list/AllContactsFragment.java16
-rw-r--r--java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java6
-rw-r--r--java/com/android/dialer/app/list/DialtactsPagerAdapter.java189
-rw-r--r--java/com/android/dialer/app/list/ListsFragment.java274
-rw-r--r--java/com/android/dialer/app/list/OldSpeedDialFragment.java (renamed from java/com/android/dialer/app/list/SpeedDialFragment.java)29
5 files changed, 261 insertions, 253 deletions
diff --git a/java/com/android/dialer/app/list/AllContactsFragment.java b/java/com/android/dialer/app/list/AllContactsFragment.java
index 29c0ec47f..04609970a 100644
--- a/java/com/android/dialer/app/list/AllContactsFragment.java
+++ b/java/com/android/dialer/app/list/AllContactsFragment.java
@@ -28,7 +28,6 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.QuickContact;
-import android.support.annotation.Nullable;
import android.support.v13.app.FragmentCompat;
import android.view.LayoutInflater;
import android.view.View;
@@ -39,10 +38,8 @@ import com.android.contacts.common.list.ContactEntryListFragment;
import com.android.contacts.common.list.ContactListFilter;
import com.android.contacts.common.list.DefaultContactListAdapter;
import com.android.dialer.app.R;
-import com.android.dialer.app.list.ListsFragment.ListsPage;
import com.android.dialer.app.widget.EmptyContentView;
import com.android.dialer.app.widget.EmptyContentView.OnEmptyViewActionButtonClickedListener;
-import com.android.dialer.common.LogUtil;
import com.android.dialer.compat.CompatUtils;
import com.android.dialer.util.DialerUtils;
import com.android.dialer.util.IntentUtil;
@@ -50,8 +47,7 @@ import com.android.dialer.util.PermissionsUtil;
/** Fragments to show all contacts with phone numbers. */
public class AllContactsFragment extends ContactEntryListFragment<ContactEntryListAdapter>
- implements ListsPage,
- OnEmptyViewActionButtonClickedListener,
+ implements OnEmptyViewActionButtonClickedListener,
FragmentCompat.OnRequestPermissionsResultCallback {
private static final int READ_CONTACTS_PERMISSION_REQUEST_CODE = 1;
@@ -193,14 +189,4 @@ public class AllContactsFragment extends ContactEntryListFragment<ContactEntryLi
}
}
}
-
- @Override
- public void onPageResume(@Nullable Activity activity) {
- LogUtil.i("AllContactsFragment.onPageResume", null);
- }
-
- @Override
- public void onPagePause(@Nullable Activity activity) {
- LogUtil.i("AllContactsFragment.onPagePause", null);
- }
}
diff --git a/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java b/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java
index 7e2525f24..542501cfd 100644
--- a/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java
+++ b/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java
@@ -185,15 +185,15 @@ public class DialerPhoneNumberListAdapter extends PhoneNumberListAdapter {
break;
case SHORTCUT_ADD_TO_EXISTING_CONTACT:
text = resources.getString(R.string.search_shortcut_add_to_contact);
- drawableId = R.drawable.ic_person_24dp;
+ drawableId = R.drawable.quantum_ic_person_white_24;
break;
case SHORTCUT_SEND_SMS_MESSAGE:
text = resources.getString(R.string.search_shortcut_send_sms_message);
- drawableId = R.drawable.ic_message_24dp;
+ drawableId = R.drawable.quantum_ic_message_white_24;
break;
case SHORTCUT_MAKE_VIDEO_CALL:
text = resources.getString(R.string.search_shortcut_make_video_call);
- drawableId = R.drawable.ic_videocam;
+ drawableId = R.drawable.quantum_ic_videocam_white_24;
break;
case SHORTCUT_BLOCK_NUMBER:
text = resources.getString(R.string.search_shortcut_block_number);
diff --git a/java/com/android/dialer/app/list/DialtactsPagerAdapter.java b/java/com/android/dialer/app/list/DialtactsPagerAdapter.java
new file mode 100644
index 000000000..3b700d81b
--- /dev/null
+++ b/java/com/android/dialer/app/list/DialtactsPagerAdapter.java
@@ -0,0 +1,189 @@
+/*
+ * 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.app.list;
+
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.support.annotation.IntDef;
+import android.support.v13.app.FragmentPagerAdapter;
+import android.view.ViewGroup;
+import com.android.dialer.app.calllog.CallLogFragment;
+import com.android.dialer.app.calllog.VisualVoicemailCallLogFragment;
+import com.android.dialer.common.Assert;
+import com.android.dialer.common.ConfigProviderBindings;
+import com.android.dialer.common.LogUtil;
+import com.android.dialer.database.CallLogQueryHandler;
+import com.android.dialer.speeddial.SpeedDialFragment;
+import com.android.dialer.util.ViewUtil;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/** ViewPager adapter for {@link com.android.dialer.app.DialtactsActivity}. */
+public class DialtactsPagerAdapter extends FragmentPagerAdapter {
+
+ /** IntDef for indices of ViewPager tabs. */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({TAB_INDEX_SPEED_DIAL, TAB_INDEX_HISTORY, TAB_INDEX_ALL_CONTACTS, TAB_INDEX_VOICEMAIL})
+ public @interface TabIndex {}
+
+ public static final int TAB_INDEX_SPEED_DIAL = 0;
+ public static final int TAB_INDEX_HISTORY = 1;
+ public static final int TAB_INDEX_ALL_CONTACTS = 2;
+ public static final int TAB_INDEX_VOICEMAIL = 3;
+ public static final int TAB_COUNT_DEFAULT = 3;
+ public static final int TAB_COUNT_WITH_VOICEMAIL = 4;
+
+ private final List<Fragment> fragments = new ArrayList<>();
+ private final String[] tabTitles;
+ private final boolean useNewSpeedDialTab;
+
+ private OldSpeedDialFragment oldSpeedDialFragment;
+ private SpeedDialFragment speedDialFragment;
+ private CallLogFragment callLogFragment;
+ private AllContactsFragment contactsFragment;
+ private CallLogFragment voicemailFragment;
+
+ public boolean hasActiveVoicemailProvider;
+
+ public DialtactsPagerAdapter(
+ Context context, FragmentManager fm, String[] tabTitles, boolean hasVoicemailProvider) {
+ super(fm);
+ useNewSpeedDialTab =
+ ConfigProviderBindings.get(context).getBoolean("enable_new_favorites_tab", false);
+ this.tabTitles = tabTitles;
+ hasActiveVoicemailProvider = hasVoicemailProvider;
+ fragments.addAll(Collections.nCopies(TAB_COUNT_WITH_VOICEMAIL, null));
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return getRtlPosition(position);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ LogUtil.d("ViewPagerAdapter.getItem", "position: %d", position);
+ switch (getRtlPosition(position)) {
+ case TAB_INDEX_SPEED_DIAL:
+ if (useNewSpeedDialTab) {
+ if (speedDialFragment == null) {
+ speedDialFragment = SpeedDialFragment.newInstance();
+ }
+ return speedDialFragment;
+ } else {
+ if (oldSpeedDialFragment == null) {
+ oldSpeedDialFragment = new OldSpeedDialFragment();
+ }
+ return oldSpeedDialFragment;
+ }
+ case TAB_INDEX_HISTORY:
+ if (callLogFragment == null) {
+ callLogFragment = new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL);
+ }
+ return callLogFragment;
+ case TAB_INDEX_ALL_CONTACTS:
+ if (contactsFragment == null) {
+ contactsFragment = new AllContactsFragment();
+ }
+ return contactsFragment;
+ case TAB_INDEX_VOICEMAIL:
+ if (voicemailFragment == null) {
+ voicemailFragment = new VisualVoicemailCallLogFragment();
+ LogUtil.v(
+ "ViewPagerAdapter.getItem",
+ "new VisualVoicemailCallLogFragment: %s",
+ voicemailFragment);
+ }
+ return voicemailFragment;
+ default:
+ throw Assert.createIllegalStateFailException("No fragment at position " + position);
+ }
+ }
+
+ @Override
+ public Fragment instantiateItem(ViewGroup container, int position) {
+ LogUtil.d("ViewPagerAdapter.instantiateItem", "position: %d", position);
+ // On rotation the FragmentManager handles rotation. Therefore getItem() isn't called.
+ // Copy the fragments that the FragmentManager finds so that we can store them in
+ // instance variables for later.
+ final Fragment fragment = (Fragment) super.instantiateItem(container, position);
+ if (fragment instanceof OldSpeedDialFragment) {
+ oldSpeedDialFragment = (OldSpeedDialFragment) fragment;
+ } else if (fragment instanceof SpeedDialFragment) {
+ speedDialFragment = (SpeedDialFragment) fragment;
+ } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_HISTORY) {
+ callLogFragment = (CallLogFragment) fragment;
+ } else if (fragment instanceof AllContactsFragment) {
+ contactsFragment = (AllContactsFragment) fragment;
+ } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_VOICEMAIL) {
+ voicemailFragment = (CallLogFragment) fragment;
+ LogUtil.v("ViewPagerAdapter.instantiateItem", voicemailFragment.toString());
+ }
+ fragments.set(position, fragment);
+ return fragment;
+ }
+
+ /**
+ * When {@link android.support.v4.view.PagerAdapter#notifyDataSetChanged} is called, this method
+ * is called on all pages to determine whether they need to be recreated. When the voicemail tab
+ * is removed, the view needs to be recreated by returning POSITION_NONE. If notifyDataSetChanged
+ * is called for some other reason, the voicemail tab is recreated only if it is active. All other
+ * tabs do not need to be recreated and POSITION_UNCHANGED is returned.
+ */
+ @Override
+ public int getItemPosition(Object object) {
+ return !hasActiveVoicemailProvider && fragments.indexOf(object) == TAB_INDEX_VOICEMAIL
+ ? POSITION_NONE
+ : POSITION_UNCHANGED;
+ }
+
+ @Override
+ public int getCount() {
+ return hasActiveVoicemailProvider ? TAB_COUNT_WITH_VOICEMAIL : TAB_COUNT_DEFAULT;
+ }
+
+ @Override
+ public CharSequence getPageTitle(@TabIndex int position) {
+ return tabTitles[position];
+ }
+
+ public int getRtlPosition(int position) {
+ if (ViewUtil.isRtl()) {
+ return getCount() - 1 - position;
+ }
+ return position;
+ }
+
+ public void removeVoicemailFragment(FragmentManager manager) {
+ if (voicemailFragment != null) {
+ manager.beginTransaction().remove(voicemailFragment).commitAllowingStateLoss();
+ voicemailFragment = null;
+ }
+ }
+
+ public boolean hasActiveVoicemailProvider() {
+ return hasActiveVoicemailProvider;
+ }
+
+ public void setHasActiveVoicemailProvider(boolean hasActiveVoicemailProvider) {
+ this.hasActiveVoicemailProvider = hasActiveVoicemailProvider;
+ }
+}
diff --git a/java/com/android/dialer/app/list/ListsFragment.java b/java/com/android/dialer/app/list/ListsFragment.java
index 3b94e1562..bf29ef310 100644
--- a/java/com/android/dialer/app/list/ListsFragment.java
+++ b/java/com/android/dialer/app/list/ListsFragment.java
@@ -13,11 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.android.dialer.app.list;
-import android.app.Activity;
+import static com.android.dialer.app.list.DialtactsPagerAdapter.TAB_COUNT_WITH_VOICEMAIL;
+import static com.android.dialer.app.list.DialtactsPagerAdapter.TAB_INDEX_ALL_CONTACTS;
+import static com.android.dialer.app.list.DialtactsPagerAdapter.TAB_INDEX_HISTORY;
+import static com.android.dialer.app.list.DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL;
+import static com.android.dialer.app.list.DialtactsPagerAdapter.TAB_INDEX_VOICEMAIL;
+
import android.app.Fragment;
-import android.app.FragmentManager;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.database.Cursor;
@@ -26,8 +31,6 @@ import android.os.Handler;
import android.os.Trace;
import android.preference.PreferenceManager;
import android.provider.VoicemailContract;
-import android.support.annotation.Nullable;
-import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
@@ -37,7 +40,6 @@ import com.android.contacts.common.list.ViewPagerTabs;
import com.android.dialer.app.R;
import com.android.dialer.app.calllog.CallLogFragment;
import com.android.dialer.app.calllog.CallLogNotificationsService;
-import com.android.dialer.app.calllog.VisualVoicemailCallLogFragment;
import com.android.dialer.app.voicemail.error.VoicemailStatusCorruptionHandler;
import com.android.dialer.app.voicemail.error.VoicemailStatusCorruptionHandler.Source;
import com.android.dialer.common.LogUtil;
@@ -45,11 +47,10 @@ import com.android.dialer.database.CallLogQueryHandler;
import com.android.dialer.logging.Logger;
import com.android.dialer.logging.nano.DialerImpression;
import com.android.dialer.logging.nano.ScreenEvent;
-import com.android.dialer.util.ViewUtil;
+import com.android.dialer.speeddial.SpeedDialFragment;
import com.android.dialer.voicemailstatus.VisualVoicemailEnabledChecker;
import com.android.dialer.voicemailstatus.VoicemailStatusHelper;
import java.util.ArrayList;
-import java.util.List;
/**
* Fragment that is used as the main screen of the Dialer.
@@ -61,51 +62,18 @@ import java.util.List;
public class ListsFragment extends Fragment
implements ViewPager.OnPageChangeListener, CallLogQueryHandler.Listener {
- /** Every fragment in the list show implement this interface. */
- public interface ListsPage {
-
- /**
- * Called when the page is resumed, including selecting the page or activity resume. Note: This
- * is called before the page fragment is attached to a activity.
- *
- * @param activity the activity hosting the ListFragment
- */
- void onPageResume(@Nullable Activity activity);
-
- /**
- * Called when the page is paused, including selecting another page or activity pause. Note:
- * This is called after the page fragment is detached from a activity.
- *
- * @param activity the activity hosting the ListFragment
- */
- void onPagePause(@Nullable Activity activity);
- }
-
- public static final int TAB_INDEX_SPEED_DIAL = 0;
- public static final int TAB_INDEX_HISTORY = 1;
- public static final int TAB_INDEX_ALL_CONTACTS = 2;
- public static final int TAB_INDEX_VOICEMAIL = 3;
- public static final int TAB_COUNT_DEFAULT = 3;
- public static final int TAB_COUNT_WITH_VOICEMAIL = 4;
private static final String TAG = "ListsFragment";
private ViewPager mViewPager;
private ViewPagerTabs mViewPagerTabs;
- private ViewPagerAdapter mViewPagerAdapter;
+ private DialtactsPagerAdapter mAdapter;
private RemoveView mRemoveView;
private View mRemoveViewContent;
- private SpeedDialFragment mSpeedDialFragment;
- private CallLogFragment mHistoryFragment;
- private AllContactsFragment mAllContactsFragment;
- private CallLogFragment mVoicemailFragment;
- private ListsPage mCurrentPage;
+ private Fragment mCurrentPage;
private SharedPreferences mPrefs;
- private boolean mHasActiveVoicemailProvider;
private boolean mHasFetchedVoicemailStatus;
private boolean mShowVoicemailTabAfterVoicemailStatusIsFetched;
private VoicemailStatusHelper mVoicemailStatusHelper;
private final ArrayList<OnPageChangeListener> mOnPageChangeListeners = new ArrayList<>();
- private String[] mTabTitles;
- private int[] mTabIcons;
/** The position of the currently selected tab. */
private int mTabIndex = TAB_INDEX_SPEED_DIAL;
@@ -125,15 +93,8 @@ public class ListsFragment extends Fragment
LogUtil.d("ListsFragment.onCreate", null);
Trace.beginSection(TAG + " onCreate");
super.onCreate(savedInstanceState);
-
mVoicemailStatusHelper = new VoicemailStatusHelper();
- mHasFetchedVoicemailStatus = false;
-
mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
- mHasActiveVoicemailProvider =
- mPrefs.getBoolean(
- VisualVoicemailEnabledChecker.PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, false);
-
Trace.endSection();
}
@@ -153,17 +114,17 @@ public class ListsFragment extends Fragment
mCallLogQueryHandler.fetchVoicemailStatus();
mCallLogQueryHandler.fetchMissedCallsUnreadCount();
Trace.endSection();
- mCurrentPage = getListsPage(mViewPager.getCurrentItem());
- if (mCurrentPage != null) {
- mCurrentPage.onPageResume(getActivity());
+ mCurrentPage = mAdapter.getItem(mViewPager.getCurrentItem());
+ if (mCurrentPage instanceof CallLogFragment) {
+ ((CallLogFragment) mCurrentPage).onVisible();
}
}
@Override
public void onPause() {
LogUtil.d("ListsFragment.onPause", null);
- if (mCurrentPage != null) {
- mCurrentPage.onPagePause(getActivity());
+ if (mCurrentPage instanceof CallLogFragment) {
+ ((CallLogFragment) mCurrentPage).onNotVisible();
}
super.onPause();
}
@@ -183,27 +144,34 @@ public class ListsFragment extends Fragment
final View parentView = inflater.inflate(R.layout.lists_fragment, container, false);
Trace.endSection();
Trace.beginSection(TAG + " setup views");
+
+ String[] tabTitles = new String[TAB_COUNT_WITH_VOICEMAIL];
+ tabTitles[TAB_INDEX_SPEED_DIAL] = getResources().getString(R.string.tab_speed_dial);
+ tabTitles[TAB_INDEX_HISTORY] = getResources().getString(R.string.tab_history);
+ tabTitles[TAB_INDEX_ALL_CONTACTS] = getResources().getString(R.string.tab_all_contacts);
+ tabTitles[TAB_INDEX_VOICEMAIL] = getResources().getString(R.string.tab_voicemail);
+
+ int[] tabIcons = new int[TAB_COUNT_WITH_VOICEMAIL];
+ tabIcons[TAB_INDEX_SPEED_DIAL] = R.drawable.quantum_ic_grade_white_24;
+ tabIcons[TAB_INDEX_HISTORY] = R.drawable.quantum_ic_schedule_white_24;
+ tabIcons[TAB_INDEX_ALL_CONTACTS] = R.drawable.quantum_ic_people_white_24;
+ tabIcons[TAB_INDEX_VOICEMAIL] = R.drawable.quantum_ic_voicemail_white_24;
+
mViewPager = (ViewPager) parentView.findViewById(R.id.lists_pager);
- mViewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager());
- mViewPager.setAdapter(mViewPagerAdapter);
+ mAdapter =
+ new DialtactsPagerAdapter(
+ getContext(),
+ getChildFragmentManager(),
+ tabTitles,
+ mPrefs.getBoolean(
+ VisualVoicemailEnabledChecker.PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, false));
+ mViewPager.setAdapter(mAdapter);
mViewPager.setOffscreenPageLimit(TAB_COUNT_WITH_VOICEMAIL - 1);
mViewPager.addOnPageChangeListener(this);
showTab(TAB_INDEX_SPEED_DIAL);
- mTabTitles = new String[TAB_COUNT_WITH_VOICEMAIL];
- mTabTitles[TAB_INDEX_SPEED_DIAL] = getResources().getString(R.string.tab_speed_dial);
- mTabTitles[TAB_INDEX_HISTORY] = getResources().getString(R.string.tab_history);
- mTabTitles[TAB_INDEX_ALL_CONTACTS] = getResources().getString(R.string.tab_all_contacts);
- mTabTitles[TAB_INDEX_VOICEMAIL] = getResources().getString(R.string.tab_voicemail);
-
- mTabIcons = new int[TAB_COUNT_WITH_VOICEMAIL];
- mTabIcons[TAB_INDEX_SPEED_DIAL] = R.drawable.ic_grade_24dp;
- mTabIcons[TAB_INDEX_HISTORY] = R.drawable.ic_schedule_24dp;
- mTabIcons[TAB_INDEX_ALL_CONTACTS] = R.drawable.ic_people_24dp;
- mTabIcons[TAB_INDEX_VOICEMAIL] = R.drawable.ic_voicemail_24dp;
-
mViewPagerTabs = (ViewPagerTabs) parentView.findViewById(R.id.lists_pager_header);
- mViewPagerTabs.configureTabIcons(mTabIcons);
+ mViewPagerTabs.configureTabIcons(tabIcons);
mViewPagerTabs.setViewPager(mViewPager);
addOnPageChangeListener(mViewPagerTabs);
@@ -239,20 +207,20 @@ public class ListsFragment extends Fragment
*/
public void showTab(int index) {
if (index == TAB_INDEX_VOICEMAIL) {
- if (mHasActiveVoicemailProvider) {
- mViewPager.setCurrentItem(getRtlPosition(TAB_INDEX_VOICEMAIL));
+ if (mAdapter.hasActiveVoicemailProvider()) {
+ mViewPager.setCurrentItem(mAdapter.getRtlPosition(TAB_INDEX_VOICEMAIL));
} else if (!mHasFetchedVoicemailStatus) {
// Try to show the voicemail tab after the voicemail status returns.
mShowVoicemailTabAfterVoicemailStatusIsFetched = true;
}
} else if (index < getTabCount()) {
- mViewPager.setCurrentItem(getRtlPosition(index));
+ mViewPager.setCurrentItem(mAdapter.getRtlPosition(index));
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- mTabIndex = getRtlPosition(position);
+ mTabIndex = mAdapter.getRtlPosition(position);
final int count = mOnPageChangeListeners.size();
for (int i = 0; i < count; i++) {
@@ -263,7 +231,7 @@ public class ListsFragment extends Fragment
@Override
public void onPageSelected(int position) {
LogUtil.i("ListsFragment.onPageSelected", "position: %d", position);
- mTabIndex = getRtlPosition(position);
+ mTabIndex = mAdapter.getRtlPosition(position);
// Show the tab which has been selected instead.
mShowVoicemailTabAfterVoicemailStatusIsFetched = false;
@@ -274,12 +242,12 @@ public class ListsFragment extends Fragment
}
sendScreenViewForCurrentPosition();
- if (mCurrentPage != null) {
- mCurrentPage.onPagePause(getActivity());
+ if (mCurrentPage instanceof CallLogFragment) {
+ ((CallLogFragment) mCurrentPage).onNotVisible();
}
- mCurrentPage = getListsPage(position);
- if (mCurrentPage != null) {
- mCurrentPage.onPageResume(getActivity());
+ mCurrentPage = mAdapter.getItem(position);
+ if (mCurrentPage instanceof CallLogFragment) {
+ ((CallLogFragment) mCurrentPage).onVisible();
}
}
@@ -302,19 +270,19 @@ public class ListsFragment extends Fragment
VoicemailStatusCorruptionHandler.maybeFixVoicemailStatus(
getContext(), statusCursor, Source.Activity);
- // Update mHasActiveVoicemailProvider, which controls the number of tabs displayed.
+ // Update hasActiveVoicemailProvider, which controls the number of tabs displayed.
boolean hasActiveVoicemailProvider =
mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor) > 0;
- if (hasActiveVoicemailProvider != mHasActiveVoicemailProvider) {
- mHasActiveVoicemailProvider = hasActiveVoicemailProvider;
- mViewPagerAdapter.notifyDataSetChanged();
+ if (hasActiveVoicemailProvider != mAdapter.hasActiveVoicemailProvider()) {
+ mAdapter.setHasActiveVoicemailProvider(hasActiveVoicemailProvider);
+ mAdapter.notifyDataSetChanged();
if (hasActiveVoicemailProvider) {
Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_TAB_VISIBLE);
mViewPagerTabs.updateTab(TAB_INDEX_VOICEMAIL);
} else {
mViewPagerTabs.removeTab(TAB_INDEX_VOICEMAIL);
- removeVoicemailFragment();
+ mAdapter.removeVoicemailFragment(getChildFragmentManager());
}
mPrefs
@@ -329,7 +297,7 @@ public class ListsFragment extends Fragment
mCallLogQueryHandler.fetchVoicemailUnreadCount();
}
- if (mHasActiveVoicemailProvider && mShowVoicemailTabAfterVoicemailStatusIsFetched) {
+ if (mAdapter.hasActiveVoicemailProvider() && mShowVoicemailTabAfterVoicemailStatusIsFetched) {
mShowVoicemailTabAfterVoicemailStatusIsFetched = false;
showTab(TAB_INDEX_VOICEMAIL);
}
@@ -386,7 +354,7 @@ public class ListsFragment extends Fragment
public void updateTabUnreadCounts() {
if (mCallLogQueryHandler != null) {
mCallLogQueryHandler.fetchMissedCallsUnreadCount();
- if (mHasActiveVoicemailProvider) {
+ if (mAdapter.hasActiveVoicemailProvider()) {
mCallLogQueryHandler.fetchVoicemailUnreadCount();
}
}
@@ -406,8 +374,11 @@ public class ListsFragment extends Fragment
mRemoveView.animate().alpha(show ? 1 : 0).start();
}
- public SpeedDialFragment getSpeedDialFragment() {
- return mSpeedDialFragment;
+ public boolean hasFrequents() {
+ Fragment page = mAdapter.getItem(mAdapter.getRtlPosition(TAB_INDEX_SPEED_DIAL));
+ return page instanceof OldSpeedDialFragment
+ ? ((OldSpeedDialFragment) page).hasFrequents()
+ : ((SpeedDialFragment) page).hasFrequents();
}
public RemoveView getRemoveView() {
@@ -415,14 +386,7 @@ public class ListsFragment extends Fragment
}
public int getTabCount() {
- return mViewPagerAdapter.getCount();
- }
-
- private int getRtlPosition(int position) {
- if (ViewUtil.isRtl()) {
- return mViewPagerAdapter.getCount() - 1 - position;
- }
- return position;
+ return mAdapter.getCount();
}
public void sendScreenViewForCurrentPosition() {
@@ -449,122 +413,4 @@ public class ListsFragment extends Fragment
}
Logger.get(getActivity()).logScreenView(screenType, getActivity());
}
-
- private void removeVoicemailFragment() {
- if (mVoicemailFragment != null) {
- getChildFragmentManager()
- .beginTransaction()
- .remove(mVoicemailFragment)
- .commitAllowingStateLoss();
- mVoicemailFragment = null;
- }
- }
-
- private ListsPage getListsPage(int position) {
- switch (getRtlPosition(position)) {
- case TAB_INDEX_SPEED_DIAL:
- return mSpeedDialFragment;
- case TAB_INDEX_HISTORY:
- return mHistoryFragment;
- case TAB_INDEX_ALL_CONTACTS:
- return mAllContactsFragment;
- case TAB_INDEX_VOICEMAIL:
- return mVoicemailFragment;
- }
- throw new IllegalStateException("No fragment at position " + position);
- }
-
- public class ViewPagerAdapter extends FragmentPagerAdapter {
-
- private final List<Fragment> mFragments = new ArrayList<>();
-
- public ViewPagerAdapter(FragmentManager fm) {
- super(fm);
- for (int i = 0; i < TAB_COUNT_WITH_VOICEMAIL; i++) {
- mFragments.add(null);
- }
- }
-
- @Override
- public long getItemId(int position) {
- return getRtlPosition(position);
- }
-
- @Override
- public Fragment getItem(int position) {
- LogUtil.d("ViewPagerAdapter.getItem", "position: %d", position);
- switch (getRtlPosition(position)) {
- case TAB_INDEX_SPEED_DIAL:
- if (mSpeedDialFragment == null) {
- mSpeedDialFragment = new SpeedDialFragment();
- }
- return mSpeedDialFragment;
- case TAB_INDEX_HISTORY:
- if (mHistoryFragment == null) {
- mHistoryFragment = new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL);
- }
- return mHistoryFragment;
- case TAB_INDEX_ALL_CONTACTS:
- if (mAllContactsFragment == null) {
- mAllContactsFragment = new AllContactsFragment();
- }
- return mAllContactsFragment;
- case TAB_INDEX_VOICEMAIL:
- if (mVoicemailFragment == null) {
- mVoicemailFragment = new VisualVoicemailCallLogFragment();
- LogUtil.v(
- "ViewPagerAdapter.getItem",
- "new VisualVoicemailCallLogFragment: %s",
- mVoicemailFragment);
- }
- return mVoicemailFragment;
- }
- throw new IllegalStateException("No fragment at position " + position);
- }
-
- @Override
- public Fragment instantiateItem(ViewGroup container, int position) {
- LogUtil.d("ViewPagerAdapter.instantiateItem", "position: %d", position);
- // On rotation the FragmentManager handles rotation. Therefore getItem() isn't called.
- // Copy the fragments that the FragmentManager finds so that we can store them in
- // instance variables for later.
- final Fragment fragment = (Fragment) super.instantiateItem(container, position);
- if (fragment instanceof SpeedDialFragment) {
- mSpeedDialFragment = (SpeedDialFragment) fragment;
- } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_HISTORY) {
- mHistoryFragment = (CallLogFragment) fragment;
- } else if (fragment instanceof AllContactsFragment) {
- mAllContactsFragment = (AllContactsFragment) fragment;
- } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_VOICEMAIL) {
- mVoicemailFragment = (CallLogFragment) fragment;
- LogUtil.v("ViewPagerAdapter.instantiateItem", mVoicemailFragment.toString());
- }
- mFragments.set(position, fragment);
- return fragment;
- }
-
- /**
- * When {@link android.support.v4.view.PagerAdapter#notifyDataSetChanged} is called, this method
- * is called on all pages to determine whether they need to be recreated. When the voicemail tab
- * is removed, the view needs to be recreated by returning POSITION_NONE. If
- * notifyDataSetChanged is called for some other reason, the voicemail tab is recreated only if
- * it is active. All other tabs do not need to be recreated and POSITION_UNCHANGED is returned.
- */
- @Override
- public int getItemPosition(Object object) {
- return !mHasActiveVoicemailProvider && mFragments.indexOf(object) == TAB_INDEX_VOICEMAIL
- ? POSITION_NONE
- : POSITION_UNCHANGED;
- }
-
- @Override
- public int getCount() {
- return mHasActiveVoicemailProvider ? TAB_COUNT_WITH_VOICEMAIL : TAB_COUNT_DEFAULT;
- }
-
- @Override
- public CharSequence getPageTitle(int position) {
- return mTabTitles[position];
- }
- }
}
diff --git a/java/com/android/dialer/app/list/SpeedDialFragment.java b/java/com/android/dialer/app/list/OldSpeedDialFragment.java
index 8e0f89028..4aafd9625 100644
--- a/java/com/android/dialer/app/list/SpeedDialFragment.java
+++ b/java/com/android/dialer/app/list/OldSpeedDialFragment.java
@@ -31,7 +31,6 @@ import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Trace;
-import android.support.annotation.Nullable;
import android.support.v13.app.FragmentCompat;
import android.support.v4.util.LongSparseArray;
import android.view.LayoutInflater;
@@ -51,7 +50,6 @@ import com.android.contacts.common.ContactTileLoaderFactory;
import com.android.contacts.common.list.ContactTileView;
import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
import com.android.dialer.app.R;
-import com.android.dialer.app.list.ListsFragment.ListsPage;
import com.android.dialer.app.widget.EmptyContentView;
import com.android.dialer.callintent.nano.CallInitiationType;
import com.android.dialer.callintent.nano.CallSpecificAppData;
@@ -61,9 +59,8 @@ import com.android.dialer.util.ViewUtil;
import java.util.ArrayList;
/** This fragment displays the user's favorite/frequent contacts in a grid. */
-public class SpeedDialFragment extends Fragment
- implements ListsPage,
- OnItemClickListener,
+public class OldSpeedDialFragment extends Fragment
+ implements OnItemClickListener,
PhoneFavoritesTileAdapter.OnDataSetChangedForAnimationListener,
EmptyContentView.OnEmptyViewActionButtonClickedListener,
FragmentCompat.OnRequestPermissionsResultCallback {
@@ -79,7 +76,7 @@ public class SpeedDialFragment extends Fragment
*/
private static final long KEY_REMOVED_ITEM_HEIGHT = Long.MAX_VALUE;
- private static final String TAG = "SpeedDialFragment";
+ private static final String TAG = "OldSpeedDialFragment";
private static final boolean DEBUG = false;
/** Used with LoaderManager. */
private static final int LOADER_ID_CONTACT_TILE = 1;
@@ -104,7 +101,7 @@ public class SpeedDialFragment extends Fragment
@Override
public void onCreate(Bundle savedState) {
if (DEBUG) {
- LogUtil.d("SpeedDialFragment.onCreate", null);
+ LogUtil.d("OldSpeedDialFragment.onCreate", null);
}
Trace.beginSection(TAG + " onCreate");
super.onCreate(savedState);
@@ -256,7 +253,7 @@ public class SpeedDialFragment extends Fragment
final int contactTileAdapterCount = mContactTileAdapter.getCount();
if (position <= contactTileAdapterCount) {
LogUtil.e(
- "SpeedDialFragment.onItemClick",
+ "OldSpeedDialFragment.onItemClick",
"event for unexpected position. The position "
+ position
+ " is before \"all\" section. Ignored.");
@@ -272,7 +269,7 @@ public class SpeedDialFragment extends Fragment
private void saveOffsets(int removedItemHeight) {
final int firstVisiblePosition = mListView.getFirstVisiblePosition();
if (DEBUG) {
- LogUtil.d("SpeedDialFragment.saveOffsets", "Child count : " + mListView.getChildCount());
+ LogUtil.d("OldSpeedDialFragment.saveOffsets", "Child count : " + mListView.getChildCount());
}
for (int i = 0; i < mListView.getChildCount(); i++) {
final View child = mListView.getChildAt(i);
@@ -286,7 +283,7 @@ public class SpeedDialFragment extends Fragment
final long itemId = mContactTileAdapter.getItemId(position);
if (DEBUG) {
LogUtil.d(
- "SpeedDialFragment.saveOffsets",
+ "OldSpeedDialFragment.saveOffsets",
"Saving itemId: " + itemId + " for listview child " + i + " Top: " + child.getTop());
}
mItemIdTopMap.put(itemId, child.getTop());
@@ -356,7 +353,7 @@ public class SpeedDialFragment extends Fragment
if (DEBUG) {
LogUtil.d(
- "SpeedDialFragment.onPreDraw",
+ "OldSpeedDialFragment.onPreDraw",
"Found itemId: "
+ itemId
+ " for listview child "
@@ -426,16 +423,6 @@ public class SpeedDialFragment extends Fragment
}
}
- @Override
- public void onPageResume(@Nullable Activity activity) {
- LogUtil.i("SpeedDialFragment.onPageResume", null);
- }
-
- @Override
- public void onPagePause(@Nullable Activity activity) {
- LogUtil.i("SpeedDialFragment.onPagePause", null);
- }
-
public interface HostInterface {
void setDragDropController(DragDropController controller);