From 023ea96d26a65d29d408ef78c9405411bb842afd Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 16 May 2022 19:58:31 +0200 Subject: -remove multiplatform dependency, library upgrade WIP --- cashier/build.gradle | 3 +++ .../main/java/net/taler/cashier/AboutDialogFragment.kt | 2 +- .../src/main/java/net/taler/cashier/BalanceFragment.kt | 2 +- .../src/main/java/net/taler/cashier/MainViewModel.kt | 17 ++++++----------- cashier/src/main/java/net/taler/cashier/Response.kt | 5 +++-- cashier/src/main/java/net/taler/cashier/SignedAmount.kt | 2 +- .../main/java/net/taler/cashier/config/ConfigManager.kt | 4 ++-- .../java/net/taler/cashier/withdraw/WithdrawManager.kt | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) (limited to 'cashier') diff --git a/cashier/build.gradle b/cashier/build.gradle index 1c9c2b6..ea59f23 100644 --- a/cashier/build.gradle +++ b/cashier/build.gradle @@ -85,6 +85,9 @@ dependencies { implementation "io.ktor:ktor-client:$ktor_version" implementation "io.ktor:ktor-client-okhttp:$ktor_version" implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version" + implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version" + implementation "io.ktor:ktor-client-content-negotiation:$ktor_version" + implementation "io.ktor:ktor-server-call-logging:$ktor_version" testImplementation "junit:junit:$junit_version" diff --git a/cashier/src/main/java/net/taler/cashier/AboutDialogFragment.kt b/cashier/src/main/java/net/taler/cashier/AboutDialogFragment.kt index cdea792..3da49d2 100644 --- a/cashier/src/main/java/net/taler/cashier/AboutDialogFragment.kt +++ b/cashier/src/main/java/net/taler/cashier/AboutDialogFragment.kt @@ -30,7 +30,7 @@ import net.taler.cashier.BuildConfig.VERSION_NAME import net.taler.cashier.config.VERSION_BANK import net.taler.cashier.databinding.FragmentAboutDialogBinding import net.taler.cashier.databinding.FragmentBalanceBinding -import net.taler.lib.common.Version +import net.taler.common.Version class AboutDialogFragment : DialogFragment() { diff --git a/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt b/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt index 002301c..fa9600b 100644 --- a/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt +++ b/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt @@ -32,10 +32,10 @@ import net.taler.cashier.BalanceFragmentDirections.Companion.actionBalanceFragme import net.taler.cashier.databinding.FragmentBalanceBinding import net.taler.cashier.withdraw.LastTransaction import net.taler.cashier.withdraw.WithdrawStatus +import net.taler.common.Amount import net.taler.common.exhaustive import net.taler.common.fadeIn import net.taler.common.fadeOut -import net.taler.lib.common.Amount sealed class BalanceResult { class Error(val msg: String) : BalanceResult() diff --git a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt index 253c7d5..1c819b9 100644 --- a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt +++ b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt @@ -24,17 +24,16 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import io.ktor.client.HttpClient import io.ktor.client.engine.okhttp.OkHttp -import io.ktor.client.features.json.JsonFeature -import io.ktor.client.features.json.serializer.KotlinxSerializer +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.serialization.kotlinx.json.json import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.serialization.json.Json import net.taler.cashier.HttpHelper.makeJsonGetRequest import net.taler.cashier.config.ConfigManager import net.taler.cashier.withdraw.WithdrawManager +import net.taler.common.Amount +import net.taler.common.AmountParserException import net.taler.common.isOnline -import net.taler.lib.common.Amount -import net.taler.lib.common.AmountParserException private val TAG = MainViewModel::class.java.simpleName @@ -46,12 +45,8 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) { retryOnConnectionFailure(true) } } - install(JsonFeature) { - serializer = KotlinxSerializer( - Json { - ignoreUnknownKeys = true - } - ) + install(ContentNegotiation) { + json() } } val configManager = ConfigManager(app, viewModelScope, httpClient) diff --git a/cashier/src/main/java/net/taler/cashier/Response.kt b/cashier/src/main/java/net/taler/cashier/Response.kt index 6a72604..89b7b33 100644 --- a/cashier/src/main/java/net/taler/cashier/Response.kt +++ b/cashier/src/main/java/net/taler/cashier/Response.kt @@ -18,8 +18,9 @@ package net.taler.cashier import android.content.Context import android.util.Log +import io.ktor.client.call.body import io.ktor.client.call.receive -import io.ktor.client.features.ResponseException +import io.ktor.client.plugins.ResponseException import io.ktor.http.HttpStatusCode import kotlinx.serialization.Serializable import net.taler.common.isOnline @@ -47,7 +48,7 @@ class Response private constructor( val response = e.response return try { Log.e("TEST", "TRY RECEIVE $response") - val error: Error = response.receive() + val error: Error = response.body() "Error ${error.code}: ${error.hint}" } catch (ex: Exception) { "Status code: ${response.status.value}" diff --git a/cashier/src/main/java/net/taler/cashier/SignedAmount.kt b/cashier/src/main/java/net/taler/cashier/SignedAmount.kt index e79acfd..4f624ae 100644 --- a/cashier/src/main/java/net/taler/cashier/SignedAmount.kt +++ b/cashier/src/main/java/net/taler/cashier/SignedAmount.kt @@ -16,7 +16,7 @@ package net.taler.cashier -import net.taler.lib.common.Amount +import net.taler.common.Amount data class SignedAmount( val positive: Boolean, diff --git a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt index 0718963..882348f 100644 --- a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt +++ b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt @@ -39,8 +39,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import net.taler.cashier.Response import net.taler.cashier.Response.Companion.response +import net.taler.common.Version import net.taler.common.getIncompatibleStringOrNull -import net.taler.lib.common.Version val VERSION_BANK = Version(0, 0, 0) private const val PREF_NAME = "net.taler.cashier.prefs" @@ -126,7 +126,7 @@ class ConfigManager( val balanceResponse = response { val authUrl = "${config.bankUrl}/accounts/${config.username}" Log.d(TAG, "Checking auth: $authUrl") - httpClient.get(authUrl) { + httpClient.get(authUrl) { header(Authorization, config.basicAuth) } } diff --git a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt index 5d34bba..360bded 100644 --- a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt +++ b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt @@ -34,9 +34,9 @@ import net.taler.cashier.HttpJsonResult.Error import net.taler.cashier.HttpJsonResult.Success import net.taler.cashier.MainViewModel import net.taler.cashier.R +import net.taler.common.Amount import net.taler.common.QrCodeManager.makeQrCode import net.taler.common.isOnline -import net.taler.lib.common.Amount import org.json.JSONObject import java.util.concurrent.TimeUnit.MINUTES import java.util.concurrent.TimeUnit.SECONDS -- cgit v1.2.3