confirm marking headlines as read from the actionbar

This commit is contained in:
Andrew Dolgov 2013-05-15 13:28:47 +04:00
parent a60225626d
commit 9e71ff1b11
3 changed files with 56 additions and 27 deletions

View File

@ -195,4 +195,5 @@
<string name="light_theme_is_not_supported_on_honeycomb">Light theme is not supported on Honeycomb</string> <string name="light_theme_is_not_supported_on_honeycomb">Light theme is not supported on Honeycomb</string>
<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>
</resources> </resources>

View File

@ -7,6 +7,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
@ -118,7 +119,7 @@ public class CommonActivity extends SherlockFragmentActivity {
initDatabase(); initDatabase();
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10; m_compatMode = android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB;
Log.d(TAG, "m_compatMode=" + m_compatMode); Log.d(TAG, "m_compatMode=" + m_compatMode);

View File

@ -746,32 +746,59 @@ public class OnlineActivity extends CommonActivity {
return true; return true;
case R.id.headlines_mark_as_read: case R.id.headlines_mark_as_read:
if (hf != null) { if (hf != null) {
ArticleList articles = hf.getUnreadArticles();
int count = hf.getUnreadArticles().size();
for (Article a : articles)
a.unread = false; if (count > 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(
ApiRequest req = new ApiRequest(getApplicationContext()) { OnlineActivity.this)
protected void onPostExecute(JsonElement result) { .setMessage(getString(R.string.mark_num_headlines_as_read, count))
if (hf.isAdded()) { .setPositiveButton(R.string.catchup,
hf.refresh(false); new Dialog.OnClickListener() {
} public void onClick(DialogInterface dialog,
} int which) {
};
ArticleList articles = hf.getUnreadArticles();
final String articleIds = articlesToIdString(articles);
for (Article a : articles)
@SuppressWarnings("serial") a.unread = false;
HashMap<String, String> map = new HashMap<String, String>() {
{ ApiRequest req = new ApiRequest(getApplicationContext()) {
put("sid", getSessionId()); protected void onPostExecute(JsonElement result) {
put("op", "updateArticle"); if (hf.isAdded()) {
put("article_ids", articleIds); hf.refresh(false);
put("mode", "0"); }
put("field", "2"); }
} };
};
req.execute(map); 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();
}
} }
return true; return true;
case R.id.headlines_view_mode: case R.id.headlines_view_mode: