Browse Source

- hide remoterss toolbar button if no server configured/connected

- show all recent remote feed items in the last month by default ordered by -date
- show "all recent" in rss feeds filter menu
- renamed RemoteRssChannel.getFiles() to getItems()
- RemoteRssItem.timestamp is now of type Date
- sort feeds by name upon fetch
- fragment_remoterss.xml now shows the right item in layout editor
pull/313/head
twig 9 years ago
parent
commit
1e850dae3f
  1. 3
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 81
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java
  3. 2
      app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java
  4. 4
      app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java
  5. 9
      app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java
  6. 13
      app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java
  7. 2
      app/src/main/res/layout/fragment_remoterss.xml

3
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -471,6 +471,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -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 @@ -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

81
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java

@ -20,6 +20,7 @@ import android.annotation.TargetApi; @@ -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; @@ -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 { @@ -54,8 +61,15 @@ public class RemoteRssActivity extends AppCompatActivity {
@InstanceState
protected ArrayList<RemoteRssChannel> feeds;
// Settings
// private IDaemonAdapter currentConnection = null;
@InstanceState
protected ArrayList<RemoteRssItem> 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 { @@ -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);
// TODO: show all items
fragmentRemoteRss.updateTorrentFiles(feeds.get(0).getFiles());
// Show all items
showRecentItems();
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 { @@ -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<RemoteRssItem>() {
@Override
public int compare(RemoteRssItem lhs, RemoteRssItem rhs) {
return rhs.getTimestamp().compareTo(lhs.getTimestamp());
}
});
}
fragmentRemoteRss.updateTorrentFiles(recentItems);
}
protected void showChannelFilters() {
List<RemoteRssChannel> 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());
}
}
}

2
app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java

@ -34,7 +34,7 @@ public abstract class RemoteRssChannel implements Parcelable, SimpleListItem { @@ -34,7 +34,7 @@ public abstract class RemoteRssChannel implements Parcelable, SimpleListItem {
return new Date(lastUpdated);
}
public List<RemoteRssItem> getFiles() {
public List<RemoteRssItem> getItems() {
return files;
}

4
app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java

@ -13,7 +13,7 @@ public abstract class RemoteRssItem implements Parcelable, SimpleListItem { @@ -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 { @@ -37,7 +37,7 @@ public abstract class RemoteRssItem implements Parcelable, SimpleListItem {
}
public Date getTimestamp() {
return new Date(timestamp);
return timestamp;
}
@Override

9
app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java

@ -71,6 +71,8 @@ import java.io.UnsupportedEncodingException; @@ -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 { @@ -333,6 +335,13 @@ public class UtorrentAdapter implements IDaemonAdapter {
e.printStackTrace();
}
}
Collections.sort(rssFeedItems, new Comparator<RemoteRssChannel>() {
@Override
public int compare(RemoteRssChannel lhs, RemoteRssChannel rhs) {
return lhs.getName().compareToIgnoreCase(rhs.getName());
}
});
}
private ArrayList<Label> parseJsonRetrieveGetLabels(JSONArray lresults) throws JSONException {

13
app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java

@ -7,6 +7,9 @@ import org.json.JSONArray; @@ -7,6 +7,9 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import java.util.Calendar;
import java.util.Date;
public class UTorrentRemoteRssItem extends RemoteRssItem {
public String name;
// public int season;
@ -16,7 +19,11 @@ public class UTorrentRemoteRssItem extends RemoteRssItem { @@ -16,7 +19,11 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
name = json.getString(0);
title = json.getString(1);
link = json.getString(2);
timestamp = json.getLong(5);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(json.getLong(5) * 1000);
timestamp = calendar.getTime();
// season = json.getInt(6);
// episode = json.getInt(7);
}
@ -37,7 +44,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem { @@ -37,7 +44,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
title = in.readString();
link = in.readString();
sourceName = in.readString();
timestamp = in.readLong();
timestamp = (Date) in.readSerializable();
// season = in.readInt();
// episode = in.readInt();
}
@ -48,7 +55,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem { @@ -48,7 +55,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
dest.writeString(title);
dest.writeString(link);
dest.writeString(sourceName);
dest.writeLong(timestamp);
dest.writeSerializable(timestamp);
// dest.writeInt(season);
// dest.writeInt(episode);
}

2
app/src/main/res/layout/fragment_remoterss.xml

@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
android:layout_height="match_parent"
android:choiceMode="multipleChoiceModal"
android:clipToPadding="false"
tools:listitem="@layout/list_item_rssitem"
tools:listitem="@layout/list_item_remoterssitem"
tools:visibility="visible"/>
</FrameLayout>

Loading…
Cancel
Save