From d54d34eaf9bb1090f6538e5e1a4efff57d0d24a8 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Mon, 17 Nov 2014 19:44:57 +0100 Subject: [PATCH] Offer only supported features in the interface (forced starting, force recheck, etc.). Fixes #180. Also fixes #183 by maintaining the torrent ID lost viewed. --- .../transdroid/core/gui/DetailsFragment.java | 43 ++++++++++++++----- .../transdroid/core/gui/ServerStatusView.java | 5 ++- .../transdroid/core/gui/TorrentsActivity.java | 16 ++++++- .../core/gui/lists/LocalTorrent.java | 2 +- .../core/widget/ListWidgetViewsService.java | 11 ++--- app/src/main/res/menu/fragment_details.xml | 8 +++- app/src/main/res/values/strings.xml | 1 + 7 files changed, 61 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java index 484709d8..013bbbab 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java @@ -76,6 +76,8 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @InstanceState protected Torrent torrent = null; @InstanceState + protected String torrentId = null; + @InstanceState protected TorrentDetails torrentDetails = null; @InstanceState protected ArrayList torrentFiles = null; @@ -139,6 +141,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen */ public void updateTorrent(Torrent newTorrent) { this.torrent = newTorrent; + this.torrentId = newTorrent.getUniqueID(); this.hasCriticalError = false; ((DetailsAdapter) detailsList.getAdapter()).updateTorrent(newTorrent); // Make the list (with details header) visible @@ -162,13 +165,13 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen */ public void updateTorrentDetails(Torrent checkTorrent, TorrentDetails newTorrentDetails) { // Check if these are actually the details of the torrent we are now showing - if (torrent == null || !torrent.getUniqueID().equals(checkTorrent.getUniqueID())) + if (torrentId == null || !torrentId.equals(checkTorrent.getUniqueID())) return; this.torrentDetails = newTorrentDetails; - ((DetailsAdapter) detailsList.getAdapter()).updateTrackers(SimpleListItemAdapter.SimpleStringItem - .wrapStringsList(newTorrentDetails.getTrackers())); - ((DetailsAdapter) detailsList.getAdapter()).updateErrors(SimpleListItemAdapter.SimpleStringItem - .wrapStringsList(newTorrentDetails.getErrors())); + ((DetailsAdapter) detailsList.getAdapter()).updateTrackers( + SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getTrackers())); + ((DetailsAdapter) detailsList.getAdapter()).updateErrors( + SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getErrors())); } /** @@ -178,7 +181,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen */ public void updateTorrentFiles(Torrent checkTorrent, ArrayList newTorrentFiles) { // Check if these are actually the details of the torrent we are now showing - if (torrent == null || !torrent.getUniqueID().equals(checkTorrent.getUniqueID())) + if (torrentId == null || !torrentId.equals(checkTorrent.getUniqueID())) return; Collections.sort(newTorrentFiles); this.torrentFiles = newTorrentFiles; @@ -192,10 +195,10 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen */ public void perhapsUpdateTorrent(List torrents) { // Only try to update if we actually were showing a torrent - if (this.torrent == null || torrents == null) + if (this.torrentId == null || torrents == null) return; for (Torrent newTorrent : torrents) { - if (newTorrent.getUniqueID().equals(this.torrent.getUniqueID())) { + if (newTorrent.getUniqueID().equals(torrentId)) { // Found, so we can update our data as well updateTorrent(newTorrent); break; @@ -252,10 +255,12 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen menu.findItem(R.id.action_resume).setVisible(false); menu.findItem(R.id.action_pause).setVisible(false); menu.findItem(R.id.action_start).setVisible(false); + menu.findItem(R.id.action_start_direct).setVisible(false); menu.findItem(R.id.action_stop).setVisible(false); menu.findItem(R.id.action_remove).setVisible(false); menu.findItem(R.id.action_remove_withdata).setVisible(false); menu.findItem(R.id.action_setlabel).setVisible(false); + menu.findItem(R.id.action_forcerecheck).setVisible(false); menu.findItem(R.id.action_updatetrackers).setVisible(false); menu.findItem(R.id.action_changelocation).setVisible(false); return; @@ -264,13 +269,17 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen boolean startStop = Daemon.supportsStoppingStarting(torrent.getDaemon()); menu.findItem(R.id.action_resume).setVisible(torrent.canResume()); menu.findItem(R.id.action_pause).setVisible(torrent.canPause()); - menu.findItem(R.id.action_start).setVisible(startStop && torrent.canStart()); + boolean forcedStart = Daemon.supportsForcedStarting(torrent.getDaemon()); + menu.findItem(R.id.action_start).setVisible(startStop && forcedStart && torrent.canStart()); + menu.findItem(R.id.action_start_direct).setVisible(startStop && !forcedStart && torrent.canStart()); menu.findItem(R.id.action_stop).setVisible(startStop && torrent.canStop()); menu.findItem(R.id.action_remove).setVisible(true); boolean removeWithData = Daemon.supportsRemoveWithData(torrent.getDaemon()); menu.findItem(R.id.action_remove_withdata).setVisible(removeWithData); boolean setLabel = Daemon.supportsSetLabel(torrent.getDaemon()); menu.findItem(R.id.action_setlabel).setVisible(setLabel); + boolean forceRecheck = Daemon.supportsForceRecheck(torrent.getDaemon()); + menu.findItem(R.id.action_forcerecheck).setVisible(forceRecheck); boolean setTrackers = Daemon.supportsSetTrackers(torrent.getDaemon()); menu.findItem(R.id.action_updatetrackers).setVisible(setTrackers); boolean setLocation = Daemon.supportsSetDownloadLocation(torrent.getDaemon()); @@ -288,6 +297,11 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen getTasksExecutor().pauseTorrent(torrent); } + @OptionsItem(resName = "action_start_direct") + protected void startTorrentDirect() { + getTasksExecutor().startTorrent(torrent, false); + } + @OptionsItem(resName = "action_start_default") protected void startTorrentDefault() { getTasksExecutor().startTorrent(torrent, false); @@ -399,8 +413,15 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen ((TorrentsActivity) getActivity()).stopRefresh = true; ((TorrentsActivity) getActivity()).stopAutoRefresh(); } - menu.findItem(R.id.action_download).setVisible( - currentServerSettings != null && Daemon.supportsFilePaths(currentServerSettings.getType())); + boolean filePaths = + currentServerSettings != null && Daemon.supportsFilePaths(currentServerSettings.getType()); + menu.findItem(R.id.action_download).setVisible(filePaths); + boolean filePriorities = currentServerSettings != null && + Daemon.supportsFilePrioritySetting(currentServerSettings.getType()); + menu.findItem(R.id.action_priority_off).setVisible(filePriorities); + menu.findItem(R.id.action_priority_low).setVisible(filePriorities); + menu.findItem(R.id.action_priority_normal).setVisible(filePriorities); + menu.findItem(R.id.action_priority_high).setVisible(filePriorities); return selectionManagerMode.onPrepareActionMode(mode, menu); } diff --git a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java index 7ed6b0c1..41ff0ee0 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java +++ b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java @@ -55,8 +55,9 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis * Updates the statistics as shown in the action bar through this server status view. * @param torrents The most recently received list of torrents * @param dormantAsInactive Whether to treat dormant (0KB/s) torrent as inactive state torrents + * @param supportsSetTransferRates Whether the connected torrent client supports setting of max transfer speeds */ - public void update(List torrents, boolean dormantAsInactive) { + public void update(List torrents, boolean dormantAsInactive, boolean supportsSetTransferRates) { if (torrents == null) { downcountText.setText(null); @@ -90,7 +91,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis upspeedText.setText(FileSizeConverter.getSize(upspeed) + "/s"); downcountSign.setVisibility(View.VISIBLE); upcountSign.setVisibility(View.VISIBLE); - speedswrapperLayout.setOnClickListener(onStartDownPickerClicked); + speedswrapperLayout.setOnClickListener(supportsSetTransferRates ? onStartDownPickerClicked : null); } 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 3c112e4d..c4051e19 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -60,6 +60,7 @@ import org.transdroid.core.service.BootReceiver; import org.transdroid.core.service.ConnectivityHelper; import org.transdroid.core.widget.ListWidgetProvider; import org.transdroid.daemon.Daemon; +import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.Priority; import org.transdroid.daemon.Torrent; @@ -424,6 +425,8 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, // There is a connection (read: settings to some server known) menu.findItem(R.id.action_add).setVisible(true); + boolean addByFile = Daemon.supportsAddByFile(currentConnection.getType()); + menu.findItem(R.id.action_add_fromfile).setVisible(addByFile); menu.findItem(R.id.action_search).setVisible(navigationHelper.enableSearchUi()); menu.findItem(R.id.action_rss).setVisible(navigationHelper.enableRssUi()); boolean hasAltMode = Daemon.supportsSetAlternativeMode(currentConnection.getType()); @@ -942,7 +945,15 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, @Background public void addTorrentByMagnetUrl(String url, String title) { - DaemonTaskResult result = AddByMagnetUrlTask.create(currentConnection, url).execute(log); + AddByMagnetUrlTask addByMagnetUrlTask = AddByMagnetUrlTask.create(currentConnection, url); + if (!Daemon.supportsAddByMagnetUrl(currentConnection.getType())) { + // No support for magnet links: forcefully let the task fail to report the error + onCommunicationError(new DaemonTaskFailureResult(addByMagnetUrlTask, + new DaemonException(DaemonException.ExceptionType.MethodUnsupported, + currentConnection.getType().name() + " does not support magnet links")), false); + return; + } + DaemonTaskResult result = addByMagnetUrlTask.execute(log); if (result instanceof DaemonTaskSuccessResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); refreshTorrents(); @@ -1259,7 +1270,8 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, } // Update the server status (counts and speeds) in the action bar - serverStatusView.update(torrents, systemSettings.treatDormantAsInactive()); + serverStatusView.update(torrents, systemSettings.treatDormantAsInactive(), + Daemon.supportsSetTransferRates(currentConnection.getType())); } diff --git a/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java b/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java index e5357bc6..312ceb4b 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java @@ -228,7 +228,7 @@ public class LocalTorrent { public static int getResourceForDaemonException(DaemonException e) { switch (e.getType()) { case MethodUnsupported: - return R.string.error_jsonrequesterror; + return R.string.error_unsupported; case ConnectionError: return R.string.error_httperror; case UnexpectedResponse: diff --git a/app/src/main/java/org/transdroid/core/widget/ListWidgetViewsService.java b/app/src/main/java/org/transdroid/core/widget/ListWidgetViewsService.java index e15f0506..a912dc52 100644 --- a/app/src/main/java/org/transdroid/core/widget/ListWidgetViewsService.java +++ b/app/src/main/java/org/transdroid/core/widget/ListWidgetViewsService.java @@ -27,15 +27,10 @@ import android.widget.RemoteViewsService; import org.androidannotations.annotations.EService; import org.transdroid.R; -import org.transdroid.core.app.settings.ApplicationSettings; -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.app.settings.*; import org.transdroid.core.gui.lists.LocalTorrent; -import org.transdroid.core.gui.log.Log; -import org.transdroid.core.gui.log.Log_; -import org.transdroid.core.service.ConnectivityHelper_; +import org.transdroid.core.gui.log.*; +import org.transdroid.core.service.*; import org.transdroid.daemon.Daemon; import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.Torrent; diff --git a/app/src/main/res/menu/fragment_details.xml b/app/src/main/res/menu/fragment_details.xml index e5c1e1f4..75a6043f 100644 --- a/app/src/main/res/menu/fragment_details.xml +++ b/app/src/main/res/menu/fragment_details.xml @@ -32,13 +32,19 @@ android:id="@+id/action_start" android:icon="?attr/ic_action_start" android:showAsAction="ifRoom" - android:title="@string/action_start_default" + android:title="@string/action_start" android:orderInCategory="202"> + Error during communication; check your connection + Your torrent client does not support this operation Internal error building request Error parsing server response (please check your settings) Web interface not connected to a running daemon