From d3cc4bb7c7c70b4c913ae6f893aa1a760a3fa179 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 11 Mar 2020 09:56:33 -0300 Subject: Show product images in full size if you click on them --- .../net/taler/wallet/payment/ProductAdapter.kt | 10 ++++- .../taler/wallet/payment/ProductImageFragment.kt | 52 ++++++++++++++++++++++ .../taler/wallet/payment/PromptPaymentFragment.kt | 10 ++++- app/src/main/res/layout/fragment_product_image.xml | 24 ++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/net/taler/wallet/payment/ProductImageFragment.kt create mode 100644 app/src/main/res/layout/fragment_product_image.xml diff --git a/app/src/main/java/net/taler/wallet/payment/ProductAdapter.kt b/app/src/main/java/net/taler/wallet/payment/ProductAdapter.kt index e1f9809..4b1b062 100644 --- a/app/src/main/java/net/taler/wallet/payment/ProductAdapter.kt +++ b/app/src/main/java/net/taler/wallet/payment/ProductAdapter.kt @@ -16,6 +16,7 @@ package net.taler.wallet.payment +import android.graphics.Bitmap import android.graphics.BitmapFactory.decodeByteArray import android.util.Base64 import android.view.LayoutInflater @@ -30,8 +31,12 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder import net.taler.wallet.R import net.taler.wallet.payment.ProductAdapter.ProductViewHolder +internal interface ProductImageClickListener { + fun onImageClick(image: Bitmap) +} -internal class ProductAdapter : RecyclerView.Adapter() { +internal class ProductAdapter(private val listener: ProductImageClickListener) : + RecyclerView.Adapter() { private val items = ArrayList() @@ -75,6 +80,9 @@ internal class ProductAdapter : RecyclerView.Adapter() { val decodedString = Base64.decode(match.groups[2]!!.value, Base64.DEFAULT) val bitmap = decodeByteArray(decodedString, 0, decodedString.size) image.setImageBitmap(bitmap) + if (itemCount > 1) image.setOnClickListener { + listener.onImageClick(bitmap) + } } name.text = product.description price.text = product.totalPrice.toString() diff --git a/app/src/main/java/net/taler/wallet/payment/ProductImageFragment.kt b/app/src/main/java/net/taler/wallet/payment/ProductImageFragment.kt new file mode 100644 index 0000000..02414a6 --- /dev/null +++ b/app/src/main/java/net/taler/wallet/payment/ProductImageFragment.kt @@ -0,0 +1,52 @@ +/* + * This file is part of GNU Taler + * (C) 2020 Taler Systems S.A. + * + * GNU Taler is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3, or (at your option) any later version. + * + * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * GNU Taler; see the file COPYING. If not, see + */ + +package net.taler.wallet.payment + +import android.graphics.Bitmap +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import kotlinx.android.synthetic.main.fragment_product_image.* +import net.taler.wallet.R + +class ProductImageFragment private constructor() : DialogFragment() { + + companion object { + private const val IMAGE = "image" + + fun new(image: Bitmap) = ProductImageFragment().apply { + arguments = Bundle().apply { + putParcelable(IMAGE, image) + } + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_product_image, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + val bitmap = arguments!!.getParcelable(IMAGE) + productImageView.setImageBitmap(bitmap) + } + +} diff --git a/app/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt b/app/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt index 2f7807a..5a53556 100644 --- a/app/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt +++ b/app/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt @@ -17,6 +17,7 @@ package net.taler.wallet.payment import android.annotation.SuppressLint +import android.graphics.Bitmap import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -41,11 +42,11 @@ import net.taler.wallet.fadeOut /** * Show a payment and ask the user to accept/decline. */ -class PromptPaymentFragment : Fragment() { +class PromptPaymentFragment : Fragment(), ProductImageClickListener { private val model: WalletViewModel by activityViewModels() private val paymentManager by lazy { model.paymentManager } - private val adapter = ProductAdapter() + private val adapter = ProductAdapter(this) override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -158,4 +159,9 @@ class PromptPaymentFragment : Fragment() { totalView.fadeIn() } + override fun onImageClick(image: Bitmap) { + val f = ProductImageFragment.new(image) + f.show(parentFragmentManager, "image") + } + } diff --git a/app/src/main/res/layout/fragment_product_image.xml b/app/src/main/res/layout/fragment_product_image.xml new file mode 100644 index 0000000..9f65d4d --- /dev/null +++ b/app/src/main/res/layout/fragment_product_image.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file -- cgit v1.2.3