Browse Source

Added editing of trackers from torrent details view.

pull/11/head
Eric Kok 11 years ago
parent
commit
65e28f5638
  1. 1
      core/res/values/strings.xml
  2. 12
      core/src/org/transdroid/core/gui/DetailsFragment.java
  3. 2
      core/src/org/transdroid/core/gui/ServerStatusView.java
  4. 22
      core/src/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java

1
core/res/values/strings.xml

@ -99,6 +99,7 @@
<string name="status_maxspeed_up">MAX UPLOAD</string> <string name="status_maxspeed_up">MAX UPLOAD</string>
<string name="status_maxspeed_unit">KB/S</string> <string name="status_maxspeed_unit">KB/S</string>
<string name="status_maxspeed_reset">Reset</string> <string name="status_maxspeed_reset">Reset</string>
<string name="status_update">Update</string>
<string name="labels_showall">All labels</string> <string name="labels_showall">All labels</string>
<string name="labels_unlabeled">Unlabeled</string> <string name="labels_unlabeled">Unlabeled</string>

12
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.NavigationHelper_; import org.transdroid.core.gui.navigation.NavigationHelper_;
import org.transdroid.core.gui.navigation.SelectionManagerMode; 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.Daemon;
import org.transdroid.daemon.Priority; import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;
@ -45,7 +47,7 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
*/ */
@EFragment(resName = "fragment_details") @EFragment(resName = "fragment_details")
@OptionsMenu(resName = "fragment_details") @OptionsMenu(resName = "fragment_details")
public class DetailsFragment extends SherlockFragment { public class DetailsFragment extends SherlockFragment implements OnTrackersUpdatedListener {
// Local data // Local data
@InstanceState @InstanceState
@ -256,7 +258,13 @@ public class DetailsFragment extends SherlockFragment {
@OptionsItem(resName = "action_updatetrackers") @OptionsItem(resName = "action_updatetrackers")
protected void 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<String> updatedTrackers) {
getTasksExecutor().updateTrackers(torrent, updatedTrackers);
} }
private MultiChoiceModeListenerCompat onDetailsSelected = new MultiChoiceModeListenerCompat() { private MultiChoiceModeListenerCompat onDetailsSelected = new MultiChoiceModeListenerCompat() {

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

@ -87,7 +87,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis
private OnClickListener onStartDownPickerClicked = new OnClickListener() { private OnClickListener onStartDownPickerClicked = new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
new SetTransferRatesDialog().setOnRatesPicked(ServerStatusView.this).show( new SetTransferRatesDialog().setOnRatesPickedListener(ServerStatusView.this).show(
activity.getSupportFragmentManager(), "SetTransferRatesDialog"); activity.getSupportFragmentManager(), "SetTransferRatesDialog");
} }
}; };

22
core/src/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java

@ -1,8 +1,9 @@
package org.transdroid.core.gui.navigation; package org.transdroid.core.gui.navigation;
import java.security.InvalidParameterException;
import org.transdroid.core.R; import org.transdroid.core.R;
import android.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -20,7 +21,7 @@ import android.widget.TextView;
*/ */
public class SetTransferRatesDialog extends DialogFragment { public class SetTransferRatesDialog extends DialogFragment {
private OnRatesPickedListener onRatesPicked; private OnRatesPickedListener onRatesPickedListener = null;
private TextView maxSpeedDown, maxSpeedUp; private TextView maxSpeedDown, maxSpeedUp;
public SetTransferRatesDialog() { 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). * 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 * @return This dialog, for method chaining
*/ */
public SetTransferRatesDialog setOnRatesPicked(OnRatesPickedListener onRatesPicked) { public SetTransferRatesDialog setOnRatesPickedListener(OnRatesPickedListener onRatesPickedListener) {
this.onRatesPicked = onRatesPicked; this.onRatesPickedListener = onRatesPickedListener;
return this; return this;
} }
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { 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, final View transferRatesContent = getActivity().getLayoutInflater().inflate(R.layout.dialog_transferrates,
null, false); null, false);
maxSpeedDown = (TextView) transferRatesContent.findViewById(R.id.maxspeeddown_text); maxSpeedDown = (TextView) transferRatesContent.findViewById(R.id.maxspeeddown_text);
@ -59,14 +63,14 @@ public class SetTransferRatesDialog extends DialogFragment {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
if (maxDown <= 0 || maxUp <= 0) { 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() { }).setNeutralButton(R.string.status_maxspeed_reset, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
onRatesPicked.resetRates(); onRatesPickedListener.resetRates();
} }
}).setNegativeButton(android.R.string.cancel, null).create(); }).setNegativeButton(android.R.string.cancel, null).create();
} }
@ -96,7 +100,9 @@ public class SetTransferRatesDialog extends DialogFragment {
*/ */
public interface OnRatesPickedListener { public interface OnRatesPickedListener {
public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed); public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed);
public void resetRates(); public void resetRates();
public void onInvalidNumber(); public void onInvalidNumber();
} }

Loading…
Cancel
Save