mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
DB version switcher for requery
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
d55c3fa68e
commit
f7ca1ec804
@ -116,6 +116,9 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
|||||||
onNewIntent(intent)
|
onNewIntent(intent)
|
||||||
} else if (!router!!.hasRootController()) {
|
} else if (!router!!.hasRootController()) {
|
||||||
if (hasDb) {
|
if (hasDb) {
|
||||||
|
if (!appPreferences.isDbRoomMigrated) {
|
||||||
|
appPreferences.isDbRoomMigrated = true
|
||||||
|
}
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
usersRepository.getUsers().collect {
|
usersRepository.getUsers().collect {
|
||||||
if (it.isNotEmpty()) {
|
if (it.isNotEmpty()) {
|
||||||
|
@ -36,16 +36,23 @@ import io.requery.reactivex.ReactiveSupport;
|
|||||||
import io.requery.sql.Configuration;
|
import io.requery.sql.Configuration;
|
||||||
import io.requery.sql.EntityDataStore;
|
import io.requery.sql.EntityDataStore;
|
||||||
import net.orange_box.storebox.StoreBox;
|
import net.orange_box.storebox.StoreBox;
|
||||||
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class DatabaseModule {
|
public class DatabaseModule {
|
||||||
public static final int DB_VERSION = 8;
|
public static final int DB_VERSION = 7;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public SqlCipherDatabaseSource provideSqlCipherDatabaseSource(@NonNull final Context context) {
|
public SqlCipherDatabaseSource provideSqlCipherDatabaseSource(
|
||||||
|
@NonNull final Context context,
|
||||||
|
final AppPreferences appPreferences) {
|
||||||
|
int version = DB_VERSION;
|
||||||
|
if (appPreferences.getIsDbRoomMigrated()) {
|
||||||
|
version++;
|
||||||
|
}
|
||||||
return new SqlCipherDatabaseSource(
|
return new SqlCipherDatabaseSource(
|
||||||
context,
|
context,
|
||||||
Models.DEFAULT,
|
Models.DEFAULT,
|
||||||
@ -57,7 +64,14 @@ public class DatabaseModule {
|
|||||||
.trim()
|
.trim()
|
||||||
+ ".sqlite",
|
+ ".sqlite",
|
||||||
context.getString(R.string.nc_talk_database_encryption_key),
|
context.getString(R.string.nc_talk_database_encryption_key),
|
||||||
DB_VERSION);
|
version) {
|
||||||
|
@Override
|
||||||
|
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
if (newVersion < 7) {
|
||||||
|
super.onDowngrade(db, oldVersion, newVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@ -71,7 +85,7 @@ public class DatabaseModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public AppPreferences providePreferences(@NonNull final Context poContext) {
|
public AppPreferences providePreferences(@NonNull final Context poContext) {
|
||||||
AppPreferences preferences = StoreBox.create(poContext, AppPreferences.class);
|
AppPreferences preferences = StoreBox.create(poContext, AppPreferences.class);
|
||||||
preferences.removeLinkPreviews();
|
preferences.removeLinkPreviews();
|
||||||
return preferences;
|
return preferences;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +288,13 @@ public interface AppPreferences {
|
|||||||
|
|
||||||
@KeyByString("db_cypher_v4_upgrade")
|
@KeyByString("db_cypher_v4_upgrade")
|
||||||
void setIsDbCypherToUpgrade(boolean value);
|
void setIsDbCypherToUpgrade(boolean value);
|
||||||
|
|
||||||
|
@KeyByString("db_room_migrated")
|
||||||
|
@DefaultValue(R.bool.value_false)
|
||||||
|
boolean getIsDbRoomMigrated();
|
||||||
|
|
||||||
|
@KeyByString("db_room_migrated")
|
||||||
|
void setIsDbRoomMigrated(boolean value);
|
||||||
|
|
||||||
@KeyByResource(R.string.nc_settings_phone_book_integration_key)
|
@KeyByResource(R.string.nc_settings_phone_book_integration_key)
|
||||||
@RegisterChangeListenerMethod
|
@RegisterChangeListenerMethod
|
||||||
|
Loading…
Reference in New Issue
Block a user