gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-android] 03/03: Show product images in full size if you cl


From: gnunet
Subject: [taler-wallet-android] 03/03: Show product images in full size if you click on them
Date: Wed, 11 Mar 2020 13:58:31 +0100

This is an automated email from the git hooks/post-receive script.

torsten-grote pushed a commit to branch master
in repository wallet-android.

commit d3cc4bb7c7c70b4c913ae6f893aa1a760a3fa179
Author: Torsten Grote <address@hidden>
AuthorDate: Wed Mar 11 09:56:33 2020 -0300

    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(-)

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<ProductViewHolder>() {
+internal class ProductAdapter(private val listener: ProductImageClickListener) 
:
+    RecyclerView.Adapter<ProductViewHolder>() {
 
     private val items = ArrayList<ContractProduct>()
 
@@ -75,6 +80,9 @@ internal class ProductAdapter : 
RecyclerView.Adapter<ProductViewHolder>() {
                 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 <http://www.gnu.org/licenses/>
+ */
+
+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<Bitmap>(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 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ 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 
<http://www.gnu.org/licenses/>
+  -->
+
+<ImageView xmlns:android="http://schemas.android.com/apk/res/android";
+        xmlns:tools="http://schemas.android.com/tools";
+        android:id="@+id/productImageView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        tools:ignore="ContentDescription">
+
+</ImageView>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]