From de9c0c4d7afbe03172cb5a63a64a9fef57f30a7a Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 9 Nov 2018 16:45:30 +0100 Subject: [PATCH] Maybe fix #469. Seems fragment is already detached and unloaded. --- .../transdroid/core/gui/DetailsActivity.java | 17 +++++++++++------ .../transdroid/core/gui/TorrentsActivity.java | 3 ++- .../transdroid/core/gui/navigation/Label.java | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java index c0194734..84ede89c 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java @@ -333,20 +333,23 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @UiThread protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) { // 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 protected void onTorrentFilesRetrieved(Torrent torrent, List torrentFiles) { // 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 protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) { log.i(this, result.getException().toString()); 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()))) .colorResource(R.color.red)); } @@ -354,9 +357,11 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @UiThread protected void onTorrentsRetrieved(List torrents, List labels) { // Update the details fragment accordingly - fragmentDetails.updateIsLoading(false, null); - fragmentDetails.perhapsUpdateTorrent(torrents); - fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); + if (fragmentDetails.isAdded()) { + fragmentDetails.updateIsLoading(false, null); + fragmentDetails.perhapsUpdateTorrent(torrents); + fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); + } } } diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index 4f1b68f5..df0627af 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/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) public void refreshScreen() { - fragmentTorrents.updateIsLoading(true); + if (fragmentTorrents.isAdded()) + fragmentTorrents.updateIsLoading(true); refreshTorrents(); if (Daemon.supportsStats(currentConnection.getType())) { getAdditionalStats(); diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/Label.java b/app/src/main/java/org/transdroid/core/gui/navigation/Label.java index 9a6b90e8..d2bae95e 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/Label.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/Label.java @@ -103,7 +103,7 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable