From dc4dd5e7da8407ac106263ae6b380b47ed536135 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 16 Mar 2015 13:37:45 -0700 Subject: Clean up extra helper methods. To assists with readability, clean up call log fragment by calling the contents of the helper methods directly, to remove extra level of indirection created by the helpers. In most cases, these helpers were one-offs, or were direct calls to another helper method. Bug: 19372817 Change-Id: I96d96bee6b300a26987513d50115de0c4cd522c1 --- .../android/dialer/calllog/CallLogFragment.java | 77 +++++++++------------- 1 file changed, 30 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index 34dd137fb..f84d75b39 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -198,14 +198,14 @@ public class CallLogFragment extends ListFragment this, mLogLimit); mKeyguardManager = (KeyguardManager) getActivity().getSystemService(Context.KEYGUARD_SERVICE); - getActivity().getContentResolver().registerContentObserver(CallLog.CONTENT_URI, true, - mCallLogObserver); + getActivity().getContentResolver().registerContentObserver( + CallLog.CONTENT_URI, true, mCallLogObserver); getActivity().getContentResolver().registerContentObserver( ContactsContract.Contacts.CONTENT_URI, true, mContactsObserver); getActivity().getContentResolver().registerContentObserver( Status.CONTENT_URI, true, mVoicemailStatusObserver); setHasOptionsMenu(true); - updateCallList(mCallTypeFilter, mDateLimit); + fetchCalls(); mExpandedItemTranslationZ = getResources().getDimension(R.dimen.call_log_expanded_translation_z); @@ -270,13 +270,21 @@ public class CallLogFragment extends ListFragment */ @Override public void onVoicemailStatusFetched(Cursor statusCursor) { - if (getActivity() == null || getActivity().isFinishing()) { + Activity activity = getActivity(); + if (activity == null || activity.isFinishing()) { return; } updateVoicemailStatusMessage(statusCursor); - int activeSources = mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor); - setVoicemailSourcesAvailable(activeSources != 0); + // If there are any changes to the presence of active voicemail services, invalidate the + // options menu so that it will be updated. + boolean hasActiveVoicemailSources = + mVoicemailStatusHelper.getNumberActivityVoicemailSources(statusCursor) != 0; + if (mVoicemailSourcesAvailable != hasActiveVoicemailSources) { + mVoicemailSourcesAvailable = hasActiveVoicemailSources; + activity.invalidateOptionsMenu(); + } + mVoicemailStatusFetched = true; destroyEmptyLoaderIfAllDataFetched(); } @@ -288,18 +296,6 @@ public class CallLogFragment extends ListFragment } } - /** Sets whether there are any voicemail sources available in the platform. */ - private void setVoicemailSourcesAvailable(boolean voicemailSourcesAvailable) { - if (mVoicemailSourcesAvailable == voicemailSourcesAvailable) return; - mVoicemailSourcesAvailable = voicemailSourcesAvailable; - - Activity activity = getActivity(); - if (activity != null) { - // This is so that the options menu content is updated. - activity.invalidateOptionsMenu(); - } - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { View view = inflater.inflate(R.layout.call_log_fragment, container, false); @@ -389,7 +385,8 @@ public class CallLogFragment extends ListFragment @Override public void onStop() { super.onStop(); - updateOnExit(); + + updateOnTransition(false /* onEntry */); } @Override @@ -418,19 +415,6 @@ public class CallLogFragment extends ListFragment mCallLogQueryHandler.fetchCalls(mCallTypeFilter, mDateLimit); } - public void startCallsQuery() { - mAdapter.setLoading(true); - mCallLogQueryHandler.fetchCalls(mCallTypeFilter, mDateLimit); - } - - private void startVoicemailStatusQuery() { - mCallLogQueryHandler.fetchVoicemailStatus(); - } - - private void updateCallList(int filterType, long dateLimit) { - mCallLogQueryHandler.fetchCalls(filterType, dateLimit); - } - private void updateEmptyMessage(int filterType) { final int messageId; switch (filterType) { @@ -461,7 +445,7 @@ public class CallLogFragment extends ListFragment if (mMenuVisible != menuVisible) { mMenuVisible = menuVisible; if (!menuVisible) { - updateOnExit(); + updateOnTransition(false /* onEntry */); } else if (isResumed()) { refreshData(); } @@ -475,24 +459,23 @@ public class CallLogFragment extends ListFragment // Mark all entries in the contact info cache as out of date, so they will be looked up // again once being shown. mAdapter.invalidateCache(); - startCallsQuery(); - startVoicemailStatusQuery(); - updateOnEntry(); - mRefreshDataRequired = false; - } - } + mAdapter.setLoading(true); - /** Updates call data and notification state while leaving the call log tab. */ - private void updateOnExit() { - updateOnTransition(false); - } + fetchCalls(); + mCallLogQueryHandler.fetchVoicemailStatus(); - /** Updates call data and notification state while entering the call log tab. */ - private void updateOnEntry() { - updateOnTransition(true); + updateOnTransition(true /* onEntry */); + mRefreshDataRequired = false; + } } - // TODO: Move to CallLogActivity + /** + * Updates the call data and notification state on entering or leaving the call log tab. + * + * If we are leaving the call log tab, mark all the missed calls as read. + * + * TODO: Move to CallLogActivity + */ private void updateOnTransition(boolean onEntry) { // We don't want to update any call data when keyguard is on because the user has likely not // seen the new calls yet. -- cgit v1.2.3