summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/transactions
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-04-11 13:40:25 -0600
committerTorsten Grote <t@grobox.de>2023-04-13 09:56:00 -0300
commit5a9174fda280a87cef83d16a3430aae9e388bc0b (patch)
treea3fb00e5de6dc676bb4747a5de3bc05186d1345a /wallet/src/main/java/net/taler/wallet/transactions
parent4d37a683d1028b374abe03d310cc2d7ca47416c2 (diff)
downloadtaler-android-5a9174fda280a87cef83d16a3430aae9e388bc0b.tar.gz
taler-android-5a9174fda280a87cef83d16a3430aae9e388bc0b.tar.bz2
taler-android-5a9174fda280a87cef83d16a3430aae9e388bc0b.zip
[wallet] Migrated payment and refund detail to Compose
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/transactions')
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionPaymentFragment.kt52
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt38
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionRefundFragment.kt57
3 files changed, 72 insertions, 75 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionPaymentFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionPaymentFragment.kt
index 068a41e..ac35fe0 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionPaymentFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionPaymentFragment.kt
@@ -19,50 +19,32 @@ package net.taler.wallet.transactions
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
-import android.view.View.VISIBLE
import android.view.ViewGroup
-import net.taler.common.toAbsoluteTime
-import net.taler.wallet.databinding.FragmentTransactionPaymentBinding
+import androidx.compose.runtime.livedata.observeAsState
+import androidx.compose.ui.platform.ComposeView
+import net.taler.wallet.compose.TalerSurface
+import net.taler.wallet.launchInAppBrowser
+import net.taler.wallet.payment.TransactionPaymentComposable
class TransactionPaymentFragment : TransactionDetailFragment() {
- private lateinit var ui: FragmentTransactionPaymentBinding
-
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
- ): View {
- ui = FragmentTransactionPaymentBinding.inflate(inflater, container, false)
- return ui.root
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- transactionManager.selectedTransaction.observe(viewLifecycleOwner) { t ->
- if (t !is TransactionPayment) return@observe
- ui.timeView.text = t.timestamp.ms.toAbsoluteTime(requireContext())
-
- ui.amountPaidWithFeesView.text = t.amountEffective.toString()
- val fee = t.amountEffective - t.amountRaw
- bindOrderAndFee(
- ui.orderSummaryView,
- ui.orderAmountView,
- ui.orderIdView,
- ui.feeView,
- t.info,
- t.amountRaw,
- fee
- )
- ui.deleteButton.setOnClickListener {
- onDeleteButtonClicked(t)
- }
- if (devMode.value == true && t.error != null) {
- ui.showErrorButton.visibility = VISIBLE
- ui.showErrorButton.setOnClickListener {
- onShowErrorButtonClicked(t)
- }
+ ): View = ComposeView(requireContext()).apply {
+ setContent {
+ TalerSurface {
+ val t = transactionManager.selectedTransaction.observeAsState().value
+ if (t is TransactionPayment) TransactionPaymentComposable(t, devMode.value,
+ onFulfill = { url ->
+ launchInAppBrowser(requireContext(), url)
+ },
+ onDelete = {
+ onDeleteButtonClicked(t)
+ }
+ )
}
}
}
-
}
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt
index 297c937..170c719 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt
@@ -24,6 +24,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.text.ClickableText
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -35,12 +36,18 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
+import androidx.compose.ui.text.SpanStyle
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.buildAnnotatedString
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import net.taler.common.Amount
import net.taler.common.toAbsoluteTime
import net.taler.wallet.R
import net.taler.wallet.compose.TalerSurface
+import net.taler.wallet.getAttrColor
import net.taler.wallet.peer.TransactionPeerPullCreditComposable
import net.taler.wallet.peer.TransactionPeerPullDebitComposable
import net.taler.wallet.peer.TransactionPeerPushCreditComposable
@@ -125,3 +132,34 @@ fun TransactionInfoComposable(label: String, info: String) {
fontSize = 24.sp,
)
}
+
+@Composable
+fun TransactionLinkComposable(label: String, info: String, onClick: () -> Unit) {
+ Text(
+ modifier = Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp),
+ text = label,
+ style = MaterialTheme.typography.bodyMedium,
+ )
+ val context = LocalContext.current
+ val linkColor = Color(context.getAttrColor(android.R.attr.textColorLink))
+ val annotatedString = buildAnnotatedString {
+ pushStringAnnotation(tag = "url", annotation = info)
+ withStyle(style = SpanStyle(color = linkColor)) {
+ append(info)
+ }
+ pop()
+ }
+ ClickableText(
+ modifier = Modifier.padding(top = 8.dp, start = 16.dp, end = 16.dp, bottom = 16.dp),
+ text = annotatedString,
+ style = TextStyle(fontSize = 24.sp, textAlign = TextAlign.Center),
+ ) { offset ->
+ annotatedString.getStringAnnotations(
+ tag = "url",
+ start = offset,
+ end = offset,
+ ).firstOrNull()?.let {
+ onClick()
+ }
+ }
+} \ No newline at end of file
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionRefundFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionRefundFragment.kt
index 9c30609..b4a3be8 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionRefundFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionRefundFragment.kt
@@ -19,55 +19,32 @@ package net.taler.wallet.transactions
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
-import android.view.View.VISIBLE
import android.view.ViewGroup
-import androidx.core.content.ContextCompat.getColor
-import net.taler.common.toAbsoluteTime
-import net.taler.wallet.R
-import net.taler.wallet.databinding.FragmentTransactionPaymentBinding
+import androidx.compose.runtime.livedata.observeAsState
+import androidx.compose.ui.platform.ComposeView
+import net.taler.wallet.compose.TalerSurface
+import net.taler.wallet.launchInAppBrowser
+import net.taler.wallet.payment.TransactionPaymentComposable
class TransactionRefundFragment : TransactionDetailFragment() {
- private lateinit var ui: FragmentTransactionPaymentBinding
-
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
- ): View {
- ui = FragmentTransactionPaymentBinding.inflate(inflater, container, false)
- return ui.root
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- transactionManager.selectedTransaction.observe(viewLifecycleOwner) { t ->
- if (t !is TransactionRefund) return@observe
- ui.timeView.text = t.timestamp.ms.toAbsoluteTime(requireContext())
-
- ui.amountPaidWithFeesLabel.text = getString(R.string.transaction_refund)
- ui.amountPaidWithFeesView.setTextColor(getColor(requireContext(), R.color.green))
- ui.amountPaidWithFeesView.text =
- getString(R.string.amount_positive, t.amountEffective.toString())
- val fee = t.amountRaw - t.amountEffective
- bindOrderAndFee(
- ui.orderSummaryView,
- ui.orderAmountView,
- ui.orderIdView,
- ui.feeView,
- t.info,
- t.amountRaw,
- fee
- )
- ui.deleteButton.setOnClickListener {
- onDeleteButtonClicked(t)
- }
- if (devMode.value == true && t.error != null) {
- ui.showErrorButton.visibility = VISIBLE
- ui.showErrorButton.setOnClickListener {
- onShowErrorButtonClicked(t)
- }
+ ): View = ComposeView(requireContext()).apply {
+ setContent {
+ TalerSurface {
+ val t = transactionManager.selectedTransaction.observeAsState().value
+ if (t is TransactionRefund) TransactionPaymentComposable(t, devMode.value,
+ onFulfill = { url ->
+ launchInAppBrowser(requireContext(), url)
+ },
+ onDelete = {
+ onDeleteButtonClicked(t)
+ }
+ )
}
}
}
-
}