Browse Source

Correct loading of details fragment (and stats and files) into phone and tablet fragments.

pull/11/head
Eric Kok 11 years ago
parent
commit
490ebbe828
  1. 36
      core/src/org/transdroid/core/gui/DetailsActivity.java
  2. 30
      core/src/org/transdroid/core/gui/DetailsFragment.java
  3. 2
      core/src/org/transdroid/core/gui/TorrentTasksExecutor.java
  4. 105
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  5. 2
      core/src/org/transdroid/core/gui/TorrentsFragment.java
  6. 6
      core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java

36
core/src/org/transdroid/core/gui/DetailsActivity.java

@ -88,8 +88,6 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -88,8 +88,6 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
// Show details and load fine stats and torrent files
fragmentDetails.updateTorrent(torrent);
refreshTorrentDetails();
refreshTorrentFiles();
}
@ -103,8 +101,6 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -103,8 +101,6 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
protected void refreshScreen() {
fragmentDetails.updateIsLoading(true);
refreshTorrent();
refreshTorrentDetails();
refreshTorrentFiles();
}
@Background
@ -119,24 +115,24 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -119,24 +115,24 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
}
@Background
protected void refreshTorrentDetails() {
public void refreshTorrentDetails(Torrent torrent) {
if (!Daemon.supportsFineDetails(torrent.getDaemon()))
return;
DaemonTaskResult result = GetTorrentDetailsTask.create(currentConnection, torrent).execute();
if (result instanceof GetTorrentDetailsTaskSuccessResult) {
onTorrentDetailsRetrieved(((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails());
onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails());
} else {
onCommunicationError((DaemonTaskFailureResult) result);
}
}
@Background
protected void refreshTorrentFiles() {
public void refreshTorrentFiles(Torrent torrent) {
if (!Daemon.supportsFileListing(torrent.getDaemon()))
return;
DaemonTaskResult result = GetFileListTask.create(currentConnection, torrent).execute();
if (result instanceof GetFileListTaskSuccessResult) {
onTorrentFilesRetrieved(((GetFileListTaskSuccessResult) result).getFiles());
onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles());
} else {
onCommunicationError((DaemonTaskFailureResult) result);
}
@ -242,6 +238,18 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -242,6 +238,18 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
navigationHelper.CROUTON_INFO_STYLE);
}
@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);
}
@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<TorrentFile>(torrentFiles));
}
@UiThread
protected void onCommunicationError(DaemonTaskFailureResult result) {
Log.i(this, result.getException().toString());
@ -257,16 +265,4 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -257,16 +265,4 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
fragmentDetails.perhapsUpdateTorrent(torrents);
}
@UiThread
protected void onTorrentDetailsRetrieved(TorrentDetails torrentDetails) {
// Update the details fragment with the new fine details for the shown torrent
fragmentDetails.updateTorrentDetails(torrentDetails);
}
@UiThread
protected void onTorrentFilesRetrieved(List<TorrentFile> torrentFiles) {
// Update the details fragment with the newly retrieved list of files
fragmentDetails.updateTorrentFiles(new ArrayList<TorrentFile>(torrentFiles));
}
}

30
core/src/org/transdroid/core/gui/DetailsFragment.java

@ -59,14 +59,14 @@ public class DetailsFragment extends SherlockFragment { @@ -59,14 +59,14 @@ public class DetailsFragment extends SherlockFragment {
if (torrent != null)
updateTorrent(torrent);
if (torrentDetails != null)
updateTorrentDetails(torrentDetails);
updateTorrentDetails(torrent, torrentDetails);
if (torrentFiles != null)
updateTorrentFiles(torrentFiles);
updateTorrentFiles(torrent, torrentFiles);
}
/**
* Updates the details adapter header to show the new torrent data
* Updates the details adapter header to show the new torrent data.
* @param newTorrent The new torrent object
*/
public void updateTorrent(Torrent newTorrent) {
@ -79,13 +79,20 @@ public class DetailsFragment extends SherlockFragment { @@ -79,13 +79,20 @@ public class DetailsFragment extends SherlockFragment {
loadingProgress.setVisibility(View.GONE);
// Also update the available actions in the action bar
getActivity().supportInvalidateOptionsMenu();
// Refresh the detailed statistics (errors) and list of files
getTasksExecutor().refreshTorrentDetails(torrent);
getTasksExecutor().refreshTorrentFiles(torrent);
}
/**
* Updates the details adapter to show the list of trackers and tracker errors
* Updates the details adapter to show the list of trackers and tracker errors.
* @param checkTorrent The torrent for which the details were retrieved
* @param newTorrentDetails The new fine details object of some torrent
*/
public void updateTorrentDetails(TorrentDetails newTorrentDetails) {
public void updateTorrentDetails(Torrent checkTorrent, TorrentDetails newTorrentDetails) {
// Check if these are actually the details of the torrent we are now showing
if (!torrent.getUniqueID().equals(checkTorrent.getUniqueID()))
return;
this.torrentDetails = newTorrentDetails;
((DetailsAdapter) detailsList.getAdapter()).updateTrackers(SimpleListItemAdapter.SimpleStringItem
.wrapStringsList(newTorrentDetails.getTrackers()));
@ -94,20 +101,27 @@ public class DetailsFragment extends SherlockFragment { @@ -94,20 +101,27 @@ public class DetailsFragment extends SherlockFragment {
}
/**
* Updates the list adapter to show a new list of torrent files, replacing the old files list
* Updates the list adapter to show a new list of torrent files, replacing the old files list.
* @param checkTorrent The torrent for which the details were retrieved
* @param newTorrents The new, updated list of torrent file objects
*/
public void updateTorrentFiles(ArrayList<TorrentFile> newTorrentFiles) {
public void updateTorrentFiles(Torrent checkTorrent, ArrayList<TorrentFile> newTorrentFiles) {
// Check if these are actually the details of the torrent we are now showing
if (!torrent.getUniqueID().equals(checkTorrent.getUniqueID()))
return;
this.torrentFiles = newTorrentFiles;
((DetailsAdapter) detailsList.getAdapter()).updateTorrentFiles(newTorrentFiles);
}
/**
* Can be called if some outside activity returned new torrents, so we can perhaps piggyback on this by update our
* data as well
* data as well.
* @param torrents The last of retrieved torrents
*/
public void perhapsUpdateTorrent(List<Torrent> torrents) {
// Only try to update if we actually were showing a torrent
if (this.torrent == null || torrents == null)
return;
for (Torrent newTorrent : torrents) {
if (newTorrent.getUniqueID().equals(this.torrent.getUniqueID())) {
// Found, so we can update our data as well

2
core/src/org/transdroid/core/gui/TorrentTasksExecutor.java

@ -13,4 +13,6 @@ public interface TorrentTasksExecutor { @@ -13,4 +13,6 @@ public interface TorrentTasksExecutor {
void updateLabel(Torrent torrent, String newLabel);
void updateTrackers(Torrent torrent, List<String> newTrackers);
void updateLocation(Torrent torrent, String newLocation);
void refreshTorrentDetails(Torrent torrent);
void refreshTorrentFiles(Torrent torrent);
}

105
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -26,10 +26,6 @@ import org.transdroid.core.gui.lists.LocalTorrent; @@ -26,10 +26,6 @@ import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog;
@ -37,14 +33,20 @@ import org.transdroid.core.gui.settings.*; @@ -37,14 +33,20 @@ import org.transdroid.core.gui.settings.*;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
import org.transdroid.daemon.task.AddByFileTask;
import org.transdroid.daemon.task.AddByMagnetUrlTask;
import org.transdroid.daemon.task.AddByUrlTask;
import org.transdroid.daemon.task.DaemonTaskFailureResult;
import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult;
import org.transdroid.daemon.task.GetStatsTask;
import org.transdroid.daemon.task.GetStatsTaskSuccessResult;
import org.transdroid.daemon.task.GetTorrentDetailsTask;
import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult;
import org.transdroid.daemon.task.PauseTask;
import org.transdroid.daemon.task.RemoveTask;
import org.transdroid.daemon.task.ResumeTask;
@ -317,8 +319,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -317,8 +319,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
private void updateFragmentVisibility(boolean hasServerSettings) {
if (filtersList != null)
filtersList.setVisibility(hasServerSettings ? View.VISIBLE : View.GONE);
if (fragmentDetails != null)
getSupportFragmentManager().beginTransaction().hide(fragmentDetails).commit();
if (fragmentDetails != null) {
if (hasServerSettings)
getSupportFragmentManager().beginTransaction().show(fragmentDetails).commit();
else
getSupportFragmentManager().beginTransaction().hide(fragmentDetails).commit();
}
}
/**
@ -447,6 +453,22 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -447,6 +453,22 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/download/")));
}
/**
* Shows the a details fragment for the given torrent, either in the dedicated details fragment pane, in the same
* pane as the torrent list was displayed or by starting a details activity.
* @param torrent The torrent to show detailed statistics for
*/
public void openDetails(Torrent torrent) {
if (fragmentDetails != null) {
fragmentDetails.updateTorrent(torrent);
} else if (filtersList != null) {
getSupportFragmentManager().beginTransaction().add(R.id.torrent_list, DetailsFragment_.builder().build())
.addToBackStack(null).commit();
} else {
DetailsActivity_.intent(this).torrent(torrent).start();
}
}
@Background
protected void refreshTorrents() {
DaemonTaskResult result = RetrieveTask.create(currentConnection).execute();
@ -454,7 +476,31 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -454,7 +476,31 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(),
((RetrieveTaskSuccessResult) result).getLabels());
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, true);
}
}
@Background
public void refreshTorrentDetails(Torrent torrent) {
if (!Daemon.supportsFineDetails(currentConnection.getType()))
return;
DaemonTaskResult result = GetTorrentDetailsTask.create(currentConnection, torrent).execute();
if (result instanceof GetTorrentDetailsTaskSuccessResult) {
onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails());
} else {
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@Background
public void refreshTorrentFiles(Torrent torrent) {
if (!Daemon.supportsFileListing(currentConnection.getType()))
return;
DaemonTaskResult result = GetFileListTask.create(currentConnection, torrent).execute();
if (result instanceof GetFileListTaskSuccessResult) {
onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles());
} else {
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -464,7 +510,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -464,7 +510,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof GetStatsTaskSuccessResult) {
onTurtleModeRetrieved(((GetStatsTaskSuccessResult) result).isAlternativeModeEnabled());
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -475,7 +521,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -475,7 +521,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Success; no need to retrieve it again - just update the visual indicator
onTurtleModeRetrieved(enable);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -486,7 +532,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -486,7 +532,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, title);
refreshTorrents();
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -497,7 +543,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -497,7 +543,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, "Torrent");
refreshTorrents();
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -508,7 +554,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -508,7 +554,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, title);
refreshTorrents();
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -557,7 +603,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -557,7 +603,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_resumed);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -569,7 +615,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -569,7 +615,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_paused);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -581,7 +627,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -581,7 +627,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_started);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -593,7 +639,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -593,7 +639,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_stopped);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -605,7 +651,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -605,7 +651,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
onTaskSucceeded((DaemonTaskSuccessResult) result, withData ? R.string.result_removed_with_data
: R.string.result_removed);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -617,7 +663,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -617,7 +663,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_labelset, newLabel);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -628,7 +674,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -628,7 +674,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_trackersupdated);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -639,7 +685,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -639,7 +685,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_locationset, newLocation);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@ -650,12 +696,13 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -650,12 +696,13 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
@UiThread
protected void onCommunicationError(DaemonTaskFailureResult result) {
protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) {
Log.i(this, result.getException().toString());
String error = getString(LocalTorrent.getResourceForDaemonException(result.getException()));
Crouton.showText(this, error, navigationHelper.CROUTON_ERROR_STYLE);
fragmentTorrents.updateIsLoading(false);
fragmentTorrents.updateError(error);
if (isCritical)
fragmentTorrents.updateError(error);
}
@UiThread
@ -679,6 +726,20 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -679,6 +726,20 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
}
@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.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 != null)
fragmentDetails.updateTorrentFiles(torrent, new ArrayList<TorrentFile>(torrentFiles));
}
@UiThread
protected void onTurtleModeRetrieved(boolean turtleModeEnabled) {
turleModeEnabled = turtleModeEnabled;

2
core/src/org/transdroid/core/gui/TorrentsFragment.java

@ -169,7 +169,7 @@ public class TorrentsFragment extends SherlockFragment { @@ -169,7 +169,7 @@ public class TorrentsFragment extends SherlockFragment {
@ItemClick(resName = "torrent_list")
protected void torrentsListClicked(Torrent torrent) {
DetailsActivity_.intent(getActivity()).torrent(torrent).start();
((TorrentsActivity)getActivity()).openDetails(torrent);
}
/**

6
core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java

@ -42,7 +42,7 @@ public class FilterListAdapter extends MergeAdapter { @@ -42,7 +42,7 @@ public class FilterListAdapter extends MergeAdapter {
this.serverItems = new FilterListItemAdapter(context, servers);
addAdapter(serverItems);
} else if (this.serverItems != null && servers != null) {
serverSeparator.setVisibility(serverItems.isEmpty()? View.GONE: View.VISIBLE);
serverSeparator.setVisibility(servers.isEmpty()? View.GONE: View.VISIBLE);
this.serverItems.update(servers);
} else {
serverSeparator.setVisibility(View.GONE);
@ -63,7 +63,7 @@ public class FilterListAdapter extends MergeAdapter { @@ -63,7 +63,7 @@ public class FilterListAdapter extends MergeAdapter {
this.statusTypeItems = new FilterListItemAdapter(context, statusTypes);
addAdapter(statusTypeItems);
} else if (this.statusTypeItems != null && statusTypes != null) {
statusTypeSeparator.setVisibility(statusTypeItems.isEmpty()? View.GONE: View.VISIBLE);
statusTypeSeparator.setVisibility(statusTypes.isEmpty()? View.GONE: View.VISIBLE);
this.statusTypeItems.update(statusTypes);
} else {
statusTypeSeparator.setVisibility(View.GONE);
@ -83,7 +83,7 @@ public class FilterListAdapter extends MergeAdapter { @@ -83,7 +83,7 @@ public class FilterListAdapter extends MergeAdapter {
this.labelItems = new FilterListItemAdapter(context, labels);
addAdapter(labelItems);
} else if (this.labelItems != null && labels != null) {
labelSeperator.setVisibility(labelItems.isEmpty()? View.GONE: View.VISIBLE);
labelSeperator.setVisibility(labels.isEmpty()? View.GONE: View.VISIBLE);
this.labelItems.update(labels);
} else {
labelSeperator.setVisibility(View.GONE);

Loading…
Cancel
Save