Browse Source

Click on empty/error messages refreshes the torrents and details screens. Fixes #20.

pull/82/head
Eric Kok 11 years ago
parent
commit
cd44899f83
  1. 13
      core/res/layout/fragment_details.xml
  2. 38
      core/src/org/transdroid/core/gui/DetailsActivity.java
  3. 39
      core/src/org/transdroid/core/gui/DetailsFragment.java
  4. 5
      core/src/org/transdroid/core/gui/TorrentTasksExecutor.java
  5. 12
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  6. 18
      core/src/org/transdroid/core/gui/TorrentsFragment.java
  7. 28
      core/src/org/transdroid/core/gui/navigation/RefreshableActivity.java
  8. 4
      core/src/org/transdroid/core/service/ConnectivityHelper.java

13
core/res/layout/fragment_details.xml

@ -52,4 +52,17 @@ @@ -52,4 +52,17 @@
android:textIsSelectable="false"
android:visibility="visible" />
<TextView
android:id="@+id/error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="8dip"
android:drawableTop="?attr/loading_progress"
android:gravity="center"
android:maxWidth="400dip"
android:padding="@dimen/margin_default"
android:textIsSelectable="false"
android:visibility="gone" />
</FrameLayout>

38
core/src/org/transdroid/core/gui/DetailsActivity.java

@ -35,6 +35,7 @@ import org.transdroid.core.gui.lists.LocalTorrent; @@ -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; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -336,7 +338,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
@UiThread
protected void onTorrentsRetrieved(List<Torrent> torrents, List<org.transdroid.daemon.Label> 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)));

39
core/src/org/transdroid/core/gui/DetailsFragment.java

@ -21,6 +21,7 @@ import java.util.Collections; @@ -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; @@ -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 @@ -85,13 +87,15 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
protected ArrayList<Label> currentLabels = null;
@InstanceState
protected boolean isLoadingTorrent = false;
@InstanceState
protected boolean hasCriticalError = false;
private ServerSetting currentServerSettings = null;
// Views
@ViewById(resName = "details_list")
protected SherlockListView detailsList;
@ViewById
protected TextView emptyText;
protected TextView emptyText, errorText;
@ViewById
protected ProgressBar loadingProgress;
@ -128,19 +132,22 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -128,19 +132,22 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
/**
* Updates the details adapter header to show the new torrent data.
* @param newTorrent The new torrent object
* @param newTorrent The new, non-null torrent object
*/
public void updateTorrent(Torrent newTorrent) {
clear();
this.torrent = newTorrent;
this.hasCriticalError = false;
((DetailsAdapter) detailsList.getAdapter()).updateTorrent(newTorrent);
// Make the list (with details header) visible
detailsList.setVisibility(View.VISIBLE);
emptyText.setVisibility(View.GONE);
errorText.setVisibility(View.GONE);
loadingProgress.setVisibility(View.GONE);
// Also update the available actions in the action bar
getActivity().supportInvalidateOptionsMenu();
// Refresh the detailed statistics (errors) and list of files
torrentDetails = null;
torrentFiles = null;
getTasksExecutor().refreshTorrentDetails(torrent);
getTasksExecutor().refreshTorrentFiles(torrent);
}
@ -208,7 +215,8 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -208,7 +215,8 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
public void clear() {
detailsList.setAdapter(new DetailsAdapter(getActivity()));
detailsList.setVisibility(View.GONE);
emptyText.setVisibility(!isLoadingTorrent ? View.VISIBLE : View.GONE);
emptyText.setVisibility(!isLoadingTorrent && !hasCriticalError ? View.VISIBLE : View.GONE);
errorText.setVisibility(!isLoadingTorrent && hasCriticalError ? View.VISIBLE : View.GONE);
loadingProgress.setVisibility(isLoadingTorrent ? View.VISIBLE : View.GONE);
// Note: this.torrent is not cleared as we need to know later what the fragment was originally bound to
torrentDetails = null;
@ -218,10 +226,13 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -218,10 +226,13 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
/**
* Updates the shown screen depending on whether the torrent is loading
* @param isLoading True if the torrent is (re)loading, false otherwise
* @param connectionErrorMessage The error message text to show to the user, or null if there was no error
*/
public void updateIsLoading(boolean isLoading) {
public void updateIsLoading(boolean isLoading, String connectionErrorMessage) {
this.isLoadingTorrent = isLoading;
if (isLoadingTorrent)
this.hasCriticalError = connectionErrorMessage != null;
errorText.setText(connectionErrorMessage);
if (isLoading || hasCriticalError)
clear();
}
@ -330,6 +341,22 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -330,6 +341,22 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
getTasksExecutor().updateLocation(torrent, newLocation);
}
@Click
protected void emptyTextClicked() {
// Refresh the activity (that contains this fragment) when the empty view gear is clicked
if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
((RefreshableActivity) getActivity()).refreshScreen();
}
}
@Click
protected void errorTextClicked() {
// Refresh the activity (that contains this fragment) when the error view gear is clicked
if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
((RefreshableActivity) getActivity()).refreshScreen();
}
}
private MultiChoiceModeListenerCompat onDetailsSelected = new MultiChoiceModeListenerCompat() {
SelectionManagerMode selectionManagerMode;

5
core/src/org/transdroid/core/gui/TorrentTasksExecutor.java

@ -22,6 +22,11 @@ import org.transdroid.daemon.Priority; @@ -22,6 +22,11 @@ import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentFile;
/**
* Interface to be implemented by any activity that wants containing fragments to be able to load data and execute
* commands against a torrent server.
* @author Eric Kok
*/
public interface TorrentTasksExecutor {
void resumeTorrent(Torrent torrent);
void pauseTorrent(Torrent torrent);

12
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -122,7 +122,8 @@ import de.keyboardsurfer.android.widget.crouton.Crouton; @@ -122,7 +122,8 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
*/
@EActivity(resName = "activity_torrents")
@OptionsMenu(resName = "activity_torrents")
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor {
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor,
RefreshableActivity {
// Navigation components
@Bean
@ -385,6 +386,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -385,6 +386,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Clear the currently shown list of torrents and perhaps the details
fragmentTorrents.clear(true, true);
if (fragmentDetails != null && fragmentDetails.getActivity() != null) {
fragmentDetails.updateIsLoading(false, null);
fragmentDetails.clear();
fragmentDetails.setCurrentServerSettings(server);
}
@ -401,6 +403,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -401,6 +403,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// Clear the details view
if (fragmentDetails != null) {
fragmentDetails.updateIsLoading(false, null);
fragmentDetails.clear();
}
}
@ -547,7 +550,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -547,7 +550,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
@OptionsItem(resName = "action_refresh")
protected void refreshScreen() {
public void refreshScreen() {
fragmentTorrents.updateIsLoading(true);
refreshTorrents();
if (Daemon.supportsStats(currentConnection.getType()))
@ -942,8 +945,11 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -942,8 +945,11 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
String error = getString(LocalTorrent.getResourceForDaemonException(result.getException()));
Crouton.showText(this, error, NavigationHelper.CROUTON_ERROR_STYLE);
fragmentTorrents.updateIsLoading(false);
if (isCritical)
if (isCritical) {
fragmentTorrents.updateError(error);
if (fragmentDetails != null)
fragmentDetails.updateIsLoading(false, error);
}
}
@UiThread

18
core/src/org/transdroid/core/gui/TorrentsFragment.java

@ -23,6 +23,7 @@ import java.util.Locale; @@ -23,6 +23,7 @@ import java.util.Locale;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.ItemClick;
@ -33,6 +34,7 @@ import org.transdroid.core.gui.lists.TorrentsAdapter; @@ -33,6 +34,7 @@ import org.transdroid.core.gui.lists.TorrentsAdapter;
import org.transdroid.core.gui.lists.TorrentsAdapter_;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter;
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;
@ -304,6 +306,22 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL @@ -304,6 +306,22 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL
};
@Click
protected void emptyTextClicked() {
// Refresh the activity (that contains this fragment) when the empty view gear is clicked
if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
((RefreshableActivity) getActivity()).refreshScreen();
}
}
@Click
protected void errorTextClicked() {
// Refresh the activity (that contains this fragment) when the error view gear is clicked
if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
((RefreshableActivity) getActivity()).refreshScreen();
}
}
@ItemClick(resName = "torrent_list")
protected void torrentsListClicked(Torrent torrent) {
((TorrentsActivity) getActivity()).openDetails(torrent);

28
core/src/org/transdroid/core/gui/navigation/RefreshableActivity.java

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.gui.navigation;
/**
* Interface to be implemented by any activity that allows its content to be refreshed; fragments can ask for
* user-initiated refreshes.
* @author Eric Kok
*/
public interface RefreshableActivity {
public void refreshScreen();
}

4
core/src/org/transdroid/core/service/ConnectivityHelper.java

@ -42,7 +42,8 @@ public class ConnectivityHelper { @@ -42,7 +42,8 @@ public class ConnectivityHelper {
return false;
// Still good? Check the current active network instead
return connectivityManager.getActiveNetworkInfo().isConnected();
return connectivityManager.getActiveNetworkInfo() != null
&& connectivityManager.getActiveNetworkInfo().isConnected();
}
public String getConnectedNetworkName() {
@ -51,4 +52,5 @@ public class ConnectivityHelper { @@ -51,4 +52,5 @@ public class ConnectivityHelper {
}
return null;
}
}

Loading…
Cancel
Save