fix headlines catchup button not respecting confirm option

This commit is contained in:
Andrew Dolgov 2013-05-29 21:13:24 +04:00
parent 68ea91c567
commit 491d8f082f
3 changed files with 79 additions and 35 deletions

View File

@ -1,6 +1,7 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
import org.fox.ttrss.CommonActivity; import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.PreferencesActivity; import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R; import org.fox.ttrss.R;
@ -246,23 +247,42 @@ public class OfflineActivity extends CommonActivity {
return true; return true;
case R.id.headlines_mark_as_read: case R.id.headlines_mark_as_read:
if (ohf != null) { if (ohf != null) {
int feedId = ohf.getFeedId(); final int feedId = ohf.getFeedId();
boolean isCat = ohf.getFeedIsCat(); final boolean isCat = ohf.getFeedIsCat();
SQLiteStatement stmt = null; int count = getUnreadArticleCount(feedId, isCat);
boolean confirm = m_prefs.getBoolean("confirm_headlines_catchup", true);
if (isCat) { if (count > 0) {
stmt = getWritableDb().compileStatement( if (confirm) {
"UPDATE articles SET modified = 1, unread = 0 WHERE feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)"); AlertDialog.Builder builder = new AlertDialog.Builder(
} else { OfflineActivity.this)
stmt = getWritableDb().compileStatement( .setMessage(getString(R.string.mark_num_headlines_as_read, count))
"UPDATE articles SET modified = 1, unread = 0 WHERE feed_id = ?"); .setPositiveButton(R.string.catchup,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
catchupFeed(feedId, isCat);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
} else {
catchupFeed(feedId, isCat);
}
} }
stmt.bindLong(1, feedId);
stmt.execute();
stmt.close();
refresh();
} }
return true; return true;
case R.id.share_article: case R.id.share_article:
@ -384,7 +404,6 @@ public class OfflineActivity extends CommonActivity {
} }
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater(); MenuInflater inflater = getSupportMenuInflater();
@ -601,6 +620,29 @@ public class OfflineActivity extends CommonActivity {
return selected; return selected;
} }
protected int getUnreadArticleCount(int feedId, boolean isCat) {
Cursor c;
if (isCat) {
c = getReadableDb().query("articles",
new String[] { "COUNT(*)" }, "unread = 1 AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)",
new String[] { String.valueOf(feedId) },
null, null, null);
} else {
c = getReadableDb().query("articles",
new String[] { "COUNT(*)" }, "unread = 1 AND feed_id = ?",
new String[] { String.valueOf(feedId) },
null, null, null);
}
c.moveToFirst();
int selected = c.getInt(0);
c.close();
return selected;
}
protected void deselectAllArticles() { protected void deselectAllArticles() {
getWritableDb().execSQL("UPDATE articles SET selected = 0 "); getWritableDb().execSQL("UPDATE articles SET selected = 0 ");
refresh(); refresh();
@ -631,4 +673,24 @@ public class OfflineActivity extends CommonActivity {
initMenu(); initMenu();
} }
public void catchupFeed(int feedId, boolean isCat) {
if (isCat) {
SQLiteStatement stmt = getWritableDb().compileStatement(
"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 modified = 1, unread = 0 WHERE feed_id = ?");
stmt.bindLong(1, feedId);
stmt.execute();
stmt.close();
}
refresh();
}
} }

View File

@ -272,31 +272,11 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
m_actionbarUpEnabled = true; m_actionbarUpEnabled = true;
} }
} }
}, 10); }, 10);
} }
} }
public void catchupFeed(int feedId, boolean isCat) {
if (isCat) {
SQLiteStatement stmt = getWritableDb().compileStatement(
"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 modified = 1, unread = 0 WHERE feed_id = ?");
stmt.bindLong(1, feedId);
stmt.execute();
stmt.close();
}
refresh();
}
@Override @Override
public void onArticleSelected(int articleId, boolean open) { public void onArticleSelected(int articleId, boolean open) {
SQLiteStatement stmt = getWritableDb().compileStatement( SQLiteStatement stmt = getWritableDb().compileStatement(

View File

@ -251,6 +251,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
} }
refresh(); refresh();
m_activity.initMenu();
} }
public void refresh() { public void refresh() {