Search in sources :

Example 91 with ContentValues

use of android.content.ContentValues in project remusic by aa112901.

the class DownFileStore method update.

public synchronized void update(DownloadDBEntity entity) {
    final SQLiteDatabase database = mMusicDatabase.getWritableDatabase();
    database.beginTransaction();
    try {
        ContentValues values = new ContentValues(6);
        values.put(DownFileStoreColumns.TOOL_SIZE, entity.getTotalSize());
        values.put(DownFileStoreColumns.FILE_LENGTH, entity.getCompletedSize());
        values.put(DownFileStoreColumns.URL, entity.getUrl());
        values.put(DownFileStoreColumns.DIR, entity.getSaveDirPath());
        values.put(DownFileStoreColumns.FILE_NAME, entity.getFileName());
        values.put(DownFileStoreColumns.DOWNSTATUS, entity.getDownloadStatus());
        database.update(DownFileStoreColumns.NAME, values, DownFileStoreColumns.ID + " = ?", new String[] { entity.getDownloadId() });
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 92 with ContentValues

use of android.content.ContentValues in project remusic by aa112901.

the class MusicPlaybackState method Insert.

public synchronized void Insert(MusicTrack track) {
    final SQLiteDatabase database = mMusicDatabase.getWritableDatabase();
    database.beginTransaction();
    try {
        ContentValues values = new ContentValues(2);
        values.put(PlaybackQueueColumns.TRACK_ID, track.mId);
        values.put(PlaybackQueueColumns.SOURCE_POSITION, track.mSourcePosition);
        database.insert(PlaybackQueueColumns.NAME, null, values);
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 93 with ContentValues

use of android.content.ContentValues in project remusic by aa112901.

the class PlaylistsManager method insertLists.

public synchronized void insertLists(Context context, long playlistid, ArrayList<MusicInfo> musicInfos) {
    final SQLiteDatabase database = mMusicDatabase.getWritableDatabase();
    database.beginTransaction();
    int len = musicInfos.size();
    try {
        for (int i = 0; i < len; i++) {
            MusicInfo info = musicInfos.get(i);
            ContentValues values = new ContentValues(11);
            values.put(PlaylistsColumns.PLAYLIST_ID, playlistid);
            values.put(PlaylistsColumns.TRACK_ID, info.songId);
            values.put(PlaylistsColumns.TRACK_ORDER, getPlaylist(playlistid).size());
            values.put(PlaylistsColumns.TRACK_NAME, info.musicName);
            values.put(PlaylistsColumns.ALBUM_ID, info.albumId);
            values.put(PlaylistsColumns.ALBUM_NAME, info.albumName);
            values.put(PlaylistsColumns.ALBUM_ART, info.albumData);
            values.put(PlaylistsColumns.ARTIST_NAME, info.artist);
            values.put(PlaylistsColumns.ARTIST_ID, info.artistId);
            values.put(PlaylistsColumns.PATH, info.data);
            values.put(PlaylistsColumns.IS_LOCAL, info.islocal);
            database.insertWithOnConflict(PlaylistsColumns.NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        }
        database.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        database.endTransaction();
    }
    PlaylistInfo playlistInfo = PlaylistInfo.getInstance(context);
    String albumart = null;
    for (int i = len - 1; i >= 0; i--) {
        MusicInfo info = musicInfos.get(i);
        albumart = info.albumData;
        if (info.islocal) {
            String art = MusicUtils.getAlbumdata(MainApplication.context, info.songId);
            if (art != null) {
                break;
            } else {
                albumart = null;
            }
        } else if (!albumart.isEmpty()) {
            break;
        }
    }
    if (albumart != null) {
        playlistInfo.update(playlistid, getPlaylist(playlistid).size(), albumart);
    } else {
        playlistInfo.update(playlistid, getPlaylist(playlistid).size());
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 94 with ContentValues

use of android.content.ContentValues in project remusic by aa112901.

the class MusicPlayer method createPlaylist.

public static final long createPlaylist(final Context context, final String name) {
    if (name != null && name.length() > 0) {
        final ContentResolver resolver = context.getContentResolver();
        final String[] projection = new String[] { MediaStore.Audio.PlaylistsColumns.NAME };
        final String selection = MediaStore.Audio.PlaylistsColumns.NAME + " = '" + name + "'";
        Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null);
        if (cursor.getCount() <= 0) {
            final ContentValues values = new ContentValues(1);
            values.put(MediaStore.Audio.PlaylistsColumns.NAME, name);
            final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values);
            return Long.parseLong(uri.getLastPathSegment());
        }
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
        return -1;
    }
    return -1;
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 95 with ContentValues

use of android.content.ContentValues in project remusic by aa112901.

the class PlaylistsManager method update.

public synchronized void update(long playlistid, long[] ids, int[] order) {
    final SQLiteDatabase database = mMusicDatabase.getWritableDatabase();
    database.beginTransaction();
    try {
        for (int i = 0; i < order.length; i++) {
            ContentValues values = new ContentValues(1);
            values.put(PlaylistsColumns.TRACK_ORDER, order[i]);
            database.update(PlaylistsColumns.NAME, values, PlaylistsColumns.PLAYLIST_ID + " = ?" + " AND " + PlaylistsColumns.TRACK_ID + " = ?", new String[] { playlistid + "", ids[i] + "" });
        }
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

ContentValues (android.content.ContentValues)3993 Cursor (android.database.Cursor)720 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)638 Uri (android.net.Uri)619 Test (org.junit.Test)374 SQLException (android.database.SQLException)231 ContentResolver (android.content.ContentResolver)212 ArrayList (java.util.ArrayList)192 Intent (android.content.Intent)162 File (java.io.File)156 IOException (java.io.IOException)131 RemoteException (android.os.RemoteException)96 CursorAssert.assertThatCursor (org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor)91 NonNull (android.support.annotation.NonNull)74 Date (java.util.Date)73 MediumTest (android.test.suitebuilder.annotation.MediumTest)63 HashMap (java.util.HashMap)62 JSONException (org.json.JSONException)60 SQLiteException (android.database.sqlite.SQLiteException)53 ContentProviderOperation (android.content.ContentProviderOperation)49