mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Inject element where they are used
This commit is contained in:
parent
abbc62dd35
commit
d2b9668d4e
2 changed files with 9 additions and 8 deletions
|
@ -18,6 +18,8 @@ package im.vector.matrix.android.internal.database
|
|||
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.internal.database.model.SessionRealmModule
|
||||
import im.vector.matrix.android.internal.di.UserCacheDirectory
|
||||
import im.vector.matrix.android.internal.di.UserMd5
|
||||
import im.vector.matrix.android.internal.session.SessionModule
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
|
@ -33,17 +35,19 @@ private const val REALM_SHOULD_CLEAR_FLAG_ = "REALM_SHOULD_CLEAR_FLAG_"
|
|||
* It's clearly not perfect but there is no way to catch the native crash.
|
||||
*/
|
||||
internal class SessionRealmConfigurationFactory @Inject constructor(private val realmKeysUtils: RealmKeysUtils,
|
||||
@UserCacheDirectory val directory: File,
|
||||
@UserMd5 val userMd5: String,
|
||||
context: Context) {
|
||||
|
||||
private val sharedPreferences = context.getSharedPreferences("im.vector.matrix.android.realm", Context.MODE_PRIVATE)
|
||||
|
||||
|
||||
fun create(directory: File, userMd5: String): RealmConfiguration {
|
||||
fun create(): RealmConfiguration {
|
||||
val shouldClearRealm = sharedPreferences.getBoolean("$REALM_SHOULD_CLEAR_FLAG_$userMd5", false)
|
||||
if (shouldClearRealm) {
|
||||
Timber.v("************************************************************")
|
||||
Timber.v("The realm file session was corrupted and couldn't be loaded. ")
|
||||
Timber.v("The file has been deleted to recover. ")
|
||||
Timber.v("The realm file session was corrupted and couldn't be loaded.")
|
||||
Timber.v("The file has been deleted to recover.")
|
||||
Timber.v("************************************************************")
|
||||
directory.deleteRecursively()
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesSer
|
|||
import im.vector.matrix.android.api.session.securestorage.SecureStorageService
|
||||
import im.vector.matrix.android.internal.database.LiveEntityObserver
|
||||
import im.vector.matrix.android.internal.database.SessionRealmConfigurationFactory
|
||||
import im.vector.matrix.android.internal.database.model.SessionRealmModule
|
||||
import im.vector.matrix.android.internal.di.*
|
||||
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
|
||||
import im.vector.matrix.android.internal.network.RetrofitFactory
|
||||
|
@ -95,10 +94,8 @@ internal abstract class SessionModule {
|
|||
@Provides
|
||||
@SessionDatabase
|
||||
@SessionScope
|
||||
fun providesRealmConfiguration(realmConfigurationFactory: SessionRealmConfigurationFactory,
|
||||
@UserCacheDirectory directory: File,
|
||||
@UserMd5 userMd5: String): RealmConfiguration {
|
||||
return realmConfigurationFactory.create(directory, userMd5)
|
||||
fun providesRealmConfiguration(realmConfigurationFactory: SessionRealmConfigurationFactory): RealmConfiguration {
|
||||
return realmConfigurationFactory.create()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
|
Loading…
Reference in a new issue