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

Commit 45f23d4d authored by Paul Sliwowski's avatar Paul Sliwowski
Browse files

Remove StreamIteams from loader and disable social updates from UI.

Bug: 10328519
Change-Id: I7df4d66ed3297f38b187fa9f3091bcfc3d4466b9
parent 949c7fc1
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -55,9 +55,6 @@ import java.util.ArrayList;
public class ContactDetailActivity extends ContactsActivity {
    private static final String TAG = "ContactDetailActivity";

    /** Shows a toogle button for hiding/showing updates. Don't submit with true */
    private static final boolean DEBUG_TRANSITIONS = false;

    private Contact mContactData;
    private Uri mLookupUri;

@@ -126,19 +123,6 @@ public class ContactDetailActivity extends ContactsActivity {
        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.star, menu);
        if (DEBUG_TRANSITIONS) {
            final MenuItem toggleSocial =
                    menu.add(mLoaderFragment.getLoadStreamItems() ? "less" : "more");
            toggleSocial.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            toggleSocial.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    mLoaderFragment.toggleLoadStreamItems();
                    invalidateOptionsMenu();
                    return false;
                }
            });
        }
        return true;
    }

+0 −17
Original line number Diff line number Diff line
@@ -109,9 +109,6 @@ public class PeopleActivity extends ContactsActivity

    private static final String TAG = "PeopleActivity";

    /** Shows a toogle button for hiding/showing updates. Don't submit with true */
    private static final boolean DEBUG_TRANSITIONS = false;

    private static final int TAB_FADE_IN_DURATION = 500;

    private static final String ENABLE_DEBUG_OPTIONS_HIDDEN_CODE = "debug debug!";
@@ -1376,20 +1373,6 @@ public class PeopleActivity extends ContactsActivity
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.people_options, menu);

        if (DEBUG_TRANSITIONS && mContactDetailLoaderFragment != null) {
            final MenuItem toggleSocial =
                    menu.add(mContactDetailLoaderFragment.getLoadStreamItems() ? "less" : "more");
            toggleSocial.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            toggleSocial.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    mContactDetailLoaderFragment.toggleLoadStreamItems();
                    invalidateOptionsMenu();
                    return false;
                }
            });
        }

        return true;
    }

+2 −16
Original line number Diff line number Diff line
@@ -186,8 +186,8 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
        public Loader<Contact> onCreateLoader(int id, Bundle args) {
            Uri lookupUri = args.getParcelable(LOADER_ARG_CONTACT_URI);
            return new ContactLoader(mContext, lookupUri, true /* loadGroupMetaData */,
                    true /* loadStreamItems */, true /* load invitable account types */,
                    true /* postViewNotification */, true /* computeFormattedPhoneNumber */);
                    true /* load invitable account types */, true /* postViewNotification */,
                    true /* computeFormattedPhoneNumber */);
        }

        @Override
@@ -467,18 +467,4 @@ public class ContactLoaderFragment extends Fragment implements FragmentKeyListen
                mContext, mLookupUri, mCustomRingtone);
        mContext.startService(intent);
    }

    /** Toggles whether to load stream items. Just for debugging */
    public void toggleLoadStreamItems() {
        Loader<Contact> loaderObj = getLoaderManager().getLoader(LOADER_DETAILS);
        ContactLoader loader = (ContactLoader) loaderObj;
        loader.setLoadStreamItems(!loader.getLoadStreamItems());
    }

    /** Returns whether to load stream items. Just for debugging */
    public boolean getLoadStreamItems() {
        Loader<Contact> loaderObj = getLoaderManager().getLoader(LOADER_DETAILS);
        ContactLoader loader = (ContactLoader) loaderObj;
        return loader != null && loader.getLoadStreamItems();
    }
}
+2 −9
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import java.util.ArrayList;
import java.util.Collections;

/**
 * A Contact represents a single person or logical entity as perceived by the user.  The information
@@ -72,7 +73,6 @@ public class Contact {
    private final boolean mStarred;
    private final Integer mPresence;
    private ImmutableList<RawContact> mRawContacts;
    private ImmutableList<StreamItemEntry> mStreamItems;
    private ImmutableMap<Long,DataStatus> mStatuses;
    private ImmutableList<AccountType> mInvitableAccountTypes;

@@ -108,7 +108,6 @@ public class Contact {
        mLookupKey = null;
        mId = -1;
        mRawContacts = null;
        mStreamItems = null;
        mStatuses = null;
        mNameRawContactId = -1;
        mDisplayNameSource = DisplayNameSources.UNDEFINED;
@@ -150,7 +149,6 @@ public class Contact {
        mLookupKey = lookupKey;
        mId = id;
        mRawContacts = null;
        mStreamItems = null;
        mStatuses = null;
        mNameRawContactId = nameRawContactId;
        mDisplayNameSource = displayNameSource;
@@ -187,7 +185,6 @@ public class Contact {
        mStarred = from.mStarred;
        mPresence = from.mPresence;
        mRawContacts = from.mRawContacts;
        mStreamItems = from.mStreamItems;
        mStatuses = from.mStatuses;
        mInvitableAccountTypes = from.mInvitableAccountTypes;

@@ -354,7 +351,7 @@ public class Contact {
     * @return
     */
    public ImmutableList<StreamItemEntry> getStreamItems() {
        return mStreamItems;
        return ImmutableList.of();
    }

    public ImmutableMap<Long, DataStatus> getStatuses() {
@@ -484,8 +481,4 @@ public class Contact {
    /* package */ void setGroupMetaData(ImmutableList<GroupMetaData> groups) {
        mGroups = groups;
    }

    /* package */ void setStreamItems(ImmutableList<StreamItemEntry> streamItems) {
        mStreamItems = streamItems;
    }
}
+3 −113
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
    private final Uri mRequestedUri;
    private Uri mLookupUri;
    private boolean mLoadGroupMetaData;
    private boolean mLoadStreamItems;
    private boolean mLoadInvitableAccountTypes;
    private boolean mPostViewNotification;
    private boolean mComputeFormattedPhoneNumber;
@@ -91,17 +90,16 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
    private final Set<Long> mNotifiedRawContactIds = Sets.newHashSet();

    public ContactLoader(Context context, Uri lookupUri, boolean postViewNotification) {
        this(context, lookupUri, false, false, false, postViewNotification, false);
        this(context, lookupUri, false, false, postViewNotification, false);
    }

    public ContactLoader(Context context, Uri lookupUri, boolean loadGroupMetaData,
            boolean loadStreamItems, boolean loadInvitableAccountTypes,
            boolean loadInvitableAccountTypes,
            boolean postViewNotification, boolean computeFormattedPhoneNumber) {
        super(context);
        mLookupUri = lookupUri;
        mRequestedUri = lookupUri;
        mLoadGroupMetaData = loadGroupMetaData;
        mLoadStreamItems = loadStreamItems;
        mLoadInvitableAccountTypes = loadInvitableAccountTypes;
        mPostViewNotification = postViewNotification;
        mComputeFormattedPhoneNumber = computeFormattedPhoneNumber;
@@ -331,9 +329,6 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
                        loadGroupMetaData(result);
                    }
                }
                if (mLoadStreamItems && result.getStreamItems() == null) {
                    loadStreamItems(result);
                }
                if (mComputeFormattedPhoneNumber) {
                    computeFormattedPhoneNumbers(result);
                }
@@ -710,95 +705,6 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        result.setGroupMetaData(groupListBuilder.build());
    }

    /**
     * Loads all stream items and stream item photos belonging to this contact.
     */
    private void loadStreamItems(Contact result) {
        final Cursor cursor = getContext().getContentResolver().query(
                Contacts.CONTENT_LOOKUP_URI.buildUpon()
                        .appendPath(result.getLookupKey())
                        .appendPath(Contacts.StreamItems.CONTENT_DIRECTORY).build(),
                null, null, null, null);
        final LongSparseArray<StreamItemEntry> streamItemsById =
                new LongSparseArray<StreamItemEntry>();
        final ArrayList<StreamItemEntry> streamItems = new ArrayList<StreamItemEntry>();
        try {
            while (cursor.moveToNext()) {
                StreamItemEntry streamItem = new StreamItemEntry(cursor);
                streamItemsById.put(streamItem.getId(), streamItem);
                streamItems.add(streamItem);
            }
        } finally {
            cursor.close();
        }

        // Pre-decode all HTMLs
        final long start = System.currentTimeMillis();
        for (StreamItemEntry streamItem : streamItems) {
            streamItem.decodeHtml(getContext());
        }
        final long end = System.currentTimeMillis();
        if (DEBUG) {
            Log.d(TAG, "Decoded HTML for " + streamItems.size() + " items, took "
                    + (end - start) + " ms");
        }

        // Now retrieve any photo records associated with the stream items.
        if (!streamItems.isEmpty()) {
            if (result.isUserProfile()) {
                // If the stream items we're loading are for the profile, we can't bulk-load the
                // stream items with a custom selection.
                for (StreamItemEntry entry : streamItems) {
                    Cursor siCursor = getContext().getContentResolver().query(
                            Uri.withAppendedPath(
                                    ContentUris.withAppendedId(
                                            StreamItems.CONTENT_URI, entry.getId()),
                                    StreamItems.StreamItemPhotos.CONTENT_DIRECTORY),
                            null, null, null, null);
                    try {
                        while (siCursor.moveToNext()) {
                            entry.addPhoto(new StreamItemPhotoEntry(siCursor));
                        }
                    } finally {
                        siCursor.close();
                    }
                }
            } else {
                String[] streamItemIdArr = new String[streamItems.size()];
                StringBuilder streamItemPhotoSelection = new StringBuilder();
                streamItemPhotoSelection.append(StreamItemPhotos.STREAM_ITEM_ID + " IN (");
                for (int i = 0; i < streamItems.size(); i++) {
                    if (i > 0) {
                        streamItemPhotoSelection.append(",");
                    }
                    streamItemPhotoSelection.append("?");
                    streamItemIdArr[i] = String.valueOf(streamItems.get(i).getId());
                }
                streamItemPhotoSelection.append(")");
                Cursor sipCursor = getContext().getContentResolver().query(
                        StreamItems.CONTENT_PHOTO_URI,
                        null, streamItemPhotoSelection.toString(), streamItemIdArr,
                        StreamItemPhotos.STREAM_ITEM_ID);
                try {
                    while (sipCursor.moveToNext()) {
                        long streamItemId = sipCursor.getLong(
                                sipCursor.getColumnIndex(StreamItemPhotos.STREAM_ITEM_ID));
                        StreamItemEntry streamItem = streamItemsById.get(streamItemId);
                        streamItem.addPhoto(new StreamItemPhotoEntry(sipCursor));
                    }
                } finally {
                    sipCursor.close();
                }
            }
        }

        // Set the sorted stream items on the result.
        Collections.sort(streamItems);
        result.setStreamItems(new ImmutableList.Builder<StreamItemEntry>()
                .addAll(streamItems.iterator())
                .build());
    }

    /**
     * Iterates over all data items that represent phone numbers are tries to calculate a formatted
     * number. This function can safely be called several times as no unformatted data is
@@ -891,29 +797,17 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        }
    }

    /**
     * Sets whether to load stream items. Will trigger a reload if the value has changed.
     * At the moment, this is only used for debugging purposes
     */
    public void setLoadStreamItems(boolean value) {
        if (mLoadStreamItems != value) {
            mLoadStreamItems = value;
            onContentChanged();
        }
    }

    /**
     * Fully upgrades this ContactLoader to one with all lists fully loaded. When done, the
     * new result will be delivered
     */
    public void upgradeToFullContact() {
        // Everything requested already? Nothing to do, so let's bail out
        if (mLoadGroupMetaData && mLoadInvitableAccountTypes && mLoadStreamItems
        if (mLoadGroupMetaData && mLoadInvitableAccountTypes
                && mPostViewNotification && mComputeFormattedPhoneNumber) return;

        mLoadGroupMetaData = true;
        mLoadInvitableAccountTypes = true;
        mLoadStreamItems = true;
        mPostViewNotification = true;
        mComputeFormattedPhoneNumber = true;

@@ -925,10 +819,6 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
        onContentChanged();
    }

    public boolean getLoadStreamItems() {
        return mLoadStreamItems;
    }

    public Uri getLookupUri() {
        return mLookupUri;
    }
Loading