Browse Source

Allow batch updating of labels in main screen and properly remember the current filter (screen type) there.

pull/11/head
Eric Kok 11 years ago
parent
commit
302f88489b
  1. 1
      core/res/values/strings.xml
  2. 14
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  3. 46
      core/src/org/transdroid/core/gui/TorrentsFragment.java
  4. 9
      core/src/org/transdroid/core/gui/navigation/Label.java

1
core/res/values/strings.xml

@ -123,6 +123,7 @@
<string name="result_started_all">Torrents started (refreshing)</string> <string name="result_started_all">Torrents started (refreshing)</string>
<string name="result_trackersupdated">Trackers updated</string> <string name="result_trackersupdated">Trackers updated</string>
<string name="result_labelset">Label set to \'%1$s\'</string> <string name="result_labelset">Label set to \'%1$s\'</string>
<string name="result_labelremoved">Label removed</string>
<string name="result_locationset">Torrent moved to \'%1$s\'</string> <string name="result_locationset">Torrent moved to \'%1$s\'</string>
<string name="result_priotitiesset">File priorities updated</string> <string name="result_priotitiesset">File priorities updated</string>
<string name="result_maxspeedsset">Maximum transfer speeds set</string> <string name="result_maxspeedsset">Maximum transfer speeds set</string>

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

@ -337,7 +337,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
navigationSpinnerAdapter.updateCurrentFilter(currentFilter); navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// 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); fragmentTorrents.clear(true, true);
if (fragmentDetails != null && fragmentDetails.getActivity() != null) { if (fragmentDetails != null && fragmentDetails.getActivity() != null) {
fragmentDetails.clear(); fragmentDetails.clear();
} }
@ -821,7 +821,10 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel) DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel)
.execute(); .execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel)); onTaskSucceeded(
(DaemonTaskSuccessResult) result,
newLabel == null ? getString(R.string.result_labelremoved) : getString(R.string.result_labelset,
newLabel));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -892,9 +895,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@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) {
lastNavigationLabels = Label.convertToNavigationLabels(labels,
getResources().getString(R.string.labels_unlabeled));
// Report the newly retrieved list of torrents to the torrents fragment // Report the newly retrieved list of torrents to the torrents fragment
fragmentTorrents.updateIsLoading(false); fragmentTorrents.updateIsLoading(false);
fragmentTorrents.updateTorrents(new ArrayList<Torrent>(torrents)); fragmentTorrents.updateTorrents(new ArrayList<Torrent>(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) { if (fragmentDetails != null) {
@ -902,8 +908,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} }
// Update local list of labels in the navigation // Update local list of labels in the navigation
lastNavigationLabels = Label.convertToNavigationLabels(labels,
getResources().getString(R.string.labels_unlabeled));
if (navigationListAdapter != null) { if (navigationListAdapter != null) {
// Labels are shown in the dedicated side navigation // Labels are shown in the dedicated side navigation
navigationListAdapter.updateLabels(lastNavigationLabels); navigationListAdapter.updateLabels(lastNavigationLabels);

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

@ -3,7 +3,6 @@ package org.transdroid.core.gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.AfterViews;
@ -16,8 +15,11 @@ import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.gui.lists.TorrentsAdapter; import org.transdroid.core.gui.lists.TorrentsAdapter;
import org.transdroid.core.gui.lists.TorrentsAdapter_; import org.transdroid.core.gui.lists.TorrentsAdapter_;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter; import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.SelectionManagerMode; import org.transdroid.core.gui.navigation.SelectionManagerMode;
import org.transdroid.core.gui.navigation.SetLabelDialog;
import org.transdroid.core.gui.navigation.SetLabelDialog.OnLabelPickedListener;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentsComparator; import org.transdroid.daemon.TorrentsComparator;
@ -41,7 +43,7 @@ import com.actionbarsherlock.view.SherlockListView.MultiChoiceModeListenerCompat
* @author Eric Kok * @author Eric Kok
*/ */
@EFragment(resName = "fragment_torrents") @EFragment(resName = "fragment_torrents")
public class TorrentsFragment extends SherlockFragment { public class TorrentsFragment extends SherlockFragment implements OnLabelPickedListener {
// Local data // Local data
@Bean @Bean
@ -49,6 +51,10 @@ public class TorrentsFragment extends SherlockFragment {
@InstanceState @InstanceState
protected ArrayList<Torrent> torrents = null; protected ArrayList<Torrent> torrents = null;
@InstanceState @InstanceState
protected ArrayList<Torrent> lastMultiSelectedTorrents;
@InstanceState
protected ArrayList<Label> currentLabels;
@InstanceState
protected NavigationFilter currentNavigationFilter = null; protected NavigationFilter currentNavigationFilter = null;
@InstanceState @InstanceState
protected TorrentsSortBy currentSortOrder = TorrentsSortBy.Alphanumeric; protected TorrentsSortBy currentSortOrder = TorrentsSortBy.Alphanumeric;
@ -87,7 +93,7 @@ public class TorrentsFragment extends SherlockFragment {
torrentsList.setMultiChoiceModeListener(onTorrentsSelected); torrentsList.setMultiChoiceModeListener(onTorrentsSelected);
torrentsList.setFastScrollEnabled(true); torrentsList.setFastScrollEnabled(true);
if (torrents != null) if (torrents != null)
updateTorrents(torrents); updateTorrents(torrents, currentLabels);
} }
@ -95,21 +101,24 @@ public class TorrentsFragment extends SherlockFragment {
* Updates the list adapter to show a new list of torrent objects, replacing the old torrents completely * Updates the list adapter to show a new list of torrent objects, replacing the old torrents completely
* @param newTorrents The new, updated list of torrents * @param newTorrents The new, updated list of torrents
*/ */
public void updateTorrents(ArrayList<Torrent> newTorrents) { public void updateTorrents(ArrayList<Torrent> newTorrents, ArrayList<Label> currentLabels) {
torrents = newTorrents; this.torrents = newTorrents;
applyNavigationFilter(null); // Resets the filter and shown list of torrents this.currentLabels = currentLabels;
applyAllFilters();
} }
/** /**
* Clears the currently visible list of torrents. * Clears the currently visible list of torrents.
* @param b * @param b
*/ */
public void clear(boolean clearError) { public void clear(boolean clearError, boolean clearFilter) {
this.torrents = null; this.torrents = null;
if (clearError) if (clearError)
this.connectionErrorMessage = null; this.connectionErrorMessage = null;
this.currentTextFilter = null; if (clearFilter) {
this.currentNavigationFilter = null; this.currentTextFilter = null;
this.currentNavigationFilter = null;
}
applyAllFilters(); applyAllFilters();
} }
@ -203,7 +212,7 @@ public class TorrentsFragment extends SherlockFragment {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Get checked torrents // Get checked torrents
List<Torrent> checked = new ArrayList<Torrent>(); ArrayList<Torrent> checked = new ArrayList<Torrent>();
for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) { for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) {
if (torrentsList.getCheckedItemPositions().valueAt(i)) if (torrentsList.getCheckedItemPositions().valueAt(i))
checked.add((Torrent) torrentsList.getAdapter().getItem( checked.add((Torrent) torrentsList.getAdapter().getItem(
@ -236,7 +245,9 @@ public class TorrentsFragment extends SherlockFragment {
mode.finish(); mode.finish();
return true; return true;
} else if (itemId == R.id.action_setlabel) { } else if (itemId == R.id.action_setlabel) {
// TODO: Open label selection dialogue lastMultiSelectedTorrents = checked;
new SetLabelDialog().setOnLabelPickedListener(TorrentsFragment.this).setCurrentLabels(currentLabels)
.show(getFragmentManager(), "SetLabelDialog");
mode.finish(); mode.finish();
return true; return true;
} else { } else {
@ -261,6 +272,13 @@ public class TorrentsFragment extends SherlockFragment {
((TorrentsActivity) getActivity()).openDetails(torrent); ((TorrentsActivity) getActivity()).openDetails(torrent);
} }
@Override
public void onLabelPicked(String newLabel) {
for (Torrent torrent : lastMultiSelectedTorrents) {
getTasksExecutor().updateLabel(torrent, newLabel);
}
}
/** /**
* Updates the shown screen depending on whether we have a connection (so torrents can be shown) or not (in case we * Updates the shown screen depending on whether we have a connection (so torrents can be shown) or not (in case we
* need to show a message suggesting help). This should only ever be called on the UI thread. * need to show a message suggesting help). This should only ever be called on the UI thread.
@ -269,7 +287,7 @@ public class TorrentsFragment extends SherlockFragment {
public void updateConnectionStatus(boolean hasAConnection) { public void updateConnectionStatus(boolean hasAConnection) {
this.hasAConnection = hasAConnection; this.hasAConnection = hasAConnection;
if (!hasAConnection) { if (!hasAConnection) {
clear(true); // Indirectly also calls updateViewVisibility() clear(true, true); // Indirectly also calls updateViewVisibility()
} else { } else {
updateViewVisibility(); updateViewVisibility();
} }
@ -283,7 +301,7 @@ public class TorrentsFragment extends SherlockFragment {
public void updateIsLoading(boolean isLoading) { public void updateIsLoading(boolean isLoading) {
this.isLoading = isLoading; this.isLoading = isLoading;
if (isLoading) { if (isLoading) {
clear(true); // Indirectly also calls updateViewVisibility() clear(true, false); // Indirectly also calls updateViewVisibility()
} else { } else {
updateViewVisibility(); updateViewVisibility();
} }
@ -299,7 +317,7 @@ public class TorrentsFragment extends SherlockFragment {
this.connectionErrorMessage = connectionErrorMessage; this.connectionErrorMessage = connectionErrorMessage;
errorText.setText(connectionErrorMessage); errorText.setText(connectionErrorMessage);
if (connectionErrorMessage != null) { if (connectionErrorMessage != null) {
clear(false); // Indirectly also calls updateViewVisibility() clear(false, false); // Indirectly also calls updateViewVisibility()
} else { } else {
updateViewVisibility(); updateViewVisibility();
} }

9
core/src/org/transdroid/core/gui/navigation/Label.java

@ -1,6 +1,7 @@
package org.transdroid.core.gui.navigation; package org.transdroid.core.gui.navigation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.SimpleListItem;
@ -14,7 +15,7 @@ import android.text.TextUtils;
* Represents some label that is active or available on the server. * Represents some label that is active or available on the server.
* @author Eric Kok * @author Eric Kok
*/ */
public class Label implements SimpleListItem, NavigationFilter { public class Label implements SimpleListItem, NavigationFilter, Comparable<Label> {
private static String unnamedLabelText = null; private static String unnamedLabelText = null;
@ -45,6 +46,11 @@ public class Label implements SimpleListItem, NavigationFilter {
return torrent.getLabelName() != null && torrent.getLabelName().equals(name); return torrent.getLabelName() != null && torrent.getLabelName().equals(name);
} }
@Override
public int compareTo(Label another) {
return this.name.compareTo(another.getName());
}
/** /**
* Converts a list of labels as retrieved from a server daemon into a list of labels that can be used in the UI as * Converts a list of labels as retrieved from a server daemon into a list of labels that can be used in the UI as
* navigation filters. * navigation filters.
@ -61,6 +67,7 @@ public class Label implements SimpleListItem, NavigationFilter {
for (org.transdroid.daemon.Label label : daemonLabels) { for (org.transdroid.daemon.Label label : daemonLabels) {
localLabels.add(new Label(label)); localLabels.add(new Label(label));
} }
Collections.sort(localLabels);
return localLabels; return localLabels;
} }

Loading…
Cancel
Save