Search in sources :

Example 51 with ContentValues

use of android.content.ContentValues in project Signal-Android by WhisperSystems.

the class SmsDatabase method insertMessageOutbox.

protected long insertMessageOutbox(long threadId, OutgoingTextMessage message, long type, boolean forceSms, long date) {
    if (message.isKeyExchange())
        type |= Types.KEY_EXCHANGE_BIT;
    else if (message.isSecureMessage())
        type |= (Types.SECURE_MESSAGE_BIT | Types.PUSH_MESSAGE_BIT);
    else if (message.isEndSession())
        type |= Types.END_SESSION_BIT;
    if (forceSms)
        type |= Types.MESSAGE_FORCE_SMS_BIT;
    String address = message.getRecipients().getPrimaryRecipient().getNumber();
    ContentValues contentValues = new ContentValues(6);
    contentValues.put(ADDRESS, PhoneNumberUtils.formatNumber(address));
    contentValues.put(THREAD_ID, threadId);
    contentValues.put(BODY, message.getMessageBody());
    contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
    contentValues.put(DATE_SENT, date);
    contentValues.put(READ, 1);
    contentValues.put(TYPE, type);
    contentValues.put(SUBSCRIPTION_ID, message.getSubscriptionId());
    contentValues.put(EXPIRES_IN, message.getExpiresIn());
    try {
        contentValues.put(RECEIPT_COUNT, earlyReceiptCache.remove(date, canonicalizeNumber(context, address)));
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
    }
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
    DatabaseFactory.getThreadDatabase(context).update(threadId, true);
    DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
    notifyConversationListeners(threadId);
    jobManager.add(new TrimThreadJob(context, threadId));
    return messageId;
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException)

Example 52 with ContentValues

use of android.content.ContentValues in project Signal-Android by WhisperSystems.

the class IdentityDatabase method saveIdentity.

public void saveIdentity(long recipientId, IdentityKey identityKey) {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    String identityKeyString = Base64.encodeBytes(identityKey.serialize());
    ContentValues contentValues = new ContentValues();
    contentValues.put(RECIPIENT, recipientId);
    contentValues.put(IDENTITY_KEY, identityKeyString);
    database.replace(TABLE_NAME, null, contentValues);
    context.getContentResolver().notifyChange(CHANGE_URI, null);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 53 with ContentValues

use of android.content.ContentValues in project Signal-Android by WhisperSystems.

the class MmsAddressDatabase method insertAddress.

private void insertAddress(long messageId, int type, @NonNull String value) {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(MMS_ID, messageId);
    contentValues.put(TYPE, type);
    contentValues.put(ADDRESS, value);
    contentValues.put(ADDRESS_CHARSET, "UTF-8");
    database.insert(TABLE_NAME, null, contentValues);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 54 with ContentValues

use of android.content.ContentValues in project Signal-Android by WhisperSystems.

the class RecipientPreferenceDatabase method setRingtone.

public void setRingtone(Recipients recipients, @Nullable Uri notification) {
    ContentValues values = new ContentValues();
    values.put(NOTIFICATION, notification == null ? null : notification.toString());
    updateOrInsert(recipients, values);
}
Also used : ContentValues(android.content.ContentValues)

Example 55 with ContentValues

use of android.content.ContentValues in project Signal-Android by WhisperSystems.

the class RecipientPreferenceDatabase method setExpireMessages.

public void setExpireMessages(Recipients recipients, int expiration) {
    recipients.setExpireMessages(expiration);
    ContentValues values = new ContentValues(1);
    values.put(EXPIRE_MESSAGES, expiration);
    updateOrInsert(recipients, values);
}
Also used : ContentValues(android.content.ContentValues)

Aggregations

ContentValues (android.content.ContentValues)3993 Cursor (android.database.Cursor)720 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)638 Uri (android.net.Uri)619 Test (org.junit.Test)374 SQLException (android.database.SQLException)231 ContentResolver (android.content.ContentResolver)212 ArrayList (java.util.ArrayList)192 Intent (android.content.Intent)162 File (java.io.File)156 IOException (java.io.IOException)131 RemoteException (android.os.RemoteException)96 CursorAssert.assertThatCursor (org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor)91 NonNull (android.support.annotation.NonNull)74 Date (java.util.Date)73 MediumTest (android.test.suitebuilder.annotation.MediumTest)63 HashMap (java.util.HashMap)62 JSONException (org.json.JSONException)60 SQLiteException (android.database.sqlite.SQLiteException)53 ContentProviderOperation (android.content.ContentProviderOperation)49