Search in sources :

Example 6 with Playlist

use of com.cyl.musiclake.bean.Playlist in project MusicLake by caiyonglong.

the class PlaylistLoader method getPlaylist.

/**
 * 获取全部歌单
 *
 * @param context
 * @return
 */
public static List<Playlist> getPlaylist(Context context) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    String sql = "SELECT *" + " , " + "(SELECT count(" + DBData.MTP_TABLE + ".mid ) FROM " + DBData.MTP_TABLE + " WHERE " + DBData.MTP_TABLE + ".pid = " + DBData.PLAYLIST_TABLE + ".pid) AS num FROM " + DBData.PLAYLIST_TABLE + " where " + DBData.PLAYLIST_TABLE + "." + DBData.PLAYLIST_DATE + " is not null ";
    LogUtil.d(TAG, sql + "----");
    Cursor cursor = dbDaoImpl.makeCursor(sql);
    List<Playlist> results = dbDaoImpl.getAllPlaylistForCursor(cursor);
    dbDaoImpl.closeDB();
    return results;
}
Also used : Playlist(com.cyl.musiclake.bean.Playlist) DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Cursor(android.database.Cursor)

Example 7 with Playlist

use of com.cyl.musiclake.bean.Playlist in project MusicLake by caiyonglong.

the class AddPlaylistDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Music music = getArguments().getParcelable("music");
    if (music.getType() == Music.Type.LOCAL) {
        return new MaterialDialog.Builder(getActivity()).title("增加到歌单").content("暂不支持添加本地歌曲到在线歌单").build();
    }
    final List<Playlist> playlists = PlaylistLoader.getPlaylist(getActivity());
    final CharSequence[] chars = new CharSequence[playlists.size() + 1];
    chars[0] = "新建歌单";
    for (int i = 0; i < playlists.size(); i++) {
        chars[i + 1] = playlists.get(i).getName();
    }
    return new MaterialDialog.Builder(getActivity()).title("增加到歌单").items(chars).itemsCallback((dialog, itemView, which, text) -> {
        if (which == 0) {
            CreatePlaylistDialog createDialog = CreatePlaylistDialog.newInstance(music);
            createDialog.show(getFragmentManager(), TAG_CREATE);
        } else {
            Log.d("addDialog", which + "----" + playlists.get(which - 1).getId() + "------" + music.getId());
            result = PlaylistLoader.addToPlaylist(getActivity(), playlists.get(which - 1).getId(), music.getId());
            if (result) {
                RxBus.getInstance().post(new Playlist());
                ToastUtils.show(getActivity(), "添加成功");
            } else {
                ToastUtils.show(getActivity(), "歌单中已有此音乐,请勿重复添加");
            }
            dialog.dismiss();
        }
    }).build();
}
Also used : List(java.util.List) Bundle(android.os.Bundle) Music(com.cyl.musiclake.bean.Music) ToastUtils(com.cyl.musiclake.utils.ToastUtils) Playlist(com.cyl.musiclake.bean.Playlist) PlaylistLoader(com.cyl.musiclake.data.source.PlaylistLoader) Dialog(android.app.Dialog) NonNull(android.support.annotation.NonNull) RxBus(com.cyl.musiclake.RxBus) DialogFragment(android.support.v4.app.DialogFragment) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Log(android.util.Log) Playlist(com.cyl.musiclake.bean.Playlist) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Music(com.cyl.musiclake.bean.Music) NonNull(android.support.annotation.NonNull)

Aggregations

Playlist (com.cyl.musiclake.bean.Playlist)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 Bundle (android.os.Bundle)2 Log (android.util.Log)2 RxBus (com.cyl.musiclake.RxBus)2 Music (com.cyl.musiclake.bean.Music)2 PlaylistLoader (com.cyl.musiclake.data.source.PlaylistLoader)2 ToastUtils (com.cyl.musiclake.utils.ToastUtils)2 List (java.util.List)2 SuppressLint (android.annotation.SuppressLint)1 Dialog (android.app.Dialog)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Build (android.os.Build)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 DialogFragment (android.support.v4.app.DialogFragment)1