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 f528b4a1..fcb2165c 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -471,6 +471,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE filterSearch.setVisibility(View.GONE); torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(false); torrentsToolbar.getMenu().findItem(R.id.action_rss).setVisible(false); + torrentsToolbar.getMenu().findItem(R.id.action_remoterss).setVisible(false); torrentsToolbar.getMenu().findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(true); actionsToolbar.getMenu().findItem(R.id.action_enableturtle).setVisible(false); @@ -499,7 +500,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE // 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_remoterss).setVisible(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 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 f5ae9917..444c5b08 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 @@ -20,6 +20,7 @@ import android.annotation.TargetApi; import android.content.Intent; import android.os.Build; import android.os.Bundle; +import android.os.Parcel; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.widget.ListView; @@ -38,8 +39,14 @@ import org.transdroid.core.gui.TorrentsActivity; 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; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +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 @@ -54,8 +61,15 @@ public class RemoteRssActivity extends AppCompatActivity { @InstanceState protected ArrayList feeds; - // Settings -// private IDaemonAdapter currentConnection = null; + @InstanceState + protected ArrayList recentItems; + +// // Settings +// @Bean +// protected ApplicationSettings applicationSettings; +// @Bean +// protected ConnectivityHelper connectivityHelper; +// private IDaemonAdapter currentConnection; // Details view components @ViewById @@ -92,17 +106,13 @@ public class RemoteRssActivity extends AppCompatActivity { // // Connect to the last used server // ServerSetting lastUsed = applicationSettings.getLastUsedServer(); -// fragmentDetails.setCurrentServerSettings(lastUsed); // currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); -// // Show details and load fine stats and torrent files -// fragmentDetails.updateTorrent(torrent); -// fragmentDetails.updateLabels(currentLabels); + // Show all items + showRecentItems(); - // TODO: show all items - fragmentRemoteRss.updateTorrentFiles(feeds.get(0).getFiles()); - - drawerList.setAdapter(new SimpleListItemAdapter(this, feeds)); + // Fill in the filter list + showChannelFilters(); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -322,8 +332,57 @@ public class RemoteRssActivity extends AppCompatActivity { // fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); // } + protected void showRecentItems() { + if (recentItems == null) { + recentItems = new ArrayList<>(); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + Date oneMonthAgo = calendar.getTime(); + + for (RemoteRssChannel feed : feeds) { + for (RemoteRssItem item : feed.getItems()) { + if (item.getTimestamp().after(oneMonthAgo)) { + recentItems.add(item); + } + } + } + + // Sort by -newest + Collections.sort(recentItems, new Comparator() { + @Override + public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { + return rhs.getTimestamp().compareTo(lhs.getTimestamp()); + } + }); + } + + fragmentRemoteRss.updateTorrentFiles(recentItems); + } + + protected void showChannelFilters() { + List feedLabels = new ArrayList<>(feeds.size() +1); + feedLabels.add(new RemoteRssChannel() { + @Override + public String getName() { + return "(All recent)"; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + } + }); + feedLabels.addAll(feeds); + + drawerList.setAdapter(new SimpleListItemAdapter(this, feedLabels)); + } + @ItemClick(R.id.drawer_list) protected void onFeedSelected(int position) { - fragmentRemoteRss.updateTorrentFiles(feeds.get(position).getFiles()); + if (position == 0) { + showRecentItems(); + } + else { + fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems()); + } } } diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java b/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java index d5fcd486..f8685813 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java @@ -34,7 +34,7 @@ public abstract class RemoteRssChannel implements Parcelable, SimpleListItem { return new Date(lastUpdated); } - public List getFiles() { + public List getItems() { return files; } diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java b/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java index dba69339..5e5de8db 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java @@ -13,7 +13,7 @@ public abstract class RemoteRssItem implements Parcelable, SimpleListItem { protected String title; protected String link; protected String sourceName; // Name of RSS feed channel - protected long timestamp; + protected Date timestamp; @Override public String getName() { @@ -37,7 +37,7 @@ public abstract class RemoteRssItem implements Parcelable, SimpleListItem { } public Date getTimestamp() { - return new Date(timestamp); + return timestamp; } @Override 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 53b2dbd8..1ea2b120 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java @@ -71,6 +71,8 @@ import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.List; @@ -333,6 +335,13 @@ public class UtorrentAdapter implements IDaemonAdapter { e.printStackTrace(); } } + + Collections.sort(rssFeedItems, new Comparator() { + @Override + public int compare(RemoteRssChannel lhs, RemoteRssChannel rhs) { + return lhs.getName().compareToIgnoreCase(rhs.getName()); + } + }); } private ArrayList