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

Commit 21299c35 authored by Yorke Lee's avatar Yorke Lee
Browse files

Fix missed calls not updating properly

This fix updates the new/old state of missed calls in the call log
properly once more.

Instead of using this flag to track whether or not to show the call
shortcut, we store a date in Dialer's shared preferences to allow
us to only show call shortcuts newer than a certain date.

Bug: 10780687
Change-Id: Icc03992a65512a85dc6673c431ded34c73b6ba2b
parent f796309c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -432,8 +432,7 @@ public class CallLogFragment extends ListFragment
        updateOnTransition(true);
    }

    // TODO krelease: Figure out if we still need this. If so, it should be probably be moved to
    // the call log activity instead, or done only in a single call log fragment.
    // 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.
@@ -441,6 +440,7 @@ public class CallLogFragment extends ListFragment
        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 (!onEntry) {
                mCallLogQueryHandler.markMissedCallsAsRead();
            }
+16 −13
Original line number Diff line number Diff line
@@ -138,22 +138,14 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler {
     * <p>
     * It will asynchronously update the content of the list view when the fetch completes.
     */
    public void fetchCalls(int callType) {
    public void fetchCalls(int callType, long newerThan) {
        cancelFetch();
        int requestId = newCallsRequest();
        fetchCalls(QUERY_CALLLOG_TOKEN, requestId, callType , false /* newOnly */);
        fetchCalls(QUERY_CALLLOG_TOKEN, requestId, callType, false /* newOnly */, newerThan);
    }

    /**
     * Fetches the list of calls from the call log for a given type.
     * This call fetches only the new (i.e. NEW = 1) ones.
     * <p>
     * It will asynchronously update the content of the list view when the fetch completes.
     */
    public void fetchNewCalls(int callType) {
        cancelFetch();
        int requestId = newCallsRequest();
        fetchCalls(QUERY_CALLLOG_TOKEN, requestId, callType , true /* newOnly */);
    public void fetchCalls(int callType) {
        fetchCalls(callType, 0);
    }

    public void fetchVoicemailStatus() {
@@ -162,7 +154,8 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler {
    }

    /** Fetches the list of calls in the call log. */
    private void fetchCalls(int token, int requestId, int callType, boolean newOnly) {
    private void fetchCalls(int token, int requestId, int callType, boolean newOnly,
            long newerThan) {
        // We need to check for NULL explicitly otherwise entries with where READ is NULL
        // may not match either the query or its negation.
        // We consider the calls that are not yet consumed (i.e. IS_READ = 0) as "new".
@@ -180,8 +173,18 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler {
            }
            // Add a clause to fetch only items of type voicemail.
            where.append(String.format("(%s = ?)", Calls.TYPE));
            // Add a clause to fetch only items newer than the requested date
            selectionArgs.add(Integer.toString(callType));
        }

        if (newerThan > 0) {
            if (where.length() > 0) {
                where.append(" AND ");
            }
            where.append(String.format("(%s > ?)", Calls.DATE));
            selectionArgs.add(Long.toString(newerThan));
        }

        final int limit = (mLogLimit == -1) ? NUM_LOGS_TO_DISPLAY : mLogLimit;
        final String selection = where.length() > 0 ? where.toString() : null;
        Uri uri = Calls.CONTENT_URI_WITH_VOICEMAIL.buildUpon()
+42 −2
Original line number Diff line number Diff line
@@ -18,9 +18,12 @@ package com.android.dialer.list;
import android.app.Activity;
import android.app.Fragment;
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.database.MatrixCursor;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
@@ -41,7 +44,9 @@ import com.android.contacts.common.ContactTileLoaderFactory;
import com.android.contacts.common.GeoUtil;
import com.android.contacts.common.list.ContactEntry;
import com.android.contacts.common.list.ContactTileView;
import com.android.dialer.DialtactsActivity;
import com.android.dialer.R;
import com.android.dialer.calllog.CallLogQuery;
import com.android.dialer.calllog.ContactInfoHelper;
import com.android.dialer.calllog.CallLogAdapter;
import com.android.dialer.calllog.CallLogQueryHandler;
@@ -73,6 +78,9 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
     */
    private static int LOADER_ID_CONTACT_TILE = 1;

    private static final String KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE =
            "key_last_dismissed_call_shortcut_date";

    public interface OnShowAllContactsListener {
        public void onShowAllContacts();
    }
@@ -156,6 +164,17 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
     */
    private View mEmptyView;

    /**
     * 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 final ContactTileView.Listener mContactTileAdapterListener =
            new ContactTileAdapterListener();
    private final LoaderManager.LoaderCallbacks<Cursor> mContactTileLoaderListener =
@@ -193,6 +212,11 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
    @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);
        getLoaderManager().getLoader(LOADER_ID_CONTACT_TILE).forceLoad();
@@ -225,7 +249,7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
        });

        mContactTileAdapter.setEmptyView(mEmptyView);
        mAdapter = new PhoneFavoriteMergedAdapter(getActivity(), mContactTileAdapter,
        mAdapter = new PhoneFavoriteMergedAdapter(getActivity(), this, mContactTileAdapter,
                mCallLogAdapter, mShowAllContactsButton);

        mListView.setAdapter(mAdapter);
@@ -302,13 +326,20 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
    @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);

        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void fetchCalls() {
        mCallLogQueryHandler.fetchNewCalls(CallLogQueryHandler.CALL_TYPE_ALL);
        mCallLogQueryHandler.fetchCalls(CallLogQueryHandler.CALL_TYPE_ALL, mLastCallShortcutDate);
    }

    @Override
@@ -479,4 +510,13 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
    public void cacheOffsetsForDatasetChange() {
        saveOffsets();
    }

    public void dismissShortcut() {
        mLastCallShortcutDate = mCurrentCallShortcutDate;
        final SharedPreferences prefs = getActivity().getSharedPreferences(
                DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
        prefs.edit().putLong(KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE, mLastCallShortcutDate)
                .apply();
        fetchCalls();
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter {
    private final PhoneFavoritesTileAdapter mContactTileAdapter;
    private final CallLogAdapter mCallLogAdapter;
    private final View mShowAllContactsButton;
    private final PhoneFavoriteFragment mFragment;

    private final int mCallLogPadding;

@@ -70,7 +71,7 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter {
            mCallLogQueryHandler.markNewVoicemailsAsOld();
            CallLogNotificationsHelper.removeMissedCallNotifications();
            CallLogNotificationsHelper.updateVoicemailNotifications(mContext);
            mCallLogQueryHandler.fetchNewCalls(CallLogQueryHandler.CALL_TYPE_ALL);
            mFragment.dismissShortcut();
        }

        @Override
@@ -96,11 +97,13 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter {
    };

    public PhoneFavoriteMergedAdapter(Context context,
            PhoneFavoriteFragment fragment,
            PhoneFavoritesTileAdapter contactTileAdapter,
            CallLogAdapter callLogAdapter,
            View showAllContactsButton) {
        final Resources resources = context.getResources();
        mContext = context;
        mFragment = fragment;
        mCallLogPadding = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding);
        mContactTileAdapter = contactTileAdapter;
        mCallLogAdapter = callLogAdapter;