diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/com/android/dialer/app/calllog/CallLogFragment.java | 31 | ||||
-rw-r--r-- | java/com/android/dialer/app/list/ListsFragment.java | 10 | ||||
-rw-r--r-- | java/com/android/dialer/main/impl/MainActivity.java | 107 |
3 files changed, 127 insertions, 21 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogFragment.java b/java/com/android/dialer/app/calllog/CallLogFragment.java index 4f5035fc6..7f635dbca 100644 --- a/java/com/android/dialer/app/calllog/CallLogFragment.java +++ b/java/com/android/dialer/app/calllog/CallLogFragment.java @@ -53,10 +53,10 @@ import com.android.dialer.app.calllog.calllogcache.CallLogCache; import com.android.dialer.app.contactinfo.ContactInfoCache; import com.android.dialer.app.contactinfo.ContactInfoCache.OnContactInfoChangedListener; import com.android.dialer.app.contactinfo.ExpirableCacheHeadlessFragment; -import com.android.dialer.app.list.ListsFragment; import com.android.dialer.app.voicemail.VoicemailPlaybackPresenter; import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; import com.android.dialer.common.Assert; +import com.android.dialer.common.FragmentUtils; import com.android.dialer.common.LogUtil; import com.android.dialer.database.CallLogQueryHandler; import com.android.dialer.database.CallLogQueryHandler.Listener; @@ -344,9 +344,10 @@ public class CallLogFragment extends Fragment recyclerView, this, this, - activityType == CallLogAdapter.ACTIVITY_TYPE_DIALTACTS - ? (CallLogAdapter.OnActionModeStateChangedListener) getActivity() - : null, + // We aren't calling getParentUnsafe because CallLogActivity doesn't need to + // implement this listener + FragmentUtils.getParent( + this, CallLogAdapter.OnActionModeStateChangedListener.class), new CallLogCache(getActivity()), contactInfoCache, getVoicemailPlaybackPresenter(), @@ -479,7 +480,7 @@ public class CallLogFragment extends Fragment public void fetchCalls() { callLogQueryHandler.fetchCalls(callTypeFilter, dateLimit); if (!isCallLogActivity) { - ((ListsFragment) getParentFragment()).updateTabUnreadCounts(); + FragmentUtils.getParentUnsafe(this, CallLogFragmentListener.class).updateTabUnreadCounts(); } } @@ -616,7 +617,8 @@ public class CallLogFragment extends Fragment public void onVisible() { LogUtil.enterBlock("CallLogFragment.onPageSelected"); if (getActivity() != null && getActivity() instanceof HostInterface) { - ((HostInterface) getActivity()).enableFloatingButton(!isModalAlertVisible()); + FragmentUtils.getParentUnsafe(this, HostInterface.class) + .enableFloatingButton(!isModalAlertVisible()); } } @@ -638,7 +640,7 @@ public class CallLogFragment extends Fragment this, getUserVisibleHint()); getAdapter().notifyDataSetChanged(); - HostInterface hostInterface = (HostInterface) getActivity(); + HostInterface hostInterface = FragmentUtils.getParent(this, HostInterface.class); if (show) { recyclerView.setVisibility(View.GONE); modalAlertView.setVisibility(View.VISIBLE); @@ -659,7 +661,8 @@ public class CallLogFragment extends Fragment multiSelectUnSelectAllViewContent.setVisibility(show ? View.VISIBLE : View.GONE); multiSelectUnSelectAllViewContent.setAlpha(show ? 0 : 1); multiSelectUnSelectAllViewContent.animate().alpha(show ? 1 : 0).start(); - ((ListsFragment) getParentFragment()).showMultiSelectRemoveView(show); + FragmentUtils.getParentUnsafe(this, CallLogFragmentListener.class) + .showMultiSelectRemoveView(show); } @Override @@ -717,4 +720,16 @@ public class CallLogFragment extends Fragment refreshDataRequired = true; } } + + /** Useful callback for ListsFragment children to use to call into ListsFragment. */ + public interface CallLogFragmentListener { + + /** + * External method to update unread count because the unread count changes when the user expands + * a voicemail in the call log or when the user expands an unread call in the call history tab. + */ + void updateTabUnreadCounts(); + + void showMultiSelectRemoveView(boolean show); + } } diff --git a/java/com/android/dialer/app/list/ListsFragment.java b/java/com/android/dialer/app/list/ListsFragment.java index bbbf056bf..d314917ef 100644 --- a/java/com/android/dialer/app/list/ListsFragment.java +++ b/java/com/android/dialer/app/list/ListsFragment.java @@ -34,6 +34,7 @@ import android.view.ViewGroup; 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.CallLogFragment.CallLogFragmentListener; import com.android.dialer.app.calllog.CallLogNotificationsService; import com.android.dialer.app.calllog.VisualVoicemailCallLogFragment; import com.android.dialer.common.LogUtil; @@ -59,7 +60,8 @@ import java.util.ArrayList; * Contacts list. This will also eventually contain the logic that allows sliding the ViewPager * containing the lists up above the search bar and pin it against the top of the screen. */ -public class ListsFragment extends Fragment implements OnPageChangeListener, Listener { +public class ListsFragment extends Fragment + implements OnPageChangeListener, Listener, CallLogFragmentListener { private static final String TAG = "ListsFragment"; @@ -423,10 +425,7 @@ public class ListsFragment extends Fragment implements OnPageChangeListener, Lis return true; } - /** - * External method to update unread count because the unread count changes when the user expands a - * voicemail in the call log or when the user expands an unread call in the call history tab. - */ + @Override public void updateTabUnreadCounts() { if (callLogQueryHandler != null) { callLogQueryHandler.fetchMissedCallsUnreadCount(); @@ -450,6 +449,7 @@ public class ListsFragment extends Fragment implements OnPageChangeListener, Lis removeView.animate().alpha(show ? 1 : 0).start(); } + @Override public void showMultiSelectRemoveView(boolean show) { viewPagerTabs.setVisibility(show ? View.GONE : View.VISIBLE); viewPager.setEnableSwipingPages(!show); diff --git a/java/com/android/dialer/main/impl/MainActivity.java b/java/com/android/dialer/main/impl/MainActivity.java index 4bc15da98..57cc684e3 100644 --- a/java/com/android/dialer/main/impl/MainActivity.java +++ b/java/com/android/dialer/main/impl/MainActivity.java @@ -30,6 +30,9 @@ import android.support.v4.app.FragmentTransaction; import android.view.View; import android.widget.ImageView; import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; +import com.android.dialer.app.calllog.CallLogAdapter; +import com.android.dialer.app.calllog.CallLogFragment; +import com.android.dialer.app.calllog.CallLogFragment.CallLogFragmentListener; import com.android.dialer.app.list.DragDropController; import com.android.dialer.app.list.OldSpeedDialFragment; import com.android.dialer.app.list.OnDragDropListener; @@ -90,6 +93,10 @@ public final class MainActivity extends TransactionSafeActivity private MainOnDialpadQueryChangedListener onDialpadQueryChangedListener; private MainDialpadListener dialpadListener; private MainSearchFragmentListener searchFragmentListener; + private MainCallLogAdapterOnActionModeStateChangedListener + callLogAdapterOnActionModeStateChangedListener; + private MainCallLogHost callLogHostInterface; + private MainCallLogFragmentListener callLogFragmentListener; private MainOnListFragmentScrolledListener onListFragmentScrolledListener; private MainOnPhoneNumberPickerActionListener onPhoneNumberPickerActionListener; private MainOldSpeedDialFragmentHostInterface oldSpeedDialFragmentHostInterface; @@ -148,6 +155,10 @@ public final class MainActivity extends TransactionSafeActivity onDialpadQueryChangedListener = new MainOnDialpadQueryChangedListener(searchController); dialpadListener = new MainDialpadListener(this, searchController, getLastOutgoingCallListener); searchFragmentListener = new MainSearchFragmentListener(searchController); + callLogAdapterOnActionModeStateChangedListener = + new MainCallLogAdapterOnActionModeStateChangedListener(); + callLogHostInterface = new MainCallLogHost(searchController, fab); + callLogFragmentListener = new MainCallLogFragmentListener(); onListFragmentScrolledListener = new MainOnListFragmentScrolledListener(snackbarContainer); onPhoneNumberPickerActionListener = new MainOnPhoneNumberPickerActionListener(this); oldSpeedDialFragmentHostInterface = @@ -228,6 +239,12 @@ public final class MainActivity extends TransactionSafeActivity return (T) dialpadFragmentHostInterface; } else if (callbackInterface.isInstance(searchFragmentListener)) { return (T) searchFragmentListener; + } else if (callbackInterface.isInstance(callLogAdapterOnActionModeStateChangedListener)) { + return (T) callLogAdapterOnActionModeStateChangedListener; + } else if (callbackInterface.isInstance(callLogHostInterface)) { + return (T) callLogHostInterface; + } else if (callbackInterface.isInstance(callLogFragmentListener)) { + return (T) callLogFragmentListener; } else if (callbackInterface.isInstance(onListFragmentScrolledListener)) { return (T) onListFragmentScrolledListener; } else if (callbackInterface.isInstance(onPhoneNumberPickerActionListener)) { @@ -360,6 +377,60 @@ public final class MainActivity extends TransactionSafeActivity } } + /** @see CallLogAdapter.OnActionModeStateChangedListener */ + // TODO(a bug): handle multiselect mode + private static final class MainCallLogAdapterOnActionModeStateChangedListener + implements CallLogAdapter.OnActionModeStateChangedListener { + + @Override + public void onActionModeStateChanged(boolean isEnabled) {} + + @Override + public boolean isActionModeStateEnabled() { + return false; + } + } + + /** @see CallLogFragment.HostInterface */ + private static final class MainCallLogHost implements CallLogFragment.HostInterface { + + private final MainSearchController searchController; + private final FloatingActionButton fab; + + MainCallLogHost(MainSearchController searchController, FloatingActionButton fab) { + this.searchController = searchController; + this.fab = fab; + } + + @Override + public void showDialpad() { + searchController.showDialpad(true); + } + + @Override + public void enableFloatingButton(boolean enabled) { + if (enabled) { + fab.show(); + } else { + fab.hide(); + } + } + } + + /** @see CallLogFragmentListener */ + private static final class MainCallLogFragmentListener implements CallLogFragmentListener { + + @Override + public void updateTabUnreadCounts() { + // TODO(a bug): implement unread counts + } + + @Override + public void showMultiSelectRemoveView(boolean show) { + // TODO(a bug): handle multiselect mode + } + } + /** @see OnListFragmentScrolledListener */ private static final class MainOnListFragmentScrolledListener implements OnListFragmentScrolledListener { @@ -521,15 +592,30 @@ public final class MainActivity extends TransactionSafeActivity @Override public void onCallLogSelected() { hideAllFragments(); - NewCallLogFragment fragment = - (NewCallLogFragment) supportFragmentManager.findFragmentByTag(CALL_LOG_TAG); - if (fragment == null) { - supportFragmentManager - .beginTransaction() - .add(R.id.fragment_container, new NewCallLogFragment(), CALL_LOG_TAG) - .commit(); + if (ConfigProviderComponent.get(context) + .getConfigProvider() + .getBoolean("enable_new_call_log", false)) { + NewCallLogFragment fragment = + (NewCallLogFragment) supportFragmentManager.findFragmentByTag(CALL_LOG_TAG); + if (fragment == null) { + supportFragmentManager + .beginTransaction() + .add(R.id.fragment_container, new NewCallLogFragment(), CALL_LOG_TAG) + .commit(); + } else { + supportFragmentManager.beginTransaction().show(fragment).commit(); + } } else { - supportFragmentManager.beginTransaction().show(fragment).commit(); + CallLogFragment fragment = + (CallLogFragment) fragmentManager.findFragmentByTag(CALL_LOG_TAG); + if (fragment == null) { + fragmentManager + .beginTransaction() + .add(R.id.fragment_container, new CallLogFragment(), CALL_LOG_TAG) + .commit(); + } else { + fragmentManager.beginTransaction().show(fragment).commit(); + } } } @@ -569,6 +655,7 @@ public final class MainActivity extends TransactionSafeActivity private void hideAllFragments() { FragmentTransaction supportTransaction = supportFragmentManager.beginTransaction(); if (supportFragmentManager.findFragmentByTag(CALL_LOG_TAG) != null) { + // NewCallLogFragment supportTransaction.hide(supportFragmentManager.findFragmentByTag(CALL_LOG_TAG)); } if (supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG) != null) { @@ -580,6 +667,10 @@ public final class MainActivity extends TransactionSafeActivity if (fragmentManager.findFragmentByTag(SPEED_DIAL_TAG) != null) { transaction.hide(fragmentManager.findFragmentByTag(SPEED_DIAL_TAG)); } + if (fragmentManager.findFragmentByTag(CALL_LOG_TAG) != null) { + // Old CallLogFragment + transaction.hide(fragmentManager.findFragmentByTag(CALL_LOG_TAG)); + } if (fragmentManager.findFragmentByTag(CONTACTS_TAG) != null) { transaction.hide(fragmentManager.findFragmentByTag(CONTACTS_TAG)); } |