OSDN Git Service

Popups: use AlertDialog instead of private APIs
[android-x86/packages-apps-Eleven.git] / src / org / lineageos / eleven / utils / MusicUtils.java
index 2d129f8..966deda 100644 (file)
@@ -63,9 +63,11 @@ import org.lineageos.eleven.provider.SongPlayCount;
 import org.lineageos.eleven.service.MusicPlaybackTrack;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import java.util.WeakHashMap;
 
 /**
@@ -1417,33 +1419,48 @@ public final class MusicUtils {
     }
 
     /**
-     * Creates a sub menu used to add items to a new playlist or an existsing
-     * one.
+     * Creates a map used to add items to a new playlist or an existing one.
      *
      * @param context The {@link Context} to use.
-     * @param groupId The group Id of the menu.
-     * @param menu The {@link Menu} to add to.
      */
-    public static void makePlaylistMenu(final Context context, final int groupId,
-            final Menu menu) {
-        menu.clear();
-        menu.add(groupId, FragmentMenuItems.NEW_PLAYLIST, Menu.NONE, R.string.new_playlist);
-        Cursor cursor = PlaylistLoader.makePlaylistCursor(context);
+    public static List<String> makePlaylist(final Context context) {
+        final List<String> menuItemMap = new ArrayList<>();
+        menuItemMap.add(context.getString(R.string.new_playlist));
+
+        final Cursor cursor = PlaylistLoader.makePlaylistCursor(context);
         if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
             while (!cursor.isAfterLast()) {
-                final Intent intent = new Intent();
-                String name = cursor.getString(1);
+                final String name = cursor.getString(1);
                 if (name != null) {
-                    intent.putExtra("playlist", getIdForPlaylist(context, name));
-                    menu.add(groupId, FragmentMenuItems.PLAYLIST_SELECTED, Menu.NONE,
-                            name).setIntent(intent);
+                    menuItemMap.add(name);
                 }
                 cursor.moveToNext();
             }
         }
         if (cursor != null) {
             cursor.close();
-            cursor = null;
+        }
+        return menuItemMap;
+    }
+
+    /**
+     * Creates a sub menu used to add items to a new playlist or an existing
+     * one.
+     *
+     * @param context The {@link Context} to use.
+     * @param groupId The group Id of the menu.
+     * @param menu The {@link Menu} to add to.
+     */
+    public static void makePlaylistMenu(final Context context, final int groupId,
+                                        final Menu menu) {
+        menu.clear();
+
+        final List<String> menuItemList = makePlaylist(context);
+        for (final String name : menuItemList) {
+            final Intent intent = new Intent();
+            intent.putExtra("playlist", getIdForPlaylist(context, name));
+            menu.add(groupId, FragmentMenuItems.PLAYLIST_SELECTED, Menu.NONE, name)
+                    .setIntent(intent);
         }
     }
 
@@ -1499,8 +1516,7 @@ public final class MusicUtils {
             } catch (final IllegalStateException ignored) {
                 // Illegal State Exception message is empty so logging will actually throw an
                 // exception.  We should come back and figure out why we get an exception in the
-                // first place and make sure we understand it completely.  I will use
-                // https://cyanogen.atlassian.net/browse/MUSIC-125 to track investigating this more
+                // first place and make sure we understand it completely.
             }
         }
     }
@@ -1516,8 +1532,7 @@ public final class MusicUtils {
             } catch (final IllegalStateException ex) {
                 // Illegal State Exception message is empty so logging will actually throw an
                 // exception.  We should come back and figure out why we get an exception in the
-                // first place and make sure we understand it completely.  I will use
-                // https://cyanogen.atlassian.net/browse/MUSIC-125 to track investigating this more
+                // first place and make sure we understand it completely.
             }
         }
         return 0;
@@ -1534,8 +1549,7 @@ public final class MusicUtils {
             } catch (final IllegalStateException ignored) {
                 // Illegal State Exception message is empty so logging will actually throw an
                 // exception.  We should come back and figure out why we get an exception in the
-                // first place and make sure we understand it completely.  I will use
-                // https://cyanogen.atlassian.net/browse/MUSIC-125 to track investigating this more
+                // first place and make sure we understand it completely.
             }
         }
         return 0;