From cd44899f83fda8747180c4696bed162205ffed22 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 11 Oct 2013 12:00:07 +0200 Subject: [PATCH 1/4] Click on empty/error messages refreshes the torrents and details screens. Fixes #20. --- core/res/layout/fragment_details.xml | 13 +++++++ .../transdroid/core/gui/DetailsActivity.java | 38 +++++++++--------- .../transdroid/core/gui/DetailsFragment.java | 39 ++++++++++++++++--- .../core/gui/TorrentTasksExecutor.java | 5 +++ .../transdroid/core/gui/TorrentsActivity.java | 12 ++++-- .../transdroid/core/gui/TorrentsFragment.java | 18 +++++++++ .../gui/navigation/RefreshableActivity.java | 28 +++++++++++++ .../core/service/ConnectivityHelper.java | 4 +- 8 files changed, 129 insertions(+), 28 deletions(-) create mode 100644 core/src/org/transdroid/core/gui/navigation/RefreshableActivity.java diff --git a/core/res/layout/fragment_details.xml b/core/res/layout/fragment_details.xml index cc8306dd..e2700c2c 100644 --- a/core/res/layout/fragment_details.xml +++ b/core/res/layout/fragment_details.xml @@ -52,4 +52,17 @@ android:textIsSelectable="false" android:visibility="visible" /> + + diff --git a/core/src/org/transdroid/core/gui/DetailsActivity.java b/core/src/org/transdroid/core/gui/DetailsActivity.java index 3f6e1bd0..0f3c816d 100644 --- a/core/src/org/transdroid/core/gui/DetailsActivity.java +++ b/core/src/org/transdroid/core/gui/DetailsActivity.java @@ -35,6 +35,7 @@ import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.navigation.Label; import org.transdroid.core.gui.navigation.NavigationHelper; +import org.transdroid.core.gui.navigation.RefreshableActivity; import org.transdroid.core.service.ConnectivityHelper; import org.transdroid.daemon.Daemon; import org.transdroid.daemon.IDaemonAdapter; @@ -79,7 +80,7 @@ import de.keyboardsurfer.android.widget.crouton.Crouton; */ @EActivity(resName = "activity_details") @OptionsMenu(resName = "activity_details") -public class DetailsActivity extends SherlockFragmentActivity implements TorrentTasksExecutor { +public class DetailsActivity extends SherlockFragmentActivity implements TorrentTasksExecutor, RefreshableActivity { @Extra @InstanceState @@ -148,8 +149,8 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent } @OptionsItem(resName = "action_refresh") - protected void refreshScreen() { - fragmentDetails.updateIsLoading(true); + public void refreshScreen() { + fragmentDetails.updateIsLoading(true, null); refreshTorrent(); refreshTorrentDetails(torrent); refreshTorrentFiles(torrent); @@ -162,7 +163,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels()); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, true); } } @@ -174,7 +175,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof GetTorrentDetailsTaskSuccessResult) { onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails()); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -186,7 +187,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof GetFileListTaskSuccessResult) { onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles()); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -198,7 +199,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName())); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -210,7 +211,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName())); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -222,7 +223,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName())); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -234,7 +235,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName())); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -247,7 +248,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent closeActivity(getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName())); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -267,7 +268,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel)); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -278,7 +279,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated)); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -289,7 +290,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation)); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -301,7 +302,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent if (result instanceof DaemonTaskResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset)); } else { - onCommunicationError((DaemonTaskFailureResult) result); + onCommunicationError((DaemonTaskFailureResult) result, false); } } @@ -326,9 +327,10 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent } @UiThread - protected void onCommunicationError(DaemonTaskFailureResult result) { + protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) { Log.i(this, result.getException().toString()); - fragmentDetails.updateIsLoading(false); + String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); + fragmentDetails.updateIsLoading(false, isCritical? error: null); Crouton.showText(this, getString(LocalTorrent.getResourceForDaemonException(result.getException())), NavigationHelper.CROUTON_ERROR_STYLE); } @@ -336,7 +338,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @UiThread protected void onTorrentsRetrieved(List torrents, List labels) { // Update the details fragment accordingly - fragmentDetails.updateIsLoading(false); + fragmentDetails.updateIsLoading(false, null); fragmentDetails.perhapsUpdateTorrent(torrents); fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); diff --git a/core/src/org/transdroid/core/gui/DetailsFragment.java b/core/src/org/transdroid/core/gui/DetailsFragment.java index 2697335b..80b2f591 100644 --- a/core/src/org/transdroid/core/gui/DetailsFragment.java +++ b/core/src/org/transdroid/core/gui/DetailsFragment.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.Click; import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.InstanceState; import org.androidannotations.annotations.OptionsItem; @@ -34,6 +35,7 @@ import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.navigation.Label; import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.NavigationHelper_; +import org.transdroid.core.gui.navigation.RefreshableActivity; import org.transdroid.core.gui.navigation.SelectionManagerMode; import org.transdroid.core.gui.navigation.SetLabelDialog; import org.transdroid.core.gui.navigation.SetLabelDialog.OnLabelPickedListener; @@ -85,13 +87,15 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat protected ArrayList