From e06afc03c0f17bdb609e03203abea4fa56e5366f Mon Sep 17 00:00:00 2001 From: Dima Date: Tue, 30 Jul 2024 01:34:17 +0900 Subject: [PATCH] Improvements to the number of instances used and memory allocation required for Realm DB operations: 1. Number of Realm instances was growing uncontrollably due to not explicitly being closed at the end of a series of DB Operations in some places throughout the app. 2. Instead of creating two instances of DbWrapper and configuring them for Main DB and the one used for translations and distinguishing between them using @BundleDataDb annotation, now separate DbWrapperMain and DbWrapperBundle classes are used to eliminate a possibility of using a wrong instance. 3. Removing unnecessary child coroutine scopes that was used in SyncActions. Upping versionCode to 85 --- .../android/api/annotations/BundleDataDb.java | 12 --- .../android/api/module/GeneralModule.kt | 17 ---- .../android/architecture/BaseViewModel2.kt | 33 ++++--- .../toolbar/SyncToolbarViewModel.kt | 6 +- .../AttachmentDownloader.kt | 6 +- .../org/zotero/android/database/Database.kt | 3 +- .../org/zotero/android/database/DbWrapper.kt | 48 ---------- .../android/database/DbWrapperBundle.kt | 21 +++++ .../zotero/android/database/DbWrapperMain.kt | 32 +++++++ .../zotero/android/database/RealmDbStorage.kt | 9 +- .../android/pdf/reader/PdfReaderViewModel.kt | 18 ++-- .../screens/allitems/AllItemsViewModel.kt | 22 ++--- .../allitems/processor/AllItemsProcessor.kt | 6 +- .../collectionedit/CollectionEditViewModel.kt | 6 +- .../CollectionPickerViewModel.kt | 6 +- .../collections/CollectionsViewModel.kt | 12 +-- .../screens/dashboard/DashboardViewModel.kt | 10 +- .../android/screens/filter/FilterViewModel.kt | 14 ++- .../itemdetails/ItemDetailsViewModel.kt | 44 ++++----- .../screens/libraries/LibrariesViewModel.kt | 6 +- .../account/SettingsAccountViewModel.kt | 6 +- .../screens/share/ShareErrorProcessor.kt | 6 +- .../screens/share/ShareItemSubmitter.kt | 20 ++-- .../android/screens/share/ShareViewModel.kt | 6 +- .../BackgroundUploadProcessor.kt | 8 +- .../ShareCollectionPickerViewModel.kt | 10 +- .../screens/tagpicker/TagPickerViewModel.kt | 6 +- .../sync/AttachmentFileCleanupController.kt | 22 ++--- .../org/zotero/android/sync/Controllers.kt | 17 ++-- .../android/sync/ObjectUserChangeObserver.kt | 6 +- .../zotero/android/sync/SyncBatchProcessor.kt | 10 +- .../org/zotero/android/sync/SyncEngine.kt | 13 ++- .../org/zotero/android/sync/SyncRepository.kt | 8 +- .../zotero/android/sync/UserControllers.kt | 16 ++-- .../android/sync/WebSocketController.kt | 6 +- .../sync/syncactions/DeleteGroupSyncAction.kt | 2 +- .../DeleteWebDavFilesSyncAction.kt | 4 +- .../FetchAndStoreGroupSyncAction.kt | 2 +- .../syncactions/LoadLibraryDataSyncAction.kt | 4 +- .../syncactions/LoadUploadDataSyncAction.kt | 2 +- .../MarkChangesAsResolvedSyncAction.kt | 2 +- .../syncactions/MarkForResyncSyncAction.kt | 2 +- .../MarkGroupAsLocalOnlySyncAction.kt | 2 +- .../MarkGroupForResyncSyncAction.kt | 2 +- .../syncactions/PerformDeletionsSyncAction.kt | 2 +- .../syncactions/RestoreDeletionsSyncAction.kt | 2 +- .../RevertLibraryFilesSyncAction.kt | 6 +- .../RevertLibraryUpdatesSyncAction.kt | 4 +- .../syncactions/StoreVersionSyncAction.kt | 7 +- .../syncactions/SubmitDeletionSyncAction.kt | 4 +- .../syncactions/SubmitUpdateSyncAction.kt | 6 +- .../syncactions/SyncSettingsSyncAction.kt | 2 +- .../syncactions/SyncVersionsSyncAction.kt | 91 +++++++++---------- .../syncactions/UploadAttachmentSyncAction.kt | 8 +- .../sync/syncactions/UploadFixSyncAction.kt | 4 +- .../syncactions/architecture/SyncAction.kt | 4 +- .../SyncActionDependencyProvider.kt | 4 +- .../translator/loader/TranslatorsLoader.kt | 6 +- .../IdentifierLookupController.kt | 12 +-- .../zotero/android/webdav/WebDavController.kt | 6 +- buildSrc/src/main/kotlin/BuildConfig.kt | 2 +- 61 files changed, 324 insertions(+), 359 deletions(-) delete mode 100755 app/src/main/java/org/zotero/android/api/annotations/BundleDataDb.java delete mode 100644 app/src/main/java/org/zotero/android/database/DbWrapper.kt create mode 100644 app/src/main/java/org/zotero/android/database/DbWrapperBundle.kt create mode 100644 app/src/main/java/org/zotero/android/database/DbWrapperMain.kt diff --git a/app/src/main/java/org/zotero/android/api/annotations/BundleDataDb.java b/app/src/main/java/org/zotero/android/api/annotations/BundleDataDb.java deleted file mode 100755 index aa91bde2..00000000 --- a/app/src/main/java/org/zotero/android/api/annotations/BundleDataDb.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.zotero.android.api.annotations; - -import static java.lang.annotation.RetentionPolicy.CLASS; - -import java.lang.annotation.Retention; - -import javax.inject.Qualifier; - -@Qualifier -@Retention(CLASS) -public @interface BundleDataDb { -} diff --git a/app/src/main/java/org/zotero/android/api/module/GeneralModule.kt b/app/src/main/java/org/zotero/android/api/module/GeneralModule.kt index 8f1acc62..f4aa2641 100644 --- a/app/src/main/java/org/zotero/android/api/module/GeneralModule.kt +++ b/app/src/main/java/org/zotero/android/api/module/GeneralModule.kt @@ -12,13 +12,11 @@ import dagger.Module import dagger.Provides import dagger.hilt.migration.DisableInstallInCheck import kotlinx.serialization.json.Json -import org.zotero.android.api.annotations.BundleDataDb import org.zotero.android.api.annotations.ForGsonWithRoundedDecimals import org.zotero.android.api.network.InternetConnectionStatusManager import org.zotero.android.api.network.internetConnectionStatus import org.zotero.android.architecture.serialization.SealedClassTypeAdapter import org.zotero.android.architecture.serialization.UriTypeAdapter -import org.zotero.android.database.DbWrapper import org.zotero.android.files.FormattedDoubleJsonSerializer import javax.inject.Singleton import kotlin.jvm.internal.Reflection @@ -78,19 +76,4 @@ object GeneralModule { gsonBuilder.registerTypeAdapter(type, FormattedDoubleJsonSerializer()) return gsonBuilder.create() } - - @Provides - @Singleton - fun provideDbWrapper( - ): DbWrapper { - return DbWrapper() - } - - @Provides - @Singleton - @BundleDataDb - fun provideBundleDataDbWrapper( - ): DbWrapper { - return DbWrapper() - } } diff --git a/app/src/main/java/org/zotero/android/architecture/BaseViewModel2.kt b/app/src/main/java/org/zotero/android/architecture/BaseViewModel2.kt index 228ba908..aea83362 100644 --- a/app/src/main/java/org/zotero/android/architecture/BaseViewModel2.kt +++ b/app/src/main/java/org/zotero/android/architecture/BaseViewModel2.kt @@ -8,7 +8,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.zotero.android.database.DbRequest import org.zotero.android.database.DbResponseRequest -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import timber.log.Timber abstract class BaseViewModel2( @@ -111,24 +111,31 @@ abstract class BaseViewModel2( } } - suspend fun perform(dbWrapper: DbWrapper, request: DbRequest):Result = withContext(Dispatchers.IO) { - try { - dbWrapper.realmDbStorage.perform(request) - Result.Success(Unit) + suspend fun perform(dbWrapper: DbWrapperMain, request: DbRequest): Result = + withContext(Dispatchers.IO) { + try { + dbWrapper.realmDbStorage.perform(request) + Result.Success(Unit) }catch (e: Exception) { Result.Failure(e) } } - suspend fun perform(dbWrapper: DbWrapper,writeRequests: List):Result = withContext(Dispatchers.IO) { - try { - dbWrapper.realmDbStorage.perform(writeRequests) - Result.Success(Unit) - }catch (e: Exception) { - Result.Failure(e) - } + + suspend fun perform(dbWrapper: DbWrapperMain, writeRequests: List): Result = + withContext(Dispatchers.IO) { + try { + dbWrapper.realmDbStorage.perform(writeRequests) + Result.Success(Unit) + } catch (e: Exception) { + Result.Failure(e) + } } - suspend inline fun perform(dbWrapper: DbWrapper, invalidateRealm: Boolean, request: DbResponseRequest): Result = withContext(Dispatchers.IO) { + suspend inline fun perform( + dbWrapper: DbWrapperMain, + invalidateRealm: Boolean, + request: DbResponseRequest + ): Result = withContext(Dispatchers.IO) { try { Result.Success(dbWrapper.realmDbStorage.perform(request, invalidateRealm = invalidateRealm)) }catch (e: Exception) { diff --git a/app/src/main/java/org/zotero/android/architecture/navigation/toolbar/SyncToolbarViewModel.kt b/app/src/main/java/org/zotero/android/architecture/navigation/toolbar/SyncToolbarViewModel.kt index e094eed7..216d189c 100644 --- a/app/src/main/java/org/zotero/android/architecture/navigation/toolbar/SyncToolbarViewModel.kt +++ b/app/src/main/java/org/zotero/android/architecture/navigation/toolbar/SyncToolbarViewModel.kt @@ -10,7 +10,7 @@ import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState import org.zotero.android.architecture.navigation.toolbar.data.SyncProgress import org.zotero.android.architecture.navigation.toolbar.data.SyncProgressEventStream -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.ReadGroupDbRequest import org.zotero.android.sync.SyncError import java.util.Timer @@ -19,7 +19,7 @@ import kotlin.concurrent.timerTask @HiltViewModel class SyncToolbarViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val syncProgressEventStream: SyncProgressEventStream, ) : BaseViewModel2(SyncToolbarViewState()) { @@ -127,7 +127,7 @@ class SyncToolbarViewModel @Inject constructor( fun getGroupNameById(groupId: Int): String { val group = - dbWrapper.realmDbStorage.perform(request = ReadGroupDbRequest(identifier = groupId)) + dbWrapperMain.realmDbStorage.perform(request = ReadGroupDbRequest(identifier = groupId)) val groupName = group.name ?: "${groupId}" return groupName } diff --git a/app/src/main/java/org/zotero/android/attachmentdownloader/AttachmentDownloader.kt b/app/src/main/java/org/zotero/android/attachmentdownloader/AttachmentDownloader.kt index edaf467a..617231c5 100644 --- a/app/src/main/java/org/zotero/android/attachmentdownloader/AttachmentDownloader.kt +++ b/app/src/main/java/org/zotero/android/attachmentdownloader/AttachmentDownloader.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.async import org.zotero.android.api.NoRedirectApi import org.zotero.android.api.SyncApi import org.zotero.android.api.network.CustomResult -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.requests.MarkFileAsDownloadedDbRequest import org.zotero.android.files.FileStore @@ -24,7 +24,7 @@ class AttachmentDownloader @Inject constructor( private val syncApi: SyncApi, private val noRedirectApi: NoRedirectApi, private val fileStorage: FileStore, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val attachmentDownloaderEventStream: AttachmentDownloaderEventStream, private val dispatcher: CoroutineDispatcher, private val unzipper: Unzipper, @@ -287,7 +287,7 @@ class AttachmentDownloader @Inject constructor( ) } is CustomResult.GeneralSuccess -> { - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( request = MarkFileAsDownloadedDbRequest( key = download.key, libraryId = download.libraryId, diff --git a/app/src/main/java/org/zotero/android/database/Database.kt b/app/src/main/java/org/zotero/android/database/Database.kt index 2522a4fe..dfd000dd 100644 --- a/app/src/main/java/org/zotero/android/database/Database.kt +++ b/app/src/main/java/org/zotero/android/database/Database.kt @@ -88,8 +88,7 @@ class Database { } - fun bundledDataConfiguration(fileStorage: FileStore): RealmConfiguration { - val dbFile = fileStorage.bundledDataDbFile() + fun bundledDataConfiguration(dbFile: File): RealmConfiguration { val builder = RealmConfiguration.Builder() .directory(dbFile.parentFile!!) .name(dbFile.name) diff --git a/app/src/main/java/org/zotero/android/database/DbWrapper.kt b/app/src/main/java/org/zotero/android/database/DbWrapper.kt deleted file mode 100644 index 562c0f10..00000000 --- a/app/src/main/java/org/zotero/android/database/DbWrapper.kt +++ /dev/null @@ -1,48 +0,0 @@ -package org.zotero.android.database - -import io.realm.Realm -import io.realm.RealmConfiguration -import org.zotero.android.files.FileStore -import java.io.File - -class DbWrapper constructor() { - - lateinit var realmDbStorage: RealmDbStorage - lateinit var config: RealmConfiguration - var isInitialized = false - - fun initWithMainConfiguration(dbFile: File) { - config = Database.mainConfiguration(dbFile = dbFile) - realmDbStorage = RealmDbStorage(config = config) - isInitialized = true - } - - fun initBundleDataConfiguration(fileStorage: FileStore) { - config = Database.bundledDataConfiguration(fileStorage) - realmDbStorage = RealmDbStorage(config = config) - isInitialized = true - } - - fun clearDatabaseFiles() { - val realmInstance = Realm.getInstance(config) - realmInstance.removeAllChangeListeners() - realmInstance.executeTransaction { - realmInstance.deleteAll() - } - println() -// val realmUrls = arrayOf( -// realmUrl, -// "$realmUrl.lock", -// "$realmUrl.note", -// "$realmUrl.management" -// ) -// -// for (url in realmUrls) { -// val file = File(url) -// val wasDeleted = file.deleteRecursively() -// if (file.exists() && !wasDeleted) { -// Timber.e("FileManager: couldn't delete file at $url") -// } -// } - } -} \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/database/DbWrapperBundle.kt b/app/src/main/java/org/zotero/android/database/DbWrapperBundle.kt new file mode 100644 index 00000000..7af0eef2 --- /dev/null +++ b/app/src/main/java/org/zotero/android/database/DbWrapperBundle.kt @@ -0,0 +1,21 @@ +package org.zotero.android.database + +import io.realm.RealmConfiguration +import org.zotero.android.files.FileStore +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class DbWrapperBundle @Inject constructor( + private val fileStore: FileStore +) { + + lateinit var realmDbStorage: RealmDbStorage + lateinit var config: RealmConfiguration + + fun initBundleDataConfiguration() { + val dbFile = fileStore.bundledDataDbFile() + this.config = Database.bundledDataConfiguration(dbFile) + this.realmDbStorage = RealmDbStorage(config) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/database/DbWrapperMain.kt b/app/src/main/java/org/zotero/android/database/DbWrapperMain.kt new file mode 100644 index 00000000..72ac2610 --- /dev/null +++ b/app/src/main/java/org/zotero/android/database/DbWrapperMain.kt @@ -0,0 +1,32 @@ +package org.zotero.android.database + +import io.realm.Realm +import io.realm.RealmConfiguration +import org.zotero.android.files.FileStore +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class DbWrapperMain @Inject constructor( + private val fileStore: FileStore +) { + lateinit var realmDbStorage: RealmDbStorage + lateinit var config: RealmConfiguration + var isInitialized = false + + fun initWithMainConfiguration(userId: Long) { + val dbFile = fileStore.dbFile(userId) + this.config = Database.mainConfiguration(dbFile = dbFile) + this.realmDbStorage = RealmDbStorage(config = config) + isInitialized = true + } + + fun clearDatabaseFiles() { + val realmInstance = Realm.getInstance(config) + realmInstance.removeAllChangeListeners() + realmInstance.executeTransaction { + realmInstance.deleteAll() + } + realmInstance.close() + } +} \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/database/RealmDbStorage.kt b/app/src/main/java/org/zotero/android/database/RealmDbStorage.kt index 040cec53..fff516d2 100644 --- a/app/src/main/java/org/zotero/android/database/RealmDbStorage.kt +++ b/app/src/main/java/org/zotero/android/database/RealmDbStorage.kt @@ -50,7 +50,7 @@ class RealmDbStorage(val config: RealmConfiguration) { val result = coordinator.perform(request = request) if (invalidateRealm) { - coordinator.refresh() + coordinator.invalidate() } return result @@ -59,13 +59,13 @@ class RealmDbStorage(val config: RealmConfiguration) { fun perform(request: DbRequest) { val coordinator = RealmDbCoordinator().init(config) coordinator.perform(request = request) - coordinator.refresh() + coordinator.invalidate() } fun perform(requests: List) { val coordinator = RealmDbCoordinator().init(config) coordinator.perform(requests) - coordinator.refresh() + coordinator.invalidate() } } @@ -138,4 +138,7 @@ class RealmDbCoordinator { realm.refresh() } + fun invalidate() { + realm.close() + } } diff --git a/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt b/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt index 4239dd10..dd49a7ac 100644 --- a/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt +++ b/app/src/main/java/org/zotero/android/pdf/reader/PdfReaderViewModel.kt @@ -74,7 +74,7 @@ import org.zotero.android.architecture.ifFailure import org.zotero.android.architecture.navigation.NavigationParamsMarshaller import org.zotero.android.architecture.require import org.zotero.android.database.DbRequest -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.AnnotationsConfig import org.zotero.android.database.objects.FieldKeys import org.zotero.android.database.objects.RItem @@ -147,7 +147,7 @@ import javax.inject.Inject @HiltViewModel class PdfReaderViewModel @Inject constructor( private val defaults: Defaults, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val sessionDataEventStream: SessionDataEventStream, private val pdfReaderCurrentThemeEventStream: PdfReaderCurrentThemeEventStream, private val pdfReaderThemeDecider: PdfReaderThemeDecider, @@ -526,7 +526,7 @@ class PdfReaderViewModel @Inject constructor( try { var pageStr = "0" var results: RealmResults? = null - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> pageStr = coordinator.perform( request = ReadDocumentDataDbRequest( attachmentKey = key, @@ -804,7 +804,7 @@ class PdfReaderViewModel @Inject constructor( viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, writeRequests = requests ).ifFailure { Timber.e(it, "PDFReaderViewModel: can't update changed annotations") @@ -2188,7 +2188,7 @@ class PdfReaderViewModel @Inject constructor( ) viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request ).ifFailure { Timber.e(it, "PDFReaderViewModel: can't add annotations") @@ -2360,7 +2360,7 @@ class PdfReaderViewModel @Inject constructor( viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request ).ifFailure { Timber.e(it, "PDFReaderViewModel: can't remove annotations $keys") @@ -2496,7 +2496,7 @@ class PdfReaderViewModel @Inject constructor( val request = EditTagsForItemDbRequest(key = key, libraryId = viewState.library.identifier, tags = tags) viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request ).ifFailure { Timber.e(it, "PDFReaderViewModel: can't set tags $key") @@ -2556,7 +2556,7 @@ class PdfReaderViewModel @Inject constructor( viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request ).ifFailure { Timber.e(it, "PDFReaderViewModel: can't update annotation $key") @@ -2577,7 +2577,7 @@ class PdfReaderViewModel @Inject constructor( ) ZoteroApplication.instance.applicationScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request ).ifFailure { Timber.e(it, "PDFReaderViewModel: can't store page") diff --git a/app/src/main/java/org/zotero/android/screens/allitems/AllItemsViewModel.kt b/app/src/main/java/org/zotero/android/screens/allitems/AllItemsViewModel.kt index 9afa0ccf..0b472c3e 100644 --- a/app/src/main/java/org/zotero/android/screens/allitems/AllItemsViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/allitems/AllItemsViewModel.kt @@ -29,7 +29,7 @@ import org.zotero.android.architecture.coroutines.Dispatchers import org.zotero.android.architecture.ifFailure import org.zotero.android.architecture.navigation.NavigationParamsMarshaller import org.zotero.android.database.DbError -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.objects.ItemTypes import org.zotero.android.database.objects.RItem @@ -97,7 +97,7 @@ import javax.inject.Inject @HiltViewModel internal class AllItemsViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val fileStore: FileStore, private val selectMedia: SelectMediaUseCase, private val getUriDetailsUseCase: GetUriDetailsUseCase, @@ -428,7 +428,7 @@ internal class AllItemsViewModel @Inject constructor( val type = schemaController.localizedItemType(ItemTypes.attachment) ?: "" val request = CreateAttachmentsDbRequest(attachments = attachments, parentKey = null, localizedType = type, collections = collections, fileStore = fileStore) - val result = perform(dbWrapper, invalidateRealm = true, request = request).ifFailure { + val result = perform(dbWrapperMain, invalidateRealm = true, request = request).ifFailure { Timber.e(it,"ItemsActionHandler: can't add attachment") updateState { copy(error = ItemsError.attachmentAdding(ItemsError.AttachmentLoading.couldNotSave)) @@ -521,7 +521,7 @@ internal class AllItemsViewModel @Inject constructor( } try { - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( EditNoteDbRequest( note = note, libraryId = libraryId @@ -538,7 +538,7 @@ internal class AllItemsViewModel @Inject constructor( collectionKey = collectionKey, parentKey = null ) - dbWrapper.realmDbStorage.perform(request = request, invalidateRealm = true) + dbWrapperMain.realmDbStorage.perform(request = request, invalidateRealm = true) } else { Timber.e(e) } @@ -803,7 +803,7 @@ internal class AllItemsViewModel @Inject constructor( fun delete(keys: Set) { viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = MarkObjectsAsDeletedDbRequest( clazz = RItem::class, keys = keys.toList(), @@ -830,7 +830,7 @@ internal class AllItemsViewModel @Inject constructor( libraryId = this.library.identifier, trashed = trashed ) - perform(dbWrapper = dbWrapper, request = request).ifFailure { error -> + perform(dbWrapper = dbWrapperMain, request = request).ifFailure { error -> Timber.e(error, "ItemsStore: can't trash items") updateState { copy( @@ -845,7 +845,7 @@ internal class AllItemsViewModel @Inject constructor( val request = ReadItemDbRequest(libraryId = this.library.identifier, key = key) try { - val item = dbWrapper.realmDbStorage.perform(request = request) + val item = dbWrapperMain.realmDbStorage.perform(request = request) stopEditing() showItemDetail(DetailType.duplication(itemKey = item.key, collectionKey = this.collection.identifier.keyGet), library = this.library) } catch (error: Exception) { @@ -941,7 +941,7 @@ internal class AllItemsViewModel @Inject constructor( fun emptyTrash() { viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = EmptyTrashDbRequest(libraryId = this@AllItemsViewModel.library.identifier) ).ifFailure { Timber.e(it, "AllItemsViewModel: can't empty trash") @@ -1012,7 +1012,7 @@ internal class AllItemsViewModel @Inject constructor( libraryId = this.library.identifier ) viewModelScope.launch { - perform(dbWrapper, request = request).ifFailure { + perform(dbWrapperMain, request = request).ifFailure { Timber.e(it, "ItemsStore: can't delete items") updateState { copy(error = ItemsError.deletionFromCollection) @@ -1030,7 +1030,7 @@ internal class AllItemsViewModel @Inject constructor( ) viewModelScope.launch { - perform(dbWrapper, request = request).ifFailure { + perform(dbWrapperMain, request = request).ifFailure { Timber.e(it, "ItemsStore: can't assign collections to items") updateState { copy(error = ItemsError.collectionAssignment) diff --git a/app/src/main/java/org/zotero/android/screens/allitems/processor/AllItemsProcessor.kt b/app/src/main/java/org/zotero/android/screens/allitems/processor/AllItemsProcessor.kt index 40f4d8c7..a2b8d46f 100644 --- a/app/src/main/java/org/zotero/android/screens/allitems/processor/AllItemsProcessor.kt +++ b/app/src/main/java/org/zotero/android/screens/allitems/processor/AllItemsProcessor.kt @@ -24,7 +24,7 @@ import org.zotero.android.architecture.LCE2 import org.zotero.android.architecture.coroutines.Dispatchers import org.zotero.android.attachmentdownloader.AttachmentDownloader import org.zotero.android.attachmentdownloader.AttachmentDownloaderEventStream -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.objects.RItem import org.zotero.android.database.requests.ReadItemsDbRequest @@ -53,7 +53,7 @@ class AllItemsProcessor @Inject constructor( dispatchers: Dispatchers, private val defaults: Defaults, private val fileStore: FileStore, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val attachmentDownloaderEventStream: AttachmentDownloaderEventStream, private val fileDownloader: AttachmentDownloader, private val fileCleanupController: AttachmentFileCleanupController, @@ -231,7 +231,7 @@ class AllItemsProcessor @Inject constructor( defaults = this.defaults, isAsync = true ) - return dbWrapper.realmDbStorage.perform(request = request) + return dbWrapperMain.realmDbStorage.perform(request = request) } private fun createComponents(searchTerm: String): List { diff --git a/app/src/main/java/org/zotero/android/screens/collectionedit/CollectionEditViewModel.kt b/app/src/main/java/org/zotero/android/screens/collectionedit/CollectionEditViewModel.kt index 865aa136..6d8f557a 100644 --- a/app/src/main/java/org/zotero/android/screens/collectionedit/CollectionEditViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/collectionedit/CollectionEditViewModel.kt @@ -13,7 +13,7 @@ import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState import org.zotero.android.architecture.ifFailure import org.zotero.android.database.DbRequest -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCollection import org.zotero.android.database.requests.CreateCollectionDbRequest import org.zotero.android.database.requests.EditCollectionDbRequest @@ -35,7 +35,7 @@ import javax.inject.Inject @HiltViewModel internal class CollectionEditViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val context: Context, private val conflictResolutionUseCase: ConflictResolutionUseCase ) : BaseViewModel2(CollectionEditViewState()) { @@ -109,7 +109,7 @@ internal class CollectionEditViewModel @Inject constructor( private fun perform(request: DbRequest) { viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request ).ifFailure { Timber.e(it, "CollectionEditViewModel: couldn't perform request") diff --git a/app/src/main/java/org/zotero/android/screens/collectionpicker/CollectionPickerViewModel.kt b/app/src/main/java/org/zotero/android/screens/collectionpicker/CollectionPickerViewModel.kt index 13f4aa5e..74b09f87 100644 --- a/app/src/main/java/org/zotero/android/screens/collectionpicker/CollectionPickerViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/collectionpicker/CollectionPickerViewModel.kt @@ -16,7 +16,7 @@ import org.zotero.android.architecture.ScreenArguments import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState import org.zotero.android.architecture.emptyImmutableSet -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCollection import org.zotero.android.database.requests.ReadCollectionsDbRequest import org.zotero.android.screens.collectionpicker.data.CollectionPickerMode @@ -35,7 +35,7 @@ import javax.inject.Inject @HiltViewModel internal class CollectionPickerViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val context: Context, ) : BaseViewModel2(CollectionPickerViewState()) { @@ -90,7 +90,7 @@ internal class CollectionPickerViewModel @Inject constructor( libraryId = libraryId, excludedKeys = this.excludedKeys ) - this.results = dbWrapper.realmDbStorage.perform(request = collectionsRequest) + this.results = dbWrapperMain.realmDbStorage.perform(request = collectionsRequest) val collectionTree = CollectionTreeBuilder.collections( this.results, libraryId = libraryId, diff --git a/app/src/main/java/org/zotero/android/screens/collections/CollectionsViewModel.kt b/app/src/main/java/org/zotero/android/screens/collections/CollectionsViewModel.kt index 67474e6c..f3e9d73b 100644 --- a/app/src/main/java/org/zotero/android/screens/collections/CollectionsViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/collections/CollectionsViewModel.kt @@ -23,7 +23,7 @@ import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState import org.zotero.android.architecture.coroutines.Dispatchers import org.zotero.android.architecture.ifFailure -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCollection import org.zotero.android.database.objects.RCustomLibraryType import org.zotero.android.database.objects.RItem @@ -55,7 +55,7 @@ import kotlin.reflect.KClass @HiltViewModel internal class CollectionsViewModel @Inject constructor( private val defaults: Defaults, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val fileStore: FileStore, dispatchers: Dispatchers, ) : BaseViewModel2(CollectionsViewState()) { @@ -134,7 +134,7 @@ internal class CollectionsViewModel @Inject constructor( val includeItemCounts = defaults.showCollectionItemCounts() try { - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> this.library = coordinator.perform(request = ReadLibraryDbRequest(libraryId = libraryId)) collections = @@ -398,7 +398,7 @@ internal class CollectionsViewModel @Inject constructor( libraryId = libraryId ) viewModelScope.launch { - perform(dbWrapper, request) + perform(dbWrapperMain, request) .ifFailure { Timber.e(it, "CollectionsActionHandler: can't change collapsed") return@launch @@ -490,7 +490,7 @@ internal class CollectionsViewModel @Inject constructor( libraryId = this.library.identifier ) perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request ).ifFailure { Timber.e(it, "CollectionsActionHandler: can't delete object") @@ -507,7 +507,7 @@ internal class CollectionsViewModel @Inject constructor( if (parentKey != null) { val request = ReadCollectionDbRequest(libraryId = this.library.identifier, key = parentKey) - val rCollection = dbWrapper.realmDbStorage.perform(request = request) + val rCollection = dbWrapperMain.realmDbStorage.perform(request = request) parent = Collection.initWithCollection(objectS = rCollection, itemCount = 0) } else { parent = null diff --git a/app/src/main/java/org/zotero/android/screens/dashboard/DashboardViewModel.kt b/app/src/main/java/org/zotero/android/screens/dashboard/DashboardViewModel.kt index b3f4bdfe..2f90fc35 100644 --- a/app/src/main/java/org/zotero/android/screens/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/dashboard/DashboardViewModel.kt @@ -24,7 +24,7 @@ import org.zotero.android.architecture.logging.debug.DebugLogging import org.zotero.android.architecture.logging.debug.DebugLoggingDialogData import org.zotero.android.architecture.logging.debug.DebugLoggingDialogDataEventStream import org.zotero.android.architecture.logging.debug.DebugLoggingInterface -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCustomLibraryType import org.zotero.android.database.objects.RGroup import org.zotero.android.database.requests.DeleteGroupDbRequest @@ -58,7 +58,7 @@ import javax.inject.Inject @HiltViewModel class DashboardViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val fileStore: FileStore, private val conflictResolutionUseCase: ConflictResolutionUseCase, private val debugLogging: DebugLogging, @@ -192,7 +192,7 @@ class DashboardViewModel @Inject constructor( var library: Library? = null try { - dbWrapper.realmDbStorage.perform(coordinatorAction = { coordinator -> + dbWrapperMain.realmDbStorage.perform(coordinatorAction = { coordinator -> when (collectionId) { is CollectionIdentifier.collection -> { val rCollection = coordinator.perform( @@ -373,7 +373,7 @@ class DashboardViewModel @Inject constructor( fun deleteNonLocalGroup(groupId: Int) { viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, DeleteGroupDbRequest(groupId = groupId) ).ifFailure { Timber.e(it, "DashboardViewModel: can't delete group") @@ -383,7 +383,7 @@ class DashboardViewModel @Inject constructor( } private fun listenToGroupDeletionEvents() { - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> this.groupLibraries = coordinator.perform(request = ReadAllGroupsDbRequest()) this.groupLibraries?.addChangeListener { _, changeSet -> diff --git a/app/src/main/java/org/zotero/android/screens/filter/FilterViewModel.kt b/app/src/main/java/org/zotero/android/screens/filter/FilterViewModel.kt index 426e16df..09da440c 100644 --- a/app/src/main/java/org/zotero/android/screens/filter/FilterViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/filter/FilterViewModel.kt @@ -1,6 +1,5 @@ package org.zotero.android.screens.filter -import android.content.Context import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow @@ -19,7 +18,7 @@ import org.zotero.android.architecture.ScreenArguments import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState import org.zotero.android.architecture.coroutines.Dispatchers -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.DeleteAutomaticTagsDbRequest import org.zotero.android.database.requests.ReadAutomaticTagsDbRequest import org.zotero.android.database.requests.ReadColoredTagsDbRequest @@ -38,9 +37,8 @@ import javax.inject.Inject @HiltViewModel internal class FilterViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val defaults: Defaults, - private val context: Context, private val dispatchers: Dispatchers, ) : BaseViewModel2(FilterViewState()) { @@ -249,7 +247,7 @@ internal class FilterViewModel @Inject constructor( ignoreCase = true ) } - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val filtered = coordinator.perform( request = ReadFilteredTagsDbRequest( collectionId = collectionId, @@ -328,7 +326,7 @@ internal class FilterViewModel @Inject constructor( // } } - coordinator.refresh() + coordinator.invalidate() if (!viewState.searchTerm.isEmpty()) { // Perform search filter if needed snapshot = sorted @@ -392,7 +390,7 @@ internal class FilterViewModel @Inject constructor( copy(showFilterOptionsPopup = false) } val request = ReadAutomaticTagsDbRequest(libraryId = ScreenArguments.filterArgs.libraryId) - val count = dbWrapper.realmDbStorage.perform(request = request).size + val count = dbWrapperMain.realmDbStorage.perform(request = request).size confirmDeletion(count) } @@ -406,7 +404,7 @@ internal class FilterViewModel @Inject constructor( fun deleteAutomaticTags() { viewModelScope.launch { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = DeleteAutomaticTagsDbRequest(libraryId = ScreenArguments.filterArgs.libraryId) ) } diff --git a/app/src/main/java/org/zotero/android/screens/itemdetails/ItemDetailsViewModel.kt b/app/src/main/java/org/zotero/android/screens/itemdetails/ItemDetailsViewModel.kt index 62898757..3f73e28d 100644 --- a/app/src/main/java/org/zotero/android/screens/itemdetails/ItemDetailsViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/itemdetails/ItemDetailsViewModel.kt @@ -31,7 +31,7 @@ import org.zotero.android.architecture.navigation.NavigationParamsMarshaller import org.zotero.android.attachmentdownloader.AttachmentDownloader import org.zotero.android.attachmentdownloader.AttachmentDownloaderEventStream import org.zotero.android.database.DbRequest -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.objects.FieldKeys import org.zotero.android.database.objects.ItemTypes @@ -123,7 +123,7 @@ val numberOfRowsInLazyColumnBeforeListOfCreatorsStarts = 1 class ItemDetailsViewModel @Inject constructor( dispatcher: CoroutineDispatcher, private val defaults: Defaults, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val fileStore: FileStore, private val urlDetector: UrlDetector, private val schemaController: SchemaController, @@ -353,7 +353,7 @@ class ItemDetailsViewModel @Inject constructor( val itemKey = type.itemKey val _collectionKey = type.collectionKey collectionKey = _collectionKey - val item = dbWrapper.realmDbStorage.perform( + val item = dbWrapperMain.realmDbStorage.perform( request = ReadItemDbRequest( libraryId = viewState.library!!.identifier, key = itemKey @@ -395,7 +395,7 @@ class ItemDetailsViewModel @Inject constructor( fileStore = fileStore ) viewModelScope.launch { - val result = perform(dbWrapper, request = request, invalidateRealm = true) + val result = perform(dbWrapperMain, request = request, invalidateRealm = true) if (result is Result.Failure) { Timber.e(result.exception, "ItemDetailActionHandler: can't create initial item") updateState { @@ -411,7 +411,7 @@ class ItemDetailsViewModel @Inject constructor( private fun reloadData(isEditing: Boolean) = viewModelScope.launch { try { currentItem?.removeAllChangeListeners() - val item = dbWrapper.realmDbStorage.perform( + val item = dbWrapperMain.realmDbStorage.perform( request = ReadItemDbRequest( libraryId = viewState.library!!.identifier, key = viewState.key @@ -613,7 +613,7 @@ class ItemDetailsViewModel @Inject constructor( orderId = orderId ) - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) if (result is Result.Failure) { Timber.e(result.exception, "ItemDetailActionHandler: can't create creator") } @@ -665,7 +665,7 @@ class ItemDetailsViewModel @Inject constructor( ) viewModelScope.launch { - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) if (result is Result.Failure) { Timber.e(result.exception, "ItemDetailActionHandler: can't store field") } @@ -697,7 +697,7 @@ class ItemDetailsViewModel @Inject constructor( dateParser = this.dateParser ) viewModelScope.launch { - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) if (result is Result.Failure) { Timber.e(result.exception, "ItemDetailActionHandler: can't store title") } @@ -723,7 +723,7 @@ class ItemDetailsViewModel @Inject constructor( ) viewModelScope.launch { - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) if (result is Result.Failure) { Timber.e(result.exception, "ItemDetailActionHandler: can't store abstract") } @@ -824,7 +824,7 @@ class ItemDetailsViewModel @Inject constructor( ) } perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, writeRequests = requests ).ifFailure { Timber.e(it) @@ -944,7 +944,7 @@ class ItemDetailsViewModel @Inject constructor( when (type) { is DetailType.duplication -> { perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = DeleteObjectsDbRequest( clazz = RItem::class, keys = listOf(viewState.key), @@ -978,7 +978,7 @@ class ItemDetailsViewModel @Inject constructor( ) } perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, writeRequests = actions ).ifFailure { Timber.e(it, "ItemDetailActionHandler: can't remove created and cancelled item") @@ -1023,7 +1023,7 @@ class ItemDetailsViewModel @Inject constructor( creatorId = creatorId ) - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) if (result is Result.Failure) { Timber.e("ItemDetailActionHandler: can't delete creator") } @@ -1095,7 +1095,7 @@ class ItemDetailsViewModel @Inject constructor( if (oldNote != null) { val request = EditNoteDbRequest (note = note, libraryId = viewState.library!!.identifier) - perform(dbWrapper = dbWrapper, request = request).ifFailure { + perform(dbWrapper = dbWrapperMain, request = request).ifFailure { finishSave(it) return } @@ -1111,7 +1111,7 @@ class ItemDetailsViewModel @Inject constructor( parentKey = viewState.key ) perform( - dbWrapper = dbWrapper, + dbWrapper = dbWrapperMain, request = request, invalidateRealm = true ).ifFailure { error -> @@ -1420,7 +1420,7 @@ class ItemDetailsViewModel @Inject constructor( libraryId = viewState.library!!.identifier, tagName = tag.name ) - perform(dbWrapper = dbWrapper, request = request).ifFailure { error -> + perform(dbWrapper = dbWrapperMain, request = request).ifFailure { error -> Timber.e(error, "ItemDetailActionHandler: can't delete tag ${tag.name}") updateState { copy( @@ -1514,7 +1514,7 @@ class ItemDetailsViewModel @Inject constructor( libraryId = viewState.library!!.identifier, trashed = true ) - perform(dbWrapper = dbWrapper, request = request).ifFailure { error -> + perform(dbWrapper = dbWrapperMain, request = request).ifFailure { error -> Timber.e(error, "ItemDetailActionHandler: can't trash item $key") updateState { copy( @@ -1717,7 +1717,7 @@ class ItemDetailsViewModel @Inject constructor( } val request = EditTagsForItemDbRequest(key = viewState.key, libraryId = viewState.library!!.identifier, tags = tags) - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) updateState { copy(backgroundProcessedItems = backgroundProcessedItems - tags.map { it.name }) @@ -1781,7 +1781,7 @@ class ItemDetailsViewModel @Inject constructor( viewModelScope.launch { val result = - perform(dbWrapper, invalidateRealm = true, request = request) + perform(dbWrapperMain, invalidateRealm = true, request = request) for (attachment in attachments) { updateState { copy(backgroundProcessedItems = backgroundProcessedItems - attachment.key) @@ -1886,7 +1886,7 @@ class ItemDetailsViewModel @Inject constructor( } val result = perform( - dbWrapper, + dbWrapperMain, request = RemoveItemFromParentDbRequest( key = attachment.key, libraryId = attachment.libraryId @@ -1953,7 +1953,7 @@ class ItemDetailsViewModel @Inject constructor( ids = viewState.data.creatorIds ) - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) if (result is Result.Failure) { Timber.e(result.exception, "ItemDetailActionHandler: can't reorder creators") } @@ -1974,7 +1974,7 @@ class ItemDetailsViewModel @Inject constructor( ) viewModelScope.launch { - val result = perform(dbWrapper = dbWrapper, request = request) + val result = perform(dbWrapper = dbWrapperMain, request = request) if (result is Result.Failure) { Timber.e(result.exception, "ItemDetailActionHandler: can't change type") } diff --git a/app/src/main/java/org/zotero/android/screens/libraries/LibrariesViewModel.kt b/app/src/main/java/org/zotero/android/screens/libraries/LibrariesViewModel.kt index 33a50282..68f8258a 100644 --- a/app/src/main/java/org/zotero/android/screens/libraries/LibrariesViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/libraries/LibrariesViewModel.kt @@ -11,7 +11,7 @@ import org.zotero.android.architecture.LCE2 import org.zotero.android.architecture.ScreenArguments import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCustomLibrary import org.zotero.android.database.objects.RCustomLibraryType import org.zotero.android.database.objects.RGroup @@ -30,7 +30,7 @@ import javax.inject.Inject @HiltViewModel internal class LibrariesViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val fileStore: FileStore, ) : BaseViewModel2(LibrariesViewState()) { @@ -46,7 +46,7 @@ internal class LibrariesViewModel @Inject constructor( } private fun loadData() { - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val libraries = coordinator.perform(request = ReadAllCustomLibrariesDbRequest()) val groups = coordinator.perform(request = ReadAllGroupsDbRequest()) diff --git a/app/src/main/java/org/zotero/android/screens/settings/account/SettingsAccountViewModel.kt b/app/src/main/java/org/zotero/android/screens/settings/account/SettingsAccountViewModel.kt index 145816bc..9883c889 100644 --- a/app/src/main/java/org/zotero/android/screens/settings/account/SettingsAccountViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/settings/account/SettingsAccountViewModel.kt @@ -23,7 +23,7 @@ import org.zotero.android.architecture.coroutines.Dispatchers import org.zotero.android.architecture.navigation.toolbar.data.SyncProgress import org.zotero.android.architecture.navigation.toolbar.data.SyncProgressEventStream import org.zotero.android.database.DbRequest -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCustomLibraryType import org.zotero.android.database.requests.DeleteAllWebDavDeletionsDbRequest import org.zotero.android.database.requests.MarkAttachmentsNotUploadedDbRequest @@ -61,7 +61,7 @@ internal class SettingsAccountViewModel @Inject constructor( private val webDavController: WebDavController, private val fileStore: FileStore, private val context: Context, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val syncScheduler: SyncScheduler, private val syncProgressEventStream: SyncProgressEventStream, private val dispatchers: Dispatchers, @@ -229,7 +229,7 @@ internal class SettingsAccountViewModel @Inject constructor( if (type == FileSyncType.zotero) { requests.add(DeleteAllWebDavDeletionsDbRequest()) } - dbWrapper.realmDbStorage.perform(requests) + dbWrapperMain.realmDbStorage.perform(requests) } private fun downloadedAttachmentKeys(): List { diff --git a/app/src/main/java/org/zotero/android/screens/share/ShareErrorProcessor.kt b/app/src/main/java/org/zotero/android/screens/share/ShareErrorProcessor.kt index 73b89e09..beb851f9 100644 --- a/app/src/main/java/org/zotero/android/screens/share/ShareErrorProcessor.kt +++ b/app/src/main/java/org/zotero/android/screens/share/ShareErrorProcessor.kt @@ -3,7 +3,7 @@ package org.zotero.android.screens.share import android.content.Context import org.zotero.android.BuildConfig import org.zotero.android.api.network.CustomResult -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.ReadGroupDbRequest import org.zotero.android.sync.LibraryIdentifier import org.zotero.android.sync.Parsing @@ -18,7 +18,7 @@ import javax.inject.Singleton @Singleton class ShareErrorProcessor @Inject constructor( private val context: Context, - private val dbWrapper: DbWrapper + private val dbWrapperMain: DbWrapperMain, ) { fun errorMessage(error: AttachmentState.Error): String? { return when (error) { @@ -75,7 +75,7 @@ class ShareErrorProcessor @Inject constructor( is LibraryIdentifier.group -> { val groupId = error.libraryIdentifier.groupId val group = - dbWrapper.realmDbStorage.perform(ReadGroupDbRequest(identifier = groupId)) + dbWrapperMain.realmDbStorage.perform(ReadGroupDbRequest(identifier = groupId)) val groupName = group?.name ?: "$groupId" return context.getString( Strings.errors_shareext_group_quota_reached, diff --git a/app/src/main/java/org/zotero/android/screens/share/ShareItemSubmitter.kt b/app/src/main/java/org/zotero/android/screens/share/ShareItemSubmitter.kt index 3c9b5f92..e977443e 100644 --- a/app/src/main/java/org/zotero/android/screens/share/ShareItemSubmitter.kt +++ b/app/src/main/java/org/zotero/android/screens/share/ShareItemSubmitter.kt @@ -4,7 +4,7 @@ import org.zotero.android.api.network.CustomResult import org.zotero.android.api.pojo.sync.ItemResponse import org.zotero.android.api.pojo.sync.TagResponse import org.zotero.android.backgrounduploader.BackgroundUpload -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.objects.FieldKeys import org.zotero.android.database.objects.ItemTypes @@ -38,7 +38,7 @@ import javax.inject.Singleton @Singleton class ShareItemSubmitter @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val schemaController: SchemaController, private val dateParser: DateParser, private val fileStore: FileStore, @@ -54,7 +54,7 @@ class ShareItemSubmitter @Inject constructor( ): Pair, Map>> { var changeUuids: MutableMap> = mutableMapOf() var parameters: MutableMap = mutableMapOf() - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val collectionKey = item.collectionKeys.firstOrNull() if (collectionKey != null) { coordinator.perform( @@ -74,7 +74,7 @@ class ShareItemSubmitter @Inject constructor( parameters = item.updateParameters?.toMutableMap() ?: mutableMapOf() changeUuids = mutableMapOf(item.key to item.changes.map { it.identifier }) - coordinator.refresh() + coordinator.invalidate() } return parameters to changeUuids @@ -86,7 +86,7 @@ class ShareItemSubmitter @Inject constructor( var changeUuids: MutableMap> = mutableMapOf() var mtime: Long? = null var md5: String? = null - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val collectionKey = item.collectionKeys.firstOrNull() if (collectionKey != null) { coordinator.perform( @@ -119,7 +119,7 @@ class ShareItemSubmitter @Inject constructor( .findFirst()?.value?.toLongOrNull() md5 = attachment.fields.where().key(FieldKeys.Item.Attachment.md5).findFirst()?.value - coordinator.refresh() + coordinator.invalidate() } if (mtime == null) { throw AttachmentState.Error.mtimeMissing @@ -145,7 +145,7 @@ class ShareItemSubmitter @Inject constructor( var md5: String? = null var mtime: Long? = null - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val collectionKey = collections.firstOrNull() if (collectionKey != null) { coordinator.perform( @@ -173,7 +173,7 @@ class ShareItemSubmitter @Inject constructor( .findFirst()?.value?.toLongOrNull() md5 = attachment.fields.where().key(FieldKeys.Item.Attachment.md5).findFirst()?.value - coordinator.refresh() + coordinator.invalidate() } mtime ?: throw AttachmentState.Error.mtimeMissing @@ -360,7 +360,7 @@ class ShareItemSubmitter @Inject constructor( key = data.attachment.key, version = response.version ) - dbWrapper.realmDbStorage.perform(request) + dbWrapperMain.realmDbStorage.perform(request) } is AuthorizeUploadResponse.new -> { @@ -426,7 +426,7 @@ class ShareItemSubmitter @Inject constructor( key = data.attachment.key, version = null ) - dbWrapper.realmDbStorage.perform(request) + dbWrapperMain.realmDbStorage.perform(request) } is WebDavUploadResult.new -> { diff --git a/app/src/main/java/org/zotero/android/screens/share/ShareViewModel.kt b/app/src/main/java/org/zotero/android/screens/share/ShareViewModel.kt index 9f80f10f..7faa8476 100644 --- a/app/src/main/java/org/zotero/android/screens/share/ShareViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/share/ShareViewModel.kt @@ -30,7 +30,7 @@ import org.zotero.android.architecture.ScreenArguments import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState import org.zotero.android.architecture.coroutines.Dispatchers -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.objects.FieldKeys import org.zotero.android.database.objects.ItemTypes @@ -86,7 +86,7 @@ internal class ShareViewModel @Inject constructor( private val syncScheduler: SyncScheduler, private val syncObservableEventStream: SyncObservableEventStream, private val translatorActionEventStream: TranslatorActionEventStream, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val itemResponseMapper: ItemResponseMapper, private val schemaController: SchemaController, private val tagResponseMapper: TagResponseMapper, @@ -397,7 +397,7 @@ internal class ShareViewModel @Inject constructor( var collection: Collection? = null var recents = mutableListOf() Timber.i("ShareViewModel: ReadCollectionAndLibraryDbRequest closure before") - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val request = ReadCollectionAndLibraryDbRequest( collectionId = this.selectedCollectionId, libraryId = this.selectedLibraryId diff --git a/app/src/main/java/org/zotero/android/screens/share/backgroundprocessor/BackgroundUploadProcessor.kt b/app/src/main/java/org/zotero/android/screens/share/backgroundprocessor/BackgroundUploadProcessor.kt index b86c3c3d..b7105a73 100644 --- a/app/src/main/java/org/zotero/android/screens/share/backgroundprocessor/BackgroundUploadProcessor.kt +++ b/app/src/main/java/org/zotero/android/screens/share/backgroundprocessor/BackgroundUploadProcessor.kt @@ -19,7 +19,7 @@ import org.zotero.android.api.network.CustomResult import org.zotero.android.api.network.safeApiCall import org.zotero.android.architecture.logging.DeviceInfoProvider import org.zotero.android.backgrounduploader.BackgroundUpload -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.MarkAttachmentUploadedDbRequest import org.zotero.android.database.requests.ReadItemDbRequest import org.zotero.android.screens.share.service.ShareUploadService @@ -39,7 +39,7 @@ class BackgroundUploadProcessor @Inject constructor( private val webDavApi: WebDavApi, private val syncApi: SyncApi, private val schemaController: SchemaController, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val context: Context, private val gson: Gson, private val updatesResponseMapper: UpdatesResponseMapper, @@ -195,7 +195,7 @@ class BackgroundUploadProcessor @Inject constructor( libraryId: LibraryIdentifier, ) { try { - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( MarkAttachmentUploadedDbRequest( libraryId = libraryId, key = key, @@ -234,7 +234,7 @@ class BackgroundUploadProcessor @Inject constructor( val loadParameters: Map try { - val item = dbWrapper.realmDbStorage.perform( + val item = dbWrapperMain.realmDbStorage.perform( request = ReadItemDbRequest( libraryId = libraryId, key = key diff --git a/app/src/main/java/org/zotero/android/screens/share/sharecollectionpicker/ShareCollectionPickerViewModel.kt b/app/src/main/java/org/zotero/android/screens/share/sharecollectionpicker/ShareCollectionPickerViewModel.kt index 2e7a3424..ea8067bf 100644 --- a/app/src/main/java/org/zotero/android/screens/share/sharecollectionpicker/ShareCollectionPickerViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/share/sharecollectionpicker/ShareCollectionPickerViewModel.kt @@ -6,7 +6,7 @@ import org.zotero.android.architecture.BaseViewModel2 import org.zotero.android.architecture.ScreenArguments import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.ReadAllCustomLibrariesDbRequest import org.zotero.android.database.requests.ReadAllWritableGroupsDbRequest import org.zotero.android.database.requests.ReadCollectionsDbRequest @@ -23,7 +23,7 @@ import javax.inject.Inject @HiltViewModel internal class ShareCollectionPickerViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, ) : BaseViewModel2(ShareCollectionPickerViewState()) { var isTablet: Boolean = true @@ -41,7 +41,7 @@ internal class ShareCollectionPickerViewModel @Inject constructor( private fun loadData() { try { - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val customLibraries = coordinator.perform(ReadAllCustomLibrariesDbRequest()) val groups = coordinator.perform(ReadAllWritableGroupsDbRequest()) val libraries = customLibraries.map { Library(it) } + groups.map { Library(it) } @@ -131,10 +131,6 @@ internal class ShareCollectionPickerViewModel @Inject constructor( return false to emptyList() } - override fun onCleared() { - super.onCleared() - } - fun onCollectionChevronTapped(libraryIdentifier: LibraryIdentifier, collection: Collection) { val tree = viewState.trees[libraryIdentifier] val collapsed = tree?.collapsed?.get(collection.identifier) ?: return diff --git a/app/src/main/java/org/zotero/android/screens/tagpicker/TagPickerViewModel.kt b/app/src/main/java/org/zotero/android/screens/tagpicker/TagPickerViewModel.kt index adbdf95e..320d7dfc 100644 --- a/app/src/main/java/org/zotero/android/screens/tagpicker/TagPickerViewModel.kt +++ b/app/src/main/java/org/zotero/android/screens/tagpicker/TagPickerViewModel.kt @@ -6,7 +6,7 @@ import org.zotero.android.architecture.BaseViewModel2 import org.zotero.android.architecture.ScreenArguments import org.zotero.android.architecture.ViewEffect import org.zotero.android.architecture.ViewState -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.ReadTagPickerTagsDbRequest import org.zotero.android.ktx.index import org.zotero.android.screens.tagpicker.data.TagPickerResult @@ -17,7 +17,7 @@ import javax.inject.Inject @HiltViewModel internal class TagPickerViewModel @Inject constructor( - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, ) : BaseViewModel2(TagPickerViewState()) { fun init() = initOnce { @@ -115,7 +115,7 @@ internal class TagPickerViewModel @Inject constructor( private fun load() { try { val request = ReadTagPickerTagsDbRequest(libraryId = viewState.libraryId!!) - val results = dbWrapper.realmDbStorage.perform(request = request) + val results = dbWrapperMain.realmDbStorage.perform(request = request) val colored = results.where().isNotEmpty("color").sort("name").findAll() val others = results.where().isEmpty("color").sort("name").findAll() val tags = colored.map { Tag(it) } + others.map { Tag(it) } diff --git a/app/src/main/java/org/zotero/android/sync/AttachmentFileCleanupController.kt b/app/src/main/java/org/zotero/android/sync/AttachmentFileCleanupController.kt index cdc5f196..542130bc 100644 --- a/app/src/main/java/org/zotero/android/sync/AttachmentFileCleanupController.kt +++ b/app/src/main/java/org/zotero/android/sync/AttachmentFileCleanupController.kt @@ -7,7 +7,7 @@ import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.zotero.android.architecture.EventBusConstants -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.objects.ItemTypes import org.zotero.android.database.objects.RCustomLibraryType @@ -30,8 +30,8 @@ import javax.inject.Singleton @Singleton class AttachmentFileCleanupController @Inject constructor( private val fileStorage: FileStore, - private val dbWrapper: DbWrapper, - private val dispatcher: CoroutineDispatcher, + private val dbWrapperMain: DbWrapperMain, + dispatcher: CoroutineDispatcher, ) { sealed class DeletionType { data class individual(val attachment: Attachment, val parentKey: String?) : DeletionType() @@ -115,7 +115,7 @@ class AttachmentFileCleanupController @Inject constructor( var libraryIds = listOf() val forUpload = mutableMapOf>() - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val groups = coordinator.perform(request = ReadAllGroupsDbRequest()) libraryIds = listOf(LibraryIdentifier.custom(RCustomLibraryType.myLibrary)) + groups.map { @@ -138,7 +138,7 @@ class AttachmentFileCleanupController @Inject constructor( } coordinator.perform(request = MarkAllFilesAsNotDownloadedDbRequest()) - coordinator.refresh() + coordinator.invalidate() } val deletedIndividually = delete(libraryIds, forUpload = forUpload) @@ -167,7 +167,7 @@ class AttachmentFileCleanupController @Inject constructor( val toDelete = mutableSetOf() val toReport = mutableSetOf() - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val items = coordinator.perform( request = ReadItemsWithKeysDbRequest( keys = keys, @@ -203,7 +203,7 @@ class AttachmentFileCleanupController @Inject constructor( ) ) - coordinator.refresh() + coordinator.invalidate() } for (key in toDelete) { @@ -226,7 +226,7 @@ class AttachmentFileCleanupController @Inject constructor( var canDelete = false - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val item = coordinator.perform( request = ReadItemDbRequest( libraryId = attachment.libraryId, @@ -246,7 +246,7 @@ class AttachmentFileCleanupController @Inject constructor( downloaded = false ) ) - coordinator.refresh() + coordinator.invalidate() canDelete = true } if (canDelete) { @@ -263,14 +263,14 @@ class AttachmentFileCleanupController @Inject constructor( try { var forUpload = listOf() - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val items = coordinator.perform(request = ReadItemsForUploadDbRequest(libraryId = libraryId)) forUpload = items.map { it.key } coordinator.perform(request = MarkLibraryFilesAsNotDownloadedDbRequest(libraryId = libraryId)) - coordinator.refresh() + coordinator.invalidate() } val deletedIndividually = diff --git a/app/src/main/java/org/zotero/android/sync/Controllers.kt b/app/src/main/java/org/zotero/android/sync/Controllers.kt index adc70d4c..1dae540e 100644 --- a/app/src/main/java/org/zotero/android/sync/Controllers.kt +++ b/app/src/main/java/org/zotero/android/sync/Controllers.kt @@ -10,14 +10,14 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.apache.commons.io.FileUtils -import org.zotero.android.api.annotations.BundleDataDb import org.zotero.android.architecture.core.EventStream import org.zotero.android.architecture.coroutines.ApplicationScope import org.zotero.android.architecture.coroutines.Dispatchers import org.zotero.android.architecture.logging.crash.CrashReporter import org.zotero.android.architecture.logging.debug.DebugLogging import org.zotero.android.attachmentdownloader.AttachmentDownloader -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperBundle +import org.zotero.android.database.DbWrapperMain import org.zotero.android.files.FileStore import org.zotero.android.screens.share.backgroundprocessor.BackgroundUploadProcessor import org.zotero.android.translator.loader.TranslationLoader @@ -35,9 +35,8 @@ class Controllers @Inject constructor( private val sessionDataEventStream: SessionDataEventStream, private val applicationScope: ApplicationScope, private val fileStore: FileStore, - private val dbWrapper: DbWrapper, - @BundleDataDb - private val bundleDataDbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, + private val bundleDataDbWrapper: DbWrapperBundle, private val isUserInitializedEventStream: IsUserInitializedEventStream, private val sessionController: SessionController, private val userControllers: UserControllers, @@ -142,7 +141,7 @@ class Controllers @Inject constructor( val realmError = error as? RealmError if (realmError != null) { - dbWrapper.clearDatabaseFiles() + dbWrapperMain.clearDatabaseFiles() } isUserInitializedEventStream.emit(false) @@ -163,8 +162,8 @@ class Controllers @Inject constructor( FileUtils.deleteDirectory(fileStore.uploads) FileUtils.deleteDirectory(fileStore.downloads) isUserInitializedEventStream.emit(false) - if (dbWrapper.isInitialized) { - dbWrapper.clearDatabaseFiles() + if (dbWrapperMain.isInitialized) { + dbWrapperMain.clearDatabaseFiles() } } @@ -188,6 +187,6 @@ class Controllers @Inject constructor( } private fun createBundleDataDbStorage() { - bundleDataDbWrapper.initBundleDataConfiguration(this.fileStore) + bundleDataDbWrapper.initBundleDataConfiguration() } } diff --git a/app/src/main/java/org/zotero/android/sync/ObjectUserChangeObserver.kt b/app/src/main/java/org/zotero/android/sync/ObjectUserChangeObserver.kt index a7c92401..f3d5f821 100644 --- a/app/src/main/java/org/zotero/android/sync/ObjectUserChangeObserver.kt +++ b/app/src/main/java/org/zotero/android/sync/ObjectUserChangeObserver.kt @@ -9,7 +9,7 @@ import kotlinx.coroutines.withContext import org.zotero.android.architecture.core.EventStream import org.zotero.android.architecture.coroutines.ApplicationScope import org.zotero.android.architecture.coroutines.Dispatchers -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.RealmDbCoordinator import org.zotero.android.database.objects.RCollection import org.zotero.android.database.objects.RCustomLibraryType @@ -27,7 +27,7 @@ class ObjectUserChangeEventStream @Inject constructor(applicationScope: Applicat EventStream>(applicationScope) class ObjectUserChangeObserver( - val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, val observable: ObjectUserChangeEventStream, val applicationScope: ApplicationScope, val dispatchers: Dispatchers @@ -48,7 +48,7 @@ class ObjectUserChangeObserver( private fun setupObserving() { try { - this.dbWrapper.realmDbStorage.perform(coordinatorAction = { coordinator -> + this.dbWrapperMain.realmDbStorage.perform(coordinatorAction = { coordinator -> this@ObjectUserChangeObserver.collectionsToken = registerObserver(coordinator = coordinator) this@ObjectUserChangeObserver.itemsToken = diff --git a/app/src/main/java/org/zotero/android/sync/SyncBatchProcessor.kt b/app/src/main/java/org/zotero/android/sync/SyncBatchProcessor.kt index 8d5eef3a..cb5f68ce 100644 --- a/app/src/main/java/org/zotero/android/sync/SyncBatchProcessor.kt +++ b/app/src/main/java/org/zotero/android/sync/SyncBatchProcessor.kt @@ -15,7 +15,7 @@ import org.zotero.android.api.mappers.ItemResponseMapper import org.zotero.android.api.mappers.SearchResponseMapper import org.zotero.android.api.network.CustomResult import org.zotero.android.api.network.safeApiCall -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.StoreCollectionsDbRequest import org.zotero.android.database.requests.StoreItemsDbResponseRequest import org.zotero.android.database.requests.StoreSearchesDbRequest @@ -32,7 +32,7 @@ class SyncBatchProcessor( val batches: List, val userId: Long, val syncApi: SyncApi, - val dbWrapper: DbWrapper, + val dbWrapperMain: DbWrapperMain, val fileStore: FileStore, val itemResponseMapper: ItemResponseMapper, val collectionResponseMapper: CollectionResponseMapper, @@ -173,7 +173,7 @@ class SyncBatchProcessor( } storeIndividualObjects(objects, type = SyncObject.collection, libraryId = libraryId) - dbWrapper.realmDbStorage.perform(request = StoreCollectionsDbRequest(response = collections)) + dbWrapperMain.realmDbStorage.perform(request = StoreCollectionsDbRequest(response = collections)) val failedKeys = failedKeys(expectedKeys = expectedKeys, parsedKeys = collections.map { it.key }) @@ -196,7 +196,7 @@ class SyncBatchProcessor( } storeIndividualObjects(objects, SyncObject.search, libraryId = libraryId) - dbWrapper.realmDbStorage.perform(request = StoreSearchesDbRequest(response = searches)) + dbWrapperMain.realmDbStorage.perform(request = StoreSearchesDbRequest(response = searches)) val failedKeys = failedKeys(expectedKeys = expectedKeys, parsedKeys = searches.map { it.key }) @@ -227,7 +227,7 @@ class SyncBatchProcessor( preferResponseData = true, denyIncorrectCreator = true, ) - val response = dbWrapper.realmDbStorage.perform(request = request, invalidateRealm = true) + val response = dbWrapperMain.realmDbStorage.perform(request = request, invalidateRealm = true) val failedKeys = failedKeys(expectedKeys = expectedKeys, parsedKeys = items.map { it.key }) diff --git a/app/src/main/java/org/zotero/android/sync/SyncEngine.kt b/app/src/main/java/org/zotero/android/sync/SyncEngine.kt index 1c32c6f2..9b9e3629 100644 --- a/app/src/main/java/org/zotero/android/sync/SyncEngine.kt +++ b/app/src/main/java/org/zotero/android/sync/SyncEngine.kt @@ -11,7 +11,7 @@ import org.zotero.android.api.mappers.SearchResponseMapper import org.zotero.android.api.network.CustomResult import org.zotero.android.architecture.Defaults import org.zotero.android.architecture.navigation.toolbar.data.SyncProgressHandler -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCustomLibraryType import org.zotero.android.database.requests.MarkObjectsAsChangedByUser import org.zotero.android.database.requests.PerformDeletionsDbRequest @@ -56,7 +56,7 @@ import javax.inject.Singleton class SyncUseCase @Inject constructor( private val syncRepository: SyncRepository, private val defaults: Defaults, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val syncApi: SyncApi, private val fileStore: FileStore, private val itemResponseMapper: ItemResponseMapper, @@ -462,7 +462,7 @@ class SyncUseCase @Inject constructor( batches = batches, userId = defaults.getUserId(), syncApi = syncApi, - dbWrapper = this.dbWrapper, + dbWrapperMain = this.dbWrapperMain, fileStore = this.fileStore, itemResponseMapper = itemResponseMapper, collectionResponseMapper = collectionResponseMapper, @@ -668,7 +668,6 @@ class SyncUseCase @Inject constructor( fetchUpdates = (options != CreateLibraryActionsOptions.onlyDownloads), loadVersions = (this.type != SyncKind.full), webDavEnabled = sessionStorage.isEnabled, - dbStorage = dbWrapper.realmDbStorage, ).result() finishCreateLibraryActions(pair = result to options) } catch (e: Exception) { @@ -1270,7 +1269,7 @@ class SyncUseCase @Inject constructor( when (libraryId) { is LibraryIdentifier.group -> { val name = - dbWrapper.realmDbStorage.perform(request = ReadGroupDbRequest(identifier = libraryId.groupId)).name + dbWrapperMain.realmDbStorage.perform(request = ReadGroupDbRequest(identifier = libraryId.groupId)).name enqueue( actions = listOf( Action.resolveGroupFileWritePermission( @@ -1877,7 +1876,7 @@ class SyncUseCase @Inject constructor( is LibraryIdentifier.group -> { val groupId = libraryId.groupId val name = - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( request = ReadGroupDbRequest (identifier = groupId) ).name @@ -1962,7 +1961,7 @@ class SyncUseCase @Inject constructor( ) try { - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) } catch (error: Exception) { Timber.e(error, "SyncController: can't mark item for upload") throw error diff --git a/app/src/main/java/org/zotero/android/sync/SyncRepository.kt b/app/src/main/java/org/zotero/android/sync/SyncRepository.kt index 9953ff48..02954c1a 100644 --- a/app/src/main/java/org/zotero/android/sync/SyncRepository.kt +++ b/app/src/main/java/org/zotero/android/sync/SyncRepository.kt @@ -1,19 +1,17 @@ package org.zotero.android.sync -import com.google.gson.Gson import org.zotero.android.api.SyncApi import org.zotero.android.api.network.CustomResult import org.zotero.android.api.network.safeApiCall import org.zotero.android.architecture.Defaults -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.SyncGroupVersionsDbRequest import javax.inject.Inject class SyncRepository @Inject constructor( private val syncApi: SyncApi, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val defaults: Defaults, - private val gson: Gson, ) { suspend fun processSyncGroupVersions(): CustomResult, List>>> { val networkResult = safeApiCall { @@ -24,7 +22,7 @@ class SyncRepository @Inject constructor( return networkResult as CustomResult.GeneralError } - val dbRes: Pair, List>> = dbWrapper.realmDbStorage.perform( + val dbRes: Pair, List>> = dbWrapperMain.realmDbStorage.perform( request = SyncGroupVersionsDbRequest(versions = networkResult.value!!), invalidateRealm = true ) diff --git a/app/src/main/java/org/zotero/android/sync/UserControllers.kt b/app/src/main/java/org/zotero/android/sync/UserControllers.kt index b10704b0..31be587a 100644 --- a/app/src/main/java/org/zotero/android/sync/UserControllers.kt +++ b/app/src/main/java/org/zotero/android/sync/UserControllers.kt @@ -13,7 +13,7 @@ import org.zotero.android.architecture.Defaults import org.zotero.android.architecture.coroutines.ApplicationScope import org.zotero.android.architecture.coroutines.Dispatchers import org.zotero.android.attachmentdownloader.AttachmentDownloader -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.CleanupUnusedTags import org.zotero.android.files.FileStore import org.zotero.android.websocket.ChangeWsResponse @@ -23,9 +23,7 @@ import javax.inject.Singleton @Singleton class UserControllers @Inject constructor( dispatcher: CoroutineDispatcher, - private val fileStore: FileStore, - private val dbWrapper: DbWrapper, - private val context: Context, + private val dbWrapperMain: DbWrapperMain, private val syncController: SyncUseCase, private val syncScheduler: SyncScheduler, private val objectUserChangeEventStream: ObjectUserChangeEventStream, @@ -34,7 +32,6 @@ class UserControllers @Inject constructor( private val webSocketController: WebSocketController, private val changeWsResponseKindEventStream: ChangeWsResponseKindEventStream, private val fileDownloader: AttachmentDownloader, - private val defaults: Defaults, ) { private lateinit var changeObserver: ObjectUserChangeObserver @@ -55,9 +52,10 @@ class UserControllers @Inject constructor( fileDownloader.init(userId = userId) var isFirstLaunch = false coroutineScope.launch { - dbWrapper.realmDbStorage.perform(coordinatorAction = { coordinator -> + dbWrapperMain.realmDbStorage.perform(coordinatorAction = { coordinator -> isFirstLaunch = coordinator.perform(InitializeCustomLibrariesDbRequest()) coordinator.perform(CleanupUnusedTags()) + coordinator.invalidate() }) } @@ -65,7 +63,8 @@ class UserControllers @Inject constructor( this.isFirstLaunch = isFirstLaunch syncScheduler.init(DelayIntervals.retry) this.changeObserver = ObjectUserChangeObserver( - dbWrapper = dbWrapper, observable = objectUserChangeEventStream, + dbWrapperMain = dbWrapperMain, + observable = objectUserChangeEventStream, applicationScope = applicationScope, dispatchers = dispatchers ) @@ -113,7 +112,6 @@ class UserControllers @Inject constructor( } private fun createDbStorage(userId: Long) { - val file = fileStore.dbFile(userId) - dbWrapper.initWithMainConfiguration(dbFile = file) + dbWrapperMain.initWithMainConfiguration(userId) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/WebSocketController.kt b/app/src/main/java/org/zotero/android/sync/WebSocketController.kt index c535d346..104b428d 100644 --- a/app/src/main/java/org/zotero/android/sync/WebSocketController.kt +++ b/app/src/main/java/org/zotero/android/sync/WebSocketController.kt @@ -14,7 +14,7 @@ import org.zotero.android.api.mappers.ChangeWsResponseMapper import org.zotero.android.api.mappers.WsResponseMapper import org.zotero.android.architecture.core.EventStream import org.zotero.android.architecture.coroutines.ApplicationScope -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.requests.ReadVersionDbRequest import org.zotero.android.websocket.ChangeWsResponse import org.zotero.android.websocket.Command @@ -54,7 +54,7 @@ private data class Response( @Singleton class WebSocketController @Inject constructor( - val dbWrapper: DbWrapper, + val dbWrapperMain: DbWrapperMain, val observable: ChangeWsResponseKindEventStream, val dispatcher: CoroutineDispatcher, @ForWebSocket @@ -370,7 +370,7 @@ class WebSocketController @Inject constructor( } try { - val localVersion = dbWrapper.realmDbStorage.perform( + val localVersion = dbWrapperMain.realmDbStorage.perform( ReadVersionDbRequest(libraryId = responseType.libraryIdentifier), invalidateRealm = true ) diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/DeleteGroupSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/DeleteGroupSyncAction.kt index 81f9fbe4..21f400d3 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/DeleteGroupSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/DeleteGroupSyncAction.kt @@ -6,6 +6,6 @@ import org.zotero.android.sync.syncactions.architecture.SyncAction class DeleteGroupSyncAction(val groupId: Int): SyncAction() { fun result() { val request = DeleteGroupDbRequest(groupId = this.groupId) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/DeleteWebDavFilesSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/DeleteWebDavFilesSyncAction.kt index 8bbcf18f..2e1f4650 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/DeleteWebDavFilesSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/DeleteWebDavFilesSyncAction.kt @@ -34,7 +34,7 @@ class DeleteWebDavFilesSyncAction( private fun loadDeletions(): CustomResult> { try { val deletions = - dbWrapper.realmDbStorage.perform(request = ReadWebDavDeletionsDbRequest(libraryId = this.libraryId)) + dbWrapperMain.realmDbStorage.perform(request = ReadWebDavDeletionsDbRequest(libraryId = this.libraryId)) val keys = deletions.map { it.key } deletions.firstOrNull()?.realm?.refresh() return CustomResult.GeneralSuccess(keys) @@ -46,7 +46,7 @@ class DeleteWebDavFilesSyncAction( private fun removeDeletions(keys: Set): CustomResult { try { - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( request = DeleteWebDavDeletionsDbRequest( keys = keys, libraryId = this.libraryId diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/FetchAndStoreGroupSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/FetchAndStoreGroupSyncAction.kt index 6cbb55ff..ab3423b9 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/FetchAndStoreGroupSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/FetchAndStoreGroupSyncAction.kt @@ -17,7 +17,7 @@ class FetchAndStoreGroupSyncAction( if (networkResult !is CustomResult.GeneralSuccess.NetworkSuccess) { return networkResult as CustomResult.GeneralError } - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( StoreGroupDbRequest( response = networkResult.value!!, userId = this.userId diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/LoadLibraryDataSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/LoadLibraryDataSyncAction.kt index eaf5dfa3..94e02858 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/LoadLibraryDataSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/LoadLibraryDataSyncAction.kt @@ -1,6 +1,5 @@ package org.zotero.android.sync.syncactions -import org.zotero.android.database.RealmDbStorage import org.zotero.android.database.requests.ReadLibrariesDataDbRequest import org.zotero.android.sync.Libraries import org.zotero.android.sync.LibraryData @@ -12,7 +11,6 @@ class LoadLibraryDataSyncAction( val fetchUpdates: Boolean, val loadVersions: Boolean, val webDavEnabled: Boolean, - val dbStorage: RealmDbStorage, ) : SyncAction() { fun result(): List { @@ -39,7 +37,7 @@ class LoadLibraryDataSyncAction( } } - return dbStorage.perform(request = request, invalidateRealm = true) + return dbWrapperMain.realmDbStorage.perform(request = request, invalidateRealm = true) } } diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/LoadUploadDataSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/LoadUploadDataSyncAction.kt index 30e3f00c..08cd9c34 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/LoadUploadDataSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/LoadUploadDataSyncAction.kt @@ -21,6 +21,6 @@ class LoadUploadDataSyncAction constructor( fileStorage = this.fileStore, defaults = this.defaults ) - return dbWrapper.realmDbStorage.perform(request = request, invalidateRealm = true) + return dbWrapperMain.realmDbStorage.perform(request = request, invalidateRealm = true) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/MarkChangesAsResolvedSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/MarkChangesAsResolvedSyncAction.kt index 5e0dd89d..8be31d09 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/MarkChangesAsResolvedSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/MarkChangesAsResolvedSyncAction.kt @@ -9,7 +9,7 @@ class MarkChangesAsResolvedSyncAction(val libraryId: LibraryIdentifier) : SyncAc fun result() { val request = MarkAllLibraryObjectChangesAsSyncedDbRequest(libraryId = this.libraryId) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/MarkForResyncSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/MarkForResyncSyncAction.kt index b6b89b55..313cb07e 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/MarkForResyncSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/MarkForResyncSyncAction.kt @@ -28,6 +28,6 @@ class MarkForResyncSyncAction( SyncObject.settings -> request = MarkForResyncDbAction(libraryId = this.libraryId, keys = this.keys, clazz = RPageIndex::class) } - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupAsLocalOnlySyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupAsLocalOnlySyncAction.kt index f58194bd..ba63e07c 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupAsLocalOnlySyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupAsLocalOnlySyncAction.kt @@ -9,7 +9,7 @@ class MarkGroupAsLocalOnlySyncAction( ) : SyncAction() { fun result() { val request = MarkGroupAsLocalOnlyDbRequest(groupId = this.groupId) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupForResyncSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupForResyncSyncAction.kt index b6ec1803..fba52d75 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupForResyncSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/MarkGroupForResyncSyncAction.kt @@ -8,7 +8,7 @@ class MarkGroupForResyncSyncAction( val identifier: Int, ) : SyncAction() { fun result() { - dbWrapper.realmDbStorage.perform(request = MarkGroupForResyncDbAction(identifier = this.identifier)) + dbWrapperMain.realmDbStorage.perform(request = MarkGroupForResyncDbAction(identifier = this.identifier)) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/PerformDeletionsSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/PerformDeletionsSyncAction.kt index d500083d..b690fce5 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/PerformDeletionsSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/PerformDeletionsSyncAction.kt @@ -22,7 +22,7 @@ class PerformDeletionsSyncAction constructor( tags = this.tags, conflictMode = this.conflictMode ) - val conflicts = dbWrapper.realmDbStorage.perform(request = request, invalidateRealm = true) + val conflicts = dbWrapperMain.realmDbStorage.perform(request = request, invalidateRealm = true) return conflicts } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/RestoreDeletionsSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/RestoreDeletionsSyncAction.kt index afa395b0..bf4429db 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/RestoreDeletionsSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/RestoreDeletionsSyncAction.kt @@ -18,7 +18,7 @@ class RestoreDeletionsSyncAction( collections = this.collections, items = this.items ) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) return CustomResult.GeneralSuccess(Unit) } catch (error: Throwable) { return CustomResult.GeneralError.CodeError(error) diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryFilesSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryFilesSyncAction.kt index f6ca299e..da7367e6 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryFilesSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryFilesSyncAction.kt @@ -22,7 +22,7 @@ class RevertLibraryFilesSyncAction( fun result() { Timber.i("RevertLibraryFilesSyncAction: revert files to upload") val toUpload = - this.dbWrapper.realmDbStorage.perform(request = ReadAllAttachmentUploadsDbRequest(libraryId = this.libraryId)) + this.dbWrapperMain.realmDbStorage.perform(request = ReadAllAttachmentUploadsDbRequest(libraryId = this.libraryId)) val cachedResponses = mutableListOf() val failedKeys = mutableListOf() for (item in toUpload) { @@ -53,7 +53,7 @@ class RevertLibraryFilesSyncAction( file.delete() } var changedFilenames = mutableListOf() - this.dbWrapper.realmDbStorage.perform { coordinator -> + this.dbWrapperMain.realmDbStorage.perform { coordinator -> Timber.e("RevertLibraryFilesSyncAction: delete failed keys") coordinator.perform( request = DeleteObjectsDbRequest( @@ -72,7 +72,7 @@ class RevertLibraryFilesSyncAction( ) changedFilenames = coordinator.perform(request = request).changedFilenames.toMutableList() - coordinator.refresh() + coordinator.invalidate() } Timber.e("RevertLibraryFilesSyncAction: rename local files to match file names") diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryUpdatesSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryUpdatesSyncAction.kt index e40fe5ac..f8daa137 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryUpdatesSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/RevertLibraryUpdatesSyncAction.kt @@ -74,7 +74,7 @@ class RevertLibraryUpdatesSyncAction( var failedSearches = mutableListOf() var failedItems = mutableListOf() - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val collections = loadCachedJsonForObject( clazz = RCollection::class, objectType = SyncObject.collection, @@ -120,7 +120,7 @@ class RevertLibraryUpdatesSyncAction( failedCollections = collections.second.toMutableList() failedSearches = searches.second.toMutableList() failedItems = items.second.toMutableList() - coordinator.refresh() + coordinator.invalidate() } renameExistingFiles(changes = changes, libraryId = this.libraryId) diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/StoreVersionSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/StoreVersionSyncAction.kt index bd2a0fad..b3fbe3b3 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/StoreVersionSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/StoreVersionSyncAction.kt @@ -1,24 +1,21 @@ package org.zotero.android.sync.syncactions -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext import org.zotero.android.database.requests.UpdateVersionType import org.zotero.android.database.requests.UpdateVersionsDbRequest import org.zotero.android.sync.LibraryIdentifier import org.zotero.android.sync.syncactions.architecture.SyncAction - class StoreVersionSyncAction( val version: Int, val type: UpdateVersionType, val libraryId: LibraryIdentifier, ) : SyncAction() { - suspend fun result() = withContext(Dispatchers.IO) { + fun result() { val request = UpdateVersionsDbRequest( version = this@StoreVersionSyncAction.version, libraryId = this@StoreVersionSyncAction.libraryId, type = this@StoreVersionSyncAction.type ) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) } } \ No newline at end of file diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/SubmitDeletionSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/SubmitDeletionSyncAction.kt index c9668ca9..05b61e01 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/SubmitDeletionSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/SubmitDeletionSyncAction.kt @@ -60,7 +60,7 @@ class SubmitDeletionSyncAction( private fun deleteFromDb(version: Int): Boolean { try { var didCreateDeletions = false - dbWrapper.realmDbStorage.perform { coordinator -> + dbWrapperMain.realmDbStorage.perform { coordinator -> val updateVersion = UpdateVersionsDbRequest( version = version, libraryId = this.libraryId, @@ -112,7 +112,7 @@ class SubmitDeletionSyncAction( } } coordinator.perform(requests) - coordinator.refresh() + coordinator.invalidate() } return didCreateDeletions } catch (error: Exception) { diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/SubmitUpdateSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/SubmitUpdateSyncAction.kt index 0e70036b..6bed2600 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/SubmitUpdateSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/SubmitUpdateSyncAction.kt @@ -111,7 +111,7 @@ class SubmitUpdateSyncAction( ) ) } - dbWrapper.realmDbStorage.perform(requests) + dbWrapperMain.realmDbStorage.perform(requests) return CustomResult.GeneralSuccess(newVersion to null) } catch (error: Exception) { Timber.e(error) @@ -190,7 +190,7 @@ class SubmitUpdateSyncAction( if (!requests.isEmpty()) { try { - dbWrapper.realmDbStorage.perform(requests) + dbWrapperMain.realmDbStorage.perform(requests) } catch (e: Exception) { Timber.e(e, "SubmitUpdateSyncAction: can't store local changes") return CustomResult.GeneralSuccess( @@ -385,7 +385,7 @@ class SubmitUpdateSyncAction( Timber.w("SubmitUpdateSyncAction: annotations too long: ${splitKeys} in ${libraryId}") try { - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( request = SplitAnnotationsDbRequest( keys = splitKeys, libraryId = libraryId diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/SyncSettingsSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/SyncSettingsSyncAction.kt index ba88ed90..8eaaae8c 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/SyncSettingsSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/SyncSettingsSyncAction.kt @@ -38,7 +38,7 @@ class SyncSettingsSyncAction( val value = networkResult.value!! val response = settingsResponseMapper.fromJson(value) val request = StoreSettingsDbRequest(response = response, libraryId = this.libraryId) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) val settingsChanged = newVersion != this.sinceVersion return CustomResult.GeneralSuccess(Pair(settingsChanged, newVersion)) } diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/SyncVersionsSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/SyncVersionsSyncAction.kt index a8da9461..f10918e6 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/SyncVersionsSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/SyncVersionsSyncAction.kt @@ -1,6 +1,5 @@ package org.zotero.android.sync.syncactions -import kotlinx.coroutines.withContext import org.zotero.android.BuildConfig import org.zotero.android.api.network.CustomResult import org.zotero.android.api.network.safeApiCall @@ -25,54 +24,54 @@ class SyncVersionsSyncAction( ) : SyncAction() { suspend fun result(): Pair> { - return withContext(dispatcher) { - when (this@SyncVersionsSyncAction.objectS) { - SyncObject.collection -> - return@withContext synchronizeVersions( - libraryId = this@SyncVersionsSyncAction.libraryId, - userId = this@SyncVersionsSyncAction.userId, objectS = this@SyncVersionsSyncAction.objectS, - sinceVersion = this@SyncVersionsSyncAction.sinceVersion, - currentVersion = this@SyncVersionsSyncAction.currentVersion, syncType = this@SyncVersionsSyncAction.syncType - ) - SyncObject.item -> { - return@withContext synchronizeVersions( - libraryId = this@SyncVersionsSyncAction.libraryId, - userId = this@SyncVersionsSyncAction.userId, - objectS = this@SyncVersionsSyncAction.objectS, - sinceVersion = this@SyncVersionsSyncAction.sinceVersion, - currentVersion = this@SyncVersionsSyncAction.currentVersion, - syncType = this@SyncVersionsSyncAction.syncType - ) - } + when (this@SyncVersionsSyncAction.objectS) { + SyncObject.collection -> + return synchronizeVersions( + libraryId = this@SyncVersionsSyncAction.libraryId, + userId = this@SyncVersionsSyncAction.userId, + objectS = this@SyncVersionsSyncAction.objectS, + sinceVersion = this@SyncVersionsSyncAction.sinceVersion, + currentVersion = this@SyncVersionsSyncAction.currentVersion, + syncType = this@SyncVersionsSyncAction.syncType + ) + + SyncObject.item -> { + return synchronizeVersions( + libraryId = this@SyncVersionsSyncAction.libraryId, + userId = this@SyncVersionsSyncAction.userId, + objectS = this@SyncVersionsSyncAction.objectS, + sinceVersion = this@SyncVersionsSyncAction.sinceVersion, + currentVersion = this@SyncVersionsSyncAction.currentVersion, + syncType = this@SyncVersionsSyncAction.syncType + ) + } - SyncObject.trash -> { - return@withContext synchronizeVersions( - libraryId = this@SyncVersionsSyncAction.libraryId, - userId = this@SyncVersionsSyncAction.userId, - objectS = this@SyncVersionsSyncAction.objectS, - sinceVersion = this@SyncVersionsSyncAction.sinceVersion, - currentVersion = this@SyncVersionsSyncAction.currentVersion, - syncType = this@SyncVersionsSyncAction.syncType - ) - } + SyncObject.trash -> { + return synchronizeVersions( + libraryId = this@SyncVersionsSyncAction.libraryId, + userId = this@SyncVersionsSyncAction.userId, + objectS = this@SyncVersionsSyncAction.objectS, + sinceVersion = this@SyncVersionsSyncAction.sinceVersion, + currentVersion = this@SyncVersionsSyncAction.currentVersion, + syncType = this@SyncVersionsSyncAction.syncType + ) + } - SyncObject.search -> { - return@withContext synchronizeVersions( - libraryId = this@SyncVersionsSyncAction.libraryId, - userId = this@SyncVersionsSyncAction.userId, - objectS = this@SyncVersionsSyncAction.objectS, - sinceVersion = this@SyncVersionsSyncAction.sinceVersion, - currentVersion = this@SyncVersionsSyncAction.currentVersion, - syncType = this@SyncVersionsSyncAction.syncType - ) - } + SyncObject.search -> { + return synchronizeVersions( + libraryId = this@SyncVersionsSyncAction.libraryId, + userId = this@SyncVersionsSyncAction.userId, + objectS = this@SyncVersionsSyncAction.objectS, + sinceVersion = this@SyncVersionsSyncAction.sinceVersion, + currentVersion = this@SyncVersionsSyncAction.currentVersion, + syncType = this@SyncVersionsSyncAction.syncType + ) + } - SyncObject.settings -> { - return@withContext Pair(0, listOf()) - } + SyncObject.settings -> { + return Pair(0, listOf()) } } - } private suspend fun synchronizeVersions( @@ -143,7 +142,7 @@ class SyncVersionsSyncAction( delayIntervals: List ): Pair> { var identifiers = mutableListOf() - dbWrapper.realmDbStorage.perform(coordinatorAction = { coordinator -> + dbWrapperMain.realmDbStorage.perform(coordinatorAction = { coordinator -> when (syncType) { SyncKind.full -> { coordinator.perform( @@ -168,7 +167,7 @@ class SyncVersionsSyncAction( ) identifiers = coordinator.perform(request = request).toMutableList() - coordinator.refresh() + coordinator.invalidate() }) return Pair(newVersion, identifiers) } diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/UploadAttachmentSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/UploadAttachmentSyncAction.kt index ff7565c9..5db1dfb8 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/UploadAttachmentSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/UploadAttachmentSyncAction.kt @@ -185,7 +185,7 @@ class UploadAttachmentSyncAction( ) ) } - dbWrapper.realmDbStorage.perform(requests) + dbWrapperMain.realmDbStorage.perform(requests) } catch (error: Exception) { Timber.e("UploadAttachmentSyncAction: can't mark attachment as uploaded - $error") throw error @@ -196,7 +196,7 @@ class UploadAttachmentSyncAction( private fun checkDatabase() { try { val request = CheckItemIsChangedDbRequest(libraryId = this.libraryId, key = this.key) - val isChanged = dbWrapper.realmDbStorage.perform(request = request, invalidateRealm = true) + val isChanged = dbWrapperMain.realmDbStorage.perform(request = request, invalidateRealm = true) if (!isChanged) { return } else { @@ -220,7 +220,7 @@ class UploadAttachmentSyncAction( } Timber.e("UploadAttachmentSyncAction: missing attachment - ${this.file.absolutePath}") - val item = dbWrapper.realmDbStorage.perform( + val item = dbWrapperMain.realmDbStorage.perform( ReadItemDbRequest( libraryId = this.libraryId, key = this.key @@ -293,7 +293,7 @@ class UploadAttachmentSyncAction( Timber.i("UploadAttachmentSyncAction: submit mtime and md5") val loadParameters: Map try { - val item = dbWrapper.realmDbStorage.perform( + val item = dbWrapperMain.realmDbStorage.perform( request = ReadItemDbRequest( libraryId = this.libraryId, key = this.key diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/UploadFixSyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/UploadFixSyncAction.kt index e837051a..66f61b1c 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/UploadFixSyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/UploadFixSyncAction.kt @@ -87,7 +87,7 @@ class UploadFixSyncAction( keys = listOf(this.key), clazz = RItem::class ) - dbWrapper.realmDbStorage.perform(listOf(markAsUploaded, markForResync)) + dbWrapperMain.realmDbStorage.perform(listOf(markAsUploaded, markForResync)) return CustomResult.GeneralSuccess(Unit) } catch (e: Exception) { return CustomResult.GeneralError.CodeError(e) @@ -113,7 +113,7 @@ class UploadFixSyncAction( } try { - val item = dbWrapper.realmDbStorage.perform( + val item = dbWrapperMain.realmDbStorage.perform( ReadItemDbRequest( libraryId = this.libraryId, key = this.key diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncAction.kt b/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncAction.kt index e90f1e0a..fe1dde4a 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncAction.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncAction.kt @@ -17,8 +17,8 @@ abstract class SyncAction { bindings.settingsResponseMapper() } - val dbWrapper by lazy { - bindings.dbWrapper() + val dbWrapperMain by lazy { + bindings.dbWrapperMain() } val gson by lazy { diff --git a/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncActionDependencyProvider.kt b/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncActionDependencyProvider.kt index 4d503ec1..8edcd771 100644 --- a/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncActionDependencyProvider.kt +++ b/app/src/main/java/org/zotero/android/sync/syncactions/architecture/SyncActionDependencyProvider.kt @@ -17,7 +17,7 @@ import org.zotero.android.architecture.Defaults import org.zotero.android.attachmentdownloader.AttachmentDownloader import org.zotero.android.attachmentdownloader.AttachmentDownloaderEventStream import org.zotero.android.backgrounduploader.BackgroundUploaderContext -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.files.FileStore import org.zotero.android.sync.DateParser import org.zotero.android.sync.SchemaController @@ -29,7 +29,7 @@ import org.zotero.android.webdav.WebDavSessionStorage interface SyncActionDependencyProvider { fun syncApi(): SyncApi fun settingsResponseMapper(): SettingsResponseMapper - fun dbWrapper(): DbWrapper + fun dbWrapperMain(): DbWrapperMain fun gson(): Gson fun backgroundUploaderContext(): BackgroundUploaderContext fun fileStore(): FileStore diff --git a/app/src/main/java/org/zotero/android/translator/loader/TranslatorsLoader.kt b/app/src/main/java/org/zotero/android/translator/loader/TranslatorsLoader.kt index 6983dbeb..448b66e7 100644 --- a/app/src/main/java/org/zotero/android/translator/loader/TranslatorsLoader.kt +++ b/app/src/main/java/org/zotero/android/translator/loader/TranslatorsLoader.kt @@ -8,10 +8,9 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import org.apache.commons.io.FileUtils import org.apache.commons.io.IOUtils -import org.zotero.android.api.annotations.BundleDataDb import org.zotero.android.architecture.Defaults import org.zotero.android.architecture.coroutines.Dispatchers -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperBundle import org.zotero.android.database.requests.SyncTranslatorsDbRequest import org.zotero.android.files.FileStore import org.zotero.android.screens.share.data.TranslatorMetadata @@ -31,8 +30,7 @@ class TranslatorsLoader @Inject constructor( private val defaults: Defaults, private val itemsUnzipper: TranslatorItemsUnzipper, private val fileStore: FileStore, - @BundleDataDb - private val bundleDbWrapper: DbWrapper + private val bundleDbWrapper: DbWrapperBundle ) { enum class UpdateType(val i: Int) { manual(1), diff --git a/app/src/main/java/org/zotero/android/uicomponents/addbyidentifier/IdentifierLookupController.kt b/app/src/main/java/org/zotero/android/uicomponents/addbyidentifier/IdentifierLookupController.kt index 6319b636..7f4ffae0 100644 --- a/app/src/main/java/org/zotero/android/uicomponents/addbyidentifier/IdentifierLookupController.kt +++ b/app/src/main/java/org/zotero/android/uicomponents/addbyidentifier/IdentifierLookupController.kt @@ -19,7 +19,7 @@ import org.zotero.android.architecture.core.EventStream import org.zotero.android.architecture.coroutines.Dispatchers import org.zotero.android.attachmentdownloader.RemoteAttachmentDownloader import org.zotero.android.attachmentdownloader.RemoteAttachmentDownloaderEventStream -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.Attachment import org.zotero.android.database.objects.ItemTypes import org.zotero.android.database.requests.CreateAttachmentDbRequest @@ -52,7 +52,7 @@ class IdentifierLookupController @Inject constructor( private val creatorResponseMapper: CreatorResponseMapper, private val dateParser: DateParser, private val schemaController: SchemaController, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val defaults: Defaults, private val translatorLoadedEventStream: TranslatorLoadedEventStream, private val attachmentDownloaderEventStream: RemoteAttachmentDownloaderEventStream, @@ -133,7 +133,7 @@ class IdentifierLookupController @Inject constructor( tags = emptyList(), fileStore = this.fileStore, ) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) } catch (error: Exception) { Timber.e(error, "IdentifierLookupController: can't store attachment after download") val (filename) = attachment.type as? Attachment.Kind.file ?: return @@ -260,7 +260,7 @@ class IdentifierLookupController @Inject constructor( schemaController = schemaController, dateParser = dateParser ) - dbWrapper.realmDbStorage.perform(request = request) + dbWrapperMain.realmDbStorage.perform(request = request) changeLookup( identifier = identifier, state = LookupData.State.translated( @@ -637,7 +637,7 @@ class IdentifierLookupController @Inject constructor( libraryId = libraryId, trashed = true ) - dbWrapper.realmDbStorage.perform(request) + dbWrapperMain.realmDbStorage.perform(request) } suspend fun lookUp( @@ -696,7 +696,7 @@ class IdentifierLookupController @Inject constructor( trashed = true ) } - dbWrapper.realmDbStorage.perform(requests = requests) + dbWrapperMain.realmDbStorage.perform(requests = requests) } catch (error: Exception) { Timber.e(error, "IdentifierLookupController: can't trash item(s)") } diff --git a/app/src/main/java/org/zotero/android/webdav/WebDavController.kt b/app/src/main/java/org/zotero/android/webdav/WebDavController.kt index 0534aba4..d5ed1f80 100644 --- a/app/src/main/java/org/zotero/android/webdav/WebDavController.kt +++ b/app/src/main/java/org/zotero/android/webdav/WebDavController.kt @@ -12,7 +12,7 @@ import org.zotero.android.api.WebDavApi import org.zotero.android.api.network.CustomResult import org.zotero.android.api.network.safeApiCall import org.zotero.android.api.network.safeApiCallSync -import org.zotero.android.database.DbWrapper +import org.zotero.android.database.DbWrapperMain import org.zotero.android.database.objects.RCustomLibraryType import org.zotero.android.database.requests.StoreMtimeForAttachmentDbRequest import org.zotero.android.files.FileStore @@ -33,14 +33,14 @@ import kotlin.coroutines.resume @Singleton class WebDavController @Inject constructor( private val sessionStorage: WebDavSessionStorage, - private val dbWrapper: DbWrapper, + private val dbWrapperMain: DbWrapperMain, private val webDavApi: WebDavApi, private val fileStore: FileStore, ) { private fun update(mtime: Long, key: String): CustomResult { try { - dbWrapper.realmDbStorage.perform( + dbWrapperMain.realmDbStorage.perform( StoreMtimeForAttachmentDbRequest( mtime = mtime, key = key, diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index d4da268b..ba525948 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -4,7 +4,7 @@ object BuildConfig { const val compileSdkVersion = 34 const val targetSdk = 34 - val versionCode = 84 // Must be updated on every build + val versionCode = 85 // Must be updated on every build val version = Version( major = 1, minor = 0,