Search in sources :

Example 21 with DBDaoImpl

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

the class ArtistLoader method getAllArtists.

/**
 * 获取所有艺术家
 *
 * @param context
 * @return
 */
public static Observable<List<Artist>> getAllArtists(Context context) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    String sql = "SELECT music.artist_id,music.artist,count(music.name) as num FROM music where music.is_online=0 GROUP BY music.artist";
    Cursor cursor = dbDaoImpl.makeCursor(sql);
    return getArtistsForDB(context, cursor);
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Cursor(android.database.Cursor)

Example 22 with DBDaoImpl

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

the class ArtistLoader method getArtistsForDB.

private static Observable<List<Artist>> getArtistsForDB(Context context, Cursor cursor) {
    return Observable.create(subscriber -> {
        try {
            DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
            List<Artist> results = dbDaoImpl.getArtistsForCursor(cursor);
            dbDaoImpl.closeDB();
            subscriber.onNext(results);
            subscriber.onComplete();
        } catch (Exception e) {
            e.printStackTrace();
            subscriber.onError(e);
        }
    });
}
Also used : Artist(com.cyl.musiclake.bean.Artist) DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl)

Example 23 with DBDaoImpl

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

the class PlayHistoryLoader method clearPlayHistory.

/**
 * 清除歌单
 */
public static void clearPlayHistory(Context context) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    dbDaoImpl.clearHistory();
    dbDaoImpl.closeDB();
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl)

Example 24 with DBDaoImpl

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

the class PlayHistoryLoader method updatePlayHistory.

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

Example 25 with DBDaoImpl

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

the class PlayHistoryLoader method addSongToHistory.

/**
 * 添加歌曲到歌单
 */
public static void addSongToHistory(Context context, Music music) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    dbDaoImpl.insertSong(music);
    dbDaoImpl.insertSongToPlaylist(DBData.HISTORY, music.getId());
    dbDaoImpl.closeDB();
}
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