offline not syncing fixes

This commit is contained in:
Andrew Dolgov 2012-09-20 09:56:02 +04:00
parent 282285ef78
commit fa05b3fe0a
5 changed files with 41 additions and 33 deletions

View File

@ -259,10 +259,10 @@ public class OfflineActivity extends CommonActivity {
if (isCat) {
stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
"UPDATE articles SET modified = 1, unread = 0 WHERE feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
} else {
stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE feed_id = ?");
"UPDATE articles SET modified = 1, unread = 0 WHERE feed_id = ?");
}
stmt.bindLong(1, feedId);
stmt.execute();
@ -283,7 +283,7 @@ public class OfflineActivity extends CommonActivity {
int articleId = oap.getSelectedArticleId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET marked = NOT marked WHERE "
"UPDATE articles SET modified = 1, marked = NOT marked WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
@ -299,7 +299,7 @@ public class OfflineActivity extends CommonActivity {
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = getWritableDb()
.compileStatement(
"UPDATE articles SET unread = NOT unread WHERE selected = 1");
"UPDATE articles SET modified = 1, unread = NOT unread WHERE selected = 1");
stmt.execute();
stmt.close();
@ -310,7 +310,7 @@ public class OfflineActivity extends CommonActivity {
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = getWritableDb()
.compileStatement(
"UPDATE articles SET marked = NOT marked WHERE selected = 1");
"UPDATE articles SET modified = 1, marked = NOT marked WHERE selected = 1");
stmt.execute();
stmt.close();
@ -321,7 +321,7 @@ public class OfflineActivity extends CommonActivity {
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = getWritableDb()
.compileStatement(
"UPDATE articles SET published = NOT published WHERE selected = 1");
"UPDATE articles SET modified = 1, published = NOT published WHERE selected = 1");
stmt.execute();
stmt.close();
@ -333,7 +333,7 @@ public class OfflineActivity extends CommonActivity {
int articleId = oap.getSelectedArticleId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET published = NOT published WHERE "
"UPDATE articles SET modified = 1, published = NOT published WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
@ -352,12 +352,12 @@ public class OfflineActivity extends CommonActivity {
if (isCat) {
stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE " +
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
} else {
stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE " +
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id = ?");
}
@ -375,7 +375,7 @@ public class OfflineActivity extends CommonActivity {
int articleId = oap.getSelectedArticleId();
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 1 WHERE "
"UPDATE articles SET modified = 1, unread = 1 WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();

View File

@ -200,14 +200,14 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
public void catchupFeed(int feedId, boolean isCat) {
if (isCat) {
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE feed_id IN (SELECT "+
"UPDATE articles SET modified = 1, unread = 0 WHERE feed_id IN (SELECT "+
BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
stmt.bindLong(1, feedId);
stmt.execute();
stmt.close();
} else {
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE feed_id = ?");
"UPDATE articles SET modified = 1, unread = 0 WHERE feed_id = ?");
stmt.bindLong(1, feedId);
stmt.execute();
stmt.close();
@ -219,7 +219,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
@Override
public void onArticleSelected(int articleId, boolean open) {
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID
"UPDATE articles SET modified = 1, unread = 0 " + "WHERE " + BaseColumns._ID
+ " = ?");
stmt.bindLong(1, articleId);

View File

@ -92,7 +92,7 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
@Override
public void onArticleSelected(int articleId, boolean open) {
SQLiteStatement stmt = getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID
"UPDATE articles SET modified = 1, unread = 0 " + "WHERE " + BaseColumns._ID
+ " = ?");
stmt.bindLong(1, articleId);

View File

@ -118,14 +118,14 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = m_activity.getWritableDb()
.compileStatement(
"UPDATE articles SET marked = NOT marked WHERE selected = 1");
"UPDATE articles SET modified = 1, marked = NOT marked WHERE selected = 1");
stmt.execute();
stmt.close();
} else {
int articleId = getArticleIdAtPosition(info.position);
SQLiteStatement stmt = m_activity.getWritableDb().compileStatement(
"UPDATE articles SET marked = NOT marked WHERE "
"UPDATE articles SET modified = 1, marked = NOT marked WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
@ -137,14 +137,14 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = m_activity.getWritableDb()
.compileStatement(
"UPDATE articles SET published = NOT published WHERE selected = 1");
"UPDATE articles SET modified = 1, published = NOT published WHERE selected = 1");
stmt.execute();
stmt.close();
} else {
int articleId = getArticleIdAtPosition(info.position);
SQLiteStatement stmt = m_activity.getWritableDb().compileStatement(
"UPDATE articles SET published = NOT published WHERE "
"UPDATE articles SET modified = 1, published = NOT published WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
@ -156,14 +156,14 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
if (getSelectedArticleCount() > 0) {
SQLiteStatement stmt = m_activity.getWritableDb()
.compileStatement(
"UPDATE articles SET unread = NOT unread WHERE selected = 1");
"UPDATE articles SET modified = 1, unread = NOT unread WHERE selected = 1");
stmt.execute();
stmt.close();
} else {
int articleId = getArticleIdAtPosition(info.position);
SQLiteStatement stmt = m_activity.getWritableDb().compileStatement(
"UPDATE articles SET unread = NOT unread WHERE "
"UPDATE articles SET modified = 1, unread = NOT unread WHERE "
+ BaseColumns._ID + " = ?");
stmt.bindLong(1, articleId);
stmt.execute();
@ -185,12 +185,12 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
if (m_feedIsCat) {
stmt = m_activity.getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE " +
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
} else {
stmt = m_activity.getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 WHERE " +
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id = ?");
}
@ -344,7 +344,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
m_listener.onArticleSelected(articleId);
} else {
SQLiteStatement stmt = m_activity.getWritableDb().compileStatement(
"UPDATE articles SET unread = 0 " + "WHERE " + BaseColumns._ID
"UPDATE articles SET modified = 1, unread = 0 " + "WHERE " + BaseColumns._ID
+ " = ?");
stmt.bindLong(1, articleId);
@ -484,7 +484,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
@Override
public void onClick(View v) {
SQLiteStatement stmtUpdate = m_activity.getWritableDb().compileStatement("UPDATE articles SET marked = NOT marked " +
SQLiteStatement stmtUpdate = m_activity.getWritableDb().compileStatement("UPDATE articles SET modified = 1, marked = NOT marked " +
"WHERE " + BaseColumns._ID + " = ?");
stmtUpdate.bindLong(1, articleId);
@ -505,7 +505,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
@Override
public void onClick(View v) {
SQLiteStatement stmtUpdate = m_activity.getWritableDb().compileStatement("UPDATE articles SET published = NOT published " +
SQLiteStatement stmtUpdate = m_activity.getWritableDb().compileStatement("UPDATE articles SET modified = 1, published = NOT published " +
"WHERE " + BaseColumns._ID + " = ?");
stmtUpdate.bindLong(1, articleId);

View File

@ -251,6 +251,11 @@ public class OfflineUploadService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
try {
if (getWritableDb().isDbLockedByCurrentThread() || getWritableDb().isDbLockedByOtherThreads()) {
return;
}
m_sessionId = intent.getStringExtra("sessionId");
if (!m_uploadInProgress) {
@ -260,6 +265,9 @@ public class OfflineUploadService extends IntentService {
uploadRead();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}