Search in sources :

Example 31 with Cursor

use of android.database.Cursor in project Talon-for-Twitter by klinker24.

the class HomeDataSource method getTrimmingCursor.

public synchronized Cursor getTrimmingCursor(int account) {
    String where = HomeSQLiteHelper.COLUMN_ACCOUNT + " = " + account;
    Cursor cursor;
    try {
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC");
    } catch (Exception e) {
        open();
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC");
    }
    return cursor;
}
Also used : Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 32 with Cursor

use of android.database.Cursor in project Talon-for-Twitter by klinker24.

the class HomeDataSource method getLastIds.

public synchronized long[] getLastIds(int account) {
    long[] id = new long[] { 0, 0, 0, 0, 0 };
    Cursor cursor;
    try {
        cursor = getCursor(account);
    } catch (Exception e) {
        return id;
    }
    try {
        if (cursor.moveToLast()) {
            int i = 0;
            do {
                id[i] = cursor.getLong(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TWEET_ID));
                i++;
            } while (cursor.moveToPrevious() && i < 5);
        }
    } catch (Exception e) {
    }
    if (cursor != null) {
        cursor.close();
    }
    return id;
}
Also used : Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 33 with Cursor

use of android.database.Cursor in project Talon-for-Twitter by klinker24.

the class InteractionsDataSource method getUsers.

public synchronized String getUsers(int account, int position, boolean unread) {
    Cursor cursor;
    if (unread) {
        cursor = getUnreadBackwordCursor(account);
    } else {
        cursor = getBackwordCursor(account);
    }
    String users = "";
    if (cursor.moveToPosition(position)) {
        users = cursor.getString(cursor.getColumnIndex(InteractionsSQLiteHelper.COLUMN_USERS));
    }
    cursor.close();
    return users;
}
Also used : Cursor(android.database.Cursor)

Example 34 with Cursor

use of android.database.Cursor in project Talon-for-Twitter by klinker24.

the class InteractionsDataSource method getUnreadCount.

public synchronized int getUnreadCount(int account) {
    Cursor cursor = getUnreadCursor(account);
    int count = cursor.getCount();
    cursor.close();
    return count;
}
Also used : Cursor(android.database.Cursor)

Example 35 with Cursor

use of android.database.Cursor in project Talon-for-Twitter by klinker24.

the class ListDataSource method getCursor.

public synchronized Cursor getCursor(long listId) {
    String users = sharedPreferences.getString("muted_users", "");
    String rts = sharedPreferences.getString("muted_rts", "");
    String hashtags = sharedPreferences.getString("muted_hashtags", "");
    String expressions = sharedPreferences.getString("muted_regex", "");
    expressions = expressions.replaceAll("'", "''");
    String where = ListSQLiteHelper.COLUMN_LIST_ID + " = " + listId;
    if (!users.equals("")) {
        String[] split = users.split(" ");
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_SCREEN_NAME + " NOT LIKE '" + s + "'";
        }
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    if (!hashtags.equals("")) {
        String[] split = hashtags.split(" ");
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_HASHTAGS + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!expressions.equals("")) {
        String[] split = expressions.split("   ");
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_TEXT + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (noRetweets) {
        where += " AND " + ListSQLiteHelper.COLUMN_RETWEETER + " = '' OR " + ListSQLiteHelper.COLUMN_RETWEETER + " is NULL";
    } else if (!rts.equals("")) {
        String[] split = rts.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    Cursor cursor;
    String sql = "SELECT COUNT(*) FROM " + ListSQLiteHelper.TABLE_HOME + " WHERE " + where;
    SQLiteStatement statement;
    try {
        statement = database.compileStatement(sql);
    } catch (Exception e) {
        open();
        statement = database.compileStatement(sql);
    }
    long count;
    try {
        count = statement.simpleQueryForLong();
    } catch (Exception e) {
        open();
        count = statement.simpleQueryForLong();
    }
    Log.v("talon_database", "list database has " + count + " entries");
    if (count > 400) {
        try {
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - 400) + "," + 400);
        } catch (Exception e) {
            open();
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - 400) + "," + 400);
        }
    } else {
        try {
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC");
        } catch (Exception e) {
            open();
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC");
        }
    }
    return cursor;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) SQLException(android.database.SQLException) SQLiteDatabaseLockedException(android.database.sqlite.SQLiteDatabaseLockedException)

Aggregations

Cursor (android.database.Cursor)4002 ArrayList (java.util.ArrayList)547 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)527 Uri (android.net.Uri)467 ContentValues (android.content.ContentValues)334 ContentResolver (android.content.ContentResolver)193 Test (org.junit.Test)183 RemoteException (android.os.RemoteException)182 File (java.io.File)170 IOException (java.io.IOException)159 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)140 SQLException (android.database.SQLException)126 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 HashMap (java.util.HashMap)108 SQLiteException (android.database.sqlite.SQLiteException)94 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)93 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75