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. 42
      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 @@ @@ -123,6 +123,7 @@
<string name="result_started_all">Torrents started (refreshing)</string>
<string name="result_trackersupdated">Trackers updated</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_priotitiesset">File priorities updated</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 @@ -337,7 +337,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// Clear the currently shown list of torrents and perhaps the details
fragmentTorrents.clear(true);
fragmentTorrents.clear(true, true);
if (fragmentDetails != null && fragmentDetails.getActivity() != null) {
fragmentDetails.clear();
}
@ -821,7 +821,10 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -821,7 +821,10 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel)
.execute();
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 {
onCommunicationError((DaemonTaskFailureResult) result, false);
}
@ -892,9 +895,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -892,9 +895,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@UiThread
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
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
if (fragmentDetails != null) {
@ -902,8 +908,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -902,8 +908,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
// Update local list of labels in the navigation
lastNavigationLabels = Label.convertToNavigationLabels(labels,
getResources().getString(R.string.labels_unlabeled));
if (navigationListAdapter != null) {
// Labels are shown in the dedicated side navigation
navigationListAdapter.updateLabels(lastNavigationLabels);

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

@ -3,7 +3,6 @@ package org.transdroid.core.gui; @@ -3,7 +3,6 @@ package org.transdroid.core.gui;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.androidannotations.annotations.AfterViews;
@ -16,8 +15,11 @@ import org.transdroid.core.R; @@ -16,8 +15,11 @@ import org.transdroid.core.R;
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.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter;
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.Torrent;
import org.transdroid.daemon.TorrentsComparator;
@ -41,7 +43,7 @@ import com.actionbarsherlock.view.SherlockListView.MultiChoiceModeListenerCompat @@ -41,7 +43,7 @@ import com.actionbarsherlock.view.SherlockListView.MultiChoiceModeListenerCompat
* @author Eric Kok
*/
@EFragment(resName = "fragment_torrents")
public class TorrentsFragment extends SherlockFragment {
public class TorrentsFragment extends SherlockFragment implements OnLabelPickedListener {
// Local data
@Bean
@ -49,6 +51,10 @@ public class TorrentsFragment extends SherlockFragment { @@ -49,6 +51,10 @@ public class TorrentsFragment extends SherlockFragment {
@InstanceState
protected ArrayList<Torrent> torrents = null;
@InstanceState
protected ArrayList<Torrent> lastMultiSelectedTorrents;
@InstanceState
protected ArrayList<Label> currentLabels;
@InstanceState
protected NavigationFilter currentNavigationFilter = null;
@InstanceState
protected TorrentsSortBy currentSortOrder = TorrentsSortBy.Alphanumeric;
@ -87,7 +93,7 @@ public class TorrentsFragment extends SherlockFragment { @@ -87,7 +93,7 @@ public class TorrentsFragment extends SherlockFragment {
torrentsList.setMultiChoiceModeListener(onTorrentsSelected);
torrentsList.setFastScrollEnabled(true);
if (torrents != null)
updateTorrents(torrents);
updateTorrents(torrents, currentLabels);
}
@ -95,21 +101,24 @@ public class TorrentsFragment extends SherlockFragment { @@ -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
* @param newTorrents The new, updated list of torrents
*/
public void updateTorrents(ArrayList<Torrent> newTorrents) {
torrents = newTorrents;
applyNavigationFilter(null); // Resets the filter and shown list of torrents
public void updateTorrents(ArrayList<Torrent> newTorrents, ArrayList<Label> currentLabels) {
this.torrents = newTorrents;
this.currentLabels = currentLabels;
applyAllFilters();
}
/**
* Clears the currently visible list of torrents.
* @param b
*/
public void clear(boolean clearError) {
public void clear(boolean clearError, boolean clearFilter) {
this.torrents = null;
if (clearError)
this.connectionErrorMessage = null;
if (clearFilter) {
this.currentTextFilter = null;
this.currentNavigationFilter = null;
}
applyAllFilters();
}
@ -203,7 +212,7 @@ public class TorrentsFragment extends SherlockFragment { @@ -203,7 +212,7 @@ public class TorrentsFragment extends SherlockFragment {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Get checked torrents
List<Torrent> checked = new ArrayList<Torrent>();
ArrayList<Torrent> checked = new ArrayList<Torrent>();
for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) {
if (torrentsList.getCheckedItemPositions().valueAt(i))
checked.add((Torrent) torrentsList.getAdapter().getItem(
@ -236,7 +245,9 @@ public class TorrentsFragment extends SherlockFragment { @@ -236,7 +245,9 @@ public class TorrentsFragment extends SherlockFragment {
mode.finish();
return true;
} 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();
return true;
} else {
@ -261,6 +272,13 @@ public class TorrentsFragment extends SherlockFragment { @@ -261,6 +272,13 @@ public class TorrentsFragment extends SherlockFragment {
((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
* 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 { @@ -269,7 +287,7 @@ public class TorrentsFragment extends SherlockFragment {
public void updateConnectionStatus(boolean hasAConnection) {
this.hasAConnection = hasAConnection;
if (!hasAConnection) {
clear(true); // Indirectly also calls updateViewVisibility()
clear(true, true); // Indirectly also calls updateViewVisibility()
} else {
updateViewVisibility();
}
@ -283,7 +301,7 @@ public class TorrentsFragment extends SherlockFragment { @@ -283,7 +301,7 @@ public class TorrentsFragment extends SherlockFragment {
public void updateIsLoading(boolean isLoading) {
this.isLoading = isLoading;
if (isLoading) {
clear(true); // Indirectly also calls updateViewVisibility()
clear(true, false); // Indirectly also calls updateViewVisibility()
} else {
updateViewVisibility();
}
@ -299,7 +317,7 @@ public class TorrentsFragment extends SherlockFragment { @@ -299,7 +317,7 @@ public class TorrentsFragment extends SherlockFragment {
this.connectionErrorMessage = connectionErrorMessage;
errorText.setText(connectionErrorMessage);
if (connectionErrorMessage != null) {
clear(false); // Indirectly also calls updateViewVisibility()
clear(false, false); // Indirectly also calls updateViewVisibility()
} else {
updateViewVisibility();
}

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package org.transdroid.core.gui.navigation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.transdroid.core.gui.lists.SimpleListItem;
@ -14,7 +15,7 @@ import android.text.TextUtils; @@ -14,7 +15,7 @@ import android.text.TextUtils;
* Represents some label that is active or available on the server.
* @author Eric Kok
*/
public class Label implements SimpleListItem, NavigationFilter {
public class Label implements SimpleListItem, NavigationFilter, Comparable<Label> {
private static String unnamedLabelText = null;
@ -45,6 +46,11 @@ public class Label implements SimpleListItem, NavigationFilter { @@ -45,6 +46,11 @@ public class Label implements SimpleListItem, NavigationFilter {
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
* navigation filters.
@ -61,6 +67,7 @@ public class Label implements SimpleListItem, NavigationFilter { @@ -61,6 +67,7 @@ public class Label implements SimpleListItem, NavigationFilter {
for (org.transdroid.daemon.Label label : daemonLabels) {
localLabels.add(new Label(label));
}
Collections.sort(localLabels);
return localLabels;
}

Loading…
Cancel
Save