Skip to content

Commit 3ab4f14

Browse files
committed
Extract dialog creation into its own method
1 parent 6cefb4b commit 3ab4f14

1 file changed

Lines changed: 33 additions & 24 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.local.playlist;
22

3+
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
4+
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
35
import static org.schabi.newpipe.error.ErrorUtil.showUiErrorSnackbar;
46
import static org.schabi.newpipe.ktx.ViewUtils.animate;
57
import static org.schabi.newpipe.local.playlist.ExportPlaylistKt.export;
@@ -23,6 +25,7 @@
2325
import android.view.View;
2426
import android.view.ViewGroup;
2527
import android.widget.LinearLayout;
28+
import android.widget.LinearLayout.LayoutParams;
2629
import android.widget.Toast;
2730

2831
import androidx.annotation.NonNull;
@@ -368,30 +371,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
368371
createRenameDialog();
369372
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
370373
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();
395375
}
396376
} else if (item.getItemId() == R.id.menu_item_remove_duplicates) {
397377
if (!isRewritingPlaylist) {
@@ -900,6 +880,35 @@ private void createShareConfirmationDialog() {
900880
.show();
901881
}
902882

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+
903912
public void setTabsPagerAdapter(
904913
@Nullable final MainFragment.SelectedTabsPagerAdapter tabsPagerAdapter) {
905914
this.tabsPagerAdapter = tabsPagerAdapter;

0 commit comments

Comments
 (0)