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_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="prefs_confirm_headlines_catchup">Confirm marking articles as read</string>
</resources>

View File

@ -129,6 +129,12 @@
android:defaultValue="false"
android:key="full_screen_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 android:title="@string/offline_mode" >
<ListPreference

View File

@ -749,55 +749,35 @@ public class OnlineActivity extends CommonActivity {
int count = hf.getUnreadArticles().size();
boolean confirm = m_prefs.getBoolean("confirm_headlines_catchup", true);
if (count > 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(
OnlineActivity.this)
.setMessage(getString(R.string.mark_num_headlines_as_read, count))
.setPositiveButton(R.string.catchup,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if (confirm) {
AlertDialog.Builder builder = new AlertDialog.Builder(
OnlineActivity.this)
.setMessage(getString(R.string.mark_num_headlines_as_read, count))
.setPositiveButton(R.string.catchup,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
ArticleList articles = hf.getUnreadArticles();
catchupVisibleArticles();
for (Article a : articles)
a.unread = false;
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
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);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
AlertDialog dlg = builder.create();
dlg.show();
} else {
catchupVisibleArticles();
}
}
}
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) {
String note = "";