From 210cd1c2d4cb92a35ff465346905b953d30cf1e5 Mon Sep 17 00:00:00 2001 From: twig Date: Thu, 2 Jun 2016 09:53:41 +1000 Subject: [PATCH] - prevent opening of openRemoteRss() when no feed items configured - (untested) now able to download remote rss items - added RemoteRssItem.isMagnetLink() - commented out UTorrentRemoteRssItem.name --- .../transdroid/core/gui/TorrentsActivity.java | 4 + .../core/gui/remoterss/RemoteRssActivity.java | 27 ++++--- .../core/gui/remoterss/RemoteRssFragment.java | 76 ++++++++++--------- .../gui/remoterss/data/RemoteRssItem.java | 6 +- .../Utorrent/data/UTorrentRemoteRssItem.java | 10 +-- 5 files changed, 74 insertions(+), 49 deletions(-) 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 fcb2165c..dc5fc0eb 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -858,6 +858,10 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE if (Daemon.supportsRemoteRssManagement(currentConnection.getType())) { ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels(); + if (rssFeedItems.size() == 0) { + return; + } + RemoteRssActivity_.intent(this) .feeds(rssFeedItems) .start() 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 444c5b08..a24d8133 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 @@ -26,6 +26,7 @@ import android.support.v7.widget.Toolbar; import android.widget.ListView; import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.FragmentById; @@ -34,12 +35,16 @@ import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.ViewById; import org.transdroid.R; +import org.transdroid.core.app.settings.ApplicationSettings; +import org.transdroid.core.app.settings.ServerSetting; 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.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; +import org.transdroid.core.service.ConnectivityHelper; +import org.transdroid.daemon.IDaemonAdapter; import java.util.ArrayList; import java.util.Calendar; @@ -64,12 +69,12 @@ public class RemoteRssActivity extends AppCompatActivity { @InstanceState protected ArrayList recentItems; -// // Settings -// @Bean -// protected ApplicationSettings applicationSettings; -// @Bean -// protected ConnectivityHelper connectivityHelper; -// private IDaemonAdapter currentConnection; + // Server connection + @Bean + protected ApplicationSettings applicationSettings; + @Bean + protected ConnectivityHelper connectivityHelper; + private IDaemonAdapter currentConnection; // Details view components @ViewById @@ -104,9 +109,9 @@ public class RemoteRssActivity extends AppCompatActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); // getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName())); -// // Connect to the last used server -// ServerSetting lastUsed = applicationSettings.getLastUsedServer(); -// currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); + // Connect to the last used server + ServerSetting lastUsed = applicationSettings.getLastUsedServer(); + currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); // Show all items showRecentItems(); @@ -385,4 +390,8 @@ public class RemoteRssActivity extends AppCompatActivity { fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems()); } } + + public IDaemonAdapter getCurrentConnection() { + return currentConnection; + } } 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 86649502..65379ab9 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 @@ -23,13 +23,25 @@ import android.support.v7.widget.ActionMenuView; import android.view.View; import android.widget.ListView; +import com.nispok.snackbar.Snackbar; +import com.nispok.snackbar.SnackbarManager; + import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.InstanceState; import org.androidannotations.annotations.ItemClick; +import org.androidannotations.annotations.UiThread; import org.androidannotations.annotations.ViewById; import org.transdroid.R; +import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; +import org.transdroid.daemon.Daemon; +import org.transdroid.daemon.IDaemonAdapter; +import org.transdroid.daemon.task.AddByMagnetUrlTask; +import org.transdroid.daemon.task.AddByUrlTask; +import org.transdroid.daemon.task.DaemonTaskResult; +import org.transdroid.daemon.task.DaemonTaskSuccessResult; import java.util.ArrayList; import java.util.List; @@ -42,6 +54,8 @@ import java.util.List; */ @EFragment(R.layout.fragment_remoterss) public class RemoteRssFragment extends Fragment { + @Bean + protected Log log; // Local data @InstanceState @@ -73,16 +87,6 @@ public class RemoteRssFragment extends Fragment { // } else { // detailsContainer.setBackgroundResource(R.drawable.details_list_background_light); // } -// } - -// if (getActivity() != null && getActivity() instanceof RefreshableActivity) { -// swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { -// @Override -// public void onRefresh() { -// ((RefreshableActivity) getActivity()).refreshScreen(); -// swipeRefreshLayout.setRefreshing(false); // Use our custom indicator -// } -// }); // } // Set up details adapter (itself containing the actual lists to show), which allows multi-select and fast @@ -109,30 +113,34 @@ public class RemoteRssFragment extends Fragment { @ItemClick(resName = "torrents_list") protected void detailsListClicked(int position) { - torrentsList.setItemChecked(position, false); + RemoteRssActivity activity = (RemoteRssActivity) getActivity(); + RemoteRssItem item = (RemoteRssItem) adapter.getItem(position); + IDaemonAdapter currentConnection = activity.getCurrentConnection(); + DaemonTaskResult result; + + if (item.isMagnetLink()) { + // Check if it's supported + if (!Daemon.supportsAddByMagnetUrl(currentConnection.getType())) { + // TODO: + return; + } + + AddByMagnetUrlTask addByMagnetUrlTask = AddByMagnetUrlTask.create(currentConnection, item.getLink()); + result = addByMagnetUrlTask.execute(log); + } + else { + result = AddByUrlTask.create(currentConnection, item.getLink(), item.getTitle()).execute(log); + } + + if (result instanceof DaemonTaskSuccessResult) { + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, item.getTitle())); + } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); + } } -// @Override -// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { -// super.onCreateOptionsMenu(menu, inflater); -// -// inflater.inflate(R.menu.fragment_details, menu); -// } -// -// @Override -// public boolean onOptionsItemSelected(MenuItem item) { -// switch (item.getItemId()) { -// case R.id.action_start_default: -//// startTorrentDefault(); -// return true; -// } -// -// return super.onOptionsItemSelected(item); -// } - -// @OptionsItem(R.id.action_start_default) -// protected void startTorrentDefault() { -// if (getTasksExecutor() != null) -// getTasksExecutor().startTorrent(torrent, false); -// } + @UiThread + protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { + SnackbarManager.show(Snackbar.with(getActivity()).text(successMessage)); + } } 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 index 5e5de8db..d9e2310d 100644 --- 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 @@ -11,7 +11,7 @@ import java.util.Date; */ public abstract class RemoteRssItem implements Parcelable, SimpleListItem { protected String title; - protected String link; + protected String link; // May be magnet or http(s) protected String sourceName; // Name of RSS feed channel protected Date timestamp; @@ -40,6 +40,10 @@ public abstract class RemoteRssItem implements Parcelable, SimpleListItem { return timestamp; } + public boolean isMagnetLink() { + return link.startsWith("magnet:?"); + } + @Override public int describeContents() { return 0; 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 index ad54e54b..d4923967 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java +++ b/app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java @@ -11,13 +11,13 @@ import java.util.Calendar; import java.util.Date; public class UTorrentRemoteRssItem extends RemoteRssItem { - public String name; +// public String name; // public int season; // public int episode; public UTorrentRemoteRssItem(JSONArray json) throws JSONException { - name = json.getString(0); - title = json.getString(1); +// name = json.getString(0); // clean name + title = json.getString(1); // filename link = json.getString(2); Calendar calendar = Calendar.getInstance(); @@ -40,7 +40,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem { }; public UTorrentRemoteRssItem(Parcel in) { - name = in.readString(); +// name = in.readString(); title = in.readString(); link = in.readString(); sourceName = in.readString(); @@ -51,7 +51,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeString(name); +// dest.writeString(name); dest.writeString(title); dest.writeString(link); dest.writeString(sourceName);