catchup above uses general catchup confirmation setting

This commit is contained in:
Andrew Dolgov 2017-01-12 19:12:28 +03:00
parent d95d9f75bb
commit 6e336ec8ac
6 changed files with 208 additions and 86 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss"
android:versionCode="412"
android:versionName="1.178" >
android:versionCode="413"
android:versionName="1.179" >
<uses-sdk
android:minSdkVersion="16"

View File

@ -1,7 +1,10 @@
package org.fox.ttrss;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
@ -181,22 +184,36 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
return true;
case R.id.catchup_above:
if (true) {
ArticleList articles = getAllArticles();
ArticleList tmp = new ArticleList();
for (Article a : articles) {
if (article.id == a.id)
break;
if (a.unread) {
a.unread = false;
tmp.add(a);
}
if (m_prefs.getBoolean("confirm_headlines_catchup", true)) {
final Article fa = article;
AlertDialog.Builder builder = new AlertDialog.Builder(
m_activity)
.setMessage(R.string.confirm_catchup_above)
.setPositiveButton(R.string.dialog_ok,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
catchupAbove(fa);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
} else {
catchupAbove(article);
}
if (tmp.size() > 0) {
m_activity.toggleArticlesUnread(tmp);
//updateHeadlines();
}
m_adapter.notifyDataSetChanged();
}
return true;
default:
@ -205,6 +222,25 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
}
}
private void catchupAbove(Article article) {
ArticleList articles = getAllArticles();
ArticleList tmp = new ArticleList();
for (Article a : articles) {
if (article.id == a.id)
break;
if (a.unread) {
a.unread = false;
tmp.add(a);
}
}
if (tmp.size() > 0) {
m_activity.toggleArticlesUnread(tmp);
//updateHeadlines();
}
m_adapter.notifyDataSetChanged();
}
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();

View File

@ -32,10 +32,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache;
import com.nostra13.universalimageloader.core.DefaultConfigurationFactory;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import org.fox.ttrss.offline.OfflineActivity;
import org.fox.ttrss.offline.OfflineDownloadService;
@ -45,12 +41,7 @@ import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
import org.fox.ttrss.types.Feed;
import org.fox.ttrss.types.Label;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
@ -897,26 +888,35 @@ public class OnlineActivity extends CommonActivity {
return true;
case R.id.catchup_above:
if (hf != null) {
if (ap != null && ap.getSelectedArticle() != null) {
Article article = ap.getSelectedArticle();
ArticleList articles = hf.getAllArticles();
ArticleList tmp = new ArticleList();
for (Article a : articles) {
if (article.id == a.id)
break;
if (a.unread) {
a.unread = false;
tmp.add(a);
}
}
if (tmp.size() > 0) {
toggleArticlesUnread(tmp);
hf.notifyUpdated();
invalidateOptionsMenu();
}
if (m_prefs.getBoolean("confirm_headlines_catchup", true)) {
AlertDialog.Builder builder = new AlertDialog.Builder(
OnlineActivity.this)
.setMessage(R.string.confirm_catchup_above)
.setPositiveButton(R.string.dialog_ok,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
catchupAbove(hf, ap);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
} else {
catchupAbove(hf, ap);
}
}
return true;
case R.id.set_labels:
@ -940,7 +940,30 @@ public class OnlineActivity extends CommonActivity {
return super.onOptionsItemSelected(item);
}
}
private void catchupAbove(HeadlinesFragment hf, ArticlePager ap) {
if (ap != null && ap.getSelectedArticle() != null) {
Article article = ap.getSelectedArticle();
ArticleList articles = hf.getAllArticles();
ArticleList tmp = new ArticleList();
for (Article a : articles) {
if (article.id == a.id)
break;
if (a.unread) {
a.unread = false;
tmp.add(a);
}
}
if (tmp.size() > 0) {
toggleArticlesUnread(tmp);
hf.notifyUpdated();
invalidateOptionsMenu();
}
}
}
protected void catchupVisibleArticles() {
final HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);

View File

@ -22,14 +22,10 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class OfflineActivity extends CommonActivity {
private final String TAG = this.getClass().getSimpleName();
@ -492,30 +488,33 @@ public class OfflineActivity extends CommonActivity {
return true;
case R.id.catchup_above:
if (oap != null) {
int articleId = oap.getSelectedArticleId();
int feedId = oap.getFeedId();
boolean isCat = oap.getFeedIsCat();
if (m_prefs.getBoolean("confirm_headlines_catchup", true)) {
SQLiteStatement stmt = null;
if (isCat) {
stmt = getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
AlertDialog.Builder builder = new AlertDialog.Builder(
OfflineActivity.this)
.setMessage(R.string.confirm_catchup_above)
.setPositiveButton(R.string.dialog_ok,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
catchupAbove(oap);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
} else {
stmt = getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id = ?");
catchupAbove(oap);
}
stmt.bindLong(1, articleId);
stmt.bindLong(2, feedId);
stmt.execute();
stmt.close();
refresh();
}
return true;
default:
@ -524,6 +523,33 @@ public class OfflineActivity extends CommonActivity {
}
}
private void catchupAbove(OfflineArticlePager oap) {
int articleId = oap.getSelectedArticleId();
int feedId = oap.getFeedId();
boolean isCat = oap.getFeedIsCat();
SQLiteStatement stmt = null;
if (isCat) {
stmt = getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
} else {
stmt = getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND feed_id = ?");
}
stmt.bindLong(1, articleId);
stmt.bindLong(2, feedId);
stmt.execute();
stmt.close();
refresh();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();

View File

@ -1,7 +1,10 @@
package org.fox.ttrss.offline;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Resources.Theme;
import android.database.Cursor;
@ -129,7 +132,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
return true;
}
private boolean onArticleMenuItemSelected(MenuItem item, int articleId) {
private boolean onArticleMenuItemSelected(MenuItem item, final int articleId) {
switch (item.getItemId()) {
case R.id.headlines_article_link_copy:
if (true) {
@ -159,28 +162,35 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
return true;
case R.id.catchup_above:
if (true) {
SQLiteStatement stmt = null;
if (m_prefs.getBoolean("confirm_headlines_catchup", true)) {
String updatedOperator = (m_prefs.getBoolean("offline_oldest_first", false)) ? "<" : ">";
AlertDialog.Builder builder = new AlertDialog.Builder(
m_activity)
.setMessage(R.string.confirm_catchup_above)
.setPositiveButton(R.string.dialog_ok,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if (m_feedIsCat) {
stmt = m_activity.getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated "+updatedOperator+" (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND unread = 1 AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
catchupAbove(articleId);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
} else {
stmt = m_activity.getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated "+updatedOperator+" (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND unread = 1 AND feed_id = ?");
catchupAbove(articleId);
}
stmt.bindLong(1, articleId);
stmt.bindLong(2, m_feedId);
stmt.execute();
stmt.close();
}
refresh();
return true;
default:
Log.d(TAG, "onArticleMenuItemSelected, unhandled id=" + item.getItemId());
@ -189,6 +199,31 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
}
private void catchupAbove(int articleId) {
SQLiteStatement stmt = null;
String updatedOperator = (m_prefs.getBoolean("offline_oldest_first", false)) ? "<" : ">";
if (m_feedIsCat) {
stmt = m_activity.getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated "+updatedOperator+" (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND unread = 1 AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)");
} else {
stmt = m_activity.getDatabase().compileStatement(
"UPDATE articles SET modified = 1, unread = 0 WHERE " +
"updated "+updatedOperator+" (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " +
"AND unread = 1 AND feed_id = ?");
}
stmt.bindLong(1, articleId);
stmt.bindLong(2, m_feedId);
stmt.execute();
stmt.close();
refresh();
}
@Override
public void onResume() {
super.onResume();

View File

@ -241,4 +241,6 @@
<string name="open_with_app">Open with app</string>
<string name="prefs_opening_links">Opening links</string>
<string name="open_with">Open with…</string>
<string name="confirm_catchup_above">Mark articles as read?</string>
<string name="dialog_ok">OK</string>
</resources>