mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-24 05:55:39 +03:00
unify room converter's json handling to always use LoganSquare
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
2a0ee1c90d
commit
25a5346435
5 changed files with 22 additions and 56 deletions
|
@ -36,10 +36,10 @@ class CapabilitiesConverter {
|
|||
|
||||
@TypeConverter
|
||||
fun fromStringToCapabilities(value: String): Capabilities? {
|
||||
if (value.isBlank()) {
|
||||
return null
|
||||
return if (value.isBlank()) {
|
||||
null
|
||||
} else {
|
||||
return LoganSquare.parse(value, Capabilities::class.java)
|
||||
}
|
||||
|
||||
return LoganSquare.parse(value, Capabilities::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,26 +21,26 @@
|
|||
package com.nextcloud.talk.data.source.local.converters
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.bluelinelabs.logansquare.LoganSquare
|
||||
import com.nextcloud.talk.models.ExternalSignalingServer
|
||||
|
||||
class ExternalSignalingServerConverter {
|
||||
val json = JsonConfiguration.customJsonConfiguration
|
||||
|
||||
@TypeConverter
|
||||
fun fromExternalSignalingServerToString(externalSignalingServer: ExternalSignalingServer?): String {
|
||||
return if (externalSignalingServer == null) {
|
||||
""
|
||||
} else {
|
||||
json.encodeToString(ExternalSignalingServer.serializer(), externalSignalingServer)
|
||||
LoganSquare.serialize(externalSignalingServer)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromStringToExternalSignalingServer(value: String): ExternalSignalingServer? {
|
||||
if (value.isBlank()) {
|
||||
return null
|
||||
return if (value.isBlank()) {
|
||||
null
|
||||
} else {
|
||||
return LoganSquare.parse(value, ExternalSignalingServer::class.java)
|
||||
}
|
||||
|
||||
return json.decodeFromString(ExternalSignalingServer.serializer(), value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Andy Scherzinger
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
|
||||
* Copyright (C) 2017-2020 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* 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.source.local.converters
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
sealed class JsonConfiguration {
|
||||
companion object {
|
||||
val customJsonConfiguration = Json {
|
||||
prettyPrint = true
|
||||
useArrayPolymorphism = true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,26 +23,26 @@
|
|||
package com.nextcloud.talk.data.source.local.converters
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.bluelinelabs.logansquare.LoganSquare
|
||||
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
||||
|
||||
class PushConfigurationConverter {
|
||||
val json = JsonConfiguration.customJsonConfiguration
|
||||
|
||||
@TypeConverter
|
||||
fun fromPushConfigurationToString(pushConfiguration: PushConfigurationState?): String {
|
||||
return if (pushConfiguration == null) {
|
||||
""
|
||||
} else {
|
||||
json.encodeToString(PushConfigurationState.serializer(), pushConfiguration)
|
||||
LoganSquare.serialize(pushConfiguration)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromStringToPushConfiguration(value: String?): PushConfigurationState? {
|
||||
if (value.isNullOrBlank()) {
|
||||
return null
|
||||
return if (value.isNullOrBlank()) {
|
||||
null
|
||||
} else {
|
||||
return LoganSquare.parse(value, PushConfigurationState::class.java)
|
||||
}
|
||||
|
||||
return json.decodeFromString(PushConfigurationState.serializer(), value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,26 +23,26 @@
|
|||
package com.nextcloud.talk.data.source.local.converters
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.bluelinelabs.logansquare.LoganSquare
|
||||
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettings
|
||||
|
||||
class SignalingSettingsConverter {
|
||||
val json = JsonConfiguration.customJsonConfiguration
|
||||
|
||||
@TypeConverter
|
||||
fun fromSignalingSettingsToString(signalingSettings: SignalingSettings?): String {
|
||||
return if (signalingSettings == null) {
|
||||
""
|
||||
} else {
|
||||
json.encodeToString(SignalingSettings.serializer(), signalingSettings)
|
||||
LoganSquare.serialize(signalingSettings)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromStringToSignalingSettings(value: String): SignalingSettings? {
|
||||
if (value.isBlank()) {
|
||||
return null
|
||||
return if (value.isBlank()) {
|
||||
null
|
||||
} else {
|
||||
return LoganSquare.parse(value, SignalingSettings::class.java)
|
||||
}
|
||||
|
||||
return json.decodeFromString(SignalingSettings.serializer(), value)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue