Browse Source

Offer only supported features in the interface (forced starting, force recheck, etc.). Fixes #180. Also fixes #183 by maintaining the torrent ID lost viewed.

pull/187/head
Eric Kok 10 years ago
parent
commit
d54d34eaf9
  1. 43
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  2. 5
      app/src/main/java/org/transdroid/core/gui/ServerStatusView.java
  3. 16
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  4. 2
      app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java
  5. 11
      app/src/main/java/org/transdroid/core/widget/ListWidgetViewsService.java
  6. 8
      app/src/main/res/menu/fragment_details.xml
  7. 1
      app/src/main/res/values/strings.xml

43
app/src/main/java/org/transdroid/core/gui/DetailsFragment.java

@ -76,6 +76,8 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
@InstanceState @InstanceState
protected Torrent torrent = null; protected Torrent torrent = null;
@InstanceState @InstanceState
protected String torrentId = null;
@InstanceState
protected TorrentDetails torrentDetails = null; protected TorrentDetails torrentDetails = null;
@InstanceState @InstanceState
protected ArrayList<TorrentFile> torrentFiles = null; protected ArrayList<TorrentFile> torrentFiles = null;
@ -139,6 +141,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
*/ */
public void updateTorrent(Torrent newTorrent) { public void updateTorrent(Torrent newTorrent) {
this.torrent = newTorrent; this.torrent = newTorrent;
this.torrentId = newTorrent.getUniqueID();
this.hasCriticalError = false; this.hasCriticalError = false;
((DetailsAdapter) detailsList.getAdapter()).updateTorrent(newTorrent); ((DetailsAdapter) detailsList.getAdapter()).updateTorrent(newTorrent);
// Make the list (with details header) visible // 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) { public void updateTorrentDetails(Torrent checkTorrent, TorrentDetails newTorrentDetails) {
// Check if these are actually the details of the torrent we are now showing // 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; return;
this.torrentDetails = newTorrentDetails; this.torrentDetails = newTorrentDetails;
((DetailsAdapter) detailsList.getAdapter()).updateTrackers(SimpleListItemAdapter.SimpleStringItem ((DetailsAdapter) detailsList.getAdapter()).updateTrackers(
.wrapStringsList(newTorrentDetails.getTrackers())); SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getTrackers()));
((DetailsAdapter) detailsList.getAdapter()).updateErrors(SimpleListItemAdapter.SimpleStringItem ((DetailsAdapter) detailsList.getAdapter()).updateErrors(
.wrapStringsList(newTorrentDetails.getErrors())); SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getErrors()));
} }
/** /**
@ -178,7 +181,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
*/ */
public void updateTorrentFiles(Torrent checkTorrent, ArrayList<TorrentFile> newTorrentFiles) { public void updateTorrentFiles(Torrent checkTorrent, ArrayList<TorrentFile> newTorrentFiles) {
// Check if these are actually the details of the torrent we are now showing // 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; return;
Collections.sort(newTorrentFiles); Collections.sort(newTorrentFiles);
this.torrentFiles = newTorrentFiles; this.torrentFiles = newTorrentFiles;
@ -192,10 +195,10 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
*/ */
public void perhapsUpdateTorrent(List<Torrent> torrents) { public void perhapsUpdateTorrent(List<Torrent> torrents) {
// Only try to update if we actually were showing a torrent // Only try to update if we actually were showing a torrent
if (this.torrent == null || torrents == null) if (this.torrentId == null || torrents == null)
return; return;
for (Torrent newTorrent : torrents) { 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 // Found, so we can update our data as well
updateTorrent(newTorrent); updateTorrent(newTorrent);
break; 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_resume).setVisible(false);
menu.findItem(R.id.action_pause).setVisible(false); menu.findItem(R.id.action_pause).setVisible(false);
menu.findItem(R.id.action_start).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_stop).setVisible(false);
menu.findItem(R.id.action_remove).setVisible(false); menu.findItem(R.id.action_remove).setVisible(false);
menu.findItem(R.id.action_remove_withdata).setVisible(false); menu.findItem(R.id.action_remove_withdata).setVisible(false);
menu.findItem(R.id.action_setlabel).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_updatetrackers).setVisible(false);
menu.findItem(R.id.action_changelocation).setVisible(false); menu.findItem(R.id.action_changelocation).setVisible(false);
return; return;
@ -264,13 +269,17 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
boolean startStop = Daemon.supportsStoppingStarting(torrent.getDaemon()); boolean startStop = Daemon.supportsStoppingStarting(torrent.getDaemon());
menu.findItem(R.id.action_resume).setVisible(torrent.canResume()); menu.findItem(R.id.action_resume).setVisible(torrent.canResume());
menu.findItem(R.id.action_pause).setVisible(torrent.canPause()); 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_stop).setVisible(startStop && torrent.canStop());
menu.findItem(R.id.action_remove).setVisible(true); menu.findItem(R.id.action_remove).setVisible(true);
boolean removeWithData = Daemon.supportsRemoveWithData(torrent.getDaemon()); boolean removeWithData = Daemon.supportsRemoveWithData(torrent.getDaemon());
menu.findItem(R.id.action_remove_withdata).setVisible(removeWithData); menu.findItem(R.id.action_remove_withdata).setVisible(removeWithData);
boolean setLabel = Daemon.supportsSetLabel(torrent.getDaemon()); boolean setLabel = Daemon.supportsSetLabel(torrent.getDaemon());
menu.findItem(R.id.action_setlabel).setVisible(setLabel); 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()); boolean setTrackers = Daemon.supportsSetTrackers(torrent.getDaemon());
menu.findItem(R.id.action_updatetrackers).setVisible(setTrackers); menu.findItem(R.id.action_updatetrackers).setVisible(setTrackers);
boolean setLocation = Daemon.supportsSetDownloadLocation(torrent.getDaemon()); boolean setLocation = Daemon.supportsSetDownloadLocation(torrent.getDaemon());
@ -288,6 +297,11 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
getTasksExecutor().pauseTorrent(torrent); getTasksExecutor().pauseTorrent(torrent);
} }
@OptionsItem(resName = "action_start_direct")
protected void startTorrentDirect() {
getTasksExecutor().startTorrent(torrent, false);
}
@OptionsItem(resName = "action_start_default") @OptionsItem(resName = "action_start_default")
protected void startTorrentDefault() { protected void startTorrentDefault() {
getTasksExecutor().startTorrent(torrent, false); getTasksExecutor().startTorrent(torrent, false);
@ -399,8 +413,15 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
((TorrentsActivity) getActivity()).stopRefresh = true; ((TorrentsActivity) getActivity()).stopRefresh = true;
((TorrentsActivity) getActivity()).stopAutoRefresh(); ((TorrentsActivity) getActivity()).stopAutoRefresh();
} }
menu.findItem(R.id.action_download).setVisible( boolean filePaths =
currentServerSettings != null && Daemon.supportsFilePaths(currentServerSettings.getType())); 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); return selectionManagerMode.onPrepareActionMode(mode, menu);
} }

5
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. * Updates the statistics as shown in the action bar through this server status view.
* @param torrents The most recently received list of torrents * @param torrents The most recently received list of torrents
* @param dormantAsInactive Whether to treat dormant (0KB/s) torrent as inactive state 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<Torrent> torrents, boolean dormantAsInactive) { public void update(List<Torrent> torrents, boolean dormantAsInactive, boolean supportsSetTransferRates) {
if (torrents == null) { if (torrents == null) {
downcountText.setText(null); downcountText.setText(null);
@ -90,7 +91,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis
upspeedText.setText(FileSizeConverter.getSize(upspeed) + "/s"); upspeedText.setText(FileSizeConverter.getSize(upspeed) + "/s");
downcountSign.setVisibility(View.VISIBLE); downcountSign.setVisibility(View.VISIBLE);
upcountSign.setVisibility(View.VISIBLE); upcountSign.setVisibility(View.VISIBLE);
speedswrapperLayout.setOnClickListener(onStartDownPickerClicked); speedswrapperLayout.setOnClickListener(supportsSetTransferRates ? onStartDownPickerClicked : null);
} }

16
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.service.ConnectivityHelper;
import org.transdroid.core.widget.ListWidgetProvider; import org.transdroid.core.widget.ListWidgetProvider;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Priority; import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent; 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) // There is a connection (read: settings to some server known)
menu.findItem(R.id.action_add).setVisible(true); 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_search).setVisible(navigationHelper.enableSearchUi());
menu.findItem(R.id.action_rss).setVisible(navigationHelper.enableRssUi()); menu.findItem(R.id.action_rss).setVisible(navigationHelper.enableRssUi());
boolean hasAltMode = Daemon.supportsSetAlternativeMode(currentConnection.getType()); boolean hasAltMode = Daemon.supportsSetAlternativeMode(currentConnection.getType());
@ -942,7 +945,15 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
@Background @Background
public void addTorrentByMagnetUrl(String url, String title) { 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) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
refreshTorrents(); refreshTorrents();
@ -1259,7 +1270,8 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
} }
// Update the server status (counts and speeds) in the action bar // 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()));
} }

2
app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java

@ -228,7 +228,7 @@ public class LocalTorrent {
public static int getResourceForDaemonException(DaemonException e) { public static int getResourceForDaemonException(DaemonException e) {
switch (e.getType()) { switch (e.getType()) {
case MethodUnsupported: case MethodUnsupported:
return R.string.error_jsonrequesterror; return R.string.error_unsupported;
case ConnectionError: case ConnectionError:
return R.string.error_httperror; return R.string.error_httperror;
case UnexpectedResponse: case UnexpectedResponse:

11
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.androidannotations.annotations.EService;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.*;
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.lists.LocalTorrent; import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.log.Log_; import org.transdroid.core.service.*;
import org.transdroid.core.service.ConnectivityHelper_;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;

8
app/src/main/res/menu/fragment_details.xml

@ -32,13 +32,19 @@
android:id="@+id/action_start" android:id="@+id/action_start"
android:icon="?attr/ic_action_start" android:icon="?attr/ic_action_start"
android:showAsAction="ifRoom" android:showAsAction="ifRoom"
android:title="@string/action_start_default" android:title="@string/action_start"
android:orderInCategory="202"> android:orderInCategory="202">
<menu> <menu>
<item android:id="@+id/action_start_default" android:title="@string/action_start_default" /> <item android:id="@+id/action_start_default" android:title="@string/action_start_default" />
<item android:id="@+id/action_start_forced" android:title="@string/action_start_forced" /> <item android:id="@+id/action_start_forced" android:title="@string/action_start_forced" />
</menu> </menu>
</item> </item>
<item
android:id="@+id/action_start_direct"
android:icon="?attr/ic_action_start"
android:showAsAction="ifRoom"
android:title="@string/action_start"
android:orderInCategory="202" />
<item <item
android:id="@+id/action_stop" android:id="@+id/action_stop"
android:icon="?attr/ic_action_stop" android:icon="?attr/ic_action_stop"

1
app/src/main/res/values/strings.xml

@ -418,6 +418,7 @@
</string-array> </string-array>
<string name="error_httperror">Error during communication; check your connection</string> <string name="error_httperror">Error during communication; check your connection</string>
<string name="error_unsupported">Your torrent client does not support this operation</string>
<string name="error_jsonrequesterror">Internal error building request</string> <string name="error_jsonrequesterror">Internal error building request</string>
<string name="error_jsonresponseerror">Error parsing server response (please check your settings)</string> <string name="error_jsonresponseerror">Error parsing server response (please check your settings)</string>
<string name="error_daemonnotconnected">Web interface not connected to a running daemon</string> <string name="error_daemonnotconnected">Web interface not connected to a running daemon</string>

Loading…
Cancel
Save