From 302f88489bfad3d045436ced199923e6b50d349b Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Sat, 27 Jul 2013 15:13:59 +0200 Subject: [PATCH] Allow batch updating of labels in main screen and properly remember the current filter (screen type) there. --- core/res/values/strings.xml | 1 + .../transdroid/core/gui/TorrentsActivity.java | 14 ++++-- .../transdroid/core/gui/TorrentsFragment.java | 46 +++++++++++++------ .../transdroid/core/gui/navigation/Label.java | 9 +++- 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index f78a0f1e..bc7a0c4d 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -123,6 +123,7 @@ Torrents started (refreshing) Trackers updated Label set to \'%1$s\' + Label removed Torrent moved to \'%1$s\' File priorities updated Maximum transfer speeds set diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java index 54d2c58f..755526db 100644 --- a/core/src/org/transdroid/core/gui/TorrentsActivity.java +++ b/core/src/org/transdroid/core/gui/TorrentsActivity.java @@ -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 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 @UiThread protected void onTorrentsRetrieved(List torrents, List 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(torrents)); + fragmentTorrents.updateTorrents(new ArrayList(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 } // 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); diff --git a/core/src/org/transdroid/core/gui/TorrentsFragment.java b/core/src/org/transdroid/core/gui/TorrentsFragment.java index aa729211..3e408d62 100644 --- a/core/src/org/transdroid/core/gui/TorrentsFragment.java +++ b/core/src/org/transdroid/core/gui/TorrentsFragment.java @@ -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; 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 * @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 { @InstanceState protected ArrayList torrents = null; @InstanceState + protected ArrayList lastMultiSelectedTorrents; + @InstanceState + protected ArrayList