use of com.android.dialer.speeddial.database.SpeedDialEntry.Channel in project android_packages_apps_Dialer by LineageOS.
the class SpeedDialUiItemMutator method insertDuoChannelsToStarredContact.
@MainThread
private SpeedDialUiItem insertDuoChannelsToStarredContact(Context context, SpeedDialUiItem item) {
Assert.isMainThread();
Assert.checkArgument(item.isStarred());
// build a new list of channels
ImmutableList.Builder<Channel> newChannelsList = ImmutableList.builder();
Channel previousChannel = item.channels().get(0);
newChannelsList.add(previousChannel);
for (int i = 1; i < item.channels().size(); i++) {
Channel currentChannel = item.channels().get(i);
// If the previous number is duo reachable, insert a duo channel.
if (!previousChannel.isVideoTechnology() && !currentChannel.isVideoTechnology() && DuoComponent.get(context).getDuo().isReachable(context, previousChannel.number())) {
newChannelsList.add(previousChannel.toBuilder().setTechnology(Channel.DUO).build());
}
newChannelsList.add(currentChannel);
previousChannel = currentChannel;
}
// Check the last channel
if (!previousChannel.isVideoTechnology() && DuoComponent.get(context).getDuo().isReachable(context, previousChannel.number())) {
newChannelsList.add(previousChannel.toBuilder().setTechnology(Channel.DUO).build());
}
return item.toBuilder().setChannels(newChannelsList.build()).build();
}
use of com.android.dialer.speeddial.database.SpeedDialEntry.Channel in project android_packages_apps_Dialer by LineageOS.
the class SpeedDialUiItem method fromCursor.
/**
* Convert a cursor with projection {@link #getPhoneProjection(boolean)} into a {@link
* SpeedDialUiItem}.
*
* <p>This cursor is structured such that contacts are grouped by contact id and lookup key and
* each row that shares the same contact id and lookup key represents a phone number that belongs
* to a single contact.
*
* <p>If the cursor started at row X, this method will advance to row Y s.t. rows X, X + 1, ... Y
* - 1 all belong to the same contact (that is, share the same contact id and lookup key).
*/
public static SpeedDialUiItem fromCursor(Resources resources, Cursor cursor, boolean isImsEnabled) {
Trace.beginSection("fromCursor");
Assert.checkArgument(cursor != null);
Assert.checkArgument(cursor.getCount() != 0);
String lookupKey = cursor.getString(LOOKUP_KEY);
SpeedDialUiItem.Builder builder = SpeedDialUiItem.builder().setLookupKey(lookupKey).setContactId(cursor.getLong(CONTACT_ID)).setName(cursor.getString(DISPLAY_NAME)).setIsStarred(cursor.getInt(STARRED) == 1).setPhotoId(cursor.getLong(PHOTO_ID)).setPhotoUri(TextUtils.isEmpty(cursor.getString(PHOTO_URI)) ? "" : cursor.getString(PHOTO_URI));
// While there are more rows and the lookup keys are the same, add a channel for each of the
// contact's phone numbers.
List<Channel> channels = new ArrayList<>();
Set<String> numbers = new ArraySet<>();
do {
String number = cursor.getString(NUMBER);
// TODO(78492722): consider using lib phone number to compare numbers
if (!numbers.add(number)) {
// Number is identical to an existing number, skip this number
continue;
}
Channel channel = Channel.builder().setNumber(number).setPhoneType(cursor.getInt(TYPE)).setLabel(getLabel(resources, cursor)).setTechnology(Channel.VOICE).build();
channels.add(channel);
if (isImsEnabled && (cursor.getInt(CARRIER_PRESENCE) & Data.CARRIER_PRESENCE_VT_CAPABLE) == 1) {
// Add another channel if the number is ViLTE reachable
channels.add(channel.toBuilder().setTechnology(Channel.IMS_VIDEO).build());
}
// TODO(a bug): add another channel for Duo (needs to happen on main thread)
} while (cursor.moveToNext() && Objects.equals(lookupKey, cursor.getString(LOOKUP_KEY)));
builder.setChannels(ImmutableList.copyOf(channels));
Trace.endSection();
return builder.build();
}
use of com.android.dialer.speeddial.database.SpeedDialEntry.Channel in project android_packages_apps_Dialer by LineageOS.
the class FavoritesViewHolder method bind.
public void bind(Context context, SpeedDialUiItem speedDialUiItem) {
this.speedDialUiItem = Assert.isNotNull(speedDialUiItem);
Assert.checkArgument(speedDialUiItem.isStarred());
nameView.setText(speedDialUiItem.name());
Channel channel = speedDialUiItem.defaultChannel();
if (channel == null) {
channel = speedDialUiItem.getDefaultVoiceChannel();
}
if (channel != null) {
phoneType.setText(channel.label());
videoCallIcon.setVisibility(channel.isVideoTechnology() ? View.VISIBLE : View.GONE);
} else {
phoneType.setText("");
videoCallIcon.setVisibility(View.GONE);
}
GlidePhotoManagerComponent.get(context).glidePhotoManager().loadQuickContactBadge(photoView, PhotoInfo.newBuilder().setPhotoId(speedDialUiItem.photoId()).setPhotoUri(speedDialUiItem.photoUri()).setName(speedDialUiItem.name()).setLookupUri(Contacts.getLookupUri(speedDialUiItem.contactId(), speedDialUiItem.lookupKey()).toString()).build());
}
use of com.android.dialer.speeddial.database.SpeedDialEntry.Channel in project android_packages_apps_Dialer by LineageOS.
the class SpeedDialUiItemMutator method getSpeedDialUiItemsFromEntries.
/**
* Returns a map of SpeedDialEntries to their corresponding SpeedDialUiItems. Mappings to null
* elements imply that the contact was deleted.
*/
@WorkerThread
private Map<SpeedDialEntry, SpeedDialUiItem> getSpeedDialUiItemsFromEntries(List<SpeedDialEntry> entries) {
Trace.beginSection("getSpeedDialUiItemsFromEntries");
Assert.isWorkerThread();
// Fetch the contact ids from the SpeedDialEntries
Set<String> contactIds = new ArraySet<>();
entries.forEach(entry -> contactIds.add(Long.toString(entry.contactId())));
if (contactIds.isEmpty()) {
Trace.endSection();
return new ArrayMap<>();
}
// Build SpeedDialUiItems from those contact ids and map them to their entries
Selection selection = Selection.builder().and(Selection.column(Phone.CONTACT_ID).in(contactIds)).build();
try (Cursor cursor = appContext.getContentResolver().query(Phone.CONTENT_URI, SpeedDialUiItem.getPhoneProjection(isPrimaryDisplayNameOrder()), selection.getSelection(), selection.getSelectionArgs(), null)) {
Map<SpeedDialEntry, SpeedDialUiItem> map = new ArrayMap<>();
for (cursor.moveToFirst(); !cursor.isAfterLast(); ) /* Iterate in the loop */
{
SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor, CallUtil.isVideoEnabled(appContext));
for (SpeedDialEntry entry : entries) {
if (entry.contactId() == item.contactId()) {
// Update the id and pinned position to match it's corresponding SpeedDialEntry.
SpeedDialUiItem.Builder entrySpeedDialItem = item.toBuilder().setSpeedDialEntryId(entry.id()).setPinnedPosition(entry.pinnedPosition());
// Preserve the default channel if it didn't change/still exists
Channel defaultChannel = entry.defaultChannel();
if (defaultChannel != null) {
if (item.channels().contains(defaultChannel) || isValidDuoDefaultChannel(item.channels(), defaultChannel)) {
entrySpeedDialItem.setDefaultChannel(defaultChannel);
}
}
// It's impossible for two contacts to exist with the same contact id, so if this entry
// was previously matched to a SpeedDialUiItem and is being matched again, something
// went horribly wrong.
Assert.checkArgument(map.put(entry, entrySpeedDialItem.build()) == null, "Each SpeedDialEntry only has one correct SpeedDialUiItem");
}
}
}
// Contact must have been deleted
for (SpeedDialEntry entry : entries) {
map.putIfAbsent(entry, null);
}
Trace.endSection();
return map;
}
}
use of com.android.dialer.speeddial.database.SpeedDialEntry.Channel in project android_packages_apps_Dialer by LineageOS.
the class SpeedDialEntryDatabaseHelper method getAllEntries.
@Override
public ImmutableList<SpeedDialEntry> getAllEntries() {
List<SpeedDialEntry> entries = new ArrayList<>();
String query = "SELECT * FROM " + TABLE_NAME;
try (SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery(query, null)) {
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
String number = cursor.getString(POSITION_PHONE_NUMBER);
Channel channel = null;
if (!TextUtils.isEmpty(number)) {
channel = Channel.builder().setNumber(number).setPhoneType(cursor.getInt(POSITION_PHONE_TYPE)).setLabel(Optional.of(cursor.getString(POSITION_PHONE_LABEL)).or("")).setTechnology(cursor.getInt(POSITION_PHONE_TECHNOLOGY)).build();
}
Optional<Integer> pinnedPosition = Optional.of(cursor.getInt(POSITION_PINNED_POSITION));
if (pinnedPosition.or(PINNED_POSITION_ABSENT) == PINNED_POSITION_ABSENT) {
pinnedPosition = Optional.absent();
}
SpeedDialEntry entry = SpeedDialEntry.builder().setDefaultChannel(channel).setContactId(cursor.getLong(POSITION_CONTACT_ID)).setLookupKey(cursor.getString(POSITION_LOOKUP_KEY)).setPinnedPosition(pinnedPosition).setId(cursor.getLong(POSITION_ID)).build();
entries.add(entry);
}
}
return ImmutableList.copyOf(entries);
}
Aggregations