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

View File

@ -200,14 +200,14 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
public void catchupFeed(int feedId, boolean isCat) { public void catchupFeed(int feedId, boolean isCat) {
if (isCat) { if (isCat) {
SQLiteStatement stmt = getWritableDb().compileStatement( 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 = ?)"); BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
stmt.bindLong(1, feedId); stmt.bindLong(1, feedId);
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} else { } else {
SQLiteStatement stmt = getWritableDb().compileStatement( 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.bindLong(1, feedId);
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
@ -219,7 +219,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
@Override @Override
public void onArticleSelected(int articleId, boolean open) { public void onArticleSelected(int articleId, boolean open) {
SQLiteStatement stmt = getWritableDb().compileStatement( 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); stmt.bindLong(1, articleId);

View File

@ -92,7 +92,7 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
@Override @Override
public void onArticleSelected(int articleId, boolean open) { public void onArticleSelected(int articleId, boolean open) {
SQLiteStatement stmt = getWritableDb().compileStatement( 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); stmt.bindLong(1, articleId);

View File

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

View File

@ -251,14 +251,22 @@ public class OfflineUploadService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
m_sessionId = intent.getStringExtra("sessionId"); try {
if (getWritableDb().isDbLockedByCurrentThread() || getWritableDb().isDbLockedByOtherThreads()) {
return;
}
if (!m_uploadInProgress) { m_sessionId = intent.getStringExtra("sessionId");
m_uploadInProgress = true;
updateNotification(R.string.notify_uploading_sending_data); if (!m_uploadInProgress) {
m_uploadInProgress = true;
uploadRead(); updateNotification(R.string.notify_uploading_sending_data);
uploadRead();
}
} catch (Exception e) {
e.printStackTrace();
} }
} }