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 @@ -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 @@ -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 @@ -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 @@ -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<TorrentFile> 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 @@ -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 @@ -357,7 +360,7 @@ 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
if (fragmentDetails.isAdded()) {
if (fragmentDetails.isResumed()) {
fragmentDetails.updateIsLoading(false, null);
fragmentDetails.perhapsUpdateTorrent(torrents);
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 @@ -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);
}

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

@ -566,7 +566,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -1355,7 +1355,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@UiThread
protected void onTorrentFilesRetrieved(Torrent torrent, List<TorrentFile> 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));
}
}

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

@ -74,8 +74,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -74,8 +74,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
protected ApplicationSettings applicationSettings;
@Bean
protected SystemSettings systemSettings;
@InstanceState
protected ArrayList<Torrent> 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<Torrent> torrents = null;
@InstanceState
protected ArrayList<Torrent> lastMultiSelectedTorrents;
@InstanceState
@ -144,7 +144,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -144,7 +144,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param newTorrents The new, updated list of torrents
*/
public void updateTorrents(ArrayList<Torrent> newTorrents, ArrayList<Label> currentLabels) {
this.torrents = newTorrents;
if (!isResumed()) return;
torrents = newTorrents;
this.currentLabels = currentLabels;
applyAllFilters();
}
@ -155,8 +156,9 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -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
*/
public void quickUpdateTorrent(Torrent affected, boolean wasRemoved) {
if (!isResumed()) return;
// Remove the old torrent object first
Iterator<Torrent> iter = this.torrents.iterator();
Iterator<Torrent> iter = torrents.iterator();
while (iter.hasNext()) {
Torrent torrent = iter.next();
if (torrent.getUniqueID().equals(affected.getUniqueID())) {
@ -166,7 +168,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -166,7 +168,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
}
// In case it was an update, add the updated torrent object
if (!wasRemoved) {
this.torrents.add(affected);
torrents.add(affected);
}
// Now refresh the screen
applyAllFilters();
@ -178,7 +180,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -178,7 +180,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param clearFilter Also clear any selected filter
*/
public void clear(boolean clearError, boolean clearFilter) {
this.torrents = null;
torrents = null;
if (clearError) {
this.connectionErrorMessage = null;
}
@ -420,6 +422,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -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
*/
public void updateConnectionStatus(boolean hasAConnection, Daemon daemonType) {
if (!isResumed()) return;
this.hasAConnection = hasAConnection;
this.daemonType = daemonType;
if (!hasAConnection) {
@ -440,6 +443,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -440,6 +443,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
* @param isLoading True if the list of torrents is (re)loading, false otherwise
*/
public void updateIsLoading(boolean isLoading) {
if (!isResumed()) return;
this.isLoading = isLoading;
if (isLoading) {
clear(true, false); // Indirectly also calls updateViewVisibility()
@ -453,6 +457,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -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
*/
public void updateError(String connectionErrorMessage) {
if (!isResumed()) return;
this.connectionErrorMessage = connectionErrorMessage;
errorText.setText(connectionErrorMessage);
if (connectionErrorMessage != null) {

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

@ -80,7 +80,7 @@ public class DummyAdapter implements IDaemonAdapter { @@ -80,7 +80,7 @@ public class DummyAdapter implements IDaemonAdapter {
TorrentStatus.Paused, TorrentStatus.Queued, TorrentStatus.Downloading, TorrentStatus.Seeding,
TorrentStatus.Error };
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);
TorrentStatus status = statuses[i % statuses.length];
int peersGetting = status == TorrentStatus.Downloading ? i * random.nextInt(16) : 0;

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

@ -18,6 +18,8 @@ @@ -18,6 +18,8 @@
<resources>
<string name="system_changelog">
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
\n
Transdroid 2.5.14\n

Loading…
Cancel
Save