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 @@ -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<TorrentFile> torrentFiles = null;
@ -139,6 +141,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -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 @@ -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 @@ -178,7 +181,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
*/
public void updateTorrentFiles(Torrent checkTorrent, ArrayList<TorrentFile> 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 @@ -192,10 +195,10 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
*/
public void perhapsUpdateTorrent(List<Torrent> 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 @@ -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 @@ -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 @@ -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 @@ -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);
}

5
app/src/main/java/org/transdroid/core/gui/ServerStatusView.java

@ -55,8 +55,9 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @@ -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<Torrent> torrents, boolean dormantAsInactive) {
public void update(List<Torrent> torrents, boolean dormantAsInactive, boolean supportsSetTransferRates) {
if (torrents == null) {
downcountText.setText(null);
@ -90,7 +91,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @@ -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);
}

16
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -60,6 +60,7 @@ import org.transdroid.core.service.BootReceiver; @@ -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, @@ -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, @@ -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, @@ -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()));
}

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

@ -228,7 +228,7 @@ public class LocalTorrent { @@ -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:

11
app/src/main/java/org/transdroid/core/widget/ListWidgetViewsService.java

@ -27,15 +27,10 @@ import android.widget.RemoteViewsService; @@ -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;

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

@ -32,13 +32,19 @@ @@ -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">
<menu>
<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" />
</menu>
</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
android:id="@+id/action_stop"
android:icon="?attr/ic_action_stop"

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

@ -418,6 +418,7 @@ @@ -418,6 +418,7 @@
</string-array>
<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_jsonresponseerror">Error parsing server response (please check your settings)</string>
<string name="error_daemonnotconnected">Web interface not connected to a running daemon</string>

Loading…
Cancel
Save