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

View File

@ -1,7 +1,10 @@
package org.fox.ttrss; package org.fox.ttrss;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
@ -181,6 +184,45 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
return true; return true;
case R.id.catchup_above: case R.id.catchup_above:
if (true) { if (true) {
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);
}
}
return true;
default:
Log.d(TAG, "onArticleMenuItemSelected, unhandled id=" + item.getItemId());
return false;
}
}
private void catchupAbove(Article article) {
ArticleList articles = getAllArticles(); ArticleList articles = getAllArticles();
ArticleList tmp = new ArticleList(); ArticleList tmp = new ArticleList();
for (Article a : articles) { for (Article a : articles) {
@ -198,12 +240,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
m_adapter.notifyDataSetChanged(); m_adapter.notifyDataSetChanged();
} }
return true;
default:
Log.d(TAG, "onArticleMenuItemSelected, unhandled id=" + item.getItemId());
return false;
}
}
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item AdapterContextMenuInfo info = (AdapterContextMenuInfo) item

View File

@ -32,10 +32,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; 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.OfflineActivity;
import org.fox.ttrss.offline.OfflineDownloadService; 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.ArticleList;
import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.Feed;
import org.fox.ttrss.types.Label; 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.lang.reflect.Type;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -897,26 +888,35 @@ public class OnlineActivity extends CommonActivity {
return true; return true;
case R.id.catchup_above: case R.id.catchup_above:
if (hf != null) { if (hf != null) {
if (ap != null && ap.getSelectedArticle() != null) {
Article article = ap.getSelectedArticle();
ArticleList articles = hf.getAllArticles(); if (m_prefs.getBoolean("confirm_headlines_catchup", true)) {
ArticleList tmp = new ArticleList();
for (Article a : articles) { AlertDialog.Builder builder = new AlertDialog.Builder(
if (article.id == a.id) OnlineActivity.this)
break; .setMessage(R.string.confirm_catchup_above)
.setPositiveButton(R.string.dialog_ok,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
catchupAbove(hf, ap);
if (a.unread) {
a.unread = false;
tmp.add(a);
} }
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
} }
if (tmp.size() > 0) { });
toggleArticlesUnread(tmp);
hf.notifyUpdated(); AlertDialog dlg = builder.create();
invalidateOptionsMenu(); dlg.show();
} } else {
catchupAbove(hf, ap);
} }
} }
return true; return true;
case R.id.set_labels: case R.id.set_labels:
@ -941,6 +941,29 @@ public class OnlineActivity extends CommonActivity {
} }
} }
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() { protected void catchupVisibleArticles() {
final HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); 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.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import org.fox.ttrss.CommonActivity; import org.fox.ttrss.CommonActivity;
import org.fox.ttrss.PreferencesActivity; import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class OfflineActivity extends CommonActivity { public class OfflineActivity extends CommonActivity {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
@ -492,6 +488,42 @@ public class OfflineActivity extends CommonActivity {
return true; return true;
case R.id.catchup_above: case R.id.catchup_above:
if (oap != null) { if (oap != null) {
if (m_prefs.getBoolean("confirm_headlines_catchup", true)) {
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 {
catchupAbove(oap);
}
}
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
}
}
private void catchupAbove(OfflineArticlePager oap) {
int articleId = oap.getSelectedArticleId(); int articleId = oap.getSelectedArticleId();
int feedId = oap.getFeedId(); int feedId = oap.getFeedId();
boolean isCat = oap.getFeedIsCat(); boolean isCat = oap.getFeedIsCat();
@ -517,12 +549,6 @@ public class OfflineActivity extends CommonActivity {
refresh(); refresh();
} }
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
}
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {

View File

@ -1,7 +1,10 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources.Theme; import android.content.res.Resources.Theme;
import android.database.Cursor; import android.database.Cursor;
@ -129,7 +132,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
return true; return true;
} }
private boolean onArticleMenuItemSelected(MenuItem item, int articleId) { private boolean onArticleMenuItemSelected(MenuItem item, final int articleId) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.headlines_article_link_copy: case R.id.headlines_article_link_copy:
if (true) { if (true) {
@ -159,6 +162,44 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
return true; return true;
case R.id.catchup_above: case R.id.catchup_above:
if (true) { if (true) {
if (m_prefs.getBoolean("confirm_headlines_catchup", true)) {
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(articleId);
}
})
.setNegativeButton(R.string.dialog_cancel,
new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
AlertDialog dlg = builder.create();
dlg.show();
} else {
catchupAbove(articleId);
}
}
return true;
default:
Log.d(TAG, "onArticleMenuItemSelected, unhandled id=" + item.getItemId());
return false;
}
}
private void catchupAbove(int articleId) {
SQLiteStatement stmt = null; SQLiteStatement stmt = null;
String updatedOperator = (m_prefs.getBoolean("offline_oldest_first", false)) ? "<" : ">"; String updatedOperator = (m_prefs.getBoolean("offline_oldest_first", false)) ? "<" : ">";
@ -179,14 +220,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
stmt.bindLong(2, m_feedId); stmt.bindLong(2, m_feedId);
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
}
refresh();
return true;
default:
Log.d(TAG, "onArticleMenuItemSelected, unhandled id=" + item.getItemId());
return false;
}
refresh();
} }
@Override @Override

View File

@ -241,4 +241,6 @@
<string name="open_with_app">Open with app</string> <string name="open_with_app">Open with app</string>
<string name="prefs_opening_links">Opening links</string> <string name="prefs_opening_links">Opening links</string>
<string name="open_with">Open with…</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> </resources>