Search in sources :

Example 26 with Cursor

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

the class HomeDataSource method markUnreadFilling.

public synchronized void markUnreadFilling(int account) {
    ContentValues cv = new ContentValues();
    cv.put(HomeSQLiteHelper.COLUMN_UNREAD, 1);
    // first get the unread cursor to find the first id to mark unread
    Cursor unread = getUnreadCursor(account);
    if (unread.moveToFirst()) {
        // this is the long for the first unread tweet in the list
        long id = unread.getLong(unread.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID));
        Cursor full = getCursor(account);
        if (full.moveToFirst()) {
            boolean startUnreads = false;
            do {
                long thisId = full.getLong(full.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID));
                if (thisId == id) {
                    startUnreads = true;
                }
                if (startUnreads) {
                    try {
                        database.update(HomeSQLiteHelper.TABLE_HOME, cv, HomeSQLiteHelper.COLUMN_TWEET_ID + " = ?", new String[] { thisId + "" });
                    } catch (Exception e) {
                        open();
                        database.update(HomeSQLiteHelper.TABLE_HOME, cv, HomeSQLiteHelper.COLUMN_TWEET_ID + " = ?", new String[] { thisId + "" });
                    }
                }
            } while (full.moveToNext());
        }
        full.close();
    }
    unread.close();
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 27 with Cursor

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

the class HomeDataSource method getWearCursor.

public synchronized Cursor getWearCursor(int account) {
    String users = sharedPreferences.getString("muted_users", "");
    String rts = sharedPreferences.getString("muted_rts", "");
    String hashtags = sharedPreferences.getString("muted_hashtags", "");
    String expressions = sharedPreferences.getString("muted_regex", "");
    String clients = sharedPreferences.getString("muted_clients", "");
    String where = HomeSQLiteHelper.COLUMN_ACCOUNT + " = " + account;
    expressions = expressions.replaceAll("'", "''");
    if (!users.equals("")) {
        String[] split = users.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_SCREEN_NAME + " NOT LIKE '" + s + "'";
        }
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    if (!hashtags.equals("")) {
        String[] split = hashtags.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_HASHTAGS + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!expressions.equals("")) {
        String[] split = expressions.split("   ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_TEXT + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!clients.equals("")) {
        String[] split = clients.split("   ");
        for (String s : split) {
            where += " AND (" + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " NOT LIKE " + "'%" + s + "%'" + " OR " + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " is NULL)";
        }
    }
    if (noRetweets) {
        where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " = '' OR " + HomeSQLiteHelper.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 " + HomeSQLiteHelper.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();
        try {
            count = statement.simpleQueryForLong();
        } catch (Exception x) {
            return null;
        }
    }
    int position = getPosition(sharedPreferences.getInt("current_account", 1));
    try {
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", count - position + "," + position);
    } catch (Exception e) {
        open();
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", count - position + "," + position);
    }
    return cursor;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 28 with Cursor

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

the class HomeDataSource method getCursor.

public synchronized Cursor getCursor(int account) {
    String users = sharedPreferences.getString("muted_users", "");
    String rts = sharedPreferences.getString("muted_rts", "");
    String hashtags = sharedPreferences.getString("muted_hashtags", "");
    String expressions = sharedPreferences.getString("muted_regex", "");
    String clients = sharedPreferences.getString("muted_clients", "");
    String where = HomeSQLiteHelper.COLUMN_ACCOUNT + " = " + account;
    expressions = expressions.replaceAll("'", "''");
    if (!users.equals("")) {
        String[] split = users.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_SCREEN_NAME + " NOT LIKE '" + s + "'";
        }
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    if (!hashtags.equals("")) {
        String[] split = hashtags.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_HASHTAGS + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!expressions.equals("")) {
        String[] split = expressions.split("   ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_TEXT + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!clients.equals("")) {
        String[] split = clients.split("   ");
        for (String s : split) {
            where += " AND (" + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " NOT LIKE " + "'%" + s + "%'" + " OR " + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " is NULL)";
        }
    }
    if (noRetweets) {
        where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " = '' OR " + HomeSQLiteHelper.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 " + HomeSQLiteHelper.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();
        try {
            count = statement.simpleQueryForLong();
        } catch (Exception x) {
            return null;
        }
    }
    Log.v("talon_database", "home database has " + count + " entries");
    if (count > timelineSize) {
        try {
            cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - timelineSize) + "," + timelineSize);
        } catch (Exception e) {
            open();
            cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - timelineSize) + "," + timelineSize);
        }
    } else {
        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 : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 29 with Cursor

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

the class HomeDataSource method getWidgetCursor.

public synchronized Cursor getWidgetCursor(int account) {
    String users = sharedPreferences.getString("muted_users", "");
    String rts = sharedPreferences.getString("muted_rts", "");
    String hashtags = sharedPreferences.getString("muted_hashtags", "");
    String expressions = sharedPreferences.getString("muted_regex", "");
    String clients = sharedPreferences.getString("muted_clients", "");
    expressions = expressions.replaceAll("'", "''");
    String where = HomeSQLiteHelper.COLUMN_ACCOUNT + " = " + account;
    if (!users.equals("")) {
        String[] split = users.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_SCREEN_NAME + " NOT LIKE '" + s + "'";
        }
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    if (!hashtags.equals("")) {
        String[] split = hashtags.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_HASHTAGS + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!expressions.equals("")) {
        String[] split = expressions.split("   ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_TEXT + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!clients.equals("")) {
        String[] split = clients.split("   ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " NOT LIKE " + "'%" + s + "%'" + " OR " + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " is NULL";
        }
    }
    if (noRetweets) {
        where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " = '' OR " + HomeSQLiteHelper.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;
    try {
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " DESC", "150");
    } catch (Exception e) {
        open();
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " DESC", "150");
    }
    return cursor;
}
Also used : Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 30 with Cursor

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

the class HomeDataSource method getPosition.

public synchronized int getPosition(int account) {
    int pos = 0;
    Cursor cursor = getCursor(account);
    if (cursor.moveToLast()) {
        String s;
        do {
            s = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_CURRENT_POS));
            if (s != null && !s.isEmpty()) {
                break;
            } else {
                pos++;
            }
        } while (cursor.moveToPrevious());
    }
    cursor.close();
    return pos;
}
Also used : Cursor(android.database.Cursor)

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