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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations