Search in sources :

Example 1 with MaterialColor

use of org.thoughtcrime.securesms.color.MaterialColor in project Signal-Android by WhisperSystems.

the class AvatarImageView method setAvatar.

public void setAvatar(@Nullable final Recipients recipients, boolean quickContactEnabled) {
    if (recipients != null) {
        MaterialColor backgroundColor = recipients.getColor();
        setImageDrawable(recipients.getContactPhoto().asDrawable(getContext(), backgroundColor.toConversationColor(getContext()), inverted));
        setAvatarClickHandler(recipients, quickContactEnabled);
    } else {
        setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(null).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted));
        setOnClickListener(null);
    }
}
Also used : MaterialColor(org.thoughtcrime.securesms.color.MaterialColor)

Example 2 with MaterialColor

use of org.thoughtcrime.securesms.color.MaterialColor in project Signal-Android by WhisperSystems.

the class RecipientPreferenceDatabase method getRecipientsPreferences.

public Optional<RecipientsPreferences> getRecipientsPreferences(@NonNull long[] recipients) {
    Arrays.sort(recipients);
    SQLiteDatabase database = databaseHelper.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = database.query(TABLE_NAME, null, RECIPIENT_IDS + " = ?", new String[] { Util.join(recipients, " ") }, null, null, null);
        if (cursor != null && cursor.moveToNext()) {
            boolean blocked = cursor.getInt(cursor.getColumnIndexOrThrow(BLOCK)) == 1;
            String notification = cursor.getString(cursor.getColumnIndexOrThrow(NOTIFICATION));
            int vibrateState = cursor.getInt(cursor.getColumnIndexOrThrow(VIBRATE));
            long muteUntil = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
            String serializedColor = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
            Uri notificationUri = notification == null ? null : Uri.parse(notification);
            boolean seenInviteReminder = cursor.getInt(cursor.getColumnIndexOrThrow(SEEN_INVITE_REMINDER)) == 1;
            int defaultSubscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(DEFAULT_SUBSCRIPTION_ID));
            int expireMessages = cursor.getInt(cursor.getColumnIndexOrThrow(EXPIRE_MESSAGES));
            MaterialColor color;
            try {
                color = serializedColor == null ? null : MaterialColor.fromSerialized(serializedColor);
            } catch (MaterialColor.UnknownColorException e) {
                Log.w(TAG, e);
                color = null;
            }
            Log.w(TAG, "Muted until: " + muteUntil);
            return Optional.of(new RecipientsPreferences(blocked, muteUntil, VibrateState.fromId(vibrateState), notificationUri, color, seenInviteReminder, defaultSubscriptionId, expireMessages));
        }
        return Optional.absent();
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MaterialColor(org.thoughtcrime.securesms.color.MaterialColor) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 3 with MaterialColor

use of org.thoughtcrime.securesms.color.MaterialColor in project Signal-Android by WhisperSystems.

the class RecipientProvider method getIndividualRecipientDetails.

@NonNull
private RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, @NonNull String number) {
    Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[] { recipientId });
    MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION, null, null, null);
    try {
        if (cursor != null && cursor.moveToFirst()) {
            final String resultNumber = cursor.getString(3);
            if (resultNumber != null) {
                Uri contactUri = Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
                String name = resultNumber.equals(cursor.getString(0)) ? null : cursor.getString(0);
                ContactPhoto contactPhoto = ContactPhotoFactory.getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""), name);
                return new RecipientDetails(cursor.getString(0), resultNumber, contactUri, contactPhoto, color);
            } else {
                Log.w(TAG, "resultNumber is null");
            }
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    if (STATIC_DETAILS.containsKey(number))
        return STATIC_DETAILS.get(number);
    else
        return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color);
}
Also used : MaterialColor(org.thoughtcrime.securesms.color.MaterialColor) RecipientsPreferences(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences) Cursor(android.database.Cursor) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull)

Aggregations

MaterialColor (org.thoughtcrime.securesms.color.MaterialColor)3 Cursor (android.database.Cursor)2 Uri (android.net.Uri)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 NonNull (android.support.annotation.NonNull)1 ContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ContactPhoto)1 RecipientsPreferences (org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences)1