From 2679a4bf1e712f82bf6bcb40b4eacd973c7206c7 Mon Sep 17 00:00:00 2001 From: Jared Fantaye Date: Wed, 4 Jan 2023 16:21:16 +0100 Subject: [PATCH] Removed the "Unset Thumbnail" item if you can't use this feature --- .../local/bookmark/BookmarkFragment.java | 52 ++++++------------- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index 8cb544e0b..e2f493a8a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -8,8 +8,6 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -34,6 +32,7 @@ import org.schabi.newpipe.local.playlist.RemotePlaylistManager; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; +import java.util.ArrayList; import java.util.List; import icepick.State; @@ -267,49 +266,30 @@ public final class BookmarkFragment extends BaseLocalListFragment arrayAdapter = getLocalDialogArrayAdapter(isThumbnailPermanent, - unsetThumbnail); - arrayAdapter.addAll(rename, delete, unsetThumbnail); + final ArrayList items = new ArrayList<>(); + items.add(rename); + items.add(delete); + if (isThumbnailPermanent) { + items.add(unsetThumbnail); + } - final DialogInterface.OnClickListener action = (dialog, index) -> { - if (index == arrayAdapter.getPosition(rename)) { + final DialogInterface.OnClickListener action = (d, index) -> { + if (items.get(index).equals(rename)) { showRenameDialog(selectedItem); - } else if (index == arrayAdapter.getPosition(delete)) { - showDeleteDialog(selectedItem.name, localPlaylistManager - .deletePlaylist(selectedItem.uid)); - } else if (isThumbnailPermanent) { + } else if (items.get(index).equals(delete)) { + showDeleteDialog(selectedItem.name, + localPlaylistManager.deletePlaylist(selectedItem.uid)); + } else if (isThumbnailPermanent && items.get(index).equals(unsetThumbnail)) { final String thumbnailUrl = localPlaylistManager .getAutomaticPlaylistThumbnail(selectedItem.uid); - localPlaylistManager.changePlaylistThumbnail(selectedItem.uid, thumbnailUrl, false) + localPlaylistManager + .changePlaylistThumbnail(selectedItem.uid, thumbnailUrl, false) .observeOn(AndroidSchedulers.mainThread()) .subscribe(); } }; - builder.setAdapter(arrayAdapter, action) - .create() - .show(); - } - - private ArrayAdapter getLocalDialogArrayAdapter(final boolean isPlaylistThumbnailSet, - final String unsetThumbnail) { - return new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1) { - @Override - public View getView(final int position, final View convertView, - final ViewGroup parent) { - final View v = super.getView(position, convertView, parent); - final TextView textView = v.findViewById(android.R.id.text1); - - // If the PlaylistThumbnail is not set permanently, the unset option is disabled. - if (!isPlaylistThumbnailSet && textView.getText().equals(unsetThumbnail)) { - textView.setEnabled(false); - return v; - } - - textView.setEnabled(true); - return v; - } - }; + builder.setItems(items.toArray(new String[0]), action).create().show(); } private void showRenameDialog(final PlaylistMetadataEntry selectedItem) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 85f82e60c..dd30aaefa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -438,7 +438,7 @@ Mute Unmute Set as playlist thumbnail - Unset thumbnail + Unset permanent thumbnail Bookmark Playlist Remove Bookmark Delete this playlist\?