From 65e28f5638caa61340616181ff95fcf6458746c4 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Sat, 27 Jul 2013 10:36:32 +0200 Subject: [PATCH] Added editing of trackers from torrent details view. --- core/res/values/strings.xml | 1 + .../transdroid/core/gui/DetailsFragment.java | 16 ++++++++++---- .../transdroid/core/gui/ServerStatusView.java | 2 +- .../navigation/SetTransferRatesDialog.java | 22 ++++++++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index a3f4749d..2b20b978 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -99,6 +99,7 @@ MAX UPLOAD KB/S Reset + Update All labels Unlabeled diff --git a/core/src/org/transdroid/core/gui/DetailsFragment.java b/core/src/org/transdroid/core/gui/DetailsFragment.java index 1a90570f..93db8e9a 100644 --- a/core/src/org/transdroid/core/gui/DetailsFragment.java +++ b/core/src/org/transdroid/core/gui/DetailsFragment.java @@ -18,6 +18,8 @@ import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.NavigationHelper_; import org.transdroid.core.gui.navigation.SelectionManagerMode; +import org.transdroid.core.gui.navigation.SetTrackersDialog; +import org.transdroid.core.gui.navigation.SetTrackersDialog.OnTrackersUpdatedListener; import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Priority; import org.transdroid.daemon.Torrent; @@ -45,7 +47,7 @@ import de.keyboardsurfer.android.widget.crouton.Crouton; */ @EFragment(resName = "fragment_details") @OptionsMenu(resName = "fragment_details") -public class DetailsFragment extends SherlockFragment { +public class DetailsFragment extends SherlockFragment implements OnTrackersUpdatedListener { // Local data @InstanceState @@ -78,7 +80,7 @@ public class DetailsFragment extends SherlockFragment { detailsList.setBackgroundResource(R.drawable.details_list_background_light); } } - + // Set up details adapter (itself containing the actual lists to show), which allows multi-select and fast // scrolling detailsList.setAdapter(new DetailsAdapter(getActivity())); @@ -256,13 +258,19 @@ public class DetailsFragment extends SherlockFragment { @OptionsItem(resName = "action_updatetrackers") protected void updateTrackers() { - // TODO: Show trackers edit dialog + new SetTrackersDialog().setOnTrackersUpdated(this).setCurrentTrackers(torrentDetails.getTrackersText()) + .show(getActivity().getSupportFragmentManager(), "SetTrackersDialog"); + } + + @Override + public void onTrackersUpdated(List updatedTrackers) { + getTasksExecutor().updateTrackers(torrent, updatedTrackers); } private MultiChoiceModeListenerCompat onDetailsSelected = new MultiChoiceModeListenerCompat() { SelectionManagerMode selectionManagerMode; - + @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Show contextual action bar to start/stop/remove/etc. torrents in batch mode diff --git a/core/src/org/transdroid/core/gui/ServerStatusView.java b/core/src/org/transdroid/core/gui/ServerStatusView.java index b74cb42e..35c10525 100644 --- a/core/src/org/transdroid/core/gui/ServerStatusView.java +++ b/core/src/org/transdroid/core/gui/ServerStatusView.java @@ -87,7 +87,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis private OnClickListener onStartDownPickerClicked = new OnClickListener() { public void onClick(View v) { - new SetTransferRatesDialog().setOnRatesPicked(ServerStatusView.this).show( + new SetTransferRatesDialog().setOnRatesPickedListener(ServerStatusView.this).show( activity.getSupportFragmentManager(), "SetTransferRatesDialog"); } }; diff --git a/core/src/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java b/core/src/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java index e96f7912..d129deb2 100644 --- a/core/src/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java +++ b/core/src/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java @@ -1,8 +1,9 @@ package org.transdroid.core.gui.navigation; +import java.security.InvalidParameterException; + import org.transdroid.core.R; -import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; @@ -20,7 +21,7 @@ import android.widget.TextView; */ public class SetTransferRatesDialog extends DialogFragment { - private OnRatesPickedListener onRatesPicked; + private OnRatesPickedListener onRatesPickedListener = null; private TextView maxSpeedDown, maxSpeedUp; public SetTransferRatesDialog() { @@ -29,16 +30,19 @@ public class SetTransferRatesDialog extends DialogFragment { /** * Sets the callback for results in this dialog (with newly selected values or a reset). - * @param onRatesPicked The event listener to this dialog + * @param onRatesPickedListener The event listener to this dialog * @return This dialog, for method chaining */ - public SetTransferRatesDialog setOnRatesPicked(OnRatesPickedListener onRatesPicked) { - this.onRatesPicked = onRatesPicked; + public SetTransferRatesDialog setOnRatesPickedListener(OnRatesPickedListener onRatesPickedListener) { + this.onRatesPickedListener = onRatesPickedListener; return this; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + if (onRatesPickedListener == null) + throw new InvalidParameterException( + "Please first set the callback listener using setOnRatesPickedListener before opening the dialog."); final View transferRatesContent = getActivity().getLayoutInflater().inflate(R.layout.dialog_transferrates, null, false); maxSpeedDown = (TextView) transferRatesContent.findViewById(R.id.maxspeeddown_text); @@ -59,14 +63,14 @@ public class SetTransferRatesDialog extends DialogFragment { } catch (NumberFormatException e) { } if (maxDown <= 0 || maxUp <= 0) { - onRatesPicked.onInvalidNumber(); + onRatesPickedListener.onInvalidNumber(); } - onRatesPicked.onRatesPicked(maxDown, maxUp); + onRatesPickedListener.onRatesPicked(maxDown, maxUp); } }).setNeutralButton(R.string.status_maxspeed_reset, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - onRatesPicked.resetRates(); + onRatesPickedListener.resetRates(); } }).setNegativeButton(android.R.string.cancel, null).create(); } @@ -96,7 +100,9 @@ public class SetTransferRatesDialog extends DialogFragment { */ public interface OnRatesPickedListener { public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed); + public void resetRates(); + public void onInvalidNumber(); }