|
|
@ -36,7 +36,9 @@ public class TorrentsFragment extends SherlockFragment { |
|
|
|
@InstanceState |
|
|
|
@InstanceState |
|
|
|
protected boolean hasAConnection = false; |
|
|
|
protected boolean hasAConnection = false; |
|
|
|
@InstanceState |
|
|
|
@InstanceState |
|
|
|
protected boolean isLoading = false; |
|
|
|
protected boolean isLoading = true; |
|
|
|
|
|
|
|
@InstanceState |
|
|
|
|
|
|
|
protected String connectionErrorMessage = null; |
|
|
|
|
|
|
|
|
|
|
|
// Views
|
|
|
|
// Views
|
|
|
|
@ViewById(resName = "torrent_list") |
|
|
|
@ViewById(resName = "torrent_list") |
|
|
@ -46,6 +48,8 @@ public class TorrentsFragment extends SherlockFragment { |
|
|
|
@ViewById |
|
|
|
@ViewById |
|
|
|
protected TextView nosettingsText; |
|
|
|
protected TextView nosettingsText; |
|
|
|
@ViewById |
|
|
|
@ViewById |
|
|
|
|
|
|
|
protected TextView errorText; |
|
|
|
|
|
|
|
@ViewById |
|
|
|
protected ProgressBar loadingProgress; |
|
|
|
protected ProgressBar loadingProgress; |
|
|
|
|
|
|
|
|
|
|
|
@AfterViews |
|
|
|
@AfterViews |
|
|
@ -69,6 +73,7 @@ public class TorrentsFragment extends SherlockFragment { |
|
|
|
* Clear currently visible list of torrents |
|
|
|
* Clear currently visible list of torrents |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void clear() { |
|
|
|
public void clear() { |
|
|
|
|
|
|
|
this.connectionErrorMessage = null; |
|
|
|
updateTorrents(null); |
|
|
|
updateTorrents(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -171,8 +176,11 @@ public class TorrentsFragment extends SherlockFragment { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void updateConnectionStatus(boolean hasAConnection) { |
|
|
|
public void updateConnectionStatus(boolean hasAConnection) { |
|
|
|
this.hasAConnection = hasAConnection; |
|
|
|
this.hasAConnection = hasAConnection; |
|
|
|
if (!hasAConnection) |
|
|
|
if (!hasAConnection) { |
|
|
|
clear(); |
|
|
|
clear(); // Indirectly also calls updateViewVisibility()
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
updateViewVisibility(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -181,8 +189,26 @@ public class TorrentsFragment extends SherlockFragment { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void updateIsLoading(boolean isLoading) { |
|
|
|
public void updateIsLoading(boolean isLoading) { |
|
|
|
this.isLoading = isLoading; |
|
|
|
this.isLoading = isLoading; |
|
|
|
if (isLoading) |
|
|
|
if (isLoading) { |
|
|
|
clear(); |
|
|
|
clear(); // Indirectly also calls updateViewVisibility()
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
updateViewVisibility(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Updates the shown screen depending on whether a connection error occurred |
|
|
|
|
|
|
|
* @param connectionErrorMessage The error message from the last failed connection attempt, or null to clear the |
|
|
|
|
|
|
|
* visible error text |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void updateError(String connectionErrorMessage) { |
|
|
|
|
|
|
|
this.connectionErrorMessage = connectionErrorMessage; |
|
|
|
|
|
|
|
errorText.setText(connectionErrorMessage); |
|
|
|
|
|
|
|
if (connectionErrorMessage != null) { |
|
|
|
|
|
|
|
clear(); // Indirectly also calls updateViewVisibility()
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
updateViewVisibility(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@UiThread |
|
|
|
@UiThread |
|
|
@ -191,14 +217,17 @@ public class TorrentsFragment extends SherlockFragment { |
|
|
|
torrentsList.setVisibility(View.GONE); |
|
|
|
torrentsList.setVisibility(View.GONE); |
|
|
|
emptyText.setVisibility(View.GONE); |
|
|
|
emptyText.setVisibility(View.GONE); |
|
|
|
loadingProgress.setVisibility(View.GONE); |
|
|
|
loadingProgress.setVisibility(View.GONE); |
|
|
|
|
|
|
|
errorText.setVisibility(View.GONE); |
|
|
|
nosettingsText.setVisibility(View.VISIBLE); |
|
|
|
nosettingsText.setVisibility(View.VISIBLE); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
boolean isEmpty = torrents == null || torrentsList.getAdapter().isEmpty(); |
|
|
|
boolean isEmpty = torrents == null || torrentsList.getAdapter().isEmpty(); |
|
|
|
|
|
|
|
boolean hasError = connectionErrorMessage == null; |
|
|
|
nosettingsText.setVisibility(View.GONE); |
|
|
|
nosettingsText.setVisibility(View.GONE); |
|
|
|
torrentsList.setVisibility(!isLoading && !isEmpty? View.GONE: View.VISIBLE); |
|
|
|
errorText.setVisibility(hasError? View.VISIBLE : View.GONE); |
|
|
|
loadingProgress.setVisibility(isLoading? View.VISIBLE: View.GONE); |
|
|
|
torrentsList.setVisibility(!hasError && !isLoading && !isEmpty ? View.GONE : View.VISIBLE); |
|
|
|
emptyText.setVisibility(!isLoading && isEmpty? View.VISIBLE: View.GONE); |
|
|
|
loadingProgress.setVisibility(!hasError && isLoading ? View.VISIBLE : View.GONE); |
|
|
|
|
|
|
|
emptyText.setVisibility(!hasError && !isLoading && isEmpty ? View.VISIBLE : View.GONE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|