From f6e8de2b52abac5e9bd0102247025237c7534aeb Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 23 Apr 2019 17:46:23 +0200 Subject: [PATCH] Fixing UI crashes due to #391 #495 #484 #483... --- .../transdroid/core/gui/DetailsActivity.java | 11 +++++++---- .../transdroid/core/gui/DetailsFragment.java | 4 ++-- .../transdroid/core/gui/TorrentsActivity.java | 18 +++++++++--------- .../transdroid/core/gui/TorrentsFragment.java | 17 +++++++++++------ .../org/transdroid/daemon/DummyAdapter.java | 2 +- app/src/main/res/values/changelog.xml | 2 ++ 6 files changed, 32 insertions(+), 22 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 84ede89c..8a0da758 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java @@ -170,6 +170,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @Background public void refreshTorrentDetails(Torrent torrent) { + if (currentConnection == null) return; if (!Daemon.supportsFineDetails(torrent.getDaemon())) { return; } @@ -183,6 +184,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @Background public void refreshTorrentFiles(Torrent torrent) { + if (currentConnection == null) return; if (!Daemon.supportsFileListing(torrent.getDaemon())) { return; } @@ -197,6 +199,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @Background @Override public void resumeTorrent(Torrent torrent) { + if (currentConnection == null) return; torrent.mimicResume(); DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(log); if (result instanceof DaemonTaskSuccessResult) { @@ -333,14 +336,14 @@ 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 - if (fragmentDetails.isAdded()) + if (fragmentDetails.isResumed()) fragmentDetails.updateTorrentDetails(torrent, torrentDetails); } @UiThread protected void onTorrentFilesRetrieved(Torrent torrent, List torrentFiles) { // Update the details fragment with the newly retrieved list of files - if (fragmentDetails.isAdded()) + if (fragmentDetails.isResumed()) fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); } @@ -348,7 +351,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) { log.i(this, result.getException().toString()); String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); - if (fragmentDetails.isAdded()) + if (fragmentDetails.isResumed()) fragmentDetails.updateIsLoading(false, isCritical ? error : null); SnackbarManager.show(Snackbar.with(this).text(getString(LocalTorrent.getResourceForDaemonException(result.getException()))) .colorResource(R.color.red)); @@ -357,7 +360,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @UiThread protected void onTorrentsRetrieved(List torrents, List labels) { // Update the details fragment accordingly - if (fragmentDetails.isAdded()) { + if (fragmentDetails.isResumed()) { 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/DetailsFragment.java b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java index 456e297e..79843c00 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java @@ -150,10 +150,10 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen if (torrent != null) { updateTorrent(torrent); } - if (torrentDetails != null) { + if (torrent != null && torrentDetails != null) { updateTorrentDetails(torrent, torrentDetails); } - if (torrentFiles != null) { + if (torrent != null && torrentFiles != null) { updateTorrentFiles(torrent, torrentFiles); } 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 df0627af..2956cf2b 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -566,7 +566,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE // Clear the currently shown list of torrents and perhaps the details fragmentTorrents.clear(true, true); - if (fragmentDetails != null && fragmentDetails.isAdded() && fragmentDetails.getActivity() != null) { + if (fragmentDetails != null && fragmentDetails.isResumed() && fragmentDetails.getActivity() != null) { fragmentDetails.updateIsLoading(false, null); fragmentDetails.clear(); fragmentDetails.setCurrentServerSettings(server); @@ -586,7 +586,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE // Remember that the user last selected this applicationSettings.setLastUsedNavigationFilter(currentFilter); // Clear the details view - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { fragmentDetails.updateIsLoading(false, null); fragmentDetails.clear(); } @@ -599,7 +599,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE * @param hasServerSettings Whether there are server settings available, so we can continue to connect */ private void updateFragmentVisibility(boolean hasServerSettings) { - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { if (hasServerSettings) { getFragmentManager().beginTransaction().show(fragmentDetails).commit(); } else { @@ -905,7 +905,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE * @param torrent The torrent to show detailed statistics for */ public void openDetails(Torrent torrent) { - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { fragmentDetails.updateTorrent(torrent); } else { DetailsActivity_.intent(this).torrent(torrent).currentLabels(lastNavigationLabels).startForResult(RESULT_DETAILS); @@ -1296,7 +1296,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE fragmentTorrents.updateIsLoading(false); if (isCritical) { fragmentTorrents.updateError(error); - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { fragmentDetails.updateIsLoading(false, error); } } @@ -1312,13 +1312,13 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE fragmentTorrents.updateTorrents(new ArrayList<>(torrents), lastNavigationLabels); // Update the details fragment if the currently shown torrent is in the newly retrieved list - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { fragmentDetails.perhapsUpdateTorrent(torrents); } // Update local list of labels in the navigation navigationListAdapter.updateLabels(lastNavigationLabels); - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { fragmentDetails.updateLabels(lastNavigationLabels); } @@ -1347,7 +1347,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @UiThread protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) { // Update the details fragment with the new fine details for the shown torrent - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { fragmentDetails.updateTorrentDetails(torrent, torrentDetails); } } @@ -1355,7 +1355,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @UiThread protected void onTorrentFilesRetrieved(Torrent torrent, List torrentFiles) { // Update the details fragment with the newly retrieved list of files - if (fragmentDetails != null && fragmentDetails.isAdded()) { + if (fragmentDetails != null && fragmentDetails.isResumed()) { fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); } } diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java index 7b2c48a5..fd9257a7 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java @@ -74,8 +74,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener protected ApplicationSettings applicationSettings; @Bean protected SystemSettings systemSettings; - @InstanceState - protected ArrayList torrents = null; + // HACK Working around #391 while hopefully we rework the UI in the future to persist the list in db or something + protected static ArrayList torrents = null; @InstanceState protected ArrayList lastMultiSelectedTorrents; @InstanceState @@ -144,7 +144,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener * @param newTorrents The new, updated list of torrents */ public void updateTorrents(ArrayList newTorrents, ArrayList