Search in sources :

Example 1 with ThreadRecord

use of org.thoughtcrime.securesms.database.model.ThreadRecord in project Signal-Android by WhisperSystems.

the class ConversationListAdapter method getItemId.

@Override
public long getItemId(@NonNull Cursor cursor) {
    ThreadRecord record = getThreadRecord(cursor);
    StringBuilder builder = new StringBuilder("" + record.getThreadId());
    for (long recipientId : record.getRecipients().getIds()) {
        builder.append("::").append(recipientId);
    }
    return Conversions.byteArrayToLong(digest.digest(builder.toString().getBytes()));
}
Also used : ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord)

Example 2 with ThreadRecord

use of org.thoughtcrime.securesms.database.model.ThreadRecord in project Signal-Android by WhisperSystems.

the class DirectShareService method onGetChooserTargets.

@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    List<ChooserTarget> results = new LinkedList<>();
    MasterSecret masterSecret = KeyCachingService.getMasterSecret(this);
    if (masterSecret == null) {
        return results;
    }
    ComponentName componentName = new ComponentName(this, ShareActivity.class);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
    Cursor cursor = threadDatabase.getDirectShareList();
    try {
        ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, new MasterCipher(masterSecret));
        ThreadRecord record;
        while ((record = reader.getNext()) != null && results.size() < 10) {
            Recipients recipients = RecipientFactory.getRecipientsForIds(this, record.getRecipients().getIds(), false);
            String name = recipients.toShortString();
            Drawable drawable = recipients.getContactPhoto().asDrawable(this, recipients.getColor().toConversationColor(this));
            Bitmap avatar = BitmapUtil.createFromDrawable(drawable, 500, 500);
            Bundle bundle = new Bundle();
            bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId());
            bundle.putLongArray(ShareActivity.EXTRA_RECIPIENT_IDS, recipients.getIds());
            bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());
            results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
        }
        return results;
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Bundle(android.os.Bundle) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Drawable(android.graphics.drawable.Drawable) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) Bitmap(android.graphics.Bitmap) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName)

Example 3 with ThreadRecord

use of org.thoughtcrime.securesms.database.model.ThreadRecord in project Signal-Android by WhisperSystems.

the class ShareListAdapter method bindView.

@Override
public void bindView(View view, Context context, Cursor cursor) {
    if (masterCipher != null) {
        ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, masterCipher);
        ThreadRecord record = reader.getCurrent();
        ((ShareListItem) view).set(record);
    }
}
Also used : ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Aggregations

ThreadRecord (org.thoughtcrime.securesms.database.model.ThreadRecord)3 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)2 ComponentName (android.content.ComponentName)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 ChooserTarget (android.service.chooser.ChooserTarget)1 LinkedList (java.util.LinkedList)1 MasterCipher (org.thoughtcrime.securesms.crypto.MasterCipher)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1