Search in sources :

Example 31 with DBDaoImpl

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

the class SongLoader method removeSong.

/**
 * 删除歌曲
 */
public static void removeSong(Context context, Music music) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    dbDaoImpl.deleteSongForId(music.getId());
    dbDaoImpl.closeDB();
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl)

Example 32 with DBDaoImpl

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

the class SongLoader method getSongsForDB.

public static List<Music> getSongsForDB(Context context) {
    DBDaoImpl dbDaoImpl = new DBDaoImpl(context);
    String sql = "select * from " + DBData.MUSIC_TABLE;
    Cursor cursor = dbDaoImpl.makeCursor(sql);
    return dbDaoImpl.getSongsForCursor(cursor);
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Cursor(android.database.Cursor)

Example 33 with DBDaoImpl

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

the class SongLoader method getSongsForDB.

/**
 * Android 扫描获取到的数据
 *
 * @param context
 * @param cursor
 * @return
 */
public static Observable<List<Music>> getSongsForDB(Context context, final Cursor cursor) {
    DBDaoImpl dbDao = new DBDaoImpl(context);
    if ((cursor != null) && (cursor.moveToFirst())) {
        do {
            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);
                    updateMusic(dbDao, music);
                }
            } else {
                music = new Music(id, albumId, artistId, title, artist, album, duration, trackNumber, path);
                dbDao.insertSong(music);
            }
        } while (cursor.moveToNext());
    }
    if (cursor != null) {
        cursor.close();
    }
    String sql = "select * from " + DBData.MUSIC_TABLE + " where " + DBData.IS_ONLINE + "=0";
    Cursor mCursor = dbDao.makeCursor(sql);
    return getSongsForCursor(context, mCursor);
}
Also used : DBDaoImpl(com.cyl.musiclake.data.source.db.DBDaoImpl) Music(com.cyl.musiclake.bean.Music) 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