use of com.simplecity.amp_library.sql.legacy.BlacklistedSong 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);
}
Aggregations