Skip to content

Commit 8d9af62

Browse files
TobiGrStypox
authored andcommitted
Extract dialog creation into its own method
1 parent 8f32532 commit 8d9af62

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;
@@ -367,30 +370,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
367370
createRenameDialog();
368371
} else if (item.getItemId() == R.id.menu_item_remove_watched) {
369372
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();
394374
}
395375
} else if (item.getItemId() == R.id.menu_item_remove_duplicates) {
396376
if (!isRewritingPlaylist) {
@@ -908,6 +888,35 @@ private void createShareConfirmationDialog() {
908888
.show();
909889
}
910890

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

0 commit comments

Comments
 (0)