|
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; |
@@ -368,30 +371,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { |
368 | 371 | createRenameDialog(); |
369 | 372 | } else if (item.getItemId() == R.id.menu_item_remove_watched) { |
370 | 373 | if (!isRewritingPlaylist) { |
371 | | - final android.widget.CheckBox removePartiallyWatchedCheckbox = |
372 | | - new android.widget.CheckBox(requireContext()); |
373 | | - removePartiallyWatchedCheckbox.setText( |
374 | | - R.string.remove_watched_popup_partially_watched_streams); |
375 | | - |
376 | | - // Wrap the checkbox in a container with dialog-like horizontal padding |
377 | | - // so it aligns with the dialog title/message on the start side. |
378 | | - final LinearLayout checkboxContainer = new LinearLayout(requireContext()); |
379 | | - checkboxContainer.setOrientation(LinearLayout.VERTICAL); |
380 | | - final int padding = DeviceUtils.dpToPx(20, requireContext()); |
381 | | - checkboxContainer.setPadding(padding, padding, padding, 0); |
382 | | - checkboxContainer.addView(removePartiallyWatchedCheckbox, |
383 | | - new android.widget.LinearLayout.LayoutParams( |
384 | | - ViewGroup.LayoutParams.MATCH_PARENT, |
385 | | - ViewGroup.LayoutParams.WRAP_CONTENT)); |
386 | | - |
387 | | - new AlertDialog.Builder(requireContext()) |
388 | | - .setMessage(R.string.remove_watched_popup_warning) |
389 | | - .setTitle(R.string.remove_watched_popup_title) |
390 | | - .setView(checkboxContainer) |
391 | | - .setPositiveButton(R.string.yes, (d, id) -> |
392 | | - removeWatchedStreams(removePartiallyWatchedCheckbox.isChecked())) |
393 | | - .setNegativeButton(R.string.cancel, (d, id) -> d.cancel()) |
394 | | - .show(); |
| 374 | + openRemoveWatchedConfirmationDialog(); |
395 | 375 | } |
396 | 376 | } else if (item.getItemId() == R.id.menu_item_remove_duplicates) { |
397 | 377 | if (!isRewritingPlaylist) { |
@@ -900,6 +880,35 @@ private void createShareConfirmationDialog() { |
900 | 880 | .show(); |
901 | 881 | } |
902 | 882 |
|
| 883 | + /** |
| 884 | + * Opens a confirmation dialog to remove watched streams from the playlist. |
| 885 | + * The user can also choose to remove partially watched streams. |
| 886 | + */ |
| 887 | + private void openRemoveWatchedConfirmationDialog() { |
| 888 | + final android.widget.CheckBox removePartiallyWatchedCheckbox = |
| 889 | + new android.widget.CheckBox(requireContext()); |
| 890 | + removePartiallyWatchedCheckbox.setText( |
| 891 | + R.string.remove_watched_popup_partially_watched_streams); |
| 892 | + |
| 893 | + // Wrap the checkbox in a container with dialog-like horizontal padding |
| 894 | + // so it aligns with the dialog title and message on the start side. |
| 895 | + final LinearLayout checkboxContainer = new LinearLayout(requireContext()); |
| 896 | + checkboxContainer.setOrientation(LinearLayout.VERTICAL); |
| 897 | + final int padding = DeviceUtils.dpToPx(20, requireContext()); |
| 898 | + checkboxContainer.setPadding(padding, padding, padding, 0); |
| 899 | + checkboxContainer.addView(removePartiallyWatchedCheckbox, |
| 900 | + new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); |
| 901 | + |
| 902 | + new AlertDialog.Builder(requireContext()) |
| 903 | + .setMessage(R.string.remove_watched_popup_warning) |
| 904 | + .setTitle(R.string.remove_watched_popup_title) |
| 905 | + .setView(checkboxContainer) |
| 906 | + .setPositiveButton(R.string.yes, (d, id) -> |
| 907 | + removeWatchedStreams(removePartiallyWatchedCheckbox.isChecked())) |
| 908 | + .setNegativeButton(R.string.cancel, (d, id) -> d.cancel()) |
| 909 | + .show(); |
| 910 | + } |
| 911 | + |
903 | 912 | public void setTabsPagerAdapter( |
904 | 913 | @Nullable final MainFragment.SelectedTabsPagerAdapter tabsPagerAdapter) { |
905 | 914 | this.tabsPagerAdapter = tabsPagerAdapter; |
|
0 commit comments