@@ -259,19 +259,51 @@ private void showRemoteDeleteDialog(final PlaylistRemoteEntity item) {
259259 }
260260
261261 private void showLocalDialog (final PlaylistMetadataEntry selectedItem ) {
262+ final String rename = getString (R .string .rename );
263+ final String delete = getString (R .string .delete );
264+ final String unsetThumbnail = getString (R .string .unset_playlist_thumbnail );
262265 final boolean isPlaylistThumbnailSet = localPlaylistManager
263266 .getIsPlaylistThumbnailSet (selectedItem .uid );
267+
264268 final AlertDialog .Builder builder = new AlertDialog .Builder (activity );
265269
266- final ArrayAdapter <String > arrayAdapter = new ArrayAdapter <>(getContext (),
270+ final ArrayAdapter <String > arrayAdapter = getLocalDialogArrayAdapter (isPlaylistThumbnailSet ,
271+ unsetThumbnail );
272+ arrayAdapter .addAll (rename , delete , unsetThumbnail );
273+
274+ final DialogInterface .OnClickListener action = (dialog , index ) -> {
275+ if (index == arrayAdapter .getPosition (rename )) {
276+ showRenameDialog (selectedItem );
277+ } else if (index == arrayAdapter .getPosition (delete )) {
278+ showDeleteDialog (selectedItem .name , localPlaylistManager
279+ .deletePlaylist (selectedItem .uid ));
280+ dialog .dismiss ();
281+ } else if (isPlaylistThumbnailSet ) {
282+ final String thumbnail_url = localPlaylistManager
283+ .getAutomaticPlaylistThumbnail (selectedItem .uid );
284+ localPlaylistManager .changePlaylistThumbnail (selectedItem .uid , thumbnail_url , false )
285+ .observeOn (AndroidSchedulers .mainThread ())
286+ .subscribe ();
287+ }
288+ };
289+
290+ builder .setAdapter (arrayAdapter , action )
291+ .create ()
292+ .show ();
293+ }
294+
295+ private ArrayAdapter <String > getLocalDialogArrayAdapter (final boolean isPlaylistThumbnailSet ,
296+ final String unsetThumbnail ) {
297+ return new ArrayAdapter <>(getContext (),
267298 android .R .layout .simple_list_item_1 ) {
268299 @ Override
269300 public View getView (final int position , final View convertView ,
270301 final ViewGroup parent ) {
271302 final View v = super .getView (position , convertView , parent );
272303 final TextView textView = v .findViewById (android .R .id .text1 );
273304
274- if (!isPlaylistThumbnailSet && position == 2 ) {
305+ // If the PlaylistThumbnail is not set permanently, the unset option is disabled.
306+ if (!isPlaylistThumbnailSet && textView .getText ().equals (unsetThumbnail )) {
275307 textView .setEnabled (false );
276308 return v ;
277309 }
@@ -280,32 +312,6 @@ public View getView(final int position, final View convertView,
280312 return v ;
281313 }
282314 };
283- arrayAdapter .addAll (getString (R .string .rename ), getString (R .string .delete ),
284- getString (R .string .unset_playlist_thumbnail ));
285-
286- // Rename = 0; Delete = 1; Unset Thumbnail = 2
287- final DialogInterface .OnClickListener action = (dialog , index ) -> {
288- switch (index ) {
289- case 0 : showRenameDialog (selectedItem );
290- break ;
291- case 1 :
292- showDeleteDialog (selectedItem .name ,
293- localPlaylistManager .deletePlaylist (selectedItem .uid ));
294- dialog .dismiss ();
295- break ;
296- case 2 :
297- if (isPlaylistThumbnailSet ) {
298- final String ur = "drawable://" + R .drawable .placeholder_thumbnail_playlist ;
299- localPlaylistManager .changePlaylistThumbnail (selectedItem .uid , ur ,
300- false ).observeOn (AndroidSchedulers .mainThread ()).subscribe ();
301- }
302- break ;
303- }
304- };
305-
306- builder .setAdapter (arrayAdapter , action )
307- .create ()
308- .show ();
309315 }
310316
311317 private void showRenameDialog (final PlaylistMetadataEntry selectedItem ) {
0 commit comments