From 255311300f7b8b8dbfb7586333ae0385043b2487 Mon Sep 17 00:00:00 2001 From: twig Date: Tue, 7 Jun 2016 19:36:26 +1000 Subject: [PATCH] - renamed RemoteRssFilesAdapter to RemoteRssItemsAdapter - renamed RemoteRssItemsAdapter.updateFiles() to updateItems() - added RemoteRssSupplier interface - removed hard cast in openRemoteRss() and used RemoteRssSupplier - updated comment for RemoteRssActivity - RemoteRssActivity.init() now displays a message about configuring RSS feeds if no items are found - moved "(All recent)" hardcoded string to strings.xml - renamed RemoteRssFragment.torrentFiles to remoteRssItems - misc commenting changes --- .../transdroid/core/gui/TorrentsActivity.java | 4 ++-- .../core/gui/remoterss/RemoteRssActivity.java | 20 ++++++++--------- .../core/gui/remoterss/RemoteRssFragment.java | 22 ++++++++++++------- ...dapter.java => RemoteRssItemsAdapter.java} | 8 +++---- .../gui/remoterss/data/RemoteRssSupplier.java | 12 ++++++++++ .../daemon/Utorrent/UtorrentAdapter.java | 5 ++++- .../main/res/layout/activity_remoterss.xml | 12 ---------- .../main/res/layout/fragment_remoterss.xml | 7 ++++++ app/src/main/res/values/strings.xml | 5 ++++- 9 files changed, 57 insertions(+), 38 deletions(-) rename app/src/main/java/org/transdroid/core/gui/remoterss/{RemoteRssFilesAdapter.java => RemoteRssItemsAdapter.java} (83%) create mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssSupplier.java 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 0b99e814..e30469a5 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -85,6 +85,7 @@ import org.transdroid.core.gui.navigation.RefreshableActivity; import org.transdroid.core.gui.navigation.StatusType; import org.transdroid.core.gui.remoterss.RemoteRssActivity_; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; +import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; import org.transdroid.core.gui.rss.RssfeedsActivity_; import org.transdroid.core.gui.search.BarcodeHelper; import org.transdroid.core.gui.search.FilePickerHelper; @@ -101,7 +102,6 @@ import org.transdroid.daemon.Torrent; import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentFile; import org.transdroid.daemon.TorrentsSortBy; -import org.transdroid.daemon.Utorrent.UtorrentAdapter; import org.transdroid.daemon.task.AddByFileTask; import org.transdroid.daemon.task.AddByMagnetUrlTask; import org.transdroid.daemon.task.AddByUrlTask; @@ -855,7 +855,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @OptionsItem(R.id.action_remoterss) protected void openRemoteRss() { - ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels(); + ArrayList rssFeedItems = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(); if (rssFeedItems.size() == 0) { return; 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 d5ffd22e..e03e9e72 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 @@ -39,7 +39,6 @@ import org.transdroid.R; import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.SystemSettings_; -import org.transdroid.core.gui.TorrentsActivity; import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; @@ -54,10 +53,12 @@ import java.util.Date; import java.util.List; /** - * An activity that holds a single torrents details fragment. It is used on devices (i.e. phones) where there is no room to show details in the {@link - * TorrentsActivity} directly. Task execution, such as loading of more details and updating file priorities, is performed in this activity via - * background methods. - * @author Eric Kok + * An activity that displays a list of {@link RemoteRssItem}s via an instance of {@link RemoteRssFragment}. + * The activity manages the drawer to filter items by the feed they came through. + * + * By default it displays the latest items within the last month. + * + * @author Twig Nguyen */ @EActivity(R.layout.activity_remoterss) public class RemoteRssActivity extends AppCompatActivity { @@ -104,8 +105,7 @@ public class RemoteRssActivity extends AppCompatActivity { // We require feeds to be specified; otherwise close the activity if (feeds == null) { - finish(); - return; + feeds = new ArrayList<>(); } // Simple action bar with up, torrent name as title and refresh button @@ -168,7 +168,7 @@ public class RemoteRssActivity extends AppCompatActivity { }); } - fragmentRemoteRss.updateTorrentFiles(recentItems); + fragmentRemoteRss.updateRemoteItems(recentItems); RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(0); getSupportActionBar().setSubtitle(channel.getName()); } @@ -178,7 +178,7 @@ public class RemoteRssActivity extends AppCompatActivity { feedLabels.add(new RemoteRssChannel() { @Override public String getName() { - return "(All recent)"; + return getString(R.string.remoterss_filter_allrecent); } @Override @@ -196,7 +196,7 @@ public class RemoteRssActivity extends AppCompatActivity { showRecentItems(); } else { - fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems()); + fragmentRemoteRss.updateRemoteItems(feeds.get(position -1).getItems()); } RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index 2f470192..cacd3593 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -22,6 +22,7 @@ import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.ActionMenuView; import android.view.View; import android.widget.ListView; +import android.widget.TextView; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; @@ -62,7 +63,7 @@ public class RemoteRssFragment extends Fragment { // Local data @InstanceState - protected ArrayList torrentFiles; + protected ArrayList remoteRssItems; // Views @ViewById @@ -73,8 +74,10 @@ public class RemoteRssFragment extends Fragment { protected SwipeRefreshLayout swipeRefreshLayout; @ViewById protected ListView torrentsList; + @ViewById + protected TextView remoterssNoFilesMessage; - protected RemoteRssFilesAdapter adapter; + protected RemoteRssItemsAdapter adapter; @AfterViews protected void init() { @@ -93,23 +96,26 @@ public class RemoteRssFragment extends Fragment { // } // Set up details adapter - adapter = new RemoteRssFilesAdapter(getActivity()); + adapter = new RemoteRssItemsAdapter(getActivity()); torrentsList.setAdapter(adapter); torrentsList.setFastScrollEnabled(true); // Restore the fragment state (on orientation changes et al.) - if (torrentFiles != null) { - updateTorrentFiles(torrentFiles); + if (remoteRssItems != null) { + updateRemoteItems(remoteRssItems); } } /** * Updates the list adapter to show a new list of torrent files, replacing the old files list. */ - public void updateTorrentFiles(List remoteRssFiles) { - torrentFiles = new ArrayList<>(remoteRssFiles); - adapter.updateFiles(torrentFiles); + public void updateRemoteItems(List remoteItems) { + remoteRssItems = new ArrayList<>(remoteItems); + adapter.updateItems(remoteRssItems); torrentsList.smoothScrollToPosition(0); + + // Show/hide a nice message if there are no items to show + remoterssNoFilesMessage.setVisibility(remoteRssItems.size() > 0 ? View.GONE : View.VISIBLE); } /** diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemsAdapter.java similarity index 83% rename from app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java rename to app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemsAdapter.java index 2a8e8da2..e9c4b07f 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemsAdapter.java @@ -10,11 +10,11 @@ import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import java.util.ArrayList; import java.util.List; -public class RemoteRssFilesAdapter extends BaseAdapter { +public class RemoteRssItemsAdapter extends BaseAdapter { protected Context context; protected List items; - public RemoteRssFilesAdapter(Context context) { + public RemoteRssItemsAdapter(Context context) { this.context = context; items = new ArrayList<>(); } @@ -50,8 +50,8 @@ public class RemoteRssFilesAdapter extends BaseAdapter { return itemView; } - public void updateFiles(List torrentFiles) { - items = torrentFiles; + public void updateItems(List remoteItems) { + items = remoteItems; notifyDataSetChanged(); } } diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssSupplier.java b/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssSupplier.java new file mode 100644 index 00000000..8e74c318 --- /dev/null +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssSupplier.java @@ -0,0 +1,12 @@ +package org.transdroid.core.gui.remoterss.data; + +import java.util.ArrayList; + +/** + * Interface for daemon adapters if they support remote RSS management. + * + * @author Twig + */ +public interface RemoteRssSupplier { + ArrayList getRemoteRssChannels(); +} diff --git a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java index 1a7fe158..171e50d4 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java @@ -30,6 +30,7 @@ import org.json.JSONException; import org.json.JSONObject; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; +import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; import org.transdroid.daemon.Daemon; import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.DaemonException.ExceptionType; @@ -81,7 +82,7 @@ import java.util.List; * HTTP GET requests and responses. * @author erickok */ -public class UtorrentAdapter implements IDaemonAdapter { +public class UtorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { private static final String LOG_NAME = "uTorrent daemon"; private static final String RPC_URL_HASH = "&hash="; @@ -332,6 +333,8 @@ public class UtorrentAdapter implements IDaemonAdapter { item = new UTorrentRemoteRssChannel(results.getJSONArray(i)); remoteRssChannels.add(item); } catch (JSONException e) { + // Ignore unparseable items so app doesn't crash. + // Haven't run into a case where this fails, yet. e.printStackTrace(); } } diff --git a/app/src/main/res/layout/activity_remoterss.xml b/app/src/main/res/layout/activity_remoterss.xml index 7353fd89..292f3a49 100644 --- a/app/src/main/res/layout/activity_remoterss.xml +++ b/app/src/main/res/layout/activity_remoterss.xml @@ -74,18 +74,6 @@ android:divider="@null" tools:listitem="@layout/list_item_filter" /> - - - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_remoterss.xml b/app/src/main/res/layout/fragment_remoterss.xml index 4759db6b..b786a4f5 100644 --- a/app/src/main/res/layout/fragment_remoterss.xml +++ b/app/src/main/res/layout/fragment_remoterss.xml @@ -20,6 +20,13 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + %1$s new RSS feed torrents New torrents for %1$s - + + (All recent) + No torrent files found.\n\nAre your RSS feeds configured correctly? + Loading… Open Transdroid SERVER VIEW