add preference to confirm marking headlines as read

This commit is contained in:
Andrew Dolgov 2013-05-18 13:28:10 +04:00
parent c1b41d9de8
commit 709b3838bb
3 changed files with 67 additions and 47 deletions

View File

@ -196,4 +196,5 @@
<string name="pref_headlines_mark_read_scroll">Mark read on scroll</string> <string name="pref_headlines_mark_read_scroll">Mark read on scroll</string>
<string name="pref_headlines_mark_read_scroll_long">Headlines will be marked read when scrolling past them</string> <string name="pref_headlines_mark_read_scroll_long">Headlines will be marked read when scrolling past them</string>
<string name="mark_num_headlines_as_read">Mark %1$d article(s) as read?</string> <string name="mark_num_headlines_as_read">Mark %1$d article(s) as read?</string>
<string name="prefs_confirm_headlines_catchup">Confirm marking articles as read</string>
</resources> </resources>

View File

@ -129,6 +129,12 @@
android:defaultValue="false" android:defaultValue="false"
android:key="full_screen_mode" android:key="full_screen_mode"
android:title="@string/prefs_fullscreen_mode" /> android:title="@string/prefs_fullscreen_mode" />
<CheckBoxPreference
android:defaultValue="true"
android:key="confirm_headlines_catchup"
android:title="@string/prefs_confirm_headlines_catchup" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/offline_mode" > <PreferenceCategory android:title="@string/offline_mode" >
<ListPreference <ListPreference

View File

@ -749,55 +749,35 @@ public class OnlineActivity extends CommonActivity {
int count = hf.getUnreadArticles().size(); int count = hf.getUnreadArticles().size();
boolean confirm = m_prefs.getBoolean("confirm_headlines_catchup", true);
if (count > 0) { if (count > 0) {
AlertDialog.Builder builder = new AlertDialog.Builder( if (confirm) {
OnlineActivity.this) AlertDialog.Builder builder = new AlertDialog.Builder(
.setMessage(getString(R.string.mark_num_headlines_as_read, count)) OnlineActivity.this)
.setPositiveButton(R.string.catchup, .setMessage(getString(R.string.mark_num_headlines_as_read, count))
new Dialog.OnClickListener() { .setPositiveButton(R.string.catchup,
public void onClick(DialogInterface dialog, new Dialog.OnClickListener() {
int which) { public void onClick(DialogInterface dialog,
int which) {
ArticleList articles = hf.getUnreadArticles(); catchupVisibleArticles();
for (Article a : articles) }
a.unread = false; })
.setNegativeButton(R.string.dialog_cancel,
ApiRequest req = new ApiRequest(getApplicationContext()) { new Dialog.OnClickListener() {
protected void onPostExecute(JsonElement result) { public void onClick(DialogInterface dialog,
if (hf.isAdded()) { int which) {
hf.refresh(false);
} }
} });
};
AlertDialog dlg = builder.create();
final String articleIds = articlesToIdString(articles); dlg.show();
} else {
@SuppressWarnings("serial") catchupVisibleArticles();
HashMap<String, String> map = new HashMap<String, String>() { }
{
put("sid", getSessionId());
put("op", "updateArticle");
put("article_ids", articleIds);
put("mode", "0");
put("field", "2");
}
};
req.execute(map);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
} }
} }
return true; return true;
@ -1020,6 +1000,39 @@ public class OnlineActivity extends CommonActivity {
} }
} }
protected void catchupVisibleArticles() {
final HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) {
ArticleList articles = hf.getUnreadArticles();
for (Article a : articles)
a.unread = false;
ApiRequest req = new ApiRequest(getApplicationContext()) {
protected void onPostExecute(JsonElement result) {
if (hf.isAdded()) {
hf.refresh(false);
}
}
};
final String articleIds = articlesToIdString(articles);
@SuppressWarnings("serial")
HashMap<String, String> map = new HashMap<String, String>() {
{
put("sid", getSessionId());
put("op", "updateArticle");
put("article_ids", articleIds);
put("mode", "0");
put("field", "2");
}
};
req.execute(map);
}
}
public void editArticleNote(final Article article) { public void editArticleNote(final Article article) {
String note = ""; String note = "";