Browse Source

Fixing UI crashes due to #391 #495 #484 #483...

bugfix/391
Eric Kok 6 years ago
parent
commit
f6e8de2b52
  1. 11
      app/src/main/java/org/transdroid/core/gui/DetailsActivity.java
  2. 4
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  3. 18
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  4. 17
      app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java
  5. 2
      app/src/main/java/org/transdroid/daemon/DummyAdapter.java
  6. 2
      app/src/main/res/values/changelog.xml

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

@ -170,6 +170,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx
@Background @Background
public void refreshTorrentDetails(Torrent torrent) { public void refreshTorrentDetails(Torrent torrent) {
if (currentConnection == null) return;
if (!Daemon.supportsFineDetails(torrent.getDaemon())) { if (!Daemon.supportsFineDetails(torrent.getDaemon())) {
return; return;
} }
@ -183,6 +184,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx
@Background @Background
public void refreshTorrentFiles(Torrent torrent) { public void refreshTorrentFiles(Torrent torrent) {
if (currentConnection == null) return;
if (!Daemon.supportsFileListing(torrent.getDaemon())) { if (!Daemon.supportsFileListing(torrent.getDaemon())) {
return; return;
} }
@ -197,6 +199,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx
@Background @Background
@Override @Override
public void resumeTorrent(Torrent torrent) { public void resumeTorrent(Torrent torrent) {
if (currentConnection == null) return;
torrent.mimicResume(); torrent.mimicResume();
DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(log); DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(log);
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
@ -333,14 +336,14 @@ 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
if (fragmentDetails.isAdded()) if (fragmentDetails.isResumed())
fragmentDetails.updateTorrentDetails(torrent, torrentDetails); 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
if (fragmentDetails.isAdded()) if (fragmentDetails.isResumed())
fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles));
} }
@ -348,7 +351,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx
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()));
if (fragmentDetails.isAdded()) if (fragmentDetails.isResumed())
fragmentDetails.updateIsLoading(false, isCritical ? error : null); 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));
@ -357,7 +360,7 @@ 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
if (fragmentDetails.isAdded()) { if (fragmentDetails.isResumed()) {
fragmentDetails.updateIsLoading(false, null); fragmentDetails.updateIsLoading(false, null);
fragmentDetails.perhapsUpdateTorrent(torrents); fragmentDetails.perhapsUpdateTorrent(torrents);
fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled)));

4
app/src/main/java/org/transdroid/core/gui/DetailsFragment.java

@ -150,10 +150,10 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
if (torrent != null) { if (torrent != null) {
updateTorrent(torrent); updateTorrent(torrent);
} }
if (torrentDetails != null) { if (torrent != null && torrentDetails != null) {
updateTorrentDetails(torrent, torrentDetails); updateTorrentDetails(torrent, torrentDetails);
} }
if (torrentFiles != null) { if (torrent != null && torrentFiles != null) {
updateTorrentFiles(torrent, torrentFiles); updateTorrentFiles(torrent, torrentFiles);
} }

18
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 // Clear the currently shown list of torrents and perhaps the details
fragmentTorrents.clear(true, true); 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.updateIsLoading(false, null);
fragmentDetails.clear(); fragmentDetails.clear();
fragmentDetails.setCurrentServerSettings(server); fragmentDetails.setCurrentServerSettings(server);
@ -586,7 +586,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
// Remember that the user last selected this // Remember that the user last selected this
applicationSettings.setLastUsedNavigationFilter(currentFilter); applicationSettings.setLastUsedNavigationFilter(currentFilter);
// Clear the details view // Clear the details view
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isResumed()) {
fragmentDetails.updateIsLoading(false, null); fragmentDetails.updateIsLoading(false, null);
fragmentDetails.clear(); 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 * @param hasServerSettings Whether there are server settings available, so we can continue to connect
*/ */
private void updateFragmentVisibility(boolean hasServerSettings) { private void updateFragmentVisibility(boolean hasServerSettings) {
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isResumed()) {
if (hasServerSettings) { if (hasServerSettings) {
getFragmentManager().beginTransaction().show(fragmentDetails).commit(); getFragmentManager().beginTransaction().show(fragmentDetails).commit();
} else { } else {
@ -905,7 +905,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
* @param torrent The torrent to show detailed statistics for * @param torrent The torrent to show detailed statistics for
*/ */
public void openDetails(Torrent torrent) { public void openDetails(Torrent torrent) {
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isResumed()) {
fragmentDetails.updateTorrent(torrent); fragmentDetails.updateTorrent(torrent);
} else { } else {
DetailsActivity_.intent(this).torrent(torrent).currentLabels(lastNavigationLabels).startForResult(RESULT_DETAILS); DetailsActivity_.intent(this).torrent(torrent).currentLabels(lastNavigationLabels).startForResult(RESULT_DETAILS);
@ -1296,7 +1296,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
fragmentTorrents.updateIsLoading(false); fragmentTorrents.updateIsLoading(false);
if (isCritical) { if (isCritical) {
fragmentTorrents.updateError(error); fragmentTorrents.updateError(error);
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isResumed()) {
fragmentDetails.updateIsLoading(false, error); fragmentDetails.updateIsLoading(false, error);
} }
} }
@ -1312,13 +1312,13 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
fragmentTorrents.updateTorrents(new ArrayList<>(torrents), lastNavigationLabels); fragmentTorrents.updateTorrents(new ArrayList<>(torrents), lastNavigationLabels);
// Update the details fragment if the currently shown torrent is in the newly retrieved list // 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); fragmentDetails.perhapsUpdateTorrent(torrents);
} }
// Update local list of labels in the navigation // Update local list of labels in the navigation
navigationListAdapter.updateLabels(lastNavigationLabels); navigationListAdapter.updateLabels(lastNavigationLabels);
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isResumed()) {
fragmentDetails.updateLabels(lastNavigationLabels); fragmentDetails.updateLabels(lastNavigationLabels);
} }
@ -1347,7 +1347,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@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
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isResumed()) {
fragmentDetails.updateTorrentDetails(torrent, torrentDetails); fragmentDetails.updateTorrentDetails(torrent, torrentDetails);
} }
} }
@ -1355,7 +1355,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@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
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isResumed()) {
fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles));
} }
} }

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

@ -74,8 +74,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
protected ApplicationSettings applicationSettings; protected ApplicationSettings applicationSettings;
@Bean @Bean
protected SystemSettings systemSettings; protected SystemSettings systemSettings;
@InstanceState // HACK Working around #391 while hopefully we rework the UI in the future to persist the list in db or something
protected ArrayList<Torrent> torrents = null; protected static ArrayList<Torrent> torrents = null;
@InstanceState @InstanceState
protected ArrayList<Torrent> lastMultiSelectedTorrents; protected ArrayList<Torrent> lastMultiSelectedTorrents;
@InstanceState @InstanceState
@ -144,7 +144,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param newTorrents The new, updated list of torrents * @param newTorrents The new, updated list of torrents
*/ */
public void updateTorrents(ArrayList<Torrent> newTorrents, ArrayList<Label> currentLabels) { public void updateTorrents(ArrayList<Torrent> newTorrents, ArrayList<Label> currentLabels) {
this.torrents = newTorrents; if (!isResumed()) return;
torrents = newTorrents;
this.currentLabels = currentLabels; this.currentLabels = currentLabels;
applyAllFilters(); applyAllFilters();
} }
@ -155,8 +156,9 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param wasRemoved Whether the affected torrent was indeed removed; otherwise it was updated somehow * @param wasRemoved Whether the affected torrent was indeed removed; otherwise it was updated somehow
*/ */
public void quickUpdateTorrent(Torrent affected, boolean wasRemoved) { public void quickUpdateTorrent(Torrent affected, boolean wasRemoved) {
if (!isResumed()) return;
// Remove the old torrent object first // Remove the old torrent object first
Iterator<Torrent> iter = this.torrents.iterator(); Iterator<Torrent> iter = torrents.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Torrent torrent = iter.next(); Torrent torrent = iter.next();
if (torrent.getUniqueID().equals(affected.getUniqueID())) { if (torrent.getUniqueID().equals(affected.getUniqueID())) {
@ -166,7 +168,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
} }
// In case it was an update, add the updated torrent object // In case it was an update, add the updated torrent object
if (!wasRemoved) { if (!wasRemoved) {
this.torrents.add(affected); torrents.add(affected);
} }
// Now refresh the screen // Now refresh the screen
applyAllFilters(); applyAllFilters();
@ -178,7 +180,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param clearFilter Also clear any selected filter * @param clearFilter Also clear any selected filter
*/ */
public void clear(boolean clearError, boolean clearFilter) { public void clear(boolean clearError, boolean clearFilter) {
this.torrents = null; torrents = null;
if (clearError) { if (clearError) {
this.connectionErrorMessage = null; this.connectionErrorMessage = null;
} }
@ -420,6 +422,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param hasAConnection True if the user has servers configured and therefore has a connection that can be used * @param hasAConnection True if the user has servers configured and therefore has a connection that can be used
*/ */
public void updateConnectionStatus(boolean hasAConnection, Daemon daemonType) { public void updateConnectionStatus(boolean hasAConnection, Daemon daemonType) {
if (!isResumed()) return;
this.hasAConnection = hasAConnection; this.hasAConnection = hasAConnection;
this.daemonType = daemonType; this.daemonType = daemonType;
if (!hasAConnection) { if (!hasAConnection) {
@ -440,6 +443,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param isLoading True if the list of torrents is (re)loading, false otherwise * @param isLoading True if the list of torrents is (re)loading, false otherwise
*/ */
public void updateIsLoading(boolean isLoading) { public void updateIsLoading(boolean isLoading) {
if (!isResumed()) return;
this.isLoading = isLoading; this.isLoading = isLoading;
if (isLoading) { if (isLoading) {
clear(true, false); // Indirectly also calls updateViewVisibility() clear(true, false); // Indirectly also calls updateViewVisibility()
@ -453,6 +457,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param connectionErrorMessage The error message from the last failed connection attempt, or null to clear the visible error text * @param connectionErrorMessage The error message from the last failed connection attempt, or null to clear the visible error text
*/ */
public void updateError(String connectionErrorMessage) { public void updateError(String connectionErrorMessage) {
if (!isResumed()) return;
this.connectionErrorMessage = connectionErrorMessage; this.connectionErrorMessage = connectionErrorMessage;
errorText.setText(connectionErrorMessage); errorText.setText(connectionErrorMessage);
if (connectionErrorMessage != null) { if (connectionErrorMessage != null) {

2
app/src/main/java/org/transdroid/daemon/DummyAdapter.java

@ -80,7 +80,7 @@ public class DummyAdapter implements IDaemonAdapter {
TorrentStatus.Paused, TorrentStatus.Queued, TorrentStatus.Downloading, TorrentStatus.Seeding, TorrentStatus.Paused, TorrentStatus.Queued, TorrentStatus.Downloading, TorrentStatus.Seeding,
TorrentStatus.Error }; TorrentStatus.Error };
Random random = new Random(); Random random = new Random();
for (int i = 1; i < 26; i++) { for (int i = 1; i < 2026; i++) {
String name = names[i % names.length] + Integer.toString(i); String name = names[i % names.length] + Integer.toString(i);
TorrentStatus status = statuses[i % statuses.length]; TorrentStatus status = statuses[i % statuses.length];
int peersGetting = status == TorrentStatus.Downloading ? i * random.nextInt(16) : 0; int peersGetting = status == TorrentStatus.Downloading ? i * random.nextInt(16) : 0;

2
app/src/main/res/values/changelog.xml

@ -18,6 +18,8 @@
<resources> <resources>
<string name="system_changelog"> <string name="system_changelog">
Transdroid 2.5.15\n Transdroid 2.5.15\n
- Hacky fix to prevent crashes on > 1000 torrents\n
- Fix crashes during background or config changes\n
- Removed donate link in Transdrone\n - Removed donate link in Transdrone\n
\n \n
Transdroid 2.5.14\n Transdroid 2.5.14\n

Loading…
Cancel
Save