From 3b1d4b86a954ece28bc4b40ff1c6e10cefaf50d4 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Fri, 24 Jun 2022 10:07:05 +0200 Subject: [PATCH] Add model to ArbitraryStorage db layer Signed-off-by: Andy Scherzinger --- .../data/storage/ArbitraryStorageMapper.kt | 48 +++++++++++++++++++ .../storage/ArbitraryStoragesRepository.kt | 6 +-- .../ArbitraryStoragesRepositoryImpl.kt | 12 +++-- .../data/storage/model/ArbitraryStorage.kt | 32 +++++++++++++ .../nextcloud/talk/utils/DisplayUtils.java | 2 +- 5 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStorageMapper.kt create mode 100644 app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt diff --git a/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStorageMapper.kt b/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStorageMapper.kt new file mode 100644 index 000000000..fe31df592 --- /dev/null +++ b/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 + * + * 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 . + */ + +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 + ) + } +} diff --git a/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepository.kt b/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepository.kt index 2e7affb96..d3b06672b 100644 --- a/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepository.kt +++ b/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 } diff --git a/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt index 9ceb92afd..05aef2c8f 100644 --- a/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt +++ b/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)) } } diff --git a/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt b/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt new file mode 100644 index 000000000..90353bc76 --- /dev/null +++ b/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 + * + * 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 . + */ + +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 diff --git a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java index b87bca7f1..11c69253f 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java +++ b/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;