Browse Source

- refactored RemoteRssChannel and RemoteRssItem to be reusable for other clients

- renamed UTorrentRssFeed to UTorrentRemoteRssChannel and removed a bunch of unnecessary data
- renamed RemoteRssFile to UTorrentRemoteRssItem
pull/313/head
twig 9 years ago
parent
commit
073fa6d9e5
  1. 4
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 8
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java
  3. 8
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java
  4. 6
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java
  5. 8
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java
  6. 45
      app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java
  7. 47
      app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java
  8. 11
      app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java
  9. 69
      app/src/main/java/org/transdroid/daemon/Utorrent/data/RemoteRssFile.java
  10. 78
      app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssChannel.java
  11. 55
      app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java

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

@ -84,6 +84,7 @@ import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.RefreshableActivity; import org.transdroid.core.gui.navigation.RefreshableActivity;
import org.transdroid.core.gui.navigation.StatusType; import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.remoterss.RemoteRssActivity_; import org.transdroid.core.gui.remoterss.RemoteRssActivity_;
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.rss.RssfeedsActivity_; import org.transdroid.core.gui.rss.RssfeedsActivity_;
import org.transdroid.core.gui.search.BarcodeHelper; import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.FilePickerHelper;
@ -101,7 +102,6 @@ import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile; import org.transdroid.daemon.TorrentFile;
import org.transdroid.daemon.TorrentsSortBy; import org.transdroid.daemon.TorrentsSortBy;
import org.transdroid.daemon.Utorrent.UtorrentAdapter; import org.transdroid.daemon.Utorrent.UtorrentAdapter;
import org.transdroid.daemon.Utorrent.data.UTorrentRssFeed;
import org.transdroid.daemon.task.AddByFileTask; import org.transdroid.daemon.task.AddByFileTask;
import org.transdroid.daemon.task.AddByMagnetUrlTask; import org.transdroid.daemon.task.AddByMagnetUrlTask;
import org.transdroid.daemon.task.AddByUrlTask; import org.transdroid.daemon.task.AddByUrlTask;
@ -855,7 +855,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@OptionsItem(R.id.action_remoterss) @OptionsItem(R.id.action_remoterss)
protected void openRemoteRss() { protected void openRemoteRss() {
if (Daemon.supportsRemoteRssManagement(currentConnection.getType())) { if (Daemon.supportsRemoteRssManagement(currentConnection.getType())) {
ArrayList<UTorrentRssFeed> rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssFeeds(); ArrayList<RemoteRssChannel> rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels();
RemoteRssActivity_.intent(this) RemoteRssActivity_.intent(this)
.feeds(rssFeedItems) .feeds(rssFeedItems)

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

@ -38,7 +38,7 @@ import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.gui.TorrentsActivity; 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.daemon.Utorrent.data.UTorrentRssFeed; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,7 +53,7 @@ import java.util.ArrayList;
public class RemoteRssActivity extends AppCompatActivity { public class RemoteRssActivity extends AppCompatActivity {
@Extra @Extra
@InstanceState @InstanceState
protected ArrayList<UTorrentRssFeed> feeds; protected ArrayList<RemoteRssChannel> feeds;
// Settings // Settings
// private IDaemonAdapter currentConnection = null; // private IDaemonAdapter currentConnection = null;
@ -101,7 +101,7 @@ public class RemoteRssActivity extends AppCompatActivity {
// fragmentDetails.updateLabels(currentLabels); // fragmentDetails.updateLabels(currentLabels);
// TODO: show all items // TODO: show all items
fragmentRemoteRss.updateTorrentFiles(feeds.get(0).files); fragmentRemoteRss.updateTorrentFiles(feeds.get(0).getFiles());
drawerList.setAdapter(new SimpleListItemAdapter(this, feeds)); drawerList.setAdapter(new SimpleListItemAdapter(this, feeds));
} }
@ -325,6 +325,6 @@ public class RemoteRssActivity extends AppCompatActivity {
@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).files); fragmentRemoteRss.updateTorrentFiles(feeds.get(position).getFiles());
} }
} }

8
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java

@ -5,14 +5,14 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import org.transdroid.daemon.Utorrent.data.RemoteRssFile; import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RemoteRssFilesAdapter extends BaseAdapter { public class RemoteRssFilesAdapter extends BaseAdapter {
protected Context context; protected Context context;
protected List<RemoteRssFile> files; protected List<RemoteRssItem> files;
public RemoteRssFilesAdapter(Context context) { public RemoteRssFilesAdapter(Context context) {
this.context = context; this.context = context;
@ -45,12 +45,12 @@ public class RemoteRssFilesAdapter extends BaseAdapter {
itemView = (RemoteRssItemView) convertView; itemView = (RemoteRssItemView) convertView;
} }
itemView.bind((RemoteRssFile) getItem(position)); itemView.bind((RemoteRssItem) getItem(position));
return itemView; return itemView;
} }
public void updateFiles(List<RemoteRssFile> torrentFiles) { public void updateFiles(List<RemoteRssItem> torrentFiles) {
files = torrentFiles; files = torrentFiles;
notifyDataSetChanged(); notifyDataSetChanged();
} }

6
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java

@ -29,7 +29,7 @@ import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.daemon.Utorrent.data.RemoteRssFile; import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -45,7 +45,7 @@ public class RemoteRssFragment extends Fragment {
// Local data // Local data
@InstanceState @InstanceState
protected ArrayList<RemoteRssFile> torrentFiles; protected ArrayList<RemoteRssItem> torrentFiles;
// Views // Views
@ViewById @ViewById
@ -102,7 +102,7 @@ public class RemoteRssFragment extends Fragment {
* @param checkTorrent The torrent for which the details were retrieved * @param checkTorrent The torrent for which the details were retrieved
* @param newTorrentFiles The new, updated list of torrent file objects * @param newTorrentFiles The new, updated list of torrent file objects
*/ */
public void updateTorrentFiles(List<RemoteRssFile> remoteRssFiles) { public void updateTorrentFiles(List<RemoteRssItem> remoteRssFiles) {
torrentFiles = new ArrayList<>(remoteRssFiles); torrentFiles = new ArrayList<>(remoteRssFiles);
adapter.updateFiles(torrentFiles); adapter.updateFiles(torrentFiles);
} }

8
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java

@ -24,7 +24,7 @@ import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.settings.RssfeedSetting; import org.transdroid.core.app.settings.RssfeedSetting;
import org.transdroid.daemon.Utorrent.data.RemoteRssFile; import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
/** /**
* View that represents some {@link RssfeedSetting} object and displays name as well as loads a favicon for the feed's site and can load how many new * View that represents some {@link RssfeedSetting} object and displays name as well as loads a favicon for the feed's site and can load how many new
@ -41,10 +41,10 @@ public class RemoteRssItemView extends LinearLayout {
super(context); super(context);
} }
public void bind(RemoteRssFile file) { public void bind(RemoteRssItem file) {
nameText.setText(file.getName()); nameText.setText(file.getName());
dateText.setText(String.valueOf(file.timestamp)); dateText.setText(String.valueOf(file.getTimestamp()));
labelText.setText(file.feedLabel); labelText.setText(file.getSourceName());
} }
} }

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

@ -0,0 +1,45 @@
package org.transdroid.core.gui.remoterss.data;
import android.os.Parcelable;
import org.transdroid.core.gui.lists.SimpleListItem;
import java.util.Date;
import java.util.List;
/**
* Created by twig on 1/06/2016.
*/
public abstract class RemoteRssChannel implements Parcelable, SimpleListItem {
protected int id;
protected String name;
protected String link;
protected long lastUpdated;
protected List<RemoteRssItem> files;
@Override
public int describeContents() {
return 0;
}
public int getId() {
return id;
}
public String getLink() {
return link;
}
public Date getLastUpdated() {
return new Date(lastUpdated);
}
public List<RemoteRssItem> getFiles() {
return files;
}
@Override
public String getName() {
return name;
}
}

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

@ -0,0 +1,47 @@
package org.transdroid.core.gui.remoterss.data;
import android.os.Parcelable;
import org.transdroid.core.gui.lists.SimpleListItem;
import java.util.Date;
/**
* Created by twig on 1/06/2016.
*/
public abstract class RemoteRssItem implements Parcelable, SimpleListItem {
protected String title;
protected String link;
protected String sourceName; // Name of RSS feed channel
protected long timestamp;
@Override
public String getName() {
return title;
}
public String getTitle() {
return title;
}
public String getLink() {
return link;
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
public Date getTimestamp() {
return new Date(timestamp);
}
@Override
public int describeContents() {
return 0;
}
}

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

@ -29,6 +29,7 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType; import org.transdroid.daemon.DaemonException.ExceptionType;
@ -40,7 +41,7 @@ import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile; import org.transdroid.daemon.TorrentFile;
import org.transdroid.daemon.TorrentStatus; import org.transdroid.daemon.TorrentStatus;
import org.transdroid.daemon.Utorrent.data.UTorrentRssFeed; import org.transdroid.daemon.Utorrent.data.UTorrentRemoteRssChannel;
import org.transdroid.daemon.task.AddByFileTask; import org.transdroid.daemon.task.AddByFileTask;
import org.transdroid.daemon.task.AddByMagnetUrlTask; import org.transdroid.daemon.task.AddByMagnetUrlTask;
import org.transdroid.daemon.task.AddByUrlTask; import org.transdroid.daemon.task.AddByUrlTask;
@ -114,7 +115,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
private DaemonSettings settings; private DaemonSettings settings;
private DefaultHttpClient httpclient; private DefaultHttpClient httpclient;
private static ArrayList<UTorrentRssFeed> rssFeedItems; private static ArrayList<RemoteRssChannel> rssFeedItems;
@ -322,11 +323,11 @@ public class UtorrentAdapter implements IDaemonAdapter {
private void parseJsonRemoteRssLists(JSONArray results) { private void parseJsonRemoteRssLists(JSONArray results) {
rssFeedItems = new ArrayList<>(); rssFeedItems = new ArrayList<>();
UTorrentRssFeed item; RemoteRssChannel item;
for (int i = 0; i < results.length(); i++) { for (int i = 0; i < results.length(); i++) {
try { try {
item = new UTorrentRssFeed(results.getJSONArray(i)); item = new UTorrentRemoteRssChannel(results.getJSONArray(i));
rssFeedItems.add(item); rssFeedItems.add(item);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@ -644,7 +645,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
return this.settings; return this.settings;
} }
public ArrayList<UTorrentRssFeed> getRemoteRssFeeds() { public ArrayList<RemoteRssChannel> getRemoteRssChannels() {
return rssFeedItems; return rssFeedItems;
} }
} }

69
app/src/main/java/org/transdroid/daemon/Utorrent/data/RemoteRssFile.java

@ -1,69 +0,0 @@
package org.transdroid.daemon.Utorrent.data;
import android.os.Parcel;
import android.os.Parcelable;
import org.json.JSONArray;
import org.json.JSONException;
import org.transdroid.core.gui.lists.SimpleListItem;
public class RemoteRssFile implements Parcelable, SimpleListItem {
public String name;
public String title;
public String link;
public String feedLabel;
public long timestamp;
public int season;
public int episode;
public RemoteRssFile(JSONArray json) throws JSONException {
name = json.getString(0);
title = json.getString(1);
link = json.getString(2);
timestamp = json.getLong(5);
season = json.getInt(6);
episode = json.getInt(7);
}
public static final Parcelable.Creator<RemoteRssFile> CREATOR = new Parcelable.Creator<RemoteRssFile>() {
public RemoteRssFile createFromParcel(Parcel in) {
return new RemoteRssFile(in);
}
public RemoteRssFile[] newArray(int size) {
return new RemoteRssFile[size];
}
};
public RemoteRssFile(Parcel in) {
name = in.readString();
title = in.readString();
link = in.readString();
feedLabel = in.readString();
timestamp = in.readLong();
season = in.readInt();
episode = in.readInt();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(title);
dest.writeString(link);
dest.writeString(feedLabel);
dest.writeLong(timestamp);
dest.writeInt(season);
dest.writeInt(episode);
}
@Override
public String getName() {
return title;
}
}

78
app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java → app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssChannel.java

@ -2,19 +2,18 @@ package org.transdroid.daemon.Utorrent.data;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.util.Log;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.transdroid.core.gui.lists.SimpleListItem; 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.List;
/** /**
* Created by twig on 29/05/2016. * Created by twig on 29/05/2016.
*/ */
public class UTorrentRssFeed implements Parcelable, SimpleListItem { public class UTorrentRemoteRssChannel extends RemoteRssChannel {
/** /**
* [ * [
* 1, // id? * 1, // id?
@ -93,83 +92,60 @@ public class UTorrentRssFeed implements Parcelable, SimpleListItem {
*/ */
public int feedID; public UTorrentRemoteRssChannel(JSONArray json) throws JSONException {
boolean enabled; // boolean enabled = json.getBoolean(1);
boolean isCustomAlias; boolean isCustomAlias = !json.getBoolean(2);
public String feedAlias;
public String feedURL;
public long lastUpdated;
public List<RemoteRssFile> files;
public UTorrentRssFeed(JSONArray json) throws JSONException { id = json.getInt(0);
Log.e("UTorrentRssFeedItem", "input"); link = json.getString(6);
feedID = json.getInt(0);
enabled = json.getBoolean(1);
isCustomAlias = !json.getBoolean(2);
feedURL = json.getString(6);
lastUpdated = json.getLong(7); lastUpdated = json.getLong(7);
if (isCustomAlias) { if (isCustomAlias) {
feedAlias = feedURL.split("\\|")[0]; name = link.split("\\|")[0];
feedURL = feedURL.split("\\|")[1]; link = link.split("\\|")[1];
} }
else { else {
feedAlias = feedURL; name = link;
} }
files = new ArrayList<>(); files = new ArrayList<>();
JSONArray filesJson = json.getJSONArray(8); JSONArray filesJson = json.getJSONArray(8);
RemoteRssFile file; RemoteRssItem file;
for (int i = 0; i < filesJson.length(); i++) { for (int i = 0; i < filesJson.length(); i++) {
file = new RemoteRssFile(filesJson.getJSONArray(i)); file = new UTorrentRemoteRssItem(filesJson.getJSONArray(i));
file.feedLabel = feedAlias; file.setSourceName(name);
files.add(file); files.add(file);
} }
} }
public UTorrentRssFeed(Parcel in) { public UTorrentRemoteRssChannel(Parcel in) {
feedID = in.readInt(); id = in.readInt();
enabled = (in.readByte() == 1); name = in.readString();
isCustomAlias = (in.readByte() == 1); link = in.readString();
feedAlias = in.readString();
feedURL = in.readString();
lastUpdated = in.readLong(); lastUpdated = in.readLong();
files = new ArrayList<>(); files = new ArrayList<>();
in.readList(files, RemoteRssFile.class.getClassLoader()); in.readList(files, UTorrentRemoteRssItem.class.getClassLoader());
}
@Override
public int describeContents() {
return 0;
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(feedID); dest.writeInt(id);
dest.writeByte((byte) (enabled ? 1 : 0)); dest.writeString(name);
dest.writeByte((byte) (isCustomAlias ? 1 : 0)); dest.writeString(link);
dest.writeString(feedAlias);
dest.writeString(feedURL);
dest.writeLong(lastUpdated); dest.writeLong(lastUpdated);
dest.writeList(files); dest.writeList(files);
} }
public static final Parcelable.Creator<UTorrentRssFeed> CREATOR = new Parcelable.Creator<UTorrentRssFeed>() { public static final Parcelable.Creator<UTorrentRemoteRssChannel> CREATOR = new Parcelable.Creator<UTorrentRemoteRssChannel>() {
public UTorrentRssFeed createFromParcel(Parcel in) { public UTorrentRemoteRssChannel createFromParcel(Parcel in) {
return new UTorrentRssFeed(in); return new UTorrentRemoteRssChannel(in);
} }
public UTorrentRssFeed[] newArray(int size) { public UTorrentRemoteRssChannel[] newArray(int size) {
return new UTorrentRssFeed[size]; return new UTorrentRemoteRssChannel[size];
} }
}; };
@Override
public String getName() {
return feedAlias;
}
} }

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

@ -0,0 +1,55 @@
package org.transdroid.daemon.Utorrent.data;
import android.os.Parcel;
import android.os.Parcelable;
import org.json.JSONArray;
import org.json.JSONException;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
public class UTorrentRemoteRssItem extends RemoteRssItem {
public String name;
// public int season;
// public int episode;
public UTorrentRemoteRssItem(JSONArray json) throws JSONException {
name = json.getString(0);
title = json.getString(1);
link = json.getString(2);
timestamp = json.getLong(5);
// season = json.getInt(6);
// episode = json.getInt(7);
}
public static final Parcelable.Creator<UTorrentRemoteRssItem> CREATOR = new Parcelable.Creator<UTorrentRemoteRssItem>() {
public UTorrentRemoteRssItem createFromParcel(Parcel in) {
return new UTorrentRemoteRssItem(in);
}
public UTorrentRemoteRssItem[] newArray(int size) {
return new UTorrentRemoteRssItem[size];
}
};
public UTorrentRemoteRssItem(Parcel in) {
name = in.readString();
title = in.readString();
link = in.readString();
sourceName = in.readString();
timestamp = in.readLong();
// season = in.readInt();
// episode = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(title);
dest.writeString(link);
dest.writeString(sourceName);
dest.writeLong(timestamp);
// dest.writeInt(season);
// dest.writeInt(episode);
}
}
Loading…
Cancel
Save