Clean up AlertDialogs

This commit is contained in:
TacoTheDank 2023-07-11 21:54:10 -04:00
parent e33bb676f9
commit c1f0a945c0
15 changed files with 89 additions and 112 deletions

View file

@ -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) {

View file

@ -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();
}

View file

@ -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();
}
}

View file

@ -264,8 +264,6 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
final boolean isThumbnailPermanent = localPlaylistManager
.getIsPlaylistThumbnailPermanent(selectedItem.uid);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final ArrayList<String> items = new ArrayList<>();
items.add(rename);
items.add(delete);
@ -289,7 +287,9 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
}
};
builder.setItems(items.toArray(new String[0]), action).create().show();
new AlertDialog.Builder(activity)
.setItems(items.toArray(new String[0]), action)
.show();
}
private void showRenameDialog(final PlaylistMetadataEntry selectedItem) {
@ -299,14 +299,13 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
dialogBinding.dialogEditText.setInputType(InputType.TYPE_CLASS_TEXT);
dialogBinding.dialogEditText.setText(selectedItem.name);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setView(dialogBinding.getRoot())
new AlertDialog.Builder(activity)
.setView(dialogBinding.getRoot())
.setPositiveButton(R.string.rename_playlist, (dialog, which) ->
changeLocalPlaylistName(
selectedItem.uid,
dialogBinding.dialogEditText.getText().toString()))
.setNegativeButton(R.string.cancel, null)
.create()
.show();
}

View file

@ -231,7 +231,6 @@ class FeedFragment : BaseStateFragment<FeedState>() {
}
}
.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<FeedState>() {
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<FeedState>() {
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<FeedState>() {
message += "\n" + cause.message
}
}
builder.setMessage(message).create().show()
builder.setMessage(message)
.show()
}
private fun updateRelativeTimeViews() {

View file

@ -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<List<PlaylistSt
new AlertDialog.Builder(requireContext())
.setMessage(R.string.remove_watched_popup_warning)
.setTitle(R.string.remove_watched_popup_title)
.setPositiveButton(R.string.ok,
(DialogInterface d, int id) -> 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<List<PlaylistSt
dialogBinding.dialogEditText.setSelection(dialogBinding.dialogEditText.getText().length());
dialogBinding.dialogEditText.setText(name);
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext())
new AlertDialog.Builder(getContext())
.setTitle(R.string.rename_playlist)
.setView(dialogBinding.getRoot())
.setCancelable(true)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.rename, (dialogInterface, i) ->
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<List<PlaylistSt
}
private void openRemoveDuplicatesDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
builder.setTitle(R.string.remove_duplicates_title)
new AlertDialog.Builder(this.getActivity())
.setTitle(R.string.remove_duplicates_title)
.setMessage(R.string.remove_duplicates_message)
.setPositiveButton(R.string.ok,
(dialog, i) -> 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() {

View file

@ -352,7 +352,6 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
AlertDialog.Builder(requireContext())
.setCustomTitle(dialogTitleBinding.root)
.setItems(commands, actions)
.create()
.show()
}

View file

@ -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);
}

View file

@ -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

View file

@ -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();
}
}

View file

@ -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();

View file

@ -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();
}
}
}

View file

@ -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;

View file

@ -538,7 +538,6 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
builder.setNegativeButton(R.string.ok, (dialog, which) -> dialog.cancel())
.setTitle(mission.storage.getName())
.create()
.show();
}

View file

@ -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();
}