Browse Source

Use AndroidX AlertDialogs

pull/594/head
TacoTheDank 3 years ago
parent
commit
a5319e25e5
  1. 10
      app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java
  2. 12
      app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java
  3. 8
      app/src/main/java/org/transdroid/core/gui/rss/RssItemsFragment.java
  4. 12
      app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java
  5. 12
      app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java
  6. 6
      app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java
  7. 10
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java
  8. 9
      app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java
  9. 8
      app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java
  10. 10
      app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java

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

@ -16,10 +16,11 @@
*/ */
package org.transdroid.core.gui; package org.transdroid.core.gui;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import org.transdroid.R; import org.transdroid.R;
@ -49,14 +50,17 @@ public class ServerPickerDialog extends DialogFragment {
dialog.show(activity.getSupportFragmentManager(), "serverpicker"); dialog.show(activity.getSupportFragmentManager(), "serverpicker");
} }
@NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
String[] serverNames = getArguments().getStringArray("serverNames"); String[] serverNames = getArguments().getStringArray("serverNames");
return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver) return new AlertDialog.Builder(getActivity())
.setTitle(R.string.navigation_pickserver)
.setItems(serverNames, (dialog, which) -> { .setItems(serverNames, (dialog, which) -> {
if (getActivity() != null && getActivity() instanceof TorrentsActivity) if (getActivity() != null && getActivity() instanceof TorrentsActivity)
((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which); ((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which);
}).create(); })
.create();
} }
} }

12
app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java

@ -30,10 +30,10 @@ import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.TypefaceSpan; import android.text.style.TypefaceSpan;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import com.afollestad.materialdialogs.MaterialDialog;
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache; import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache; import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
@ -159,11 +159,11 @@ public class NavigationHelper {
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
// Never asked again: show a dialog with an explanation // Never asked again: show a dialog with an explanation
activity.runOnUiThread(() -> activity.runOnUiThread(() ->
new MaterialDialog.Builder(context) new AlertDialog.Builder(context)
.content(R.string.permission_readtorrent) .setMessage(R.string.permission_readtorrent)
.positiveText(android.R.string.ok) .setPositiveButton(android.R.string.ok, (dialog, which) ->
.onPositive((dialog, which) -> ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode))
ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode)).show()); .show());
return false; return false;
} }
// Permission not granted (and we asked for it already before) // Permission not granted (and we asked for it already before)

8
app/src/main/java/org/transdroid/core/gui/rss/RssItemsFragment.java

@ -16,7 +16,6 @@
*/ */
package org.transdroid.core.gui.rss; package org.transdroid.core.gui.rss;
import android.app.AlertDialog;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
@ -33,6 +32,7 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -151,8 +151,10 @@ public class RssItemsFragment extends Fragment {
final Item first = checked.get(0); final Item first = checked.get(0);
if (itemId == R.id.action_showdetails) { if (itemId == R.id.action_showdetails) {
// Show a dialog box with the RSS item description text // Show a dialog box with the RSS item description text
new AlertDialog.Builder(getActivity()).setMessage(first.getDescription()) new AlertDialog.Builder(getActivity())
.setPositiveButton(R.string.action_close, null).show(); .setMessage(first.getDescription())
.setPositiveButton(R.string.action_close, null)
.show();
} else if (itemId == R.id.action_openwebsite) { } else if (itemId == R.id.action_openwebsite) {
// Open the browser to show the website contained in the item's link tag // Open the browser to show the website contained in the item's link tag
Toast.makeText(getActivity(), getString(R.string.search_openingdetails, first.getTitle()), Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), getString(R.string.search_openingdetails, first.getTitle()), Toast.LENGTH_LONG).show();

12
app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java

@ -18,11 +18,12 @@ package org.transdroid.core.gui.search;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import androidx.appcompat.app.AlertDialog;
import org.transdroid.R; import org.transdroid.R;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -73,12 +74,15 @@ public class BarcodeHelper {
} catch (Exception e) { } catch (Exception e) {
// Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present // Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present
final WeakReference<Context> intentStartContext = new WeakReference<>(activity); final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) new AlertDialog.Builder(activity)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_barcodescannernotfound)) .setMessage(activity.getString(R.string.search_barcodescannernotfound))
.setPositiveButton(android.R.string.yes, (dialog, which) -> { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (intentStartContext.get() != null) if (intentStartContext.get() != null)
intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI));
}).setNegativeButton(android.R.string.no, null).show(); })
.setNegativeButton(android.R.string.cancel, null)
.show();
} }
} }

12
app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java

@ -18,11 +18,12 @@ package org.transdroid.core.gui.search;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import androidx.appcompat.app.AlertDialog;
import org.transdroid.R; import org.transdroid.R;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -52,12 +53,15 @@ public class FilePickerHelper {
} catch (Exception e2) { } catch (Exception e2) {
// Can't start the file manager, for example with a SecurityException or when IO File Manager is not present // Can't start the file manager, for example with a SecurityException or when IO File Manager is not present
final WeakReference<Context> intentStartContext = new WeakReference<>(activity); final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) new AlertDialog.Builder(activity)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_filemanagernotfound)) .setMessage(activity.getString(R.string.search_filemanagernotfound))
.setPositiveButton(android.R.string.yes, (dialog, which) -> { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (intentStartContext.get() != null) if (intentStartContext.get() != null)
intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI)); intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI));
}).setNegativeButton(android.R.string.no, null).show(); })
.setNegativeButton(android.R.string.cancel, null)
.show();
} }
} }
} }

6
app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java

@ -17,7 +17,6 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
@ -26,6 +25,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceClickListener; import androidx.preference.Preference.OnPreferenceClickListener;
@ -272,7 +272,9 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
seedboxes[i + 1] = getString(R.string.pref_seedbox_addseedbox, SeedboxProvider.activeProviders()[i].getSettings().getName()); seedboxes[i + 1] = getString(R.string.pref_seedbox_addseedbox, SeedboxProvider.activeProviders()[i].getSettings().getName());
} }
seedboxes[seedboxes.length - 1] = getString(R.string.pref_seedbox_xirvikviaqr); seedboxes[seedboxes.length - 1] = getString(R.string.pref_seedbox_xirvikviaqr);
return new AlertDialog.Builder(this).setItems(seedboxes, onAddSeedbox).create(); return new AlertDialog.Builder(this)
.setItems(seedboxes, onAddSeedbox)
.create();
} }
return null; return null;
} }

10
app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java

@ -17,12 +17,13 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
@ -73,11 +74,14 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id == DIALOG_CONFIRMREMOVE) { if (id == DIALOG_CONFIRMREMOVE) {
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) return new AlertDialog.Builder(this)
.setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, (dialog, which) -> { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key); ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key);
finish(); finish();
}).setNegativeButton(android.R.string.cancel, null).create(); })
.setNegativeButton(android.R.string.cancel, null)
.create();
} }
return null; return null;
} }

9
app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -17,7 +17,6 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -25,6 +24,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.EditTextPreference; import androidx.preference.EditTextPreference;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -109,11 +109,14 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id == DIALOG_CONFIRMREMOVE) { if (id == DIALOG_CONFIRMREMOVE) {
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) return new AlertDialog.Builder(this)
.setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, (dialog, which) -> { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key); ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key);
finish(); finish();
}).setNegativeButton(android.R.string.cancel, null).create(); })
.setNegativeButton(android.R.string.cancel, null)
.create();
} }
return null; return null;
} }

8
app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java

@ -17,7 +17,6 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
@ -28,6 +27,7 @@ import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference.OnPreferenceClickListener; import androidx.preference.Preference.OnPreferenceClickListener;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -263,7 +263,8 @@ public class SystemSettingsActivity extends PreferenceCompatActivity {
SettingsPersistence.DEFAULT_SETTINGS_FILE.toString())) SettingsPersistence.DEFAULT_SETTINGS_FILE.toString()))
.setPositiveButton(R.string.pref_import_fromfile, importSettingsFromFile) .setPositiveButton(R.string.pref_import_fromfile, importSettingsFromFile)
.setNeutralButton(R.string.pref_import_fromqr, importSettingsFromQr) .setNeutralButton(R.string.pref_import_fromqr, importSettingsFromQr)
.setNegativeButton(android.R.string.cancel, null).create(); .setNegativeButton(android.R.string.cancel, null)
.create();
// @formatter:on // @formatter:on
case DIALOG_EXPORTSETTINGS: case DIALOG_EXPORTSETTINGS:
// @formatter:off // @formatter:off
@ -276,7 +277,8 @@ public class SystemSettingsActivity extends PreferenceCompatActivity {
SettingsPersistence.DEFAULT_SETTINGS_FILE.toString())) SettingsPersistence.DEFAULT_SETTINGS_FILE.toString()))
.setPositiveButton(R.string.pref_export_tofile, exportSettingsToFile) .setPositiveButton(R.string.pref_export_tofile, exportSettingsToFile)
.setNeutralButton(R.string.pref_export_toqr, exportSettingsToQr) .setNeutralButton(R.string.pref_export_toqr, exportSettingsToQr)
.setNegativeButton(android.R.string.cancel, null).create(); .setNegativeButton(android.R.string.cancel, null)
.create();
// @formatter:on // @formatter:on
} }
return null; return null;

10
app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java

@ -17,12 +17,13 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
@ -69,11 +70,14 @@ public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id == DIALOG_CONFIRMREMOVE) { if (id == DIALOG_CONFIRMREMOVE) {
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) return new AlertDialog.Builder(this)
.setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, (dialog, which) -> { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key); ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key);
finish(); finish();
}).setNegativeButton(android.R.string.cancel, null).create(); })
.setNegativeButton(android.R.string.cancel, null)
.create();
} }
return null; return null;
} }

Loading…
Cancel
Save