Search in sources :

Example 26 with DBDaoImpl

use of com.cyl.musiclake.data.source.db.DBDaoImpl in project MusicLake by caiyonglong.

the class PlayQueueLoader method addSongToQueue.

/**
 * 添加歌曲到歌单
 */
private static void addSongToQueue(Context context, List<Music> musics) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    dbDaoImpl.insertSongs(musics);
    for (int i = 0; i < musics.size(); i++) {
        dbDaoImpl.insertSongToPlaylist(DBData.PLAY_QUEUE, musics.get(i).getId());
    }
    dbDaoImpl.closeDB();
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl)

Example 27 with DBDaoImpl

use of com.cyl.musiclake.data.source.db.DBDaoImpl in project MusicLake by caiyonglong.

the class PlayQueueLoader method updateQueue.

/**
 * 添加歌曲到歌单
 */
public static void updateQueue(Context context, List<Music> musics) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    dbDaoImpl.insertSongs(musics);
    dbDaoImpl.clearPlayQueue();
    for (int i = 0; i < musics.size(); i++) {
        dbDaoImpl.insertSongToPlaylist(DBData.PLAY_QUEUE, musics.get(i).getId());
    }
    dbDaoImpl.closeDB();
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl)

Example 28 with DBDaoImpl

use of com.cyl.musiclake.data.source.db.DBDaoImpl in project MusicLake by caiyonglong.

the class PlaylistLoader method getMusicForPlaylist.

/**
 * 扫描歌单歌曲
 */
public static Observable<List<Music>> getMusicForPlaylist(Context context, String playlist_id) {
    return Observable.create(subscriber -> {
        String sql = "select * from " + DBData.MUSIC_TABLE + " , " + DBData.MTP_TABLE + " where " + DBData.MUSIC_TABLE + ".mid = " + DBData.MTP_TABLE + ".mid " + "and " + DBData.MTP_TABLE + ".pid=" + playlist_id + " ORDER BY music_playlist.date_added DESC";
        DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
        if (playlist_id.equals("1")) {
            sql = "SELECT DISTINCT  music.mid,  music.name,  music.filename,  music.path,  music.lrc_path,  music.duration,  music.size,  music.artist_id,  music.artist,  music.album,  music.album_id,  music.cover,  music.coverBig,  music.coverSmall,  music.type,  music.is_love,  music.is_online,  music.prefix,  music.years,  (   SELECT    music_playlist.date_added   FROM    music_playlist   WHERE    music_playlist.pid = 0   AND music_playlist.mid = music.mid   ORDER BY    music_playlist.date_added DESC  ) AS time,  (   SELECT    Count(music_playlist.mid)   FROM    music_playlist   WHERE    music_playlist.pid = 0   AND music_playlist.mid = music.mid  ) AS num FROM  music_playlist,  music WHERE  music_playlist.mid = music.mid AND music_playlist.pid = 1 ORDER BY  time DESC";
        } else if (playlist_id.equals("0")) {
            sql = "SELECT DISTINCT  music.mid,  music.name,  music.filename,  music.path,  music.lrc_path,  music.duration,  music.size,  music.artist_id,  music.artist,  music.album,  music.album_id,  music.cover,  music.coverBig,  music.coverSmall,  music.type,  music.is_love,  music.is_online,  music.prefix,  music.years,  (   SELECT    music_playlist.date_added   FROM    music_playlist   WHERE    music_playlist.pid = 0   AND music_playlist.mid = music.mid   ORDER BY    music_playlist.date_added DESC  ) AS time,  (   SELECT    Count(music_playlist.mid)   FROM    music_playlist   WHERE    music_playlist.pid = 0   AND music_playlist.mid = music.mid  ) AS num FROM  music_playlist,  music WHERE  music_playlist.mid = music.mid AND music_playlist.pid = 0 ORDER BY  time DESC";
        }
        Cursor cursor = dbDaoImpl.makeCursor(sql);
        List<Music> results = dbDaoImpl.getSongsForCursor(cursor);
        dbDaoImpl.closeDB();
        subscriber.onNext(results);
        subscriber.onComplete();
    });
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Music(com.cyl.musiclake.bean.Music) Cursor(android.database.Cursor)

Example 29 with DBDaoImpl

use of com.cyl.musiclake.data.source.db.DBDaoImpl 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 30 with DBDaoImpl

use of com.cyl.musiclake.data.source.db.DBDaoImpl in project MusicLake by caiyonglong.

the class PlaylistLoader method addToPlaylist.

/**
 * 添加歌曲到歌单
 */
public static boolean addToPlaylist(Context context, String pid, String mid) {
    boolean result = false;
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    if (!dbDaoImpl.hasSongPlaylist(pid, mid)) {
        dbDaoImpl.insertSongToPlaylist(pid, mid);
        result = true;
    }
    dbDaoImpl.closeDB();
    return result;
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl)

Aggregations

DBDaoImpl (com.cyl.musiclake.data.source.db.DBDaoImpl)33 Cursor (android.database.Cursor)13 Music (com.cyl.musiclake.bean.Music)9 Album (com.cyl.musiclake.bean.Album)2 Artist (com.cyl.musiclake.bean.Artist)1 Playlist (com.cyl.musiclake.bean.Playlist)1 ArrayList (java.util.ArrayList)1