From 073fa6d9e5890b9aeb1c22cdce822605fd22a864 Mon Sep 17 00:00:00 2001 From: twig Date: Wed, 1 Jun 2016 10:16:56 +1000 Subject: [PATCH] - 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 --- .../transdroid/core/gui/TorrentsActivity.java | 4 +- .../core/gui/remoterss/RemoteRssActivity.java | 8 +- .../gui/remoterss/RemoteRssFilesAdapter.java | 8 +- .../core/gui/remoterss/RemoteRssFragment.java | 6 +- .../core/gui/remoterss/RemoteRssItemView.java | 8 +- .../gui/remoterss/data/RemoteRssChannel.java | 45 +++++++++++ .../gui/remoterss/data/RemoteRssItem.java | 47 +++++++++++ .../daemon/Utorrent/UtorrentAdapter.java | 11 +-- .../daemon/Utorrent/data/RemoteRssFile.java | 69 ---------------- ...eed.java => UTorrentRemoteRssChannel.java} | 78 +++++++------------ .../Utorrent/data/UTorrentRemoteRssItem.java | 55 +++++++++++++ 11 files changed, 197 insertions(+), 142 deletions(-) create mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssChannel.java create mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java delete mode 100644 app/src/main/java/org/transdroid/daemon/Utorrent/data/RemoteRssFile.java rename app/src/main/java/org/transdroid/daemon/Utorrent/data/{UTorrentRssFeed.java => UTorrentRemoteRssChannel.java} (88%) create mode 100644 app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.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 eb91e483..f528b4a1 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/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.StatusType; 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.search.BarcodeHelper; 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.TorrentsSortBy; import org.transdroid.daemon.Utorrent.UtorrentAdapter; -import org.transdroid.daemon.Utorrent.data.UTorrentRssFeed; 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() { if (Daemon.supportsRemoteRssManagement(currentConnection.getType())) { - ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssFeeds(); + ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels(); RemoteRssActivity_.intent(this) .feeds(rssFeedItems) 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 383e0808..7b1daed2 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 @@ -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.lists.SimpleListItemAdapter; -import org.transdroid.daemon.Utorrent.data.UTorrentRssFeed; +import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import java.util.ArrayList; @@ -53,7 +53,7 @@ import java.util.ArrayList; public class RemoteRssActivity extends AppCompatActivity { @Extra @InstanceState - protected ArrayList feeds; + protected ArrayList feeds; // Settings // private IDaemonAdapter currentConnection = null; @@ -101,7 +101,7 @@ public class RemoteRssActivity extends AppCompatActivity { // fragmentDetails.updateLabels(currentLabels); // TODO: show all items - fragmentRemoteRss.updateTorrentFiles(feeds.get(0).files); + fragmentRemoteRss.updateTorrentFiles(feeds.get(0).getFiles()); drawerList.setAdapter(new SimpleListItemAdapter(this, feeds)); } @@ -325,6 +325,6 @@ public class RemoteRssActivity extends AppCompatActivity { @ItemClick(R.id.drawer_list) protected void onFeedSelected(int position) { - fragmentRemoteRss.updateTorrentFiles(feeds.get(position).files); + fragmentRemoteRss.updateTorrentFiles(feeds.get(position).getFiles()); } } diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java index 97ae6a9b..f731d947 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java +++ b/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.widget.BaseAdapter; -import org.transdroid.daemon.Utorrent.data.RemoteRssFile; +import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import java.util.ArrayList; import java.util.List; public class RemoteRssFilesAdapter extends BaseAdapter { protected Context context; - protected List files; + protected List files; public RemoteRssFilesAdapter(Context context) { this.context = context; @@ -45,12 +45,12 @@ public class RemoteRssFilesAdapter extends BaseAdapter { itemView = (RemoteRssItemView) convertView; } - itemView.bind((RemoteRssFile) getItem(position)); + itemView.bind((RemoteRssItem) getItem(position)); return itemView; } - public void updateFiles(List torrentFiles) { + public void updateFiles(List torrentFiles) { files = torrentFiles; notifyDataSetChanged(); } 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 f35552ff..86649502 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 @@ -29,7 +29,7 @@ import org.androidannotations.annotations.InstanceState; import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ViewById; 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.List; @@ -45,7 +45,7 @@ public class RemoteRssFragment extends Fragment { // Local data @InstanceState - protected ArrayList torrentFiles; + protected ArrayList torrentFiles; // Views @ViewById @@ -102,7 +102,7 @@ public class RemoteRssFragment extends Fragment { * @param checkTorrent The torrent for which the details were retrieved * @param newTorrentFiles The new, updated list of torrent file objects */ - public void updateTorrentFiles(List remoteRssFiles) { + public void updateTorrentFiles(List remoteRssFiles) { torrentFiles = new ArrayList<>(remoteRssFiles); adapter.updateFiles(torrentFiles); } diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java index e7701472..b9be7e5c 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java +++ b/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.transdroid.R; 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 @@ -41,10 +41,10 @@ public class RemoteRssItemView extends LinearLayout { super(context); } - public void bind(RemoteRssFile file) { + public void bind(RemoteRssItem file) { nameText.setText(file.getName()); - dateText.setText(String.valueOf(file.timestamp)); - labelText.setText(file.feedLabel); + dateText.setText(String.valueOf(file.getTimestamp())); + labelText.setText(file.getSourceName()); } } 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 new file mode 100644 index 00000000..d5fcd486 --- /dev/null +++ b/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 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 getFiles() { + return files; + } + + @Override + public String getName() { + return name; + } +} 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 new file mode 100644 index 00000000..dba69339 --- /dev/null +++ b/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; + } +} 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 cbf0aea8..53b2dbd8 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java +++ b/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.JSONObject; import org.transdroid.core.gui.log.Log; +import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.daemon.Daemon; import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.DaemonException.ExceptionType; @@ -40,7 +41,7 @@ import org.transdroid.daemon.Torrent; import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentFile; 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.AddByMagnetUrlTask; import org.transdroid.daemon.task.AddByUrlTask; @@ -114,7 +115,7 @@ public class UtorrentAdapter implements IDaemonAdapter { private DaemonSettings settings; private DefaultHttpClient httpclient; - private static ArrayList rssFeedItems; + private static ArrayList rssFeedItems; @@ -322,11 +323,11 @@ public class UtorrentAdapter implements IDaemonAdapter { private void parseJsonRemoteRssLists(JSONArray results) { rssFeedItems = new ArrayList<>(); - UTorrentRssFeed item; + RemoteRssChannel item; for (int i = 0; i < results.length(); i++) { try { - item = new UTorrentRssFeed(results.getJSONArray(i)); + item = new UTorrentRemoteRssChannel(results.getJSONArray(i)); rssFeedItems.add(item); } catch (JSONException e) { e.printStackTrace(); @@ -644,7 +645,7 @@ public class UtorrentAdapter implements IDaemonAdapter { return this.settings; } - public ArrayList getRemoteRssFeeds() { + public ArrayList getRemoteRssChannels() { return rssFeedItems; } } diff --git a/app/src/main/java/org/transdroid/daemon/Utorrent/data/RemoteRssFile.java b/app/src/main/java/org/transdroid/daemon/Utorrent/data/RemoteRssFile.java deleted file mode 100644 index 04f01736..00000000 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/data/RemoteRssFile.java +++ /dev/null @@ -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 CREATOR = new Parcelable.Creator() { - 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; - } -} diff --git a/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java b/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssChannel.java similarity index 88% rename from app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java rename to app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssChannel.java index d1aa551c..b837005d 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java +++ b/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.Parcelable; -import android.util.Log; import org.json.JSONArray; 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.List; /** * Created by twig on 29/05/2016. */ -public class UTorrentRssFeed implements Parcelable, SimpleListItem { +public class UTorrentRemoteRssChannel extends RemoteRssChannel { /** * [ * 1, // id? @@ -93,83 +92,60 @@ public class UTorrentRssFeed implements Parcelable, SimpleListItem { */ - public int feedID; - boolean enabled; - boolean isCustomAlias; - public String feedAlias; - public String feedURL; - public long lastUpdated; - public List files; + public UTorrentRemoteRssChannel(JSONArray json) throws JSONException { +// boolean enabled = json.getBoolean(1); + boolean isCustomAlias = !json.getBoolean(2); - public UTorrentRssFeed(JSONArray json) throws JSONException { - Log.e("UTorrentRssFeedItem", "input"); - - feedID = json.getInt(0); - enabled = json.getBoolean(1); - isCustomAlias = !json.getBoolean(2); - feedURL = json.getString(6); + id = json.getInt(0); + link = json.getString(6); lastUpdated = json.getLong(7); if (isCustomAlias) { - feedAlias = feedURL.split("\\|")[0]; - feedURL = feedURL.split("\\|")[1]; + name = link.split("\\|")[0]; + link = link.split("\\|")[1]; } else { - feedAlias = feedURL; + name = link; } files = new ArrayList<>(); JSONArray filesJson = json.getJSONArray(8); - RemoteRssFile file; + RemoteRssItem file; for (int i = 0; i < filesJson.length(); i++) { - file = new RemoteRssFile(filesJson.getJSONArray(i)); - file.feedLabel = feedAlias; + file = new UTorrentRemoteRssItem(filesJson.getJSONArray(i)); + file.setSourceName(name); files.add(file); } } - public UTorrentRssFeed(Parcel in) { - feedID = in.readInt(); - enabled = (in.readByte() == 1); - isCustomAlias = (in.readByte() == 1); - feedAlias = in.readString(); - feedURL = in.readString(); + public UTorrentRemoteRssChannel(Parcel in) { + id = in.readInt(); + name = in.readString(); + link = in.readString(); lastUpdated = in.readLong(); files = new ArrayList<>(); - in.readList(files, RemoteRssFile.class.getClassLoader()); - } - - @Override - public int describeContents() { - return 0; + in.readList(files, UTorrentRemoteRssItem.class.getClassLoader()); } @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(feedID); - dest.writeByte((byte) (enabled ? 1 : 0)); - dest.writeByte((byte) (isCustomAlias ? 1 : 0)); - dest.writeString(feedAlias); - dest.writeString(feedURL); + dest.writeInt(id); + dest.writeString(name); + dest.writeString(link); dest.writeLong(lastUpdated); dest.writeList(files); } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public UTorrentRssFeed createFromParcel(Parcel in) { - return new UTorrentRssFeed(in); + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public UTorrentRemoteRssChannel createFromParcel(Parcel in) { + return new UTorrentRemoteRssChannel(in); } - public UTorrentRssFeed[] newArray(int size) { - return new UTorrentRssFeed[size]; + public UTorrentRemoteRssChannel[] newArray(int size) { + return new UTorrentRemoteRssChannel[size]; } }; - - @Override - public String getName() { - return feedAlias; - } } diff --git a/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java b/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java new file mode 100644 index 00000000..156e6236 --- /dev/null +++ b/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 CREATOR = new Parcelable.Creator() { + 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); + } +}