Kaynağa Gözat

add arbitrary storage business layer

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 2 yıl önce
ebeveyn
işleme
12f793567e

+ 39 - 0
app/src/main/java/com/nextcloud/talk/arbitrarystorage/ArbitraryStorageManager.kt

@@ -0,0 +1,39 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Andy Scherzinger
+ * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.arbitrarystorage
+
+import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository
+import com.nextcloud.talk.data.storage.model.ArbitraryStorage
+import io.reactivex.Maybe
+
+class ArbitraryStorageManager(private val arbitraryStoragesRepository: ArbitraryStoragesRepository) {
+    fun storeStorageSetting(accountIdentifier: Long, key: String?, value: String?, objectString: String?) {
+        arbitraryStoragesRepository.saveArbitraryStorage(ArbitraryStorage(accountIdentifier, key, objectString, value))
+    }
+
+    fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): Maybe<ArbitraryStorage> {
+        return arbitraryStoragesRepository.getStorageSetting(accountIdentifier, key, objectString)
+    }
+
+    suspend fun deleteAllEntriesForAccountIdentifier(accountIdentifier: Long) {
+        return arbitraryStoragesRepository.deleteArbitraryStorage(accountIdentifier)
+    }
+}

+ 6 - 1
app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesDao.kt

@@ -25,6 +25,7 @@ import androidx.room.Insert
 import androidx.room.OnConflictStrategy
 import androidx.room.Query
 import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
+import io.reactivex.Maybe
 
 @Dao
 abstract class ArbitraryStoragesDao {
@@ -34,7 +35,11 @@ abstract class ArbitraryStoragesDao {
             "\"key\" = :key AND " +
             "object = :objectString"
     )
-    abstract fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorageEntity
+    abstract fun getStorageSetting(
+        accountIdentifier: Long,
+        key: String,
+        objectString: String
+    ): Maybe<ArbitraryStorageEntity>
 
     @Query("DELETE FROM ArbitraryStorage WHERE accountIdentifier = :accountIdentifier")
     abstract suspend fun deleteArbitraryStorage(accountIdentifier: Long)

+ 2 - 1
app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepository.kt

@@ -21,9 +21,10 @@
 package com.nextcloud.talk.data.storage
 
 import com.nextcloud.talk.data.storage.model.ArbitraryStorage
+import io.reactivex.Maybe
 
 interface ArbitraryStoragesRepository {
-    fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorage
+    fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): Maybe<ArbitraryStorage>
     suspend fun deleteArbitraryStorage(accountIdentifier: Long)
     fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long
 }

+ 5 - 4
app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt

@@ -21,6 +21,7 @@
 package com.nextcloud.talk.data.storage
 
 import com.nextcloud.talk.data.storage.model.ArbitraryStorage
+import io.reactivex.Maybe
 
 class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: ArbitraryStoragesDao) :
     ArbitraryStoragesRepository {
@@ -28,10 +29,10 @@ class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: Arbitrar
         accountIdentifier: Long,
         key: String,
         objectString: String
-    ): ArbitraryStorage {
-        return ArbitraryStorageMapper.toModel(
-            arbitraryStoragesDao.getStorageSetting(accountIdentifier, key, objectString)
-        )!!
+    ): Maybe<ArbitraryStorage> {
+        return arbitraryStoragesDao
+            .getStorageSetting(accountIdentifier, key, objectString)
+            .map { ArbitraryStorageMapper.toModel(it) }
     }
 
     override suspend fun deleteArbitraryStorage(accountIdentifier: Long) {

+ 8 - 0
app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageModule.java

@@ -21,7 +21,10 @@ package com.nextcloud.talk.utils.database.arbitrarystorage;
 
 import autodagger.AutoInjector;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
+import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager;
 import com.nextcloud.talk.dagger.modules.DatabaseModule;
+import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository;
+
 import dagger.Module;
 import dagger.Provides;
 import io.requery.Persistable;
@@ -41,4 +44,9 @@ public class ArbitraryStorageModule {
     public ArbitraryStorageUtils provideArbitraryStorageUtils(ReactiveEntityStore<Persistable> dataStore) {
         return new ArbitraryStorageUtils(dataStore);
     }
+
+    @Provides
+    public ArbitraryStorageManager provideArbitraryStorageManager(ArbitraryStoragesRepository repository) {
+        return new ArbitraryStorageManager(repository);
+    }
 }

+ 1 - 0
app/src/main/java/com/nextcloud/talk/utils/database/arbitrarystorage/ArbitraryStorageUtils.java

@@ -29,6 +29,7 @@ import io.requery.query.Result;
 import io.requery.reactivex.ReactiveEntityStore;
 import io.requery.reactivex.ReactiveScalar;
 
+@Deprecated
 public class ArbitraryStorageUtils {
     private ReactiveEntityStore<Persistable> dataStore;