Search in sources :

Example 1 with SpeedDialEntryDao

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

the class SpeedDialUiItemMutator method removeStarredSpeedDialUiItem.

/**
 * Delete the SpeedDialEntry associated with the passed in SpeedDialUiItem. Additionally, if the
 * entry being deleted is the only entry for that contact, unstar it in the cp2.
 */
@WorkerThread
private void removeStarredSpeedDialUiItem(SpeedDialUiItem speedDialUiItem) {
    Assert.isWorkerThread();
    Assert.checkArgument(speedDialUiItem.isStarred());
    SpeedDialEntryDao db = getSpeedDialEntryDao();
    ImmutableList<SpeedDialEntry> entries = db.getAllEntries();
    SpeedDialEntry entryToDelete = null;
    int entriesForTheSameContact = 0;
    for (SpeedDialEntry entry : entries) {
        if (entry.contactId() == speedDialUiItem.contactId()) {
            entriesForTheSameContact++;
        }
        if (Objects.equals(entry.id(), speedDialUiItem.speedDialEntryId())) {
            Assert.checkArgument(entryToDelete == null);
            entryToDelete = entry;
        }
    }
    db.delete(ImmutableList.of(entryToDelete.id()));
    if (entriesForTheSameContact == 1) {
        unstarContact(speedDialUiItem);
    }
}
Also used : SpeedDialEntryDao(com.android.dialer.speeddial.database.SpeedDialEntryDao) SpeedDialEntry(com.android.dialer.speeddial.database.SpeedDialEntry) WorkerThread(android.support.annotation.WorkerThread)

Example 2 with SpeedDialEntryDao

use of com.android.dialer.speeddial.database.SpeedDialEntryDao 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)

Aggregations

WorkerThread (android.support.annotation.WorkerThread)2 SpeedDialEntry (com.android.dialer.speeddial.database.SpeedDialEntry)2 SpeedDialEntryDao (com.android.dialer.speeddial.database.SpeedDialEntryDao)2 ArrayList (java.util.ArrayList)1