1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

Merge pull request #10223 from TacoTheDank/cleanAlertDialogs

Clean up AlertDialogs
This commit is contained in:
Stypox 2023-07-12 19:02:57 +02:00 committed by GitHub
commit 5c7a9a52f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) .setTitle(R.string.general_error)
.setMessage(msg) .setMessage(msg)
.setNegativeButton(getString(R.string.ok), null) .setNegativeButton(getString(R.string.ok), null)
.create()
.show(); .show();
} }
@ -983,7 +982,7 @@ public class DownloadDialog extends DialogFragment
break; break;
} }
askDialog.create().show(); askDialog.show();
return; return;
} }
@ -1027,7 +1026,7 @@ public class DownloadDialog extends DialogFragment
} }
}); });
askDialog.create().show(); askDialog.show();
} }
private void continueSelectedDownload(@NonNull final StoredFileHelper storage) { 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); ShareUtils.openUrlInApp(this, ERROR_GITHUB_ISSUE_URL);
} }
}) })
.setNegativeButton(R.string.decline, (dialog, which) -> { .setNegativeButton(R.string.decline, null)
// do nothing
})
.show(); .show();
} }

View File

@ -2089,7 +2089,8 @@ public final class VideoDetailFragment
.setPositiveButton(R.string.ok, (dialog, which) -> { .setPositiveButton(R.string.ok, (dialog, which) -> {
onAllow.run(); onAllow.run();
dialog.dismiss(); dialog.dismiss();
}).show(); })
.show();
} }
private void showExternalVideoPlaybackDialog() { private void showExternalVideoPlaybackDialog() {
@ -2155,25 +2156,24 @@ public final class VideoDetailFragment
} else if (audioTracks.size() == 1) { } else if (audioTracks.size() == 1) {
startOnExternalPlayer(activity, currentInfo, audioTracks.get(0)); startOnExternalPlayer(activity, currentInfo, audioTracks.get(0));
} else { } 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 = final int selectedAudioStream =
ListHelper.getDefaultAudioFormat(activity, audioTracks); ListHelper.getDefaultAudioFormat(activity, audioTracks);
final CharSequence[] trackNames = audioTracks.stream() final CharSequence[] trackNames = audioTracks.stream()
.map(audioStream -> Localization.audioTrackName(activity, audioStream)) .map(audioStream -> Localization.audioTrackName(activity, audioStream))
.toArray(CharSequence[]::new); .toArray(CharSequence[]::new);
builder.setSingleChoiceItems(trackNames, selectedAudioStream, null); new AlertDialog.Builder(activity)
builder.setNegativeButton(R.string.cancel, null); .setTitle(R.string.select_audio_track_external_players)
builder.setPositiveButton(R.string.ok, (dialog, i) -> { .setNeutralButton(R.string.open_in_browser, (dialog, i) ->
final int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); ShareUtils.openUrlInBrowser(requireActivity(), url))
startOnExternalPlayer(activity, currentInfo, .setSingleChoiceItems(trackNames, selectedAudioStream, null)
audioTracks.get(index)); .setNegativeButton(R.string.cancel, null)
}); .setPositiveButton(R.string.ok, (dialog, i) -> {
builder.show(); 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 final boolean isThumbnailPermanent = localPlaylistManager
.getIsPlaylistThumbnailPermanent(selectedItem.uid); .getIsPlaylistThumbnailPermanent(selectedItem.uid);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final ArrayList<String> items = new ArrayList<>(); final ArrayList<String> items = new ArrayList<>();
items.add(rename); items.add(rename);
items.add(delete); 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) { 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.setInputType(InputType.TYPE_CLASS_TEXT);
dialogBinding.dialogEditText.setText(selectedItem.name); dialogBinding.dialogEditText.setText(selectedItem.name);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity); new AlertDialog.Builder(activity)
builder.setView(dialogBinding.getRoot()) .setView(dialogBinding.getRoot())
.setPositiveButton(R.string.rename_playlist, (dialog, which) -> .setPositiveButton(R.string.rename_playlist, (dialog, which) ->
changeLocalPlaylistName( changeLocalPlaylistName(
selectedItem.uid, selectedItem.uid,
dialogBinding.dialogEditText.getText().toString())) dialogBinding.dialogEditText.getText().toString()))
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create()
.show(); .show();
} }

View File

@ -231,7 +231,6 @@ class FeedFragment : BaseStateFragment<FeedState>() {
} }
} }
.setPositiveButton(resources.getString(R.string.ok), null) .setPositiveButton(resources.getString(R.string.ok), null)
.create()
.show() .show()
return true return true
} else if (item.itemId == R.id.menu_item_feed_toggle_played_items) { } else if (item.itemId == R.id.menu_item_feed_toggle_played_items) {
@ -254,22 +253,18 @@ class FeedFragment : BaseStateFragment<FeedState>() {
viewModel.getShowFutureItemsFromPreferences() viewModel.getShowFutureItemsFromPreferences()
) )
val builder = AlertDialog.Builder(context!!) AlertDialog.Builder(context!!)
builder.setTitle(R.string.feed_hide_streams_title) .setTitle(R.string.feed_hide_streams_title)
builder.setMultiChoiceItems(dialogItems, checkedDialogItems) { _, which, isChecked -> .setMultiChoiceItems(dialogItems, checkedDialogItems) { _, which, isChecked ->
checkedDialogItems[which] = isChecked checkedDialogItems[which] = isChecked
} }
.setPositiveButton(R.string.ok) { _, _ ->
builder.setPositiveButton(R.string.ok) { _, _ ->
viewModel.setSaveShowPlayedItems(checkedDialogItems[0]) viewModel.setSaveShowPlayedItems(checkedDialogItems[0])
viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1]) viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1])
viewModel.setSaveShowFutureItems(checkedDialogItems[2]) viewModel.setSaveShowFutureItems(checkedDialogItems[2])
} }
builder.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show()
builder.create().show()
} }
override fun onDestroyOptionsMenu() { override fun onDestroyOptionsMenu() {
@ -490,15 +485,13 @@ class FeedFragment : BaseStateFragment<FeedState>() {
val builder = AlertDialog.Builder(requireContext()) val builder = AlertDialog.Builder(requireContext())
.setTitle(R.string.feed_load_error) .setTitle(R.string.feed_load_error)
.setPositiveButton( .setPositiveButton(R.string.unsubscribe) { _, _ ->
R.string.unsubscribe SubscriptionManager(requireContext())
) { _, _ -> .deleteSubscription(subscriptionEntity.serviceId, subscriptionEntity.url)
SubscriptionManager(requireContext()).deleteSubscription( .subscribe()
subscriptionEntity.serviceId, subscriptionEntity.url
).subscribe()
handleItemsErrors(nextItemsErrors) handleItemsErrors(nextItemsErrors)
} }
.setNegativeButton(R.string.cancel) { _, _ -> } .setNegativeButton(R.string.cancel, null)
var message = getString(R.string.feed_load_error_account_info, subscriptionEntity.name) var message = getString(R.string.feed_load_error_account_info, subscriptionEntity.name)
if (cause is AccountTerminatedException) { if (cause is AccountTerminatedException) {
@ -515,7 +508,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
message += "\n" + cause.message message += "\n" + cause.message
} }
} }
builder.setMessage(message).create().show() builder.setMessage(message)
.show()
} }
private fun updateRelativeTimeViews() { 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 static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.InputType; import android.text.InputType;
@ -358,14 +357,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
new AlertDialog.Builder(requireContext()) new AlertDialog.Builder(requireContext())
.setMessage(R.string.remove_watched_popup_warning) .setMessage(R.string.remove_watched_popup_warning)
.setTitle(R.string.remove_watched_popup_title) .setTitle(R.string.remove_watched_popup_title)
.setPositiveButton(R.string.ok, .setPositiveButton(R.string.ok, (d, id) ->
(DialogInterface d, int id) -> removeWatchedStreams(false)) removeWatchedStreams(false))
.setNeutralButton( .setNeutralButton(
R.string.remove_watched_popup_yes_and_partially_watched_videos, R.string.remove_watched_popup_yes_and_partially_watched_videos,
(DialogInterface d, int id) -> removeWatchedStreams(true)) (d, id) -> removeWatchedStreams(true))
.setNegativeButton(R.string.cancel, .setNegativeButton(R.string.cancel,
(DialogInterface d, int id) -> d.cancel()) (d, id) -> d.cancel())
.create()
.show(); .show();
} }
} else if (item.getItemId() == R.id.menu_item_remove_duplicates) { } 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.setSelection(dialogBinding.dialogEditText.getText().length());
dialogBinding.dialogEditText.setText(name); dialogBinding.dialogEditText.setText(name);
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()) new AlertDialog.Builder(getContext())
.setTitle(R.string.rename_playlist) .setTitle(R.string.rename_playlist)
.setView(dialogBinding.getRoot()) .setView(dialogBinding.getRoot())
.setCancelable(true) .setCancelable(true)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.rename, (dialogInterface, i) -> .setPositiveButton(R.string.rename, (dialogInterface, i) ->
changePlaylistName(dialogBinding.dialogEditText.getText().toString())); changePlaylistName(dialogBinding.dialogEditText.getText().toString()))
.show();
dialogBuilder.show();
} }
private void changePlaylistName(final String title) { private void changePlaylistName(final String title) {
@ -634,15 +631,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
} }
private void openRemoveDuplicatesDialog() { private void openRemoveDuplicatesDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity()); new AlertDialog.Builder(this.getActivity())
.setTitle(R.string.remove_duplicates_title)
builder.setTitle(R.string.remove_duplicates_title)
.setMessage(R.string.remove_duplicates_message) .setMessage(R.string.remove_duplicates_message)
.setPositiveButton(R.string.ok, .setPositiveButton(R.string.ok, (dialog, i) ->
(dialog, i) -> removeDuplicatesInPlaylist()) removeDuplicatesInPlaylist())
.setNeutralButton(R.string.cancel, null); .setNeutralButton(R.string.cancel, null)
.show();
builder.create().show();
} }
private void removeDuplicatesInPlaylist() { private void removeDuplicatesInPlaylist() {

View File

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

View File

@ -182,7 +182,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
importDatabase(file, lastImportDataUri)) importDatabase(file, lastImportDataUri))
.setNegativeButton(R.string.cancel, (d, id) -> .setNegativeButton(R.string.cancel, (d, id) ->
d.cancel()) d.cancel())
.create()
.show(); .show();
} }
} }
@ -223,20 +222,19 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
// if settings file exist, ask if it should be imported. // if settings file exist, ask if it should be imported.
if (manager.extractSettings(file)) { if (manager.extractSettings(file)) {
final AlertDialog.Builder alert = new AlertDialog.Builder(requireContext()); new AlertDialog.Builder(requireContext())
alert.setTitle(R.string.import_settings); .setTitle(R.string.import_settings)
.setNegativeButton(R.string.cancel, (dialog, which) -> {
alert.setNegativeButton(R.string.cancel, (dialog, which) -> {
dialog.dismiss(); dialog.dismiss();
finishImport(importDataUri); finishImport(importDataUri);
}); })
alert.setPositiveButton(R.string.ok, (dialog, which) -> { .setPositiveButton(R.string.ok, (dialog, which) -> {
dialog.dismiss(); dialog.dismiss();
manager.loadSharedPreferences(PreferenceManager manager.loadSharedPreferences(PreferenceManager
.getDefaultSharedPreferences(requireContext())); .getDefaultSharedPreferences(requireContext()));
finishImport(importDataUri); finishImport(importDataUri);
}); })
alert.show(); .show();
} else { } else {
finishImport(importDataUri); finishImport(importDataUri);
} }

View File

@ -170,11 +170,11 @@ public class DownloadSettingsFragment extends BasePreferenceFragment {
} }
private void showMessageDialog(@StringRes final int title, @StringRes final int message) { private void showMessageDialog(@StringRes final int title, @StringRes final int message) {
final AlertDialog.Builder msg = new AlertDialog.Builder(ctx); new AlertDialog.Builder(ctx)
msg.setTitle(title); .setTitle(title)
msg.setMessage(message); .setMessage(message)
msg.setPositiveButton(getString(R.string.ok), null); .setPositiveButton(getString(R.string.ok), null)
msg.show(); .show();
} }
@Override @Override

View File

@ -132,7 +132,6 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
disposables.add(getWholeStreamHistoryDisposable(context, recordManager)); disposables.add(getWholeStreamHistoryDisposable(context, recordManager));
disposables.add(getRemoveOrphanedRecordsDisposable(context, recordManager)); disposables.add(getRemoveOrphanedRecordsDisposable(context, recordManager));
})) }))
.create()
.show(); .show();
} }
@ -144,7 +143,6 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss())) .setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss()))
.setPositiveButton(R.string.delete, ((dialog, which) -> .setPositiveButton(R.string.delete, ((dialog, which) ->
disposables.add(getDeletePlaybackStatesDisposable(context, recordManager)))) disposables.add(getDeletePlaybackStatesDisposable(context, recordManager))))
.create()
.show(); .show();
} }
@ -156,7 +154,6 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss())) .setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss()))
.setPositiveButton(R.string.delete, ((dialog, which) -> .setPositiveButton(R.string.delete, ((dialog, which) ->
disposables.add(getDeleteSearchHistoryDisposable(context, recordManager)))) disposables.add(getDeleteSearchHistoryDisposable(context, recordManager))))
.create()
.show(); .show();
} }
} }

View File

@ -325,11 +325,11 @@ public final class NavigationHelper {
if (context instanceof Activity) { if (context instanceof Activity) {
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setMessage(R.string.no_player_found) .setMessage(R.string.no_player_found)
.setPositiveButton(R.string.install, .setPositiveButton(R.string.install, (dialog, which) ->
(dialog, which) -> ShareUtils.installApp(context, ShareUtils.installApp(context,
context.getString(R.string.vlc_package))) context.getString(R.string.vlc_package)))
.setNegativeButton(R.string.cancel, (dialog, which) .setNegativeButton(R.string.cancel, (dialog, which) ->
-> Log.i("NavigationHelper", "You unlocked a secret unicorn.")) Log.i("NavigationHelper", "You unlocked a secret unicorn."))
.show(); .show();
} else { } else {
Toast.makeText(context, R.string.no_player_found_toast, Toast.LENGTH_LONG).show(); 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); .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (!tryOpenIntentInApp(context, intent)) { if (!tryOpenIntentInApp(context, intent)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context); new AlertDialog.Builder(context)
builder.setMessage(R.string.kore_not_found) .setMessage(R.string.kore_not_found)
.setPositiveButton(R.string.install, (dialog, which) -> installKore(context)) .setPositiveButton(R.string.install, (dialog, which) ->
.setNegativeButton(R.string.cancel, (dialog, which) -> { }); installKore(context))
builder.create().show(); .setNegativeButton(R.string.cancel, null)
.show();
} }
} }
} }

View File

@ -169,7 +169,7 @@ public final class InternalUrlsHandler {
.setTitle(R.string.player_stream_failure) .setTitle(R.string.player_stream_failure)
.setMessage( .setMessage(
ErrorPanelHelper.Companion.getExceptionDescription(throwable)) ErrorPanelHelper.Companion.getExceptionDescription(throwable))
.setPositiveButton(R.string.ok, (v, b) -> { }) .setPositiveButton(R.string.ok, null)
.show(); .show();
})); }));
return true; 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()) builder.setNegativeButton(R.string.ok, (dialog, which) -> dialog.cancel())
.setTitle(mission.storage.getName()) .setTitle(mission.storage.getName())
.create()
.show(); .show();
} }

View File

@ -211,12 +211,11 @@ public class MissionsFragment extends Fragment {
.setTitle(R.string.clear_download_history) .setTitle(R.string.clear_download_history)
.setMessage(R.string.confirm_prompt) .setMessage(R.string.confirm_prompt)
// Intentionally misusing buttons' purpose in order to achieve good order // Intentionally misusing buttons' purpose in order to achieve good order
.setNegativeButton(R.string.clear_download_history, .setNegativeButton(R.string.clear_download_history, (dialog, which) ->
(dialog, which) -> mAdapter.clearFinishedDownloads(false)) mAdapter.clearFinishedDownloads(false))
.setNeutralButton(R.string.cancel, null) .setNeutralButton(R.string.cancel, null)
.setPositiveButton(R.string.delete_downloaded_files, .setPositiveButton(R.string.delete_downloaded_files, (dialog, which) ->
(dialog, which) -> showDeleteDownloadedFilesConfirmationPrompt()) showDeleteDownloadedFilesConfirmationPrompt())
.create()
.show(); .show();
} }
@ -225,9 +224,8 @@ public class MissionsFragment extends Fragment {
new AlertDialog.Builder(mContext) new AlertDialog.Builder(mContext)
.setTitle(R.string.delete_downloaded_files_confirm) .setTitle(R.string.delete_downloaded_files_confirm)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.ok, .setPositiveButton(R.string.ok, (dialog, which) ->
(dialog, which) -> mAdapter.clearFinishedDownloads(true)) mAdapter.clearFinishedDownloads(true))
.create()
.show(); .show();
} }