Browse Source

Fixes crash when adding torrent and showing the server selection dialog. Partially fixes #466.

pull/471/head
Eric Kok 6 years ago
parent
commit
62707f2d01
  1. 57
      app/src/main/java/org/transdroid/core/gui/FilterEntryDialog.java
  2. 52
      app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java

57
app/src/main/java/org/transdroid/core/gui/FilterEntryDialog.java

@ -1,57 +0,0 @@
/*
* Copyright 2010-2018 Eric Kok et al.
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.gui;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.text.InputType;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
public class FilterEntryDialog {
/**
* Opens a dialog that allows entry of a filter string, which (on confirmation) will be used to filter the list of
* torrents.
* @param activity The activity that opens (and owns) this dialog
*/
@SuppressLint("ValidFragment")
public static void startFilterEntry(final TorrentsActivity activity) {
new DialogFragment() {
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
final EditText filterInput = new EditText(activity);
filterInput.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(
InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
return new AlertDialog.Builder(activity).setView(filterInput)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String filterText = filterInput.getText().toString();
if (activity != null)
activity.filterTorrents(filterText);
}
}).setNegativeButton(android.R.string.cancel, null).create();
};
}.show(activity.getFragmentManager(), "filterentry");
}
}

52
app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java

@ -1,16 +1,47 @@
/*
* Copyright 2010-2018 Eric Kok et al.
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.gui; package org.transdroid.core.gui;
import java.util.List; import java.util.List;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.ServerSetting;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.DialogFragment;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
public class ServerPickerDialog { public class ServerPickerDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
String[] serverNames = getArguments().getStringArray("serverNames");
return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver)
.setItems(serverNames, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (getActivity() != null && getActivity() instanceof TorrentsActivity)
((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which);
}
}).create();
}
/** /**
* Opens a dialog that allows the selection of a configured server (manual or seedbox). The calling activity will * Opens a dialog that allows the selection of a configured server (manual or seedbox). The calling activity will
@ -24,18 +55,11 @@ public class ServerPickerDialog {
for (int i = 0; i < serverSettings.size(); i++) { for (int i = 0; i < serverSettings.size(); i++) {
serverNames[i] = serverSettings.get(i).getName(); serverNames[i] = serverSettings.get(i).getName();
} }
new DialogFragment() { ServerPickerDialog dialog = new ServerPickerDialog();
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { Bundle arguments = new Bundle();
return new AlertDialog.Builder(activity).setTitle(R.string.navigation_pickserver) arguments.putStringArray("serverNames", serverNames);
.setItems(serverNames, new OnClickListener() { dialog.setArguments(arguments);
@Override dialog.show(activity.getFragmentManager(), "serverpicker");
public void onClick(DialogInterface dialog, int which) {
if (activity != null)
activity.switchServerAndAddFromIntent(which);
}
}).create();
};
}.show(activity.getFragmentManager(), "serverpicker");
} }
} }

Loading…
Cancel
Save