diff options
Diffstat (limited to 'wallet/src/main/java/net/taler')
4 files changed, 58 insertions, 27 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/history/HistoryAdapter.kt b/wallet/src/main/java/net/taler/wallet/history/HistoryAdapter.kt index 881ada5..1c7f15e 100644 --- a/wallet/src/main/java/net/taler/wallet/history/HistoryAdapter.kt +++ b/wallet/src/main/java/net/taler/wallet/history/HistoryAdapter.kt @@ -33,6 +33,7 @@ import net.taler.wallet.history.HistoryAdapter.HistoryEventViewHolder internal class HistoryAdapter( + private val devMode: Boolean, private val listener: OnEventClickListener, private var history: History = History() ) : Adapter<HistoryEventViewHolder>() { @@ -73,7 +74,11 @@ internal class HistoryAdapter( @CallSuper open fun bind(event: HistoryEvent) { - v.setOnClickListener { listener.onEventClicked(event) } + if (devMode || event.detailPageLayout != 0) { + v.setOnClickListener { listener.onEventClicked(event) } + } else { + v.background = null + } icon.setImageResource(event.icon) if (event.title == 0) title.text = event::class.java.simpleName else title.setText(event.title) diff --git a/wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt b/wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt index 86a7ac0..57bf6a3 100644 --- a/wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt +++ b/wallet/src/main/java/net/taler/wallet/history/HistoryEvent.kt @@ -138,6 +138,8 @@ abstract class HistoryEvent( val timestamp: Timestamp, @get:LayoutRes open val layout: Int = R.layout.history_row, + @get:LayoutRes + open val detailPageLayout: Int = 0, @get:StringRes open val title: Int = 0, @get:DrawableRes @@ -215,6 +217,7 @@ class HistoryWithdrawnEvent( val amountWithdrawnEffective: Amount ) : HistoryEvent(timestamp) { override val layout = R.layout.history_receive + override val detailPageLayout = R.layout.fragment_event_withdraw override val title = R.string.history_event_withdrawn override val icon = R.drawable.history_withdrawn override val showToUser = true @@ -270,6 +273,7 @@ class HistoryPaymentSentEvent( val sessionId: String? ) : HistoryEvent(timestamp) { override val layout = R.layout.history_payment + override val detailPageLayout = R.layout.fragment_event_paid override val title = R.string.history_event_payment_sent override val icon = R.drawable.ic_cash_usd_outline override val showToUser = true diff --git a/wallet/src/main/java/net/taler/wallet/history/HistoryEventFragment.kt b/wallet/src/main/java/net/taler/wallet/history/HistoryEventFragment.kt index f0dec75..6a07625 100644 --- a/wallet/src/main/java/net/taler/wallet/history/HistoryEventFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/history/HistoryEventFragment.kt @@ -23,9 +23,14 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup +import android.widget.Toast +import android.widget.Toast.LENGTH_LONG import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import kotlinx.android.synthetic.main.fragment_history_event.* +import kotlinx.android.synthetic.main.fragment_event_paid.* +import kotlinx.android.synthetic.main.fragment_event_withdraw.* +import kotlinx.android.synthetic.main.fragment_event_withdraw.feeView +import kotlinx.android.synthetic.main.fragment_event_withdraw.timeView import net.taler.common.toAbsoluteTime import net.taler.wallet.R import net.taler.wallet.WalletViewModel @@ -39,28 +44,29 @@ class HistoryEventFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (model.devMode.value == true) setHasOptionsMenu(true) + setHasOptionsMenu(model.devMode.value == true) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - return inflater.inflate(R.layout.fragment_history_event, container, false) + return inflater.inflate(event.detailPageLayout, container, false) } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val event = event as HistoryWithdrawnEvent + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + requireActivity().title = + getString(if (event.title != 0) event.title else R.string.history_detail_title) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { timeView.text = event.timestamp.ms.toAbsoluteTime(requireContext()) - effectiveAmountLabel.text = getString(R.string.withdraw_total) - effectiveAmountView.text = event.amountWithdrawnEffective.toString() - chosenAmountLabel.text = getString(R.string.amount_chosen) - chosenAmountView.text = - getString(R.string.amount_positive, event.amountWithdrawnRaw.toString()) - val fee = event.amountWithdrawnRaw - event.amountWithdrawnEffective - feeView.text = getString(R.string.amount_negative, fee.toString()) - exchangeView.text = cleanExchange(event.exchangeBaseUrl) + when (val e = event) { + is HistoryWithdrawnEvent -> bind(e) + is HistoryPaymentSentEvent -> bind(e) + else -> Toast.makeText(requireContext(), "event not implement", LENGTH_LONG).show() + } } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { @@ -77,4 +83,25 @@ class HistoryEventFragment : Fragment() { } } + private fun bind(event: HistoryWithdrawnEvent) { + effectiveAmountLabel.text = getString(R.string.withdraw_total) + effectiveAmountView.text = event.amountWithdrawnEffective.toString() + chosenAmountLabel.text = getString(R.string.amount_chosen) + chosenAmountView.text = + getString(R.string.amount_positive, event.amountWithdrawnRaw.toString()) + val fee = event.amountWithdrawnRaw - event.amountWithdrawnEffective + feeView.text = getString(R.string.amount_negative, fee.toString()) + exchangeView.text = cleanExchange(event.exchangeBaseUrl) + } + + private fun bind(event: HistoryPaymentSentEvent) { + amountPaidWithFeesView.text = event.amountPaidWithFees.toString() + orderAmountView.text = event.orderShortInfo.amount.toString() + val fee = event.amountPaidWithFees - event.orderShortInfo.amount + feeView.text = getString(R.string.amount_negative, fee.toString()) + orderSummaryView.text = event.orderShortInfo.summary + orderIdView.text = + getString(R.string.history_event_payment_sent_order_id, event.orderShortInfo.orderId) + } + } diff --git a/wallet/src/main/java/net/taler/wallet/history/HistoryFragment.kt b/wallet/src/main/java/net/taler/wallet/history/HistoryFragment.kt index b0f6728..73dbae0 100644 --- a/wallet/src/main/java/net/taler/wallet/history/HistoryFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/history/HistoryFragment.kt @@ -33,7 +33,6 @@ import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL import kotlinx.android.synthetic.main.fragment_show_history.* -import net.taler.common.exhaustive import net.taler.common.fadeIn import net.taler.common.fadeOut import net.taler.wallet.R @@ -49,7 +48,7 @@ class HistoryFragment : Fragment(), OnEventClickListener { private val historyManager by lazy { model.historyManager } private lateinit var showAllItem: MenuItem private var reloadHistoryItem: MenuItem? = null - private val historyAdapter = HistoryAdapter(this) + private val historyAdapter by lazy { HistoryAdapter(model.devMode.value == true, this) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -109,17 +108,13 @@ class HistoryFragment : Fragment(), OnEventClickListener { } override fun onEventClicked(event: HistoryEvent) { - when (event) { - is HistoryWithdrawnEvent -> { - historyManager.selectedEvent = event - findNavController().navigate(R.id.action_walletHistory_to_historyEventFragment) - } - else -> { - if (model.devMode.value != true) return - JsonDialogFragment.new(event.json.toString(2)) - .show(parentFragmentManager, null) - } - }.exhaustive + if (event.detailPageLayout != 0) { + historyManager.selectedEvent = event + findNavController().navigate(R.id.action_walletHistory_to_historyEventFragment) + } else if (model.devMode.value == true) { + JsonDialogFragment.new(event.json.toString(2)) + .show(parentFragmentManager, null) + } } private fun onHistoryResult(result: HistoryResult) = when (result) { |