Search in sources :

Example 61 with ContentValues

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

the class ThreadDatabase method updateThread.

private void updateThread(long threadId, long count, String body, @Nullable Uri attachment, long date, int status, int receiptCount, long type, boolean unarchive, long expiresIn) {
    ContentValues contentValues = new ContentValues(7);
    contentValues.put(DATE, date - date % 1000);
    contentValues.put(MESSAGE_COUNT, count);
    contentValues.put(SNIPPET, body);
    contentValues.put(SNIPPET_URI, attachment == null ? null : attachment.toString());
    contentValues.put(SNIPPET_TYPE, type);
    contentValues.put(STATUS, status);
    contentValues.put(RECEIPT_COUNT, receiptCount);
    contentValues.put(EXPIRES_IN, expiresIn);
    if (unarchive) {
        contentValues.put(ARCHIVED, 0);
    }
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] { threadId + "" });
    notifyConversationListListeners();
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 62 with ContentValues

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

the class ThreadDatabase method setLastSeen.

public void setLastSeen(long threadId) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(LAST_SEEN, System.currentTimeMillis());
    db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] { String.valueOf(threadId) });
    notifyConversationListListeners();
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 63 with ContentValues

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

the class ThreadDatabase method setRead.

public List<MarkedMessageInfo> setRead(long threadId, boolean lastSeen) {
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(READ, 1);
    if (lastSeen) {
        contentValues.put(LAST_SEEN, System.currentTimeMillis());
    }
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] { threadId + "" });
    final List<MarkedMessageInfo> smsRecords = DatabaseFactory.getSmsDatabase(context).setMessagesRead(threadId);
    final List<MarkedMessageInfo> mmsRecords = DatabaseFactory.getMmsDatabase(context).setMessagesRead(threadId);
    notifyConversationListListeners();
    return new LinkedList<MarkedMessageInfo>() {

        {
            addAll(smsRecords);
            addAll(mmsRecords);
        }
    };
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo) LinkedList(java.util.LinkedList)

Example 64 with ContentValues

use of android.content.ContentValues in project okhttp-OkGo by jeasonlzy.

the class DownloadInfo method buildContentValues.

public static ContentValues buildContentValues(DownloadInfo downloadInfo) {
    ContentValues values = new ContentValues();
    values.put(TASK_KEY, downloadInfo.getTaskKey());
    values.put(URL, downloadInfo.getUrl());
    values.put(TARGET_FOLDER, downloadInfo.getTargetFolder());
    values.put(TARGET_PATH, downloadInfo.getTargetPath());
    values.put(FILE_NAME, downloadInfo.getFileName());
    values.put(PROGRESS, downloadInfo.getProgress());
    values.put(TOTAL_LENGTH, downloadInfo.getTotalLength());
    values.put(DOWNLOAD_LENGTH, downloadInfo.getDownloadLength());
    values.put(NETWORK_SPEED, downloadInfo.getNetworkSpeed());
    values.put(STATE, downloadInfo.getState());
    BaseRequest request = downloadInfo.getRequest();
    DownloadRequest downloadRequest = downloadInfo.getDownloadRequest();
    downloadRequest.cacheKey = request.getCacheKey();
    downloadRequest.cacheTime = request.getCacheTime();
    downloadRequest.cacheMode = request.getCacheMode();
    downloadRequest.url = request.getBaseUrl();
    downloadRequest.params = request.getParams();
    downloadRequest.headers = request.getHeaders();
    downloadRequest.method = DownloadRequest.getMethod(request);
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oos = null;
    try {
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        oos.writeObject(downloadRequest);
        oos.flush();
        byte[] requestData = baos.toByteArray();
        values.put(DownloadInfo.DOWNLOAD_REQUEST, requestData);
    } catch (IOException e) {
        OkLogger.e(e);
    } finally {
        try {
            if (oos != null)
                oos.close();
            if (baos != null)
                baos.close();
        } catch (IOException e) {
            OkLogger.e(e);
        }
    }
    try {
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        oos.writeObject(downloadInfo.getData());
        oos.flush();
        byte[] data = baos.toByteArray();
        values.put(DownloadInfo.DATA, data);
    } catch (IOException e) {
        OkLogger.e(e);
    } finally {
        try {
            if (oos != null)
                oos.close();
            if (baos != null)
                baos.close();
        } catch (IOException e) {
            OkLogger.e(e);
        }
    }
    return values;
}
Also used : ContentValues(android.content.ContentValues) BaseRequest(com.lzy.okgo.request.BaseRequest) DownloadRequest(com.lzy.okserver.download.db.DownloadRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 65 with ContentValues

use of android.content.ContentValues in project ZhihuDailyPurify by izzyleung.

the class DailyNewsDataSource method insertDailyNewsList.

public List<DailyNews> insertDailyNewsList(String date, String content) {
    ContentValues values = new ContentValues();
    values.put(DBHelper.COLUMN_DATE, date);
    values.put(DBHelper.COLUMN_CONTENT, content);
    long insertId = database.insert(DBHelper.TABLE_NAME, null, values);
    Cursor cursor = database.query(DBHelper.TABLE_NAME, allColumns, DBHelper.COLUMN_ID + " = " + insertId, null, null, null, null);
    cursor.moveToFirst();
    List<DailyNews> newsList = cursorToNewsList(cursor);
    cursor.close();
    return newsList;
}
Also used : ContentValues(android.content.ContentValues) DailyNews(io.github.izzyleung.zhihudailypurify.bean.DailyNews) Cursor(android.database.Cursor)

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