Search in sources :

Example 11 with DBDaoImpl

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

the class SongLoader method getFavoriteSong.

/**
 * 获取所有收藏的歌曲
 *
 * @param context
 * @return
 */
public static Observable<List<Music>> getFavoriteSong(final Context context) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    String sql = "select * from " + DBData.MUSIC_TABLE + " where " + DBData.IS_LOVE + "= 1";
    Cursor cursor = dbDaoImpl.makeCursor(sql);
    return getSongsForCursor(context, cursor);
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Cursor(android.database.Cursor)

Example 12 with DBDaoImpl

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

the class SongLoader method updateFavoriteSong.

public static Observable<Music> updateFavoriteSong(final Context context, Music music) {
    return Observable.create(subscriber -> {
        try {
            DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
            music.setLove(!music.isLove());
            dbDaoImpl.insertSong(music);
            dbDaoImpl.updateSong(music);
            dbDaoImpl.closeDB();
            subscriber.onNext(music);
            subscriber.onComplete();
        } catch (Exception e) {
            subscriber.onError(e);
        }
    });
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl)

Example 13 with DBDaoImpl

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

the class SongLoader method getSongsForMedia.

/**
 * Android 扫描获取到的数据
 *
 * @param context
 * @param cursor
 * @return
 */
public static Observable<List<Music>> getSongsForMedia(Context context, final Cursor cursor) {
    return Observable.create(subscriber -> {
        DBDaoImpl dbDao = new DBDaoImpl(context);
        List<Music> results = new ArrayList<>();
        try {
            if ((cursor != null) && (cursor.moveToFirst())) {
                do {
                    int is_music = cursor.getInt(9);
                    long id = cursor.getLong(0);
                    String title = cursor.getString(1);
                    String artist = cursor.getString(2);
                    String album = cursor.getString(3);
                    int duration = cursor.getInt(4);
                    int trackNumber = cursor.getInt(5);
                    String artistId = cursor.getString(6);
                    long albumId = cursor.getLong(7);
                    String path = cursor.getString(8);
                    String coverUri = CoverLoader.getInstance().getCoverUri(context, albumId);
                    Music music = dbDao.getMusicInfo(id + "");
                    if (music != null) {
                        if (coverUri != null) {
                            music.setCoverUri(coverUri);
                        }
                    } else {
                        music = new Music(id, albumId, artistId, title, artist, album, duration, trackNumber, path);
                    }
                    results.add(music);
                } while (cursor.moveToNext());
            }
            if (cursor != null) {
                cursor.close();
            }
            subscriber.onNext(results);
            subscriber.onComplete();
        } catch (Exception e) {
            subscriber.onError(e);
        }
    });
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Music(com.cyl.musiclake.bean.Music) ArrayList(java.util.ArrayList)

Example 14 with DBDaoImpl

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

the class AlbumSongLoader method getSongsForAlbumDB.

public static Observable<List<Music>> getSongsForAlbumDB(final Context context, final Cursor cursor) {
    return Observable.create(subscriber -> {
        DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
        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)

Example 15 with DBDaoImpl

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

the class ArtistSongLoader method getSongsForArtist.

/**
 * 获取艺术家所有歌曲
 *
 * @param context
 * @return
 */
public static Observable<List<Music>> getSongsForArtist(Context context, String artistName) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    String sql = "SELECT * FROM music where music.is_online=0 and artist like '%" + artistName + "%'";
    Cursor cursor = dbDaoImpl.makeCursor(sql);
    return getSongsForArtistDB(context, cursor);
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Cursor(android.database.Cursor)

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