Browse Source

Maybe fix #469. Seems fragment is already detached and unloaded.

pull/487/head
Eric Kok 6 years ago
parent
commit
de9c0c4d7a
  1. 17
      app/src/main/java/org/transdroid/core/gui/DetailsActivity.java
  2. 3
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  3. 2
      app/src/main/java/org/transdroid/core/gui/navigation/Label.java

17
app/src/main/java/org/transdroid/core/gui/DetailsActivity.java

@ -333,20 +333,23 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx
@UiThread @UiThread
protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) { protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) {
// Update the details fragment with the new fine details for the shown torrent // Update the details fragment with the new fine details for the shown torrent
fragmentDetails.updateTorrentDetails(torrent, torrentDetails); if (fragmentDetails.isAdded())
fragmentDetails.updateTorrentDetails(torrent, torrentDetails);
} }
@UiThread @UiThread
protected void onTorrentFilesRetrieved(Torrent torrent, List<TorrentFile> torrentFiles) { protected void onTorrentFilesRetrieved(Torrent torrent, List<TorrentFile> torrentFiles) {
// Update the details fragment with the newly retrieved list of files // Update the details fragment with the newly retrieved list of files
fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); if (fragmentDetails.isAdded())
fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles));
} }
@UiThread @UiThread
protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) { protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) {
log.i(this, result.getException().toString()); log.i(this, result.getException().toString());
String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); String error = getString(LocalTorrent.getResourceForDaemonException(result.getException()));
fragmentDetails.updateIsLoading(false, isCritical ? error : null); if (fragmentDetails.isAdded())
fragmentDetails.updateIsLoading(false, isCritical ? error : null);
SnackbarManager.show(Snackbar.with(this).text(getString(LocalTorrent.getResourceForDaemonException(result.getException()))) SnackbarManager.show(Snackbar.with(this).text(getString(LocalTorrent.getResourceForDaemonException(result.getException())))
.colorResource(R.color.red)); .colorResource(R.color.red));
} }
@ -354,9 +357,11 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx
@UiThread @UiThread
protected void onTorrentsRetrieved(List<Torrent> torrents, List<org.transdroid.daemon.Label> labels) { protected void onTorrentsRetrieved(List<Torrent> torrents, List<org.transdroid.daemon.Label> labels) {
// Update the details fragment accordingly // Update the details fragment accordingly
fragmentDetails.updateIsLoading(false, null); if (fragmentDetails.isAdded()) {
fragmentDetails.perhapsUpdateTorrent(torrents); fragmentDetails.updateIsLoading(false, null);
fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); fragmentDetails.perhapsUpdateTorrent(torrents);
fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled)));
}
} }
} }

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

@ -791,7 +791,8 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@OptionsItem(R.id.action_refresh) @OptionsItem(R.id.action_refresh)
public void refreshScreen() { public void refreshScreen() {
fragmentTorrents.updateIsLoading(true); if (fragmentTorrents.isAdded())
fragmentTorrents.updateIsLoading(true);
refreshTorrents(); refreshTorrents();
if (Daemon.supportsStats(currentConnection.getType())) { if (Daemon.supportsStats(currentConnection.getType())) {
getAdditionalStats(); getAdditionalStats();

2
app/src/main/java/org/transdroid/core/gui/navigation/Label.java

@ -103,7 +103,7 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
unnamedLabelText = unnamedLabel; unnamedLabelText = unnamedLabel;
localLabels.add(new Label(unnamedLabel, -1, true)); localLabels.add(new Label(unnamedLabel, -1, true));
for (org.transdroid.daemon.Label label : daemonLabels) { for (org.transdroid.daemon.Label label : daemonLabels) {
if (!TextUtils.isEmpty(label.getName())) { if (label != null && !TextUtils.isEmpty(label.getName())) {
localLabels.add(new Label(label)); localLabels.add(new Label(label));
} }
} }

Loading…
Cancel
Save