Commit 0d44d1ad authored by Alexander Martinz's avatar Alexander Martinz Committed by Michael Bestas

Popups: use AlertDialog instead of private APIs

Change-Id: Id6b4ee753cd498055b7cac0fe27b4e014e548d89
Signed-off-by: default avatarAlexander Martinz <amartinz@shiftphones.com>
parent 77ff10a9
......@@ -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);
}
}
......
......@@ -16,14 +16,14 @@
package org.lineageos.eleven.utils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import com.android.internal.view.menu.ContextMenuBuilder;
import com.android.internal.view.menu.MenuBuilder;
import org.lineageos.eleven.Config;
import org.lineageos.eleven.R;
import org.lineageos.eleven.menu.CreateNewPlaylist;
......@@ -31,6 +31,7 @@ import org.lineageos.eleven.menu.FragmentMenuItems;
import org.lineageos.eleven.menu.RenamePlaylist;
import org.lineageos.eleven.provider.RecentStore;
import java.util.List;
import java.util.TreeSet;
/**
......@@ -335,21 +336,23 @@ public abstract class PopupMenuHelper implements PopupMenu.OnMenuItemClickListen
MusicUtils.addToQueue(mActivity, getIdList(), getSourceId(), getSourceType());
return true;
case FragmentMenuItems.ADD_TO_PLAYLIST:
ContextMenuBuilder builder = new ContextMenuBuilder(mActivity);
MusicUtils.makePlaylistMenu(mActivity, getGroupId(), builder);
builder.setHeaderTitle(R.string.add_to_playlist);
builder.setCallback(new MenuBuilder.Callback() {
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
return onMenuItemClick(item);
}
@Override
public void onMenuModeChange(MenuBuilder menu) {
// do nothing
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(R.string.add_to_playlist);
final List<String> menuItemList = MusicUtils.makePlaylist(mActivity);
builder.setItems(menuItemList.toArray(new String[0]), new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
CreateNewPlaylist.getInstance(getIdList()).show(
mFragmentManager, "CreatePlaylist");
return;
}
final String name = menuItemList.get(which);
final long playListId = MusicUtils.getIdForPlaylist(mActivity, name);
MusicUtils.addToPlaylist(mActivity, getIdList(), playListId);
}
});
builder.showDialog(null, null);
builder.show();
return true;
case FragmentMenuItems.NEW_PLAYLIST:
CreateNewPlaylist.getInstance(getIdList()).show(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment