Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb559812 authored by Sarmad Hashmi's avatar Sarmad Hashmi
Browse files

Mark missed calls as read on swipe.

When swiping to a new tab, if the previous tab that the user was in was
the call history tab, all missed calls are marked as read and the tab
count is updated. Also fixes b/27153608 and clearing of missed calls on
orientation change.

BUG=27136093
BUG=27153608
BUG=27154514

Change-Id: I5be31b1a3978784b941fb8e1af22f93fb6ca944a
parent cdc14da9
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -240,6 +240,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
    private FloatingActionButtonController mFloatingActionButtonController;

    private int mActionBarHeight;
    private int mPreviouslySelectedTabIndex;

    /**
     * The text returned from a voice search query.  Set in {@link #onActivityResult} and used in
@@ -423,7 +424,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O

        mIsLandscape = getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE;

        mPreviouslySelectedTabIndex = ListsFragment.TAB_INDEX_SPEED_DIAL;
        final View floatingActionButtonContainer = findViewById(
                R.id.floating_action_button_container);
        ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
@@ -567,6 +568,11 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O

    @Override
    protected void onPause() {
        // Only clear missed calls if the pause was not triggered by an orientation change
        // (or any other confirguration change)
        if (!isChangingConfigurations()) {
            updateMissedCalls();
        }
        if (mClearSearchOnPause) {
            hideDialpadAndSearchUi();
            mClearSearchOnPause = false;
@@ -1328,7 +1334,9 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O

    @Override
    public void onPageSelected(int position) {
        updateMissedCalls();
        int tabIndex = mListsFragment.getCurrentTabIndex();
        mPreviouslySelectedTabIndex = tabIndex;
        if (tabIndex == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
            mFloatingActionButtonController.changeIcon(
                    getResources().getDrawable(R.drawable.ic_person_add_24dp),
@@ -1389,4 +1397,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
        }
        return FloatingActionButtonController.ALIGN_END;
    }

    private void updateMissedCalls() {
        if (mPreviouslySelectedTabIndex == ListsFragment.TAB_INDEX_HISTORY) {
            mListsFragment.markMissedCallsAsReadAndRemoveNotifications();
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.dialer.calllog;

import com.android.dialer.DialtactsActivity;
import com.google.common.annotations.VisibleForTesting;

import android.content.Context;
@@ -171,6 +172,9 @@ public class CallLogAdapter extends GroupingListAdapter
            } else {
                if (viewHolder.callType == CallLog.Calls.MISSED_TYPE) {
                    CallLogAsyncTaskUtil.markCallAsRead(mContext, viewHolder.callIds);
                    if (!mIsCallLogActivity) {
                        ((DialtactsActivity) v.getContext()).updateTabUnreadCounts();
                    }
                }
                expandViewHolderActions(viewHolder);
            }
+14 −14
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
    private static final String KEY_FILTER_TYPE = "filter_type";
    private static final String KEY_LOG_LIMIT = "log_limit";
    private static final String KEY_DATE_LIMIT = "date_limit";
    private static final String KEY_IS_CALL_LOG_ACTIVITY = "is_call_log_activity";

    // No limit specified for the number of logs to show; use the CallLogQueryHandler's default.
    private static final int NO_LOG_LIMIT = -1;
@@ -194,6 +195,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
            mCallTypeFilter = state.getInt(KEY_FILTER_TYPE, mCallTypeFilter);
            mLogLimit = state.getInt(KEY_LOG_LIMIT, mLogLimit);
            mDateLimit = state.getLong(KEY_DATE_LIMIT, mDateLimit);
            mIsCallLogActivity = state.getBoolean(KEY_IS_CALL_LOG_ACTIVITY, mIsCallLogActivity);
        }

        final Activity activity = getActivity();
@@ -355,7 +357,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis

    @Override
    public void onStop() {
        updateOnTransition(false /* onEntry */);
        updateOnTransition();

        super.onStop();
    }
@@ -375,6 +377,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
        outState.putInt(KEY_FILTER_TYPE, mCallTypeFilter);
        outState.putInt(KEY_LOG_LIMIT, mLogLimit);
        outState.putLong(KEY_DATE_LIMIT, mDateLimit);
        outState.putBoolean(KEY_IS_CALL_LOG_ACTIVITY, mIsCallLogActivity);

        mAdapter.onSaveInstanceState(outState);
    }
@@ -382,6 +385,9 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
    @Override
    public void fetchCalls() {
        mCallLogQueryHandler.fetchCalls(mCallTypeFilter, mDateLimit);
        if (!mIsCallLogActivity) {
            ((ListsFragment) getParentFragment()).updateTabUnreadCounts();
        }
    }

    private void updateEmptyMessage(int filterType) {
@@ -429,7 +435,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
        if (mMenuVisible != menuVisible) {
            mMenuVisible = menuVisible;
            if (!menuVisible) {
                updateOnTransition(false /* onEntry */);
                updateOnTransition();
            } else if (isResumed()) {
                refreshData();
            }
@@ -448,7 +454,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
            fetchCalls();
            mCallLogQueryHandler.fetchVoicemailStatus();
            mCallLogQueryHandler.fetchMissedCallsUnreadCount();
            updateOnTransition(true /* onEntry */);
            updateOnTransition();
            mRefreshDataRequired = false;
        } else {
            // Refresh the display of the existing data to update the timestamp text descriptions.
@@ -457,25 +463,19 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
    }

    /**
     * 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.
     * Updates the voicemail notification state.
     *
     * TODO: Move to CallLogActivity
     */
    private void updateOnTransition(boolean onEntry) {
    private void updateOnTransition() {
        // We don't want to update any call data when keyguard is on because the user has likely not
        // seen the new calls yet.
        // This might be called before onCreate() and thus we need to check null explicitly.
        if (mKeyguardManager != null && !mKeyguardManager.inKeyguardRestrictedInputMode()) {
            // On either of the transitions we update the missed call and voicemail notifications.
            // While exiting we additionally consume all missed calls (by marking them as read).
            mCallLogQueryHandler.markNewCallsAsOld();
            if (mCallTypeFilter == Calls.VOICEMAIL_TYPE) {
        if (mKeyguardManager != null && !mKeyguardManager.inKeyguardRestrictedInputMode()
                && mCallTypeFilter == Calls.VOICEMAIL_TYPE) {
            CallLogNotificationsHelper.updateVoicemailNotifications(getActivity());
        }
    }
    }

    @Override
    public void onEmptyViewActionButtonClicked() {
+14 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.contacts.common.list.ViewPagerTabs;
import com.android.dialer.DialtactsActivity;
import com.android.dialer.R;
import com.android.dialer.calllog.CallLogFragment;
import com.android.dialer.calllog.CallLogNotificationsHelper;
import com.android.dialer.calllog.CallLogQueryHandler;
import com.android.dialer.calllog.VisualVoicemailCallLogFragment;
import com.android.dialer.logging.Logger;
@@ -376,7 +377,8 @@ public class ListsFragment extends Fragment

    /**
     * External method to update unread count because the unread count changes when the user
     * expands a voicemail in the call log.
     * expands a voicemail in the call log or when the user expands an unread call in the call
     * history tab.
     */
    public void updateTabUnreadCounts() {
        if (mCallLogQueryHandler != null) {
@@ -387,6 +389,17 @@ public class ListsFragment extends Fragment
        }
    }

    /**
     * External method to mark all missed calls as read.
     */
    public void markMissedCallsAsReadAndRemoveNotifications() {
        if (mCallLogQueryHandler != null) {
            mCallLogQueryHandler.markMissedCallsAsRead();
            CallLogNotificationsHelper.removeMissedCallNotifications(getActivity());
        }
    }


    public void showRemoveView(boolean show) {
        mRemoveViewContent.setVisibility(show ? View.VISIBLE : View.GONE);
        mRemoveView.setAlpha(show ? 0 : 1);