From 46c606610e1d84d62f562818332987e98f834ffa Mon Sep 17 00:00:00 2001 From: twig Date: Wed, 1 Jun 2016 07:48:37 +1000 Subject: [PATCH] - added Daemon.supportsRemoteRssManagement() - toggle menu visibility depending on version and connectivity - renamed action_testing/openTesting() to action_remoterss/openRemoteRss() - use Daemon.supportsRemoteRssManagement() instead of instanceof UtorrentAdapter - display list of feeds in swipe menu - UTorrentRssFeed now implements SimpleListItem --- .../org/transdroid/core/gui/TorrentsActivity.java | 8 +++++--- .../core/gui/remoterss/RemoteRssActivity.java | 13 +++++++++++++ app/src/main/java/org/transdroid/daemon/Daemon.java | 3 +++ .../daemon/Utorrent/data/UTorrentRssFeed.java | 8 +++++++- app/src/main/res/menu/activity_torrents_main.xml | 11 +++++------ app/src/main/res/values/strings.xml | 1 + 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index 310f5cbf..eb91e483 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -494,10 +494,12 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE filtersList.setVisibility(View.VISIBLE); filterSearch.setVisibility(View.VISIBLE); boolean addByFile = Daemon.supportsAddByFile(currentConnection.getType()); + boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(currentConnection.getType()); addmenuFileButton.setVisibility(addByFile ? View.VISIBLE : View.GONE); // Primary toolbar menu torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(navigationHelper.enableSearchUi()); torrentsToolbar.getMenu().findItem(R.id.action_rss).setVisible(navigationHelper.enableRssUi()); + torrentsToolbar.getMenu().findItem(R.id.action_remoterss).setVisible(navigationHelper.enableRssUi() && hasRemoteRss); torrentsToolbar.getMenu().findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(false); // Secondary toolbar menu @@ -850,9 +852,9 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE MainSettingsActivity_.intent(this).start(); } - @OptionsItem(R.id.action_testing) - protected void openTesting() { - if (currentConnection instanceof UtorrentAdapter) { + @OptionsItem(R.id.action_remoterss) + protected void openRemoteRss() { + if (Daemon.supportsRemoteRssManagement(currentConnection.getType())) { ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssFeeds(); RemoteRssActivity_.intent(this) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java index ca2056b9..383e0808 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java @@ -22,12 +22,14 @@ import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.widget.ListView; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.FragmentById; import org.androidannotations.annotations.InstanceState; +import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.ViewById; @@ -35,6 +37,7 @@ import org.transdroid.R; import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.gui.TorrentsActivity; import org.transdroid.core.gui.TorrentsActivity_; +import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.daemon.Utorrent.data.UTorrentRssFeed; import java.util.ArrayList; @@ -59,6 +62,9 @@ public class RemoteRssActivity extends AppCompatActivity { @ViewById protected Toolbar torrentsToolbar; + @ViewById + protected ListView drawerList; + @FragmentById(R.id.remoterss_fragment) protected RemoteRssFragment fragmentRemoteRss; @@ -96,6 +102,8 @@ public class RemoteRssActivity extends AppCompatActivity { // TODO: show all items fragmentRemoteRss.updateTorrentFiles(feeds.get(0).files); + + drawerList.setAdapter(new SimpleListItemAdapter(this, feeds)); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -314,4 +322,9 @@ public class RemoteRssActivity extends AppCompatActivity { // fragmentDetails.perhapsUpdateTorrent(torrents); // fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); // } + + @ItemClick(R.id.drawer_list) + protected void onFeedSelected(int position) { + fragmentRemoteRss.updateTorrentFiles(feeds.get(position).files); + } } diff --git a/app/src/main/java/org/transdroid/daemon/Daemon.java b/app/src/main/java/org/transdroid/daemon/Daemon.java index 9d02d30b..9cb96642 100644 --- a/app/src/main/java/org/transdroid/daemon/Daemon.java +++ b/app/src/main/java/org/transdroid/daemon/Daemon.java @@ -375,4 +375,7 @@ public enum Daemon { return type == Deluge || type == Aria2; } + public static boolean supportsRemoteRssManagement(Daemon type) { + return type == uTorrent; + } } diff --git a/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java b/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java index 653aac41..d1aa551c 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java +++ b/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java @@ -6,6 +6,7 @@ import android.util.Log; import org.json.JSONArray; import org.json.JSONException; +import org.transdroid.core.gui.lists.SimpleListItem; import java.util.ArrayList; import java.util.List; @@ -13,7 +14,7 @@ import java.util.List; /** * Created by twig on 29/05/2016. */ -public class UTorrentRssFeed implements Parcelable { +public class UTorrentRssFeed implements Parcelable, SimpleListItem { /** * [ * 1, // id? @@ -166,4 +167,9 @@ public class UTorrentRssFeed implements Parcelable { return new UTorrentRssFeed[size]; } }; + + @Override + public String getName() { + return feedAlias; + } } diff --git a/app/src/main/res/menu/activity_torrents_main.xml b/app/src/main/res/menu/activity_torrents_main.xml index e4cd2353..427872af 100644 --- a/app/src/main/res/menu/activity_torrents_main.xml +++ b/app/src/main/res/menu/activity_torrents_main.xml @@ -28,6 +28,11 @@ android:icon="@drawable/ic_action_rss" android:title="@string/action_rss" app:showAsAction="ifRoom" /> + - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8181e78..1f580397 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ Search Refresh RSS + Server RSS Enable turtle mode Disable turtle mode Sort list