Search in sources :

Example 1 with WhitelistFolder

use of com.simplecity.amp_library.sql.legacy.WhitelistFolder in project Shuttle by timusus.

the class InclExclDbOpenHelper method onCreate.

@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE_WHITELIST);
    // It's OK to block here, we're already on a background thread. Not sure if this is a given
    // with SQLiteOpenHelper, but certainly since we're using SqlBrite, we're safe. We need to block
    // so we can complete the SQL transaction in the onCreate() block, allowing the framework to commit
    // the transaction (which happens after this method is called).
    // Blacklist
    List<BlacklistedSong> blacklistedSongs = LegacyDatabaseUtils.getBlacklistSongsObservable().blockingGet();
    if (!blacklistedSongs.isEmpty()) {
        List<Song> allSongs = DataManager.getInstance().getAllSongsRelay().first(Collections.emptyList()).blockingGet();
        Stream.of(allSongs).filter(song -> Stream.of(blacklistedSongs).anyMatch(blacklistedSong -> blacklistedSong.songId == song.id)).forEach(song -> {
            ContentValues contentValues = new ContentValues(2);
            contentValues.put(InclExclDbOpenHelper.COLUMN_PATH, song.path);
            contentValues.put(InclExclDbOpenHelper.COLUMN_TYPE, InclExclItem.Type.EXCLUDE);
            database.insert(TABLE_NAME, null, contentValues);
        });
    }
    // Whitelist
    List<WhitelistFolder> whitelistFolders = LegacyDatabaseUtils.getWhitelistFolders().blockingGet();
    Stream.of(whitelistFolders).forEach(whitelistFolder -> {
        ContentValues contentValues = new ContentValues(2);
        contentValues.put(InclExclDbOpenHelper.COLUMN_PATH, whitelistFolder.folder);
        contentValues.put(InclExclDbOpenHelper.COLUMN_TYPE, InclExclItem.Type.INCLUDE);
        database.insert(TABLE_NAME, null, contentValues);
    });
    ShuttleApplication.getInstance().deleteDatabase(BlacklistDbOpenHelper.DATABASE_NAME);
    ShuttleApplication.getInstance().deleteDatabase(WhitelistDbOpenHelper.DATABASE_NAME);
}
Also used : Context(android.content.Context) LegacyDatabaseUtils(com.simplecity.amp_library.sql.legacy.LegacyDatabaseUtils) Stream(com.annimon.stream.Stream) WhitelistFolder(com.simplecity.amp_library.sql.legacy.WhitelistFolder) BlacklistedSong(com.simplecity.amp_library.sql.legacy.BlacklistedSong) WhitelistDbOpenHelper(com.simplecity.amp_library.sql.legacy.WhitelistDbOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) Song(com.simplecity.amp_library.model.Song) List(java.util.List) SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) DataManager(com.simplecity.amp_library.utils.DataManager) BlacklistDbOpenHelper(com.simplecity.amp_library.sql.legacy.BlacklistDbOpenHelper) ContentValues(android.content.ContentValues) InclExclItem(com.simplecity.amp_library.model.InclExclItem) Collections(java.util.Collections) ContentValues(android.content.ContentValues) BlacklistedSong(com.simplecity.amp_library.sql.legacy.BlacklistedSong) Song(com.simplecity.amp_library.model.Song) BlacklistedSong(com.simplecity.amp_library.sql.legacy.BlacklistedSong) WhitelistFolder(com.simplecity.amp_library.sql.legacy.WhitelistFolder)

Aggregations

ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)1 Stream (com.annimon.stream.Stream)1 ShuttleApplication (com.simplecity.amp_library.ShuttleApplication)1 InclExclItem (com.simplecity.amp_library.model.InclExclItem)1 Song (com.simplecity.amp_library.model.Song)1 BlacklistDbOpenHelper (com.simplecity.amp_library.sql.legacy.BlacklistDbOpenHelper)1 BlacklistedSong (com.simplecity.amp_library.sql.legacy.BlacklistedSong)1 LegacyDatabaseUtils (com.simplecity.amp_library.sql.legacy.LegacyDatabaseUtils)1 WhitelistDbOpenHelper (com.simplecity.amp_library.sql.legacy.WhitelistDbOpenHelper)1 WhitelistFolder (com.simplecity.amp_library.sql.legacy.WhitelistFolder)1 DataManager (com.simplecity.amp_library.utils.DataManager)1 Collections (java.util.Collections)1 List (java.util.List)1