diff options
author | Torsten Grote <t@grobox.de> | 2020-08-24 14:28:34 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-08-24 14:28:34 -0300 |
commit | 35bc91761ad1f8336f331c6b04cff8bf4d9ae064 (patch) | |
tree | 330c195f60d909de5de4d156357a1f74847da70e /wallet | |
parent | d3955c2d8ae552c22547a186ab196274e32919e7 (diff) | |
download | taler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.tar.gz taler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.tar.bz2 taler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.zip |
Upgrade to Kotlin 1.4
Diffstat (limited to 'wallet')
5 files changed, 26 insertions, 29 deletions
diff --git a/wallet/build.gradle b/wallet/build.gradle index 87019f8..8806a5a 100644 --- a/wallet/build.gradle +++ b/wallet/build.gradle @@ -20,7 +20,7 @@ plugins { id "com.android.application" id "kotlin-android" id "kotlin-android-extensions" - id 'kotlinx-serialization' + id "kotlinx-serialization" id "de.undercouch.download" } @@ -104,7 +104,7 @@ dependencies { implementation 'androidx.preference:preference:1.1.1' implementation 'com.google.android.material:material:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.constraintlayout:constraintlayout:2.0.0' // Lists and Selection implementation "androidx.recyclerview:recyclerview:1.1.0" diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt index 5ca2255..693fe7e 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt @@ -32,7 +32,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.KSerializer import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonConfiguration import net.taler.wallet.backend.WalletBackendService.Companion.MSG_COMMAND import net.taler.wallet.backend.WalletBackendService.Companion.MSG_NOTIFY import net.taler.wallet.backend.WalletBackendService.Companion.MSG_REPLY @@ -49,9 +48,9 @@ class WalletBackendApi( private val app: Application, private val notificationHandler: ((payload: JSONObject) -> Unit) ) { - private val json = Json( - JsonConfiguration.Stable.copy(ignoreUnknownKeys = true) - ) + private val json = Json { + ignoreUnknownKeys = true + } private var walletBackendMessenger: Messenger? = null private val queuedMessages = LinkedList<Message>() private val handlers = ConcurrentHashMap<Int, (isError: Boolean, message: JSONObject) -> Unit>() @@ -153,14 +152,14 @@ class WalletBackendApi( serializer: KSerializer<T>? = null, args: (JSONObject.() -> JSONObject)? = null ): WalletResponse<T> = withContext(Dispatchers.Default) { - suspendCoroutine<WalletResponse<T>> { cont -> + suspendCoroutine { cont -> sendRequest(operation, args?.invoke(JSONObject())) { isError, message -> val response = if (isError) { - val error = json.parse(WalletErrorInfo.serializer(), message.toString()) - WalletResponse.Error<T>(error) + val error = json.decodeFromString(WalletErrorInfo.serializer(), message.toString()) + WalletResponse.Error(error) } else { @Suppress("UNCHECKED_CAST") // if serializer is null, T must be Unit - val t: T = serializer?.let { json.parse(serializer, message.toString()) } ?: Unit as T + val t: T = serializer?.let { json.decodeFromString(serializer, message.toString()) } ?: Unit as T WalletResponse.Success(t) } cont.resume(response) @@ -173,11 +172,11 @@ class WalletBackendApi( mapper: ObjectMapper, noinline args: (JSONObject.() -> JSONObject)? = null ): WalletResponse<T> = withContext(Dispatchers.Default) { - suspendCoroutine<WalletResponse<T>> { cont -> + suspendCoroutine { cont -> sendRequest(operation, args?.invoke(JSONObject())) { isError, message -> val response = if (isError) { val error: WalletErrorInfo = mapper.readValue(message.toString()) - WalletResponse.Error<T>(error) + WalletResponse.Error(error) } else { val t: T = mapper.readValue(message.toString()) WalletResponse.Success(t) diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt index ab3d42e..57ce82e 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt @@ -21,18 +21,17 @@ import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.deser.std.StdDeserializer -import kotlinx.serialization.Decoder -import kotlinx.serialization.Encoder import kotlinx.serialization.KSerializer -import kotlinx.serialization.PrimitiveDescriptor -import kotlinx.serialization.PrimitiveKind.STRING import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonInput +import kotlinx.serialization.descriptors.PrimitiveKind.STRING +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonDecoder import kotlinx.serialization.json.JsonObject import org.json.JSONObject - @Serializable sealed class WalletResponse<T> { @Serializable @@ -96,11 +95,11 @@ data class WalletErrorInfo( class JSONObjectDeserializer : KSerializer<JSONObject> { - override val descriptor = PrimitiveDescriptor("JSONObjectDeserializer", STRING) + override val descriptor = PrimitiveSerialDescriptor("JSONObjectDeserializer", STRING) override fun deserialize(decoder: Decoder): JSONObject { - val input = decoder as JsonInput - val tree = input.decodeJson() as JsonObject + val input = decoder as JsonDecoder + val tree = input.decodeJsonElement() as JsonObject return JSONObject(tree.toString()) } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt index 3d00900..99a6ec8 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt @@ -58,7 +58,7 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - paymentManager.payStatus.observe(viewLifecycleOwner, this::onPaymentStatusChanged) + paymentManager.payStatus.observe(viewLifecycleOwner, ::onPaymentStatusChanged) paymentManager.detailsShown.observe(viewLifecycleOwner, Observer { shown -> beginDelayedTransition(view as ViewGroup) val res = if (shown) R.string.payment_hide_details else R.string.payment_show_details @@ -91,7 +91,7 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { } } - private fun onPaymentStatusChanged(payStatus: PayStatus) { + private fun onPaymentStatusChanged(payStatus: PayStatus?) { when (payStatus) { is PayStatus.Prepared -> { showLoading(false) diff --git a/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt b/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt index d8f28c5..a81626c 100644 --- a/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt +++ b/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.KotlinModule import com.fasterxml.jackson.module.kotlin.readValue import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonConfiguration import net.taler.lib.common.Amount import net.taler.lib.common.AmountMixin import net.taler.lib.common.Timestamp @@ -32,9 +31,9 @@ import org.junit.Test class WalletResponseTest { - private val json = Json( - JsonConfiguration.Stable.copy(ignoreUnknownKeys = true) - ) + private val json = Json { + ignoreUnknownKeys = true + } private val mapper = ObjectMapper() .registerModule(KotlinModule()) @@ -45,7 +44,7 @@ class WalletResponseTest { @Test fun testBalanceResponse() { val serializer = WalletResponse.Success.serializer(BalanceResponse.serializer()) - val response = json.parse( + val response = json.decodeFromString( serializer, """ { "type": "response", @@ -82,7 +81,7 @@ class WalletResponseTest { "message":"unexpected exception: Error: BUG: invariant violation (purchase status)" } """.trimIndent() - val info = json.parse(WalletErrorInfo.serializer(), infoJson) + val info = json.decodeFromString(WalletErrorInfo.serializer(), infoJson) val infoJackson: WalletErrorInfo = mapper.readValue(infoJson) println(info.userFacingMsg) assertEquals(info.userFacingMsg, infoJackson.userFacingMsg) |