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
filterSearch.setVisibility(View.GONE); filterSearch.setVisibility(View.GONE);
torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(false); torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(false);
torrentsToolbar.getMenu().findItem(R.id.action_rss).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_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(true); torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(true);
actionsToolbar.getMenu().findItem(R.id.action_enableturtle).setVisible(false); actionsToolbar.getMenu().findItem(R.id.action_enableturtle).setVisible(false);
@ -499,7 +500,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
// Primary toolbar menu // Primary toolbar menu
torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(navigationHelper.enableSearchUi()); 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_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_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(false); torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(false);
// Secondary toolbar menu // Secondary toolbar menu

81
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.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.widget.ListView; 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.TorrentsActivity_;
import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import java.util.ArrayList; 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 * 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 @InstanceState
protected ArrayList<RemoteRssChannel> feeds; protected ArrayList<RemoteRssChannel> feeds;
// Settings @InstanceState
// private IDaemonAdapter currentConnection = null; protected ArrayList<RemoteRssItem> recentItems;
// // Settings
// @Bean
// protected ApplicationSettings applicationSettings;
// @Bean
// protected ConnectivityHelper connectivityHelper;
// private IDaemonAdapter currentConnection;
// Details view components // Details view components
@ViewById @ViewById
@ -92,17 +106,13 @@ public class RemoteRssActivity extends AppCompatActivity {
// // Connect to the last used server // // Connect to the last used server
// ServerSetting lastUsed = applicationSettings.getLastUsedServer(); // ServerSetting lastUsed = applicationSettings.getLastUsedServer();
// fragmentDetails.setCurrentServerSettings(lastUsed);
// currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); // currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
// // Show details and load fine stats and torrent files // Show all items
// fragmentDetails.updateTorrent(torrent); showRecentItems();
// fragmentDetails.updateLabels(currentLabels);
// TODO: show all items // Fill in the filter list
fragmentRemoteRss.updateTorrentFiles(feeds.get(0).getFiles()); showChannelFilters();
drawerList.setAdapter(new SimpleListItemAdapter(this, feeds));
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @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))); // 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) @ItemClick(R.id.drawer_list)
protected void onFeedSelected(int position) { 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 {
return new Date(lastUpdated); return new Date(lastUpdated);
} }
public List<RemoteRssItem> getFiles() { public List<RemoteRssItem> getItems() {
return files; 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 {
protected String title; protected String title;
protected String link; protected String link;
protected String sourceName; // Name of RSS feed channel protected String sourceName; // Name of RSS feed channel
protected long timestamp; protected Date timestamp;
@Override @Override
public String getName() { public String getName() {
@ -37,7 +37,7 @@ public abstract class RemoteRssItem implements Parcelable, SimpleListItem {
} }
public Date getTimestamp() { public Date getTimestamp() {
return new Date(timestamp); return timestamp;
} }
@Override @Override

9
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.URI;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -333,6 +335,13 @@ public class UtorrentAdapter implements IDaemonAdapter {
e.printStackTrace(); 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 { 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;
import org.json.JSONException; import org.json.JSONException;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import java.util.Calendar;
import java.util.Date;
public class UTorrentRemoteRssItem extends RemoteRssItem { public class UTorrentRemoteRssItem extends RemoteRssItem {
public String name; public String name;
// public int season; // public int season;
@ -16,7 +19,11 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
name = json.getString(0); name = json.getString(0);
title = json.getString(1); title = json.getString(1);
link = json.getString(2); 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); // season = json.getInt(6);
// episode = json.getInt(7); // episode = json.getInt(7);
} }
@ -37,7 +44,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
title = in.readString(); title = in.readString();
link = in.readString(); link = in.readString();
sourceName = in.readString(); sourceName = in.readString();
timestamp = in.readLong(); timestamp = (Date) in.readSerializable();
// season = in.readInt(); // season = in.readInt();
// episode = in.readInt(); // episode = in.readInt();
} }
@ -48,7 +55,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
dest.writeString(title); dest.writeString(title);
dest.writeString(link); dest.writeString(link);
dest.writeString(sourceName); dest.writeString(sourceName);
dest.writeLong(timestamp); dest.writeSerializable(timestamp);
// dest.writeInt(season); // dest.writeInt(season);
// dest.writeInt(episode); // dest.writeInt(episode);
} }

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

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

Loading…
Cancel
Save