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; @@ -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; @@ -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 @@ -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<UTorrentRssFeed> rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssFeeds();
ArrayList<RemoteRssChannel> rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels();
RemoteRssActivity_.intent(this)
.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_; @@ -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; @@ -53,7 +53,7 @@ import java.util.ArrayList;
public class RemoteRssActivity extends AppCompatActivity {
@Extra
@InstanceState
protected ArrayList<UTorrentRssFeed> feeds;
protected ArrayList<RemoteRssChannel> feeds;
// Settings
// private IDaemonAdapter currentConnection = null;
@ -101,7 +101,7 @@ public class RemoteRssActivity extends AppCompatActivity { @@ -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 { @@ -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());
}
}

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

@ -5,14 +5,14 @@ import android.view.View; @@ -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<RemoteRssFile> files;
protected List<RemoteRssItem> files;
public RemoteRssFilesAdapter(Context context) {
this.context = context;
@ -45,12 +45,12 @@ public class RemoteRssFilesAdapter extends BaseAdapter { @@ -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<RemoteRssFile> torrentFiles) {
public void updateFiles(List<RemoteRssItem> torrentFiles) {
files = torrentFiles;
notifyDataSetChanged();
}

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

@ -29,7 +29,7 @@ import org.androidannotations.annotations.InstanceState; @@ -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 { @@ -45,7 +45,7 @@ public class RemoteRssFragment extends Fragment {
// Local data
@InstanceState
protected ArrayList<RemoteRssFile> torrentFiles;
protected ArrayList<RemoteRssItem> torrentFiles;
// Views
@ViewById
@ -102,7 +102,7 @@ public class RemoteRssFragment extends Fragment { @@ -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<RemoteRssFile> remoteRssFiles) {
public void updateTorrentFiles(List<RemoteRssItem> remoteRssFiles) {
torrentFiles = new ArrayList<>(remoteRssFiles);
adapter.updateFiles(torrentFiles);
}

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

@ -24,7 +24,7 @@ import org.androidannotations.annotations.EViewGroup; @@ -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 { @@ -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());
}
}

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

@ -0,0 +1,45 @@ @@ -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 @@ @@ -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; @@ -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; @@ -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 { @@ -114,7 +115,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
private DaemonSettings settings;
private DefaultHttpClient httpclient;
private static ArrayList<UTorrentRssFeed> rssFeedItems;
private static ArrayList<RemoteRssChannel> rssFeedItems;
@ -322,11 +323,11 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -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 { @@ -644,7 +645,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
return this.settings;
}
public ArrayList<UTorrentRssFeed> getRemoteRssFeeds() {
public ArrayList<RemoteRssChannel> getRemoteRssChannels() {
return rssFeedItems;
}
}

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

@ -1,69 +0,0 @@ @@ -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; @@ -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 { @@ -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<RemoteRssFile> 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<UTorrentRssFeed> CREATOR = new Parcelable.Creator<UTorrentRssFeed>() {
public UTorrentRssFeed createFromParcel(Parcel in) {
return new UTorrentRssFeed(in);
public static final Parcelable.Creator<UTorrentRemoteRssChannel> CREATOR = new Parcelable.Creator<UTorrentRemoteRssChannel>() {
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;
}
}

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

@ -0,0 +1,55 @@ @@ -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