Search in sources :

Example 6 with SpeedDialEntry

use of com.android.dialer.speeddial.database.SpeedDialEntry in project android_packages_apps_Dialer by LineageOS.

the class SpeedDialUiItemMutator method loadSpeedDialUiItemsInternal.

@WorkerThread
private ImmutableList<SpeedDialUiItem> loadSpeedDialUiItemsInternal() {
    Trace.beginSection("loadSpeedDialUiItemsInternal");
    Assert.isWorkerThread();
    Trace.beginSection("getAllEntries");
    SpeedDialEntryDao db = getSpeedDialEntryDao();
    // getAllEntries
    Trace.endSection();
    // This is the list of contacts that we will display to the user
    List<SpeedDialUiItem> speedDialUiItems = new ArrayList<>();
    // We'll use these lists to update the SpeedDialEntry database
    List<SpeedDialEntry> entriesToInsert = new ArrayList<>();
    List<SpeedDialEntry> entriesToUpdate = new ArrayList<>();
    List<Long> entriesToDelete = new ArrayList<>();
    // Get all SpeedDialEntries and update their contact ids and lookupkeys.
    List<SpeedDialEntry> entries = db.getAllEntries();
    entries = updateContactIdsAndLookupKeys(entries);
    // Build SpeedDialUiItems from our updated entries.
    Map<SpeedDialEntry, SpeedDialUiItem> entriesToUiItems = getSpeedDialUiItemsFromEntries(entries);
    Assert.checkArgument(entries.size() == entriesToUiItems.size(), "Updated entries are incomplete: " + entries.size() + " != " + entriesToUiItems.size());
    // Mark the SpeedDialEntries to be updated or deleted
    Trace.beginSection("updateOrDeleteEntries");
    for (SpeedDialEntry entry : entries) {
        SpeedDialUiItem contact = entriesToUiItems.get(entry);
        // Remove contacts that no longer exist or are no longer starred
        if (contact == null || !contact.isStarred()) {
            entriesToDelete.add(entry.id());
            continue;
        }
        // Contact exists, so update its entry in SpeedDialEntry Database
        entriesToUpdate.add(entry.toBuilder().setLookupKey(contact.lookupKey()).setContactId(contact.contactId()).setDefaultChannel(contact.defaultChannel()).build());
        // These are our existing starred entries
        speedDialUiItems.add(contact);
    }
    // updateOrDeleteEntries
    Trace.endSection();
    // Get all starred contacts
    List<SpeedDialUiItem> starredContacts = getStarredContacts();
    // If it is starred and not already accounted for above, then insert into the SpeedDialEntry DB.
    Trace.beginSection("addStarredContact");
    for (SpeedDialUiItem contact : starredContacts) {
        if (speedDialUiItems.stream().noneMatch(c -> c.contactId() == contact.contactId())) {
            entriesToInsert.add(contact.buildSpeedDialEntry());
            // These are our newly starred contacts
            speedDialUiItems.add(contact);
        }
    }
    // addStarredContact
    Trace.endSection();
    Trace.beginSection("insertUpdateAndDelete");
    requestHighResolutionPhoto(entriesToInsert);
    ImmutableMap<SpeedDialEntry, Long> insertedEntriesToIdsMap = db.insertUpdateAndDelete(ImmutableList.copyOf(entriesToInsert), ImmutableList.copyOf(entriesToUpdate), ImmutableList.copyOf(entriesToDelete));
    // insertUpdateAndDelete
    Trace.endSection();
    // loadSpeedDialUiItemsInternal
    Trace.endSection();
    return speedDialUiItemsWithUpdatedIds(speedDialUiItems, insertedEntriesToIdsMap);
}
Also used : SpeedDialEntryDao(com.android.dialer.speeddial.database.SpeedDialEntryDao) SpeedDialEntry(com.android.dialer.speeddial.database.SpeedDialEntry) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread)

Example 7 with SpeedDialEntry

use of com.android.dialer.speeddial.database.SpeedDialEntry in project android_packages_apps_Dialer by LineageOS.

the class SpeedDialUiItemMutator method requestHighResolutionPhoto.

@WorkerThread
private void requestHighResolutionPhoto(List<SpeedDialEntry> newEntries) {
    ContactsComponent.get(appContext).highResolutionPhotoLoader();
    for (SpeedDialEntry entry : newEntries) {
        Uri uri;
        uri = Contacts.getLookupUri(entry.contactId(), entry.lookupKey());
        Futures.addCallback(highResolutionPhotoRequester.request(uri), new DefaultFutureCallback<>(), MoreExecutors.directExecutor());
    }
}
Also used : SpeedDialEntry(com.android.dialer.speeddial.database.SpeedDialEntry) Uri(android.net.Uri) WorkerThread(android.support.annotation.WorkerThread)

Example 8 with SpeedDialEntry

use of com.android.dialer.speeddial.database.SpeedDialEntry in project android_packages_apps_Dialer by LineageOS.

the class SpeedDialUiItemMutator method speedDialUiItemsWithUpdatedIds.

/**
 * Since newly starred contacts sometimes aren't in the SpeedDialEntry database, we couldn't set
 * their ids when we created our initial list of {@link SpeedDialUiItem speedDialUiItems}. Now
 * that we've inserted the entries into the database and we have their ids, build a new list of
 * speedDialUiItems with the now known ids.
 */
private ImmutableList<SpeedDialUiItem> speedDialUiItemsWithUpdatedIds(List<SpeedDialUiItem> speedDialUiItems, ImmutableMap<SpeedDialEntry, Long> insertedEntriesToIdsMap) {
    if (insertedEntriesToIdsMap.isEmpty()) {
        // There were no newly inserted entries, so all entries ids are set already.
        return ImmutableList.copyOf(speedDialUiItems);
    }
    ImmutableList.Builder<SpeedDialUiItem> updatedItems = ImmutableList.builder();
    for (SpeedDialUiItem speedDialUiItem : speedDialUiItems) {
        SpeedDialEntry entry = speedDialUiItem.buildSpeedDialEntry();
        if (insertedEntriesToIdsMap.containsKey(entry)) {
            // Get the id for newly inserted entry, update our SpeedDialUiItem and add it to our list
            Long id = Assert.isNotNull(insertedEntriesToIdsMap.get(entry));
            updatedItems.add(speedDialUiItem.toBuilder().setSpeedDialEntryId(id).build());
            continue;
        }
        // Starred contacts that aren't in the map, should already have speed dial entry ids.
        // Non-starred contacts aren't in the speed dial entry database, so they
        // shouldn't have speed dial entry ids.
        Assert.checkArgument(speedDialUiItem.isStarred() == (speedDialUiItem.speedDialEntryId() != null), "Contact must be starred with a speed dial entry id, or not starred with no id " + "(suggested contacts)");
        updatedItems.add(speedDialUiItem);
    }
    return updatedItems.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SpeedDialEntry(com.android.dialer.speeddial.database.SpeedDialEntry)

Aggregations

SpeedDialEntry (com.android.dialer.speeddial.database.SpeedDialEntry)8 WorkerThread (android.support.annotation.WorkerThread)7 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 Uri (android.net.Uri)2 ArraySet (android.util.ArraySet)2 SpeedDialEntryDao (com.android.dialer.speeddial.database.SpeedDialEntryDao)2 ImmutableList (com.google.common.collect.ImmutableList)2 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentValues (android.content.ContentValues)1 OperationApplicationException (android.content.OperationApplicationException)1 RemoteException (android.os.RemoteException)1 ArrayMap (android.util.ArrayMap)1 Selection (com.android.dialer.common.database.Selection)1 Channel (com.android.dialer.speeddial.database.SpeedDialEntry.Channel)1 SpeedDialEntryDatabaseHelper (com.android.dialer.speeddial.database.SpeedDialEntryDatabaseHelper)1