aboutsummaryrefslogtreecommitdiff
path: root/wallet
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-06-01 13:31:38 +0200
committerFlorian Dold <florian@dold.me>2022-06-01 13:31:38 +0200
commita229b33997842a66295aa4d8dfb5dab6d2f769df (patch)
tree72031a742800ceaae337f04377fb052c91cc2068 /wallet
parent1ef7ae77475f5dd99401a992a92f6c622b29c0a6 (diff)
downloadtaler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.tar.gz
taler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.tar.bz2
taler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.zip
use new annotation for polymorphic serialization
Diffstat (limited to 'wallet')
-rw-r--r--wallet/build.gradle11
-rw-r--r--wallet/src/main/AndroidManifest.xml1
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt5
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt6
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt8
-rw-r--r--wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt46
-rw-r--r--wallet/src/test/java/net/taler/wallet/payment/PaymentResponsesTest.kt1
7 files changed, 54 insertions, 24 deletions
diff --git a/wallet/build.gradle b/wallet/build.gradle
index b0a8b97..faebdde 100644
--- a/wallet/build.gradle
+++ b/wallet/build.gradle
@@ -23,8 +23,8 @@ plugins {
id "de.undercouch.download"
}
-def walletCoreVersion = "v0.9.0-dev.10"
-def walletCoreSha256 = "3c9aa9afeb6d61091599553719ffd1010be7817b7368c2d0ace5f77d8089d513"
+def walletCoreVersion = "v0.9.0-dev.11"
+def walletCoreSha256 = "0ee5eae7d0afd6f251f7d33975758055d06926ccb67ae9099d589a79d34be39d"
static def versionCodeEpoch() {
return (new Date().getTime() / 1000).toInteger()
@@ -188,7 +188,14 @@ task verifyWalletLibrary(type: Verify, dependsOn: downloadWalletLibrary) {
algorithm 'SHA-256'
checksum walletCoreSha256
}
+
tasks.withType(MergeResources) {
inputs.dir walletLibraryDir
dependsOn verifyWalletLibrary
}
+
+tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
+ kotlinOptions {
+ freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
+ }
+} \ No newline at end of file
diff --git a/wallet/src/main/AndroidManifest.xml b/wallet/src/main/AndroidManifest.xml
index b0e4ffe..61191b6 100644
--- a/wallet/src/main/AndroidManifest.xml
+++ b/wallet/src/main/AndroidManifest.xml
@@ -20,6 +20,7 @@
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature
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 a2b48b6..76aceb2 100644
--- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
+++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
@@ -30,7 +30,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.Json
-import net.taler.lib.android.CustomClassDiscriminator
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
@@ -42,7 +41,6 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
-import kotlin.reflect.full.companionObjectInstance
class WalletBackendApi(
private val app: Application,
@@ -152,9 +150,6 @@ class WalletBackendApi(
suspendCoroutine { cont ->
val json = Json {
ignoreUnknownKeys = true
- (T::class.companionObjectInstance as? CustomClassDiscriminator)?.let {
- classDiscriminator = it.discriminator
- }
}
sendRequest(operation, args?.invoke(JSONObject())) { isError, message ->
val response = try {
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 1071e9a..e52fd4f 100644
--- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
+++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
@@ -32,13 +32,13 @@ sealed class WalletResponse<T> {
@Serializable
@SerialName("response")
data class Success<T>(
- val result: T
+ val result: T,
) : WalletResponse<T>()
@Serializable
@SerialName("error")
data class Error<T>(
- val error: TalerErrorInfo
+ val error: TalerErrorInfo,
) : WalletResponse<T>()
fun onSuccess(block: (result: T) -> Unit): WalletResponse<T> {
@@ -67,7 +67,7 @@ data class TalerErrorInfo(
// Error details
@Serializable(JSONObjectDeserializer::class)
- val details: JSONObject? = null
+ val details: JSONObject? = null,
) {
val userFacingMsg: String
get() {
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt
index fb206be..7e03472 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt
@@ -16,18 +16,18 @@
package net.taler.wallet.payment
+import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
+import kotlinx.serialization.json.JsonClassDiscriminator
import net.taler.common.Amount
import net.taler.common.ContractTerms
-import net.taler.lib.android.CustomClassDiscriminator
import net.taler.wallet.backend.TalerErrorInfo
+@OptIn(ExperimentalSerializationApi::class)
@Serializable
+@JsonClassDiscriminator("status")
sealed class PreparePayResponse {
- companion object : CustomClassDiscriminator {
- override val discriminator: String = "status"
- }
@Serializable
@SerialName("payment-possible")
diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
index bd6ce1a..1a17d78 100644
--- a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
@@ -18,6 +18,8 @@ package net.taler.wallet.settings
import android.os.Bundle
import android.view.View
+import android.widget.Toast
+import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.activityViewModels
import androidx.preference.Preference
@@ -26,7 +28,6 @@ import androidx.preference.SwitchPreferenceCompat
import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_SHORT
import com.google.android.material.snackbar.Snackbar
import net.taler.common.showError
-import net.taler.common.showLogViewer
import net.taler.common.toRelativeTime
import net.taler.wallet.BuildConfig.FLAVOR
import net.taler.wallet.BuildConfig.VERSION_CODE
@@ -64,6 +65,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
)
}
+ val createDocumentActivity =
+ registerForActivityResult(ActivityResultContracts.CreateDocument()) { uri ->
+
+ }
+
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.settings_main, rootKey)
prefBackup = findPreference("pref_backup")!!
@@ -80,12 +86,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- model.lastBackup.observe(viewLifecycleOwner, {
+ model.lastBackup.observe(viewLifecycleOwner) {
val time = it.toRelativeTime(requireContext())
prefBackup.summary = getString(R.string.backup_last, time)
- })
+ }
- model.devMode.observe(viewLifecycleOwner, { enabled ->
+ model.devMode.observe(viewLifecycleOwner) { enabled ->
prefDevMode.isChecked = enabled
if (enabled) {
prefVersionApp.summary = "$VERSION_NAME ($FLAVOR $VERSION_CODE)"
@@ -94,13 +100,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
model.merchantVersion?.let { prefVersionMerchant.summary = it }
}
devPrefs.forEach { it.isVisible = enabled }
- })
+ }
prefDevMode.setOnPreferenceChangeListener { _, newValue ->
model.devMode.value = newValue as Boolean
true
}
- withdrawManager.testWithdrawalStatus.observe(viewLifecycleOwner, { status ->
+ withdrawManager.testWithdrawalStatus.observe(viewLifecycleOwner) { status ->
if (status == null) return@observe
val loading = status is WithdrawTestStatus.Withdrawing
prefWithdrawTest.isEnabled = !loading
@@ -109,14 +115,37 @@ class SettingsFragment : PreferenceFragmentCompat() {
requireActivity().showError(R.string.withdraw_error_test, status.message)
}
withdrawManager.testWithdrawalStatus.value = null
- })
+ }
prefWithdrawTest.setOnPreferenceClickListener {
withdrawManager.withdrawTestkudos()
true
}
prefLogcat.setOnPreferenceClickListener {
- requireContext().showLogViewer("taler-wallet")
+ val toast =
+ Toast.makeText(requireActivity(), "Log export currently unavailable", Toast.LENGTH_LONG)
+ toast.show()
+
+// val myPid = android.os.Process.myPid()
+// val proc = Runtime.getRuntime()
+// .exec(arrayOf("logcat", "-d", "--pid=$myPid", "*:V"))
+// val bytes = proc.inputStream.readBytes()
+// val f = File(requireActivity().getExternalFilesDir(null),
+// "taler-wallet-log-${System.currentTimeMillis()}.txt")
+// f.writeBytes(bytes)
+// val toast = Toast.makeText(requireActivity(), "Saved to ${f.absolutePath}", Toast.LENGTH_LONG)
+// toast.show()
+// val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
+// addCategory(Intent.CATEGORY_OPENABLE)
+// type = "application/pdf"
+// putExtra(Intent.EXTRA_TITLE, "invoice.pdf")
+//
+// // Optionally, specify a URI for the directory that should be opened in
+// // the system file picker before your app creates the document.
+// putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
+// }
+// startActivityForResult(intent, CREATE_FILE)
+// ActivityResultContracts.CreateDocument
true
}
@@ -138,5 +167,4 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
.show()
}
-
}
diff --git a/wallet/src/test/java/net/taler/wallet/payment/PaymentResponsesTest.kt b/wallet/src/test/java/net/taler/wallet/payment/PaymentResponsesTest.kt
index fbdc07d..da2378e 100644
--- a/wallet/src/test/java/net/taler/wallet/payment/PaymentResponsesTest.kt
+++ b/wallet/src/test/java/net/taler/wallet/payment/PaymentResponsesTest.kt
@@ -23,7 +23,6 @@ class PaymentResponsesTest {
private val json = Json {
ignoreUnknownKeys = true
- classDiscriminator = PreparePayResponse.discriminator
}
@Test