Explorar o código

Add model to ArbitraryStorage db layer

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger %!s(int64=2) %!d(string=hai) anos
pai
achega
3b1d4b86a9

+ 48 - 0
app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStorageMapper.kt

@@ -0,0 +1,48 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Andy Scherzinger
+ * Copyright (C) 2022 Andy Scherzinger <infoi@andy-scherzinger.de>
+ *
+ * model 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.
+ *
+ * model 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 model program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.data.storage
+
+import com.nextcloud.talk.data.storage.model.ArbitraryStorage
+import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
+
+object ArbitraryStorageMapper {
+    fun toModel(entity: ArbitraryStorageEntity?): ArbitraryStorage? {
+        return if (entity == null) {
+            null
+        } else {
+            ArbitraryStorage(
+                entity.accountIdentifier,
+                entity.key,
+                entity.storageObject,
+                entity.value
+            )
+        }
+    }
+
+    fun toEntity(model: ArbitraryStorage): ArbitraryStorageEntity {
+        return ArbitraryStorageEntity(
+            accountIdentifier = model.accountIdentifier,
+            key = model.key,
+            storageObject = model.storageObject,
+            value = model.value
+        )
+    }
+}

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

@@ -20,10 +20,10 @@
 
 package com.nextcloud.talk.data.storage
 
-import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
+import com.nextcloud.talk.data.storage.model.ArbitraryStorage
 
 interface ArbitraryStoragesRepository {
-    fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorageEntity
+    fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorage
     suspend fun deleteArbitraryStorage(accountIdentifier: Long)
-    fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorageEntity): Long
+    fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long
 }

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

@@ -20,7 +20,7 @@
 
 package com.nextcloud.talk.data.storage
 
-import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
+import com.nextcloud.talk.data.storage.model.ArbitraryStorage
 
 class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: ArbitraryStoragesDao) :
     ArbitraryStoragesRepository {
@@ -28,15 +28,17 @@ class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: Arbitrar
         accountIdentifier: Long,
         key: String,
         objectString: String
-    ): ArbitraryStorageEntity {
-        return arbitraryStoragesDao.getStorageSetting(accountIdentifier, key, objectString)
+    ): ArbitraryStorage {
+        return ArbitraryStorageMapper.toModel(
+            arbitraryStoragesDao.getStorageSetting(accountIdentifier, key, objectString)
+        )!!
     }
 
     override suspend fun deleteArbitraryStorage(accountIdentifier: Long) {
         arbitraryStoragesDao.deleteArbitraryStorage(accountIdentifier)
     }
 
-    override fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorageEntity): Long {
-        return arbitraryStoragesDao.saveArbitraryStorage(arbitraryStorage)
+    override fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long {
+        return arbitraryStoragesDao.saveArbitraryStorage(ArbitraryStorageMapper.toEntity(arbitraryStorage))
     }
 }

+ 32 - 0
app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt

@@ -0,0 +1,32 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Andy Scherzinger
+ * Copyright (C) 2022 Andy Scherzinger <infoi@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.data.storage.model
+
+import android.os.Parcelable
+import kotlinx.android.parcel.Parcelize
+
+@Parcelize
+data class ArbitraryStorage(
+    var accountIdentifier: Long = 0,
+    var key: String? = null,
+    var storageObject: String? = null,
+    var value: String? = null
+) : Parcelable

+ 1 - 1
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java

@@ -80,8 +80,8 @@ import com.google.android.material.chip.ChipDrawable;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.data.user.model.User;
-import com.nextcloud.talk.data.user.model.UserEntity;
 import com.nextcloud.talk.events.UserMentionClickEvent;
+import com.nextcloud.talk.models.database.UserEntity;
 import com.nextcloud.talk.utils.text.Spans;
 
 import org.greenrobot.eventbus.EventBus;