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 @@ -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<TorrentFile> 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 @@ -354,9 +357,11 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx
@UiThread
protected void onTorrentsRetrieved(List<Torrent> torrents, List<org.transdroid.daemon.Label> 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)));
}
}
}

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

@ -791,7 +791,8 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -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();

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

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

Loading…
Cancel
Save