|
1 | 1 | package org.schabi.newpipe.local.playlist; |
2 | 2 |
|
| 3 | +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 4 | +import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
3 | 5 | import static org.schabi.newpipe.error.ErrorUtil.showUiErrorSnackbar; |
4 | 6 | import static org.schabi.newpipe.ktx.ViewUtils.animate; |
5 | 7 | import static org.schabi.newpipe.local.playlist.ExportPlaylistKt.export; |
|
23 | 25 | import android.view.View; |
24 | 26 | import android.view.ViewGroup; |
25 | 27 | import android.widget.LinearLayout; |
| 28 | +import android.widget.LinearLayout.LayoutParams; |
26 | 29 | import android.widget.Toast; |
27 | 30 |
|
28 | 31 | import androidx.annotation.NonNull; |
@@ -367,30 +370,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { |
367 | 370 | createRenameDialog(); |
368 | 371 | } else if (item.getItemId() == R.id.menu_item_remove_watched) { |
369 | 372 | if (!isRewritingPlaylist) { |
370 | | - final android.widget.CheckBox removePartiallyWatchedCheckbox = |
371 | | - new android.widget.CheckBox(requireContext()); |
372 | | - removePartiallyWatchedCheckbox.setText( |
373 | | - R.string.remove_watched_popup_partially_watched_streams); |
374 | | - |
375 | | - // Wrap the checkbox in a container with dialog-like horizontal padding |
376 | | - // so it aligns with the dialog title/message on the start side. |
377 | | - final LinearLayout checkboxContainer = new LinearLayout(requireContext()); |
378 | | - checkboxContainer.setOrientation(LinearLayout.VERTICAL); |
379 | | - final int padding = DeviceUtils.dpToPx(20, requireContext()); |
380 | | - checkboxContainer.setPadding(padding, padding, padding, 0); |
381 | | - checkboxContainer.addView(removePartiallyWatchedCheckbox, |
382 | | - new android.widget.LinearLayout.LayoutParams( |
383 | | - ViewGroup.LayoutParams.MATCH_PARENT, |
384 | | - ViewGroup.LayoutParams.WRAP_CONTENT)); |
385 | | - |
386 | | - new AlertDialog.Builder(requireContext()) |
387 | | - .setMessage(R.string.remove_watched_popup_warning) |
388 | | - .setTitle(R.string.remove_watched_popup_title) |
389 | | - .setView(checkboxContainer) |
390 | | - .setPositiveButton(R.string.yes, (d, id) -> |
391 | | - removeWatchedStreams(removePartiallyWatchedCheckbox.isChecked())) |
392 | | - .setNegativeButton(R.string.cancel, (d, id) -> d.cancel()) |
393 | | - .show(); |
| 373 | + openRemoveWatchedConfirmationDialog(); |
394 | 374 | } |
395 | 375 | } else if (item.getItemId() == R.id.menu_item_remove_duplicates) { |
396 | 376 | if (!isRewritingPlaylist) { |
@@ -908,6 +888,35 @@ private void createShareConfirmationDialog() { |
908 | 888 | .show(); |
909 | 889 | } |
910 | 890 |
|
| 891 | + /** |
| 892 | + * Opens a confirmation dialog to remove watched streams from the playlist. |
| 893 | + * The user can also choose to remove partially watched streams. |
| 894 | + */ |
| 895 | + private void openRemoveWatchedConfirmationDialog() { |
| 896 | + final android.widget.CheckBox removePartiallyWatchedCheckbox = |
| 897 | + new android.widget.CheckBox(requireContext()); |
| 898 | + removePartiallyWatchedCheckbox.setText( |
| 899 | + R.string.remove_watched_popup_partially_watched_streams); |
| 900 | + |
| 901 | + // Wrap the checkbox in a container with dialog-like horizontal padding |
| 902 | + // so it aligns with the dialog title and message on the start side. |
| 903 | + final LinearLayout checkboxContainer = new LinearLayout(requireContext()); |
| 904 | + checkboxContainer.setOrientation(LinearLayout.VERTICAL); |
| 905 | + final int padding = DeviceUtils.dpToPx(20, requireContext()); |
| 906 | + checkboxContainer.setPadding(padding, padding, padding, 0); |
| 907 | + checkboxContainer.addView(removePartiallyWatchedCheckbox, |
| 908 | + new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); |
| 909 | + |
| 910 | + new AlertDialog.Builder(requireContext()) |
| 911 | + .setMessage(R.string.remove_watched_popup_warning) |
| 912 | + .setTitle(R.string.remove_watched_popup_title) |
| 913 | + .setView(checkboxContainer) |
| 914 | + .setPositiveButton(R.string.yes, (d, id) -> |
| 915 | + removeWatchedStreams(removePartiallyWatchedCheckbox.isChecked())) |
| 916 | + .setNegativeButton(R.string.cancel, (d, id) -> d.cancel()) |
| 917 | + .show(); |
| 918 | + } |
| 919 | + |
911 | 920 | public void setTabsPagerAdapter( |
912 | 921 | @Nullable final MainFragment.SelectedTabsPagerAdapter tabsPagerAdapter) { |
913 | 922 | this.tabsPagerAdapter = tabsPagerAdapter; |
|
0 commit comments