From c1f0a945c068d48ebf22751dbce6412ca26d4b4b Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Tue, 11 Jul 2023 21:54:10 -0400 Subject: [PATCH] Clean up AlertDialogs --- .../newpipe/download/DownloadDialog.java | 5 +-- .../schabi/newpipe/error/ErrorActivity.java | 4 +- .../fragments/detail/VideoDetailFragment.java | 28 ++++++------ .../local/bookmark/BookmarkFragment.java | 11 +++-- .../schabi/newpipe/local/feed/FeedFragment.kt | 44 ++++++++----------- .../local/playlist/LocalPlaylistFragment.java | 31 ++++++------- .../subscription/SubscriptionFragment.kt | 1 - .../settings/ContentSettingsFragment.java | 28 ++++++------ .../settings/DownloadSettingsFragment.java | 10 ++--- .../settings/HistorySettingsFragment.java | 3 -- .../schabi/newpipe/util/NavigationHelper.java | 8 ++-- .../external_communication/KoreUtils.java | 11 ++--- .../util/text/InternalUrlsHandler.java | 2 +- .../giga/ui/adapter/MissionAdapter.java | 1 - .../giga/ui/fragment/MissionsFragment.java | 14 +++--- 15 files changed, 89 insertions(+), 112 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 88a3484d9..4b9455006 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -770,7 +770,6 @@ public class DownloadDialog extends DialogFragment .setTitle(R.string.general_error) .setMessage(msg) .setNegativeButton(getString(R.string.ok), null) - .create() .show(); } @@ -983,7 +982,7 @@ public class DownloadDialog extends DialogFragment break; } - askDialog.create().show(); + askDialog.show(); return; } @@ -1027,7 +1026,7 @@ public class DownloadDialog extends DialogFragment } }); - askDialog.create().show(); + askDialog.show(); } private void continueSelectedDownload(@NonNull final StoredFileHelper storage) { diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java index dd065c3bb..6b34c8e90 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java @@ -176,9 +176,7 @@ public class ErrorActivity extends AppCompatActivity { ShareUtils.openUrlInApp(this, ERROR_GITHUB_ISSUE_URL); } }) - .setNegativeButton(R.string.decline, (dialog, which) -> { - // do nothing - }) + .setNegativeButton(R.string.decline, null) .show(); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 3c07b1a93..def1774b7 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -2089,7 +2089,8 @@ public final class VideoDetailFragment .setPositiveButton(R.string.ok, (dialog, which) -> { onAllow.run(); dialog.dismiss(); - }).show(); + }) + .show(); } private void showExternalVideoPlaybackDialog() { @@ -2155,25 +2156,24 @@ public final class VideoDetailFragment } else if (audioTracks.size() == 1) { startOnExternalPlayer(activity, currentInfo, audioTracks.get(0)); } else { - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.select_audio_track_external_players); - builder.setNeutralButton(R.string.open_in_browser, (dialog, i) -> - ShareUtils.openUrlInBrowser(requireActivity(), url)); - final int selectedAudioStream = ListHelper.getDefaultAudioFormat(activity, audioTracks); final CharSequence[] trackNames = audioTracks.stream() .map(audioStream -> Localization.audioTrackName(activity, audioStream)) .toArray(CharSequence[]::new); - builder.setSingleChoiceItems(trackNames, selectedAudioStream, null); - builder.setNegativeButton(R.string.cancel, null); - builder.setPositiveButton(R.string.ok, (dialog, i) -> { - final int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); - startOnExternalPlayer(activity, currentInfo, - audioTracks.get(index)); - }); - builder.show(); + new AlertDialog.Builder(activity) + .setTitle(R.string.select_audio_track_external_players) + .setNeutralButton(R.string.open_in_browser, (dialog, i) -> + ShareUtils.openUrlInBrowser(requireActivity(), url)) + .setSingleChoiceItems(trackNames, selectedAudioStream, null) + .setNegativeButton(R.string.cancel, null) + .setPositiveButton(R.string.ok, (dialog, i) -> { + final int index = ((AlertDialog) dialog).getListView() + .getCheckedItemPosition(); + startOnExternalPlayer(activity, currentInfo, audioTracks.get(index)); + }) + .show(); } } diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index 0969dbfcc..0df84d6c0 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -264,8 +264,6 @@ public final class BookmarkFragment extends BaseLocalListFragment items = new ArrayList<>(); items.add(rename); items.add(delete); @@ -289,7 +287,9 @@ public final class BookmarkFragment extends BaseLocalListFragment changeLocalPlaylistName( selectedItem.uid, dialogBinding.dialogEditText.getText().toString())) .setNegativeButton(R.string.cancel, null) - .create() .show(); } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 9fe90969f..ea9a3f36e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -231,7 +231,6 @@ class FeedFragment : BaseStateFragment() { } } .setPositiveButton(resources.getString(R.string.ok), null) - .create() .show() return true } else if (item.itemId == R.id.menu_item_feed_toggle_played_items) { @@ -254,22 +253,18 @@ class FeedFragment : BaseStateFragment() { viewModel.getShowFutureItemsFromPreferences() ) - val builder = AlertDialog.Builder(context!!) - builder.setTitle(R.string.feed_hide_streams_title) - builder.setMultiChoiceItems(dialogItems, checkedDialogItems) { _, which, isChecked -> - checkedDialogItems[which] = isChecked - } - - builder.setPositiveButton(R.string.ok) { _, _ -> - viewModel.setSaveShowPlayedItems(checkedDialogItems[0]) - - viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1]) - - viewModel.setSaveShowFutureItems(checkedDialogItems[2]) - } - builder.setNegativeButton(R.string.cancel, null) - - builder.create().show() + AlertDialog.Builder(context!!) + .setTitle(R.string.feed_hide_streams_title) + .setMultiChoiceItems(dialogItems, checkedDialogItems) { _, which, isChecked -> + checkedDialogItems[which] = isChecked + } + .setPositiveButton(R.string.ok) { _, _ -> + viewModel.setSaveShowPlayedItems(checkedDialogItems[0]) + viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1]) + viewModel.setSaveShowFutureItems(checkedDialogItems[2]) + } + .setNegativeButton(R.string.cancel, null) + .show() } override fun onDestroyOptionsMenu() { @@ -490,15 +485,13 @@ class FeedFragment : BaseStateFragment() { val builder = AlertDialog.Builder(requireContext()) .setTitle(R.string.feed_load_error) - .setPositiveButton( - R.string.unsubscribe - ) { _, _ -> - SubscriptionManager(requireContext()).deleteSubscription( - subscriptionEntity.serviceId, subscriptionEntity.url - ).subscribe() + .setPositiveButton(R.string.unsubscribe) { _, _ -> + SubscriptionManager(requireContext()) + .deleteSubscription(subscriptionEntity.serviceId, subscriptionEntity.url) + .subscribe() handleItemsErrors(nextItemsErrors) } - .setNegativeButton(R.string.cancel) { _, _ -> } + .setNegativeButton(R.string.cancel, null) var message = getString(R.string.feed_load_error_account_info, subscriptionEntity.name) if (cause is AccountTerminatedException) { @@ -515,7 +508,8 @@ class FeedFragment : BaseStateFragment() { message += "\n" + cause.message } } - builder.setMessage(message).create().show() + builder.setMessage(message) + .show() } private fun updateRelativeTimeViews() { diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 08e43df95..2a639a69f 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -5,7 +5,6 @@ import static org.schabi.newpipe.ktx.ViewUtils.animate; import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout; import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.os.Parcelable; import android.text.InputType; @@ -358,14 +357,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment removeWatchedStreams(false)) + .setPositiveButton(R.string.ok, (d, id) -> + removeWatchedStreams(false)) .setNeutralButton( R.string.remove_watched_popup_yes_and_partially_watched_videos, - (DialogInterface d, int id) -> removeWatchedStreams(true)) + (d, id) -> removeWatchedStreams(true)) .setNegativeButton(R.string.cancel, - (DialogInterface d, int id) -> d.cancel()) - .create() + (d, id) -> d.cancel()) .show(); } } else if (item.getItemId() == R.id.menu_item_remove_duplicates) { @@ -560,15 +558,14 @@ public class LocalPlaylistFragment extends BaseLocalListFragment - changePlaylistName(dialogBinding.dialogEditText.getText().toString())); - - dialogBuilder.show(); + changePlaylistName(dialogBinding.dialogEditText.getText().toString())) + .show(); } private void changePlaylistName(final String title) { @@ -634,15 +631,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment removeDuplicatesInPlaylist()) - .setNeutralButton(R.string.cancel, null); - - builder.create().show(); + .setPositiveButton(R.string.ok, (dialog, i) -> + removeDuplicatesInPlaylist()) + .setNeutralButton(R.string.cancel, null) + .show(); } private void removeDuplicatesInPlaylist() { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index bc2f96f73..da1eba225 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -352,7 +352,6 @@ class SubscriptionFragment : BaseStateFragment() { AlertDialog.Builder(requireContext()) .setCustomTitle(dialogTitleBinding.root) .setItems(commands, actions) - .create() .show() } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 37f83057b..434056b20 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -182,7 +182,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment { importDatabase(file, lastImportDataUri)) .setNegativeButton(R.string.cancel, (d, id) -> d.cancel()) - .create() .show(); } } @@ -223,20 +222,19 @@ public class ContentSettingsFragment extends BasePreferenceFragment { // if settings file exist, ask if it should be imported. if (manager.extractSettings(file)) { - final AlertDialog.Builder alert = new AlertDialog.Builder(requireContext()); - alert.setTitle(R.string.import_settings); - - alert.setNegativeButton(R.string.cancel, (dialog, which) -> { - dialog.dismiss(); - finishImport(importDataUri); - }); - alert.setPositiveButton(R.string.ok, (dialog, which) -> { - dialog.dismiss(); - manager.loadSharedPreferences(PreferenceManager - .getDefaultSharedPreferences(requireContext())); - finishImport(importDataUri); - }); - alert.show(); + new AlertDialog.Builder(requireContext()) + .setTitle(R.string.import_settings) + .setNegativeButton(R.string.cancel, (dialog, which) -> { + dialog.dismiss(); + finishImport(importDataUri); + }) + .setPositiveButton(R.string.ok, (dialog, which) -> { + dialog.dismiss(); + manager.loadSharedPreferences(PreferenceManager + .getDefaultSharedPreferences(requireContext())); + finishImport(importDataUri); + }) + .show(); } else { finishImport(importDataUri); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java index 782b7b906..472db6afe 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java @@ -170,11 +170,11 @@ public class DownloadSettingsFragment extends BasePreferenceFragment { } private void showMessageDialog(@StringRes final int title, @StringRes final int message) { - final AlertDialog.Builder msg = new AlertDialog.Builder(ctx); - msg.setTitle(title); - msg.setMessage(message); - msg.setPositiveButton(getString(R.string.ok), null); - msg.show(); + new AlertDialog.Builder(ctx) + .setTitle(title) + .setMessage(message) + .setPositiveButton(getString(R.string.ok), null) + .show(); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java index 86e651e2b..9bc9058c8 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java @@ -132,7 +132,6 @@ public class HistorySettingsFragment extends BasePreferenceFragment { disposables.add(getWholeStreamHistoryDisposable(context, recordManager)); disposables.add(getRemoveOrphanedRecordsDisposable(context, recordManager)); })) - .create() .show(); } @@ -144,7 +143,6 @@ public class HistorySettingsFragment extends BasePreferenceFragment { .setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss())) .setPositiveButton(R.string.delete, ((dialog, which) -> disposables.add(getDeletePlaybackStatesDisposable(context, recordManager)))) - .create() .show(); } @@ -156,7 +154,6 @@ public class HistorySettingsFragment extends BasePreferenceFragment { .setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss())) .setPositiveButton(R.string.delete, ((dialog, which) -> disposables.add(getDeleteSearchHistoryDisposable(context, recordManager)))) - .create() .show(); } } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 2c8db77e0..e212edd07 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -325,11 +325,11 @@ public final class NavigationHelper { if (context instanceof Activity) { new AlertDialog.Builder(context) .setMessage(R.string.no_player_found) - .setPositiveButton(R.string.install, - (dialog, which) -> ShareUtils.installApp(context, + .setPositiveButton(R.string.install, (dialog, which) -> + ShareUtils.installApp(context, context.getString(R.string.vlc_package))) - .setNegativeButton(R.string.cancel, (dialog, which) - -> Log.i("NavigationHelper", "You unlocked a secret unicorn.")) + .setNegativeButton(R.string.cancel, (dialog, which) -> + Log.i("NavigationHelper", "You unlocked a secret unicorn.")) .show(); } else { Toast.makeText(context, R.string.no_player_found_toast, Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/org/schabi/newpipe/util/external_communication/KoreUtils.java b/app/src/main/java/org/schabi/newpipe/util/external_communication/KoreUtils.java index 4dc9c7c07..6a605e982 100644 --- a/app/src/main/java/org/schabi/newpipe/util/external_communication/KoreUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/external_communication/KoreUtils.java @@ -61,11 +61,12 @@ public final class KoreUtils { .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (!tryOpenIntentInApp(context, intent)) { - final AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setMessage(R.string.kore_not_found) - .setPositiveButton(R.string.install, (dialog, which) -> installKore(context)) - .setNegativeButton(R.string.cancel, (dialog, which) -> { }); - builder.create().show(); + new AlertDialog.Builder(context) + .setMessage(R.string.kore_not_found) + .setPositiveButton(R.string.install, (dialog, which) -> + installKore(context)) + .setNegativeButton(R.string.cancel, null) + .show(); } } } diff --git a/app/src/main/java/org/schabi/newpipe/util/text/InternalUrlsHandler.java b/app/src/main/java/org/schabi/newpipe/util/text/InternalUrlsHandler.java index b87618922..066515d6b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/text/InternalUrlsHandler.java +++ b/app/src/main/java/org/schabi/newpipe/util/text/InternalUrlsHandler.java @@ -169,7 +169,7 @@ public final class InternalUrlsHandler { .setTitle(R.string.player_stream_failure) .setMessage( ErrorPanelHelper.Companion.getExceptionDescription(throwable)) - .setPositiveButton(R.string.ok, (v, b) -> { }) + .setPositiveButton(R.string.ok, null) .show(); })); return true; diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index 695e7aead..23f1bf6a7 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -538,7 +538,6 @@ public class MissionAdapter extends Adapter implements Handler.Callb builder.setNegativeButton(R.string.ok, (dialog, which) -> dialog.cancel()) .setTitle(mission.storage.getName()) - .create() .show(); } diff --git a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java index b5fc0297c..690ed4a97 100644 --- a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java +++ b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java @@ -211,12 +211,11 @@ public class MissionsFragment extends Fragment { .setTitle(R.string.clear_download_history) .setMessage(R.string.confirm_prompt) // Intentionally misusing buttons' purpose in order to achieve good order - .setNegativeButton(R.string.clear_download_history, - (dialog, which) -> mAdapter.clearFinishedDownloads(false)) + .setNegativeButton(R.string.clear_download_history, (dialog, which) -> + mAdapter.clearFinishedDownloads(false)) .setNeutralButton(R.string.cancel, null) - .setPositiveButton(R.string.delete_downloaded_files, - (dialog, which) -> showDeleteDownloadedFilesConfirmationPrompt()) - .create() + .setPositiveButton(R.string.delete_downloaded_files, (dialog, which) -> + showDeleteDownloadedFilesConfirmationPrompt()) .show(); } @@ -225,9 +224,8 @@ public class MissionsFragment extends Fragment { new AlertDialog.Builder(mContext) .setTitle(R.string.delete_downloaded_files_confirm) .setNegativeButton(R.string.cancel, null) - .setPositiveButton(R.string.ok, - (dialog, which) -> mAdapter.clearFinishedDownloads(true)) - .create() + .setPositiveButton(R.string.ok, (dialog, which) -> + mAdapter.clearFinishedDownloads(true)) .show(); }