mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-25 06:25:40 +03:00
finish migration to room: remove requery
Resolves #2244 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
125d6770b4
commit
66b2d44739
10 changed files with 29 additions and 267 deletions
|
@ -246,10 +246,7 @@ dependencies {
|
|||
compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
|
||||
// Android only
|
||||
implementation 'org.greenrobot:eventbus:3.3.1'
|
||||
implementation 'io.requery:requery:1.6.1'
|
||||
implementation 'io.requery:requery-android:1.6.1'
|
||||
implementation 'net.zetetic:android-database-sqlcipher:4.5.1'
|
||||
kapt 'io.requery:requery-processor:1.6.1'
|
||||
|
||||
implementation "androidx.room:room-runtime:${roomVersion}"
|
||||
implementation "androidx.room:room-rxjava2:${roomVersion}"
|
||||
|
|
|
@ -63,9 +63,6 @@ import io.reactivex.SingleObserver
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.requery.Persistable
|
||||
import io.requery.android.sqlcipher.SqlCipherDatabaseSource
|
||||
import io.requery.reactivex.ReactiveEntityStore
|
||||
import org.parceler.Parcels
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -73,12 +70,6 @@ import javax.inject.Inject
|
|||
class MainActivity : BaseActivity(), ActionBarProvider {
|
||||
lateinit var binding: ActivityMainBinding
|
||||
|
||||
@Inject
|
||||
lateinit var dataStore: ReactiveEntityStore<Persistable>
|
||||
|
||||
@Inject
|
||||
lateinit var sqlCipherDatabaseSource: SqlCipherDatabaseSource
|
||||
|
||||
@Inject
|
||||
lateinit var ncApi: NcApi
|
||||
|
||||
|
@ -103,46 +94,34 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
|||
|
||||
router = Conductor.attachRouter(this, binding.controllerContainer, savedInstanceState)
|
||||
|
||||
var hasDb = true
|
||||
|
||||
try {
|
||||
sqlCipherDatabaseSource.writableDatabase
|
||||
} catch (exception: Exception) {
|
||||
hasDb = false
|
||||
}
|
||||
|
||||
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
|
||||
onNewIntent(intent)
|
||||
} else if (!router!!.hasRootController()) {
|
||||
if (hasDb) {
|
||||
if (!appPreferences.isDbRoomMigrated) {
|
||||
appPreferences.isDbRoomMigrated = true
|
||||
if (!appPreferences.isDbRoomMigrated) {
|
||||
appPreferences.isDbRoomMigrated = true
|
||||
}
|
||||
|
||||
userManager.users.subscribe(object : SingleObserver<List<User>> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
userManager.users.subscribe(object : SingleObserver<List<User>> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onSuccess(users: List<User>) {
|
||||
if (users.isNotEmpty()) {
|
||||
runOnUiThread {
|
||||
setDefaultRootController()
|
||||
}
|
||||
} else {
|
||||
runOnUiThread {
|
||||
launchLoginScreen()
|
||||
}
|
||||
override fun onSuccess(users: List<User>) {
|
||||
if (users.isNotEmpty()) {
|
||||
runOnUiThread {
|
||||
setDefaultRootController()
|
||||
}
|
||||
} else {
|
||||
runOnUiThread {
|
||||
launchLoginScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error loading existing users", e)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
launchLoginScreen()
|
||||
}
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error loading existing users", e)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ import com.facebook.cache.disk.DiskCacheConfig
|
|||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.imagepipeline.core.ImagePipelineConfig
|
||||
import com.nextcloud.talk.BuildConfig
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.components.filebrowser.webdav.DavUtils
|
||||
import com.nextcloud.talk.dagger.modules.BusModule
|
||||
import com.nextcloud.talk.dagger.modules.ContextModule
|
||||
|
@ -62,7 +61,6 @@ import com.nextcloud.talk.dagger.modules.ViewModelModule
|
|||
import com.nextcloud.talk.jobs.AccountRemovalWorker
|
||||
import com.nextcloud.talk.jobs.CapabilitiesWorker
|
||||
import com.nextcloud.talk.jobs.SignalingSettingsWorker
|
||||
import com.nextcloud.talk.models.database.Models
|
||||
import com.nextcloud.talk.utils.ClosedInterfaceImpl
|
||||
import com.nextcloud.talk.utils.DeviceUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
|
@ -76,17 +74,14 @@ import com.vanniktech.emoji.EmojiManager
|
|||
import com.vanniktech.emoji.google.GoogleEmojiProvider
|
||||
import de.cotech.hw.SecurityKeyManager
|
||||
import de.cotech.hw.SecurityKeyManagerConfig
|
||||
import io.requery.android.sqlcipher.SqlCipherDatabaseSource
|
||||
import net.sqlcipher.database.SQLiteDatabase
|
||||
import net.sqlcipher.database.SQLiteDatabaseHook
|
||||
import net.sqlcipher.database.SQLiteOpenHelper
|
||||
import okhttp3.OkHttpClient
|
||||
import org.conscrypt.Conscrypt
|
||||
import org.webrtc.PeerConnectionFactory
|
||||
import org.webrtc.voiceengine.WebRtcAudioManager
|
||||
import org.webrtc.voiceengine.WebRtcAudioUtils
|
||||
import java.security.Security
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -172,8 +167,6 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {
|
|||
|
||||
componentApplication.inject(this)
|
||||
|
||||
checkAndUpgradeDbCypher()
|
||||
|
||||
Coil.setImageLoader(buildDefaultImageLoader())
|
||||
setAppTheme(appPreferences.theme)
|
||||
super.onCreate()
|
||||
|
@ -262,47 +255,6 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {
|
|||
.build()
|
||||
}
|
||||
|
||||
private fun checkAndUpgradeDbCypher() {
|
||||
if (appPreferences.isDbCypherToUpgrade) {
|
||||
val database = object : SqlCipherDatabaseSource(
|
||||
this,
|
||||
Models.DEFAULT,
|
||||
this
|
||||
.resources
|
||||
.getString(R.string.nc_app_product_name)
|
||||
.lowercase(Locale.getDefault())
|
||||
.replace(" ", "_")
|
||||
.trim { it <= ' ' } +
|
||||
".sqlite",
|
||||
this.getString(R.string.nc_talk_database_encryption_key),
|
||||
DatabaseModule.DB_VERSION
|
||||
) {
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
checkAndUpdateCipherMigrationStatus(newVersion, appPreferences)
|
||||
super.onUpgrade(db, oldVersion, newVersion)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
val field = SQLiteOpenHelper::class.java.getDeclaredField("mHook")
|
||||
field.isAccessible = true
|
||||
field.set(database, hook)
|
||||
} catch (e: NoSuchFieldException) {
|
||||
Log.e("SqlCipherDatabaseSource", "Error accessing mHook field")
|
||||
} catch (e: IllegalAccessException) {
|
||||
Log.e("SqlCipherDatabaseSource", "Error setting mHook field")
|
||||
}
|
||||
|
||||
checkAndUpdateCipherMigrationStatus(database.writableDatabase.version, appPreferences)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAndUpdateCipherMigrationStatus(version: Int, appPreferences: AppPreferences) {
|
||||
if (version >= CIPHER_V4_MIGRATION && appPreferences.isDbCypherToUpgrade) {
|
||||
appPreferences.isDbCypherToUpgrade = false
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = NextcloudTalkApplication::class.java.simpleName
|
||||
const val FIFTY_PERCENT = 0.5
|
||||
|
|
|
@ -67,8 +67,6 @@ import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder
|
|||
import com.nextcloud.talk.utils.ssl.MagicTrustManager
|
||||
import de.cotech.hw.fido.WebViewFidoBridge
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.requery.Persistable
|
||||
import io.requery.reactivex.ReactiveEntityStore
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.lang.reflect.Field
|
||||
import java.net.CookieManager
|
||||
|
@ -89,9 +87,6 @@ class WebViewLoginController(args: Bundle? = null) : NewBaseController(
|
|||
@Inject
|
||||
lateinit var userManager: UserManager
|
||||
|
||||
@Inject
|
||||
lateinit var dataStore: ReactiveEntityStore<Persistable>
|
||||
|
||||
@Inject
|
||||
lateinit var magicTrustManager: MagicTrustManager
|
||||
|
||||
|
|
|
@ -22,66 +22,20 @@
|
|||
package com.nextcloud.talk.dagger.modules;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.nextcloud.talk.R;
|
||||
|
||||
import com.nextcloud.talk.data.source.local.TalkDatabase;
|
||||
import com.nextcloud.talk.models.database.Models;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.android.sqlcipher.SqlCipherDatabaseSource;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import io.requery.reactivex.ReactiveSupport;
|
||||
import io.requery.sql.Configuration;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
|
||||
import net.orange_box.storebox.StoreBox;
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class DatabaseModule {
|
||||
public static final int DB_VERSION = 7;
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SqlCipherDatabaseSource provideSqlCipherDatabaseSource(
|
||||
@NonNull final Context context,
|
||||
final AppPreferences appPreferences) {
|
||||
int version = DB_VERSION;
|
||||
if (appPreferences.getIsDbRoomMigrated()) {
|
||||
version++;
|
||||
}
|
||||
return new SqlCipherDatabaseSource(
|
||||
context,
|
||||
Models.DEFAULT,
|
||||
context
|
||||
.getResources()
|
||||
.getString(R.string.nc_app_product_name)
|
||||
.toLowerCase()
|
||||
.replace(" ", "_")
|
||||
.trim()
|
||||
+ ".sqlite",
|
||||
context.getString(R.string.nc_talk_database_encryption_key),
|
||||
version) {
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (newVersion < 7) {
|
||||
super.onDowngrade(db, oldVersion, newVersion);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public ReactiveEntityStore<Persistable> provideDataStore(
|
||||
@NonNull final SqlCipherDatabaseSource sqlCipherDatabaseSource) {
|
||||
final Configuration configuration = sqlCipherDatabaseSource.getConfiguration();
|
||||
return ReactiveSupport.toReactiveStore(new EntityDataStore<>(configuration));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public AppPreferences providePreferences(@NonNull final Context poContext) {
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.models.database;
|
||||
|
||||
import android.os.Parcelable;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Legacy arbitrary storage entity, please migrate to {@link com.nextcloud.talk.data.storage.model.ArbitraryStorage}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Entity
|
||||
public interface ArbitraryStorage extends Parcelable, Persistable, Serializable {
|
||||
@Key
|
||||
long getAccountIdentifier();
|
||||
|
||||
String getKey();
|
||||
|
||||
String getObject();
|
||||
|
||||
String getValue();
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* @author Andy Scherzinger
|
||||
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
|
||||
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.talk.models.database;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.requery.Entity;
|
||||
import io.requery.Generated;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
|
||||
/**
|
||||
* Legacy user entity, please migrate to {@link com.nextcloud.talk.data.user.model.User}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Entity
|
||||
public interface User extends Parcelable, Persistable, Serializable {
|
||||
String TAG = "UserEntity";
|
||||
|
||||
@Key
|
||||
@Generated
|
||||
long getId();
|
||||
|
||||
String getUserId();
|
||||
|
||||
String getUsername();
|
||||
|
||||
String getBaseUrl();
|
||||
|
||||
String getToken();
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
String getPushConfigurationState();
|
||||
|
||||
String getCapabilities();
|
||||
|
||||
String getClientCertificate();
|
||||
|
||||
String getExternalSignalingServer();
|
||||
|
||||
boolean getCurrent();
|
||||
|
||||
boolean getScheduledForDeletion();
|
||||
}
|
|
@ -32,7 +32,6 @@ import com.nextcloud.talk.R;
|
|||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.data.user.model.User;
|
||||
import com.nextcloud.talk.models.RetrofitBucket;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
|
@ -81,7 +81,6 @@ import com.nextcloud.talk.R;
|
|||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.data.user.model.User;
|
||||
import com.nextcloud.talk.events.UserMentionClickEvent;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.utils.text.Spans;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
@ -93,7 +92,6 @@ import java.text.DateFormat;
|
|||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
|
@ -19,18 +19,16 @@
|
|||
*/
|
||||
package com.nextcloud.talk.utils.database.arbitrarystorage;
|
||||
|
||||
import autodagger.AutoInjector;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager;
|
||||
import com.nextcloud.talk.dagger.modules.DatabaseModule;
|
||||
import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import autodagger.AutoInjector;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Module(includes = DatabaseModule.class)
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
|
|
Loading…
Reference in a new issue