Browse Source

- prevent opening of openRemoteRss() when no feed items configured

- (untested) now able to download remote rss items
- added RemoteRssItem.isMagnetLink()
- commented out UTorrentRemoteRssItem.name
pull/313/head
twig 9 years ago
parent
commit
210cd1c2d4
  1. 4
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 27
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java
  3. 76
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java
  4. 6
      app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssItem.java
  5. 10
      app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRemoteRssItem.java

4
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())) { if (Daemon.supportsRemoteRssManagement(currentConnection.getType())) {
ArrayList<RemoteRssChannel> rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels(); ArrayList<RemoteRssChannel> rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels();
if (rssFeedItems.size() == 0) {
return;
}
RemoteRssActivity_.intent(this) RemoteRssActivity_.intent(this)
.feeds(rssFeedItems) .feeds(rssFeedItems)
.start() .start()

27
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 android.widget.ListView;
import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.FragmentById; import org.androidannotations.annotations.FragmentById;
@ -34,12 +35,16 @@ import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.R; 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.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.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; 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.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -64,12 +69,12 @@ public class RemoteRssActivity extends AppCompatActivity {
@InstanceState @InstanceState
protected ArrayList<RemoteRssItem> recentItems; protected ArrayList<RemoteRssItem> recentItems;
// // Settings // Server connection
// @Bean @Bean
// protected ApplicationSettings applicationSettings; protected ApplicationSettings applicationSettings;
// @Bean @Bean
// protected ConnectivityHelper connectivityHelper; protected ConnectivityHelper connectivityHelper;
// private IDaemonAdapter currentConnection; private IDaemonAdapter currentConnection;
// Details view components // Details view components
@ViewById @ViewById
@ -104,9 +109,9 @@ public class RemoteRssActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName())); // getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName()));
// // Connect to the last used server // Connect to the last used server
// ServerSetting lastUsed = applicationSettings.getLastUsedServer(); ServerSetting lastUsed = applicationSettings.getLastUsedServer();
// currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
// Show all items // Show all items
showRecentItems(); showRecentItems();
@ -385,4 +390,8 @@ public class RemoteRssActivity extends AppCompatActivity {
fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems()); fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems());
} }
} }
public IDaemonAdapter getCurrentConnection() {
return currentConnection;
}
} }

76
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.view.View;
import android.widget.ListView; import android.widget.ListView;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.InstanceState; import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; 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.ArrayList;
import java.util.List; import java.util.List;
@ -42,6 +54,8 @@ import java.util.List;
*/ */
@EFragment(R.layout.fragment_remoterss) @EFragment(R.layout.fragment_remoterss)
public class RemoteRssFragment extends Fragment { public class RemoteRssFragment extends Fragment {
@Bean
protected Log log;
// Local data // Local data
@InstanceState @InstanceState
@ -73,16 +87,6 @@ public class RemoteRssFragment extends Fragment {
// } else { // } else {
// detailsContainer.setBackgroundResource(R.drawable.details_list_background_light); // 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 // 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") @ItemClick(resName = "torrents_list")
protected void detailsListClicked(int position) { 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 @UiThread
// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) {
// super.onCreateOptionsMenu(menu, inflater); SnackbarManager.show(Snackbar.with(getActivity()).text(successMessage));
// }
// 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);
// }
} }

6
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 { public abstract class RemoteRssItem implements Parcelable, SimpleListItem {
protected String title; protected String title;
protected String link; protected String link; // May be magnet or http(s)
protected String sourceName; // Name of RSS feed channel protected String sourceName; // Name of RSS feed channel
protected Date timestamp; protected Date timestamp;
@ -40,6 +40,10 @@ public abstract class RemoteRssItem implements Parcelable, SimpleListItem {
return timestamp; return timestamp;
} }
public boolean isMagnetLink() {
return link.startsWith("magnet:?");
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

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

@ -11,13 +11,13 @@ import java.util.Calendar;
import java.util.Date; 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;
// public int episode; // public int episode;
public UTorrentRemoteRssItem(JSONArray json) throws JSONException { public UTorrentRemoteRssItem(JSONArray json) throws JSONException {
name = json.getString(0); // name = json.getString(0); // clean name
title = json.getString(1); title = json.getString(1); // filename
link = json.getString(2); link = json.getString(2);
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -40,7 +40,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
}; };
public UTorrentRemoteRssItem(Parcel in) { public UTorrentRemoteRssItem(Parcel in) {
name = in.readString(); // name = in.readString();
title = in.readString(); title = in.readString();
link = in.readString(); link = in.readString();
sourceName = in.readString(); sourceName = in.readString();
@ -51,7 +51,7 @@ public class UTorrentRemoteRssItem extends RemoteRssItem {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name); // dest.writeString(name);
dest.writeString(title); dest.writeString(title);
dest.writeString(link); dest.writeString(link);
dest.writeString(sourceName); dest.writeString(sourceName);

Loading…
Cancel
Save