aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-08-24 14:28:34 -0300
committerTorsten Grote <t@grobox.de>2020-08-24 14:28:34 -0300
commit35bc91761ad1f8336f331c6b04cff8bf4d9ae064 (patch)
tree330c195f60d909de5de4d156357a1f74847da70e /wallet/src/main
parentd3955c2d8ae552c22547a186ab196274e32919e7 (diff)
downloadtaler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.tar.gz
taler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.tar.bz2
taler-android-35bc91761ad1f8336f331c6b04cff8bf4d9ae064.zip
Upgrade to Kotlin 1.4
Diffstat (limited to 'wallet/src/main')
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt19
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt17
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt4
3 files changed, 19 insertions, 21 deletions
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)