diff --git a/app/src/main/java/org/transdroid/core/gui/FilterEntryDialog.java b/app/src/main/java/org/transdroid/core/gui/FilterEntryDialog.java deleted file mode 100644 index 3a7f81b6..00000000 --- a/app/src/main/java/org/transdroid/core/gui/FilterEntryDialog.java +++ /dev/null @@ -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 . - */ -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"); - } - -} diff --git a/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java b/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java index 8525018c..fa159c1a 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java +++ b/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 . + */ package org.transdroid.core.gui; import java.util.List; +import android.app.Dialog; +import android.app.DialogFragment; +import android.os.Bundle; import org.transdroid.R; import org.transdroid.core.app.settings.ServerSetting; import android.app.AlertDialog; -import android.app.DialogFragment; import android.content.DialogInterface; 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 @@ -24,18 +55,11 @@ public class ServerPickerDialog { for (int i = 0; i < serverSettings.size(); i++) { serverNames[i] = serverSettings.get(i).getName(); } - new DialogFragment() { - public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { - return new AlertDialog.Builder(activity).setTitle(R.string.navigation_pickserver) - .setItems(serverNames, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (activity != null) - activity.switchServerAndAddFromIntent(which); - } - }).create(); - }; - }.show(activity.getFragmentManager(), "serverpicker"); + ServerPickerDialog dialog = new ServerPickerDialog(); + Bundle arguments = new Bundle(); + arguments.putStringArray("serverNames", serverNames); + dialog.setArguments(arguments); + dialog.show(activity.getFragmentManager(), "serverpicker"); } }