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

Commit 30e1ef19 authored by Brian Attwell's avatar Brian Attwell
Browse files

Move contactInteractionsToEntries() off UI thread

This removes one missed frame from QuickContactActivity's entrance
scroll animation. There is still one more frame that will be missed
because of the re-measuring that occurs after setting the recentCard
and aboutCard VISIBLE.

Bug: 17360983
Change-Id: I7ff6af6de92a984b9d5b38fc33e1de785cd894fd
parent 1deb532f
Loading
Loading
Loading
Loading
+57 −29
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.Toolbar;

@@ -208,6 +207,7 @@ public class QuickContactActivity extends ContactsActivity {
    private MultiShrinkScroller mScroller;
    private SelectAccountDialogFragmentListener mSelectAccountFragmentListener;
    private AsyncTask<Void, Void, Cp2DataCardModel> mEntriesAndActionsTask;
    private AsyncTask<Void, Void, Void> mRecentDataTask;
    /**
     * The last copy of Cp2DataCardModel that was passed to {@link #populateContactAndAboutCard}.
     */
@@ -1746,6 +1746,13 @@ public class QuickContactActivity extends ContactsActivity {

    private void bindRecentData() {
        final List<ContactInteraction> allInteractions = new ArrayList<>();
        final List<List<Entry>> interactionsWrapper = new ArrayList<>();

        mRecentDataTask = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                Trace.beginSection("sort recent loader results");

                for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) {
                    allInteractions.addAll(loaderInteractions);
                }
@@ -1758,13 +1765,25 @@ public class QuickContactActivity extends ContactsActivity {
                    }
                });

                Trace.endSection();
                Trace.beginSection("contactInteractionsToEntries");

                // Wrap each interaction in its own list so that an icon is displayed for each entry
        List<List<Entry>> interactionsWrapper = new ArrayList<>();
                for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) {
                    List<Entry> entryListWrapper = new ArrayList<>(1);
                    entryListWrapper.add(contactInteraction);
                    interactionsWrapper.add(entryListWrapper);
                }

                Trace.endSection();
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                Trace.beginSection("initialize recents card");

                if (allInteractions.size() > 0) {
                    mRecentCard.initialize(interactionsWrapper,
                    /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN,
@@ -1773,14 +1792,20 @@ public class QuickContactActivity extends ContactsActivity {
                    mRecentCard.setVisibility(View.VISIBLE);
                }

                Trace.endSection();

                // About card is initialized along with the contact card, but since it appears after
        // the recent card in the UI, we hold off until making it visible until the recent card
        // is also ready to avoid stuttering.
                // the recent card in the UI, we hold off until making it visible until the recent
                // card is also ready to avoid stuttering.
                if (mAboutCard.shouldShow()) {
                    mAboutCard.setVisibility(View.VISIBLE);
                } else {
                    mAboutCard.setVisibility(View.GONE);
                }
                mRecentDataTask = null;
            }
        };
        mRecentDataTask.execute();
    }

    @Override
@@ -1794,6 +1819,9 @@ public class QuickContactActivity extends ContactsActivity {
            // the entire process will be killed.
            mEntriesAndActionsTask.cancel(/* mayInterruptIfRunning = */ false);
        }
        if (mRecentDataTask != null) {
            mRecentDataTask.cancel(/* mayInterruptIfRunning = */ false);
        }
    }

    /**