gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-android] branch master updated: [pos] add button for adding


From: gnunet
Subject: [taler-taler-android] branch master updated: [pos] add button for adding custom products
Date: Wed, 08 Mar 2023 19:55:55 +0100

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

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

The following commit(s) were added to refs/heads/master by this push:
     new e690df6  [pos] add button for adding custom products
e690df6 is described below

commit e690df6d0eaacb60ca9edf1d4caf382711278b8b
Author: Torsten Grote <t@grobox.de>
AuthorDate: Wed Mar 8 15:55:07 2023 -0300

    [pos] add button for adding custom products
---
 .../taler/merchantpos/order/CategoriesFragment.kt  |   4 +-
 .../merchantpos/order/CustomDialogFragment.kt      |  67 ++++++++++++
 .../main/java/net/taler/merchantpos/order/Order.kt |   2 +-
 .../net/taler/merchantpos/order/OrderFragment.kt   |  28 ++---
 .../net/taler/merchantpos/order/OrderManager.kt    |   2 +-
 .../src/main/res/drawable/ic_dialpad.xml           |  25 +++++
 .../src/main/res/layout/fragment_custom_dialog.xml | 117 +++++++++++++++++++++
 .../src/main/res/layout/fragment_order.xml         |  13 ++-
 merchant-terminal/src/main/res/values/strings.xml  |   4 +
 9 files changed, 244 insertions(+), 18 deletions(-)

diff --git 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/CategoriesFragment.kt
 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/CategoriesFragment.kt
index 69e74ce..8c8b1d5 100644
--- 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/CategoriesFragment.kt
+++ 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/CategoriesFragment.kt
@@ -55,10 +55,10 @@ class CategoriesFragment : Fragment(), 
CategorySelectionListener {
             layoutManager = LinearLayoutManager(requireContext())
         }
 
-        orderManager.categories.observe(viewLifecycleOwner, { categories ->
+        orderManager.categories.observe(viewLifecycleOwner) { categories ->
             adapter.setItems(categories)
             ui.progressBar.visibility = INVISIBLE
-        })
+        }
     }
 
     override fun onCategorySelected(category: Category) {
diff --git 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/CustomDialogFragment.kt
 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/CustomDialogFragment.kt
new file mode 100644
index 0000000..bf14aae
--- /dev/null
+++ 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/CustomDialogFragment.kt
@@ -0,0 +1,67 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2023 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.merchantpos.order
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.DialogFragment
+import androidx.fragment.app.activityViewModels
+import net.taler.common.Amount
+import net.taler.merchantpos.MainViewModel
+import net.taler.merchantpos.config.ConfigProduct
+import net.taler.merchantpos.databinding.FragmentCustomDialogBinding
+
+class CustomDialogFragment : DialogFragment() {
+
+    companion object {
+        const val TAG = "CustomDialogFragment"
+    }
+
+    private val viewModel: MainViewModel by activityViewModels()
+
+    private lateinit var ui: FragmentCustomDialogBinding
+
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?,
+    ): View {
+        ui = FragmentCustomDialogBinding.inflate(inflater, container, false)
+        return ui.root
+    }
+
+    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+        val currency = viewModel.configManager.currency ?: error("No currency")
+        ui.currencyView.text = currency
+        ui.addButton.setOnClickListener {
+            val currentOrderId =
+                viewModel.orderManager.currentOrderId.value ?: 
return@setOnClickListener
+            val product = ConfigProduct(
+                description = ui.productNameLayout.editText!!.text.toString(),
+                price = Amount.fromString(currency, 
ui.amountLayout.editText!!.text.toString()),
+                categories = listOf(Int.MIN_VALUE),
+            )
+            viewModel.orderManager.addProduct(currentOrderId, product)
+            dismiss()
+        }
+        ui.cancelButton.setOnClickListener {
+            dismiss()
+        }
+    }
+}
diff --git 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/Order.kt 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/Order.kt
index 2d4d32c..a22ab0a 100644
--- a/merchant-terminal/src/main/java/net/taler/merchantpos/order/Order.kt
+++ b/merchant-terminal/src/main/java/net/taler/merchantpos/order/Order.kt
@@ -73,7 +73,7 @@ data class Order(val id: Int, val currency: String, val 
availableCategories: Map
         val categories = HashMap<Category, Int>()
         products.forEach { product ->
             val categoryId = product.categories[0]
-            val category = availableCategories.getValue(categoryId)
+            val category = availableCategories[categoryId] ?: return@forEach 
// custom products
             val oldQuantity = categories[category] ?: 0
             categories[category] = oldQuantity + product.quantity
         }
diff --git 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt
index 0de5939..cdd2b67 100644
--- 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt
+++ 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderFragment.kt
@@ -44,15 +44,14 @@ class OrderFragment : Fragment() {
     override fun onCreateView(
         inflater: LayoutInflater,
         container: ViewGroup?,
-        savedInstanceState: Bundle?
-    ): View? {
+        savedInstanceState: Bundle?,
+    ): View {
         ui = FragmentOrderBinding.inflate(inflater, container, false)
         return ui.root
     }
 
-    @Deprecated("Deprecated in Java")
-    override fun onActivityCreated(savedInstanceState: Bundle?) {
-        super.onActivityCreated(savedInstanceState)
+    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+        super.onViewCreated(view, savedInstanceState)
         orderManager.currentOrderId.observe(viewLifecycleOwner) { orderId ->
             val liveOrder = orderManager.getOrder(orderId)
             onOrderSwitched(orderId, liveOrder)
@@ -62,6 +61,9 @@ class OrderFragment : Fragment() {
                 .replace(R.id.fragment1, OrderStateFragment())
                 .commit()
         }
+        ui.customButton.setOnClickListener {
+            CustomDialogFragment().show(childFragmentManager, 
CustomDialogFragment.TAG)
+        }
     }
 
     override fun onStart() {
@@ -75,13 +77,13 @@ class OrderFragment : Fragment() {
 
     private fun onOrderSwitched(orderId: Int, liveOrder: LiveOrder) {
         // order title
-        liveOrder.order.observe(viewLifecycleOwner, { order ->
+        liveOrder.order.observe(viewLifecycleOwner) { order ->
             if (order == null) return@observe
             activity?.title = getString(R.string.order_label_title, 
order.title)
-        })
+        }
         // restart button
         ui.restartButton.setOnClickListener { liveOrder.restartOrUndo() }
-        liveOrder.restartState.observe(viewLifecycleOwner, { state ->
+        liveOrder.restartState.observe(viewLifecycleOwner) { state ->
             beginDelayedTransition(view as ViewGroup)
             if (state == UNDO) {
                 ui.restartButton.setText(R.string.order_undo)
@@ -92,19 +94,19 @@ class OrderFragment : Fragment() {
                 ui.restartButton.isEnabled = state == ENABLED
                 ui.completeButton.isEnabled = state == ENABLED
             }
-        })
+        }
         // -1 and +1 buttons
-        liveOrder.modifyOrderAllowed.observe(viewLifecycleOwner, { allowed ->
+        liveOrder.modifyOrderAllowed.observe(viewLifecycleOwner) { allowed ->
             ui.minusButton.isEnabled = allowed
             ui.plusButton.isEnabled = allowed
-        })
+        }
         ui.minusButton.setOnClickListener { 
liveOrder.decreaseSelectedOrderLine() }
         ui.plusButton.setOnClickListener { 
liveOrder.increaseSelectedOrderLine() }
         // previous and next button
         ui.prevButton.isEnabled = orderManager.hasPreviousOrder(orderId)
-        orderManager.hasNextOrder(orderId).observe(viewLifecycleOwner, { 
hasNextOrder ->
+        orderManager.hasNextOrder(orderId).observe(viewLifecycleOwner) { 
hasNextOrder ->
             ui.nextButton.isEnabled = hasNextOrder
-        })
+        }
         ui.prevButton.setOnClickListener { orderManager.previousOrder() }
         ui.nextButton.setOnClickListener { orderManager.nextOrder() }
         // complete button
diff --git 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderManager.kt 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderManager.kt
index 6c5ecdf..96d2e83 100644
--- 
a/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderManager.kt
+++ 
b/merchant-terminal/src/main/java/net/taler/merchantpos/order/OrderManager.kt
@@ -32,7 +32,7 @@ import net.taler.merchantpos.order.RestartState.ENABLED
 class OrderManager(private val context: Context) : ConfigurationReceiver {
 
     companion object {
-        val TAG = OrderManager::class.java.simpleName
+        val TAG: String = OrderManager::class.java.simpleName
     }
 
     private lateinit var currency: String
diff --git a/merchant-terminal/src/main/res/drawable/ic_dialpad.xml 
b/merchant-terminal/src/main/res/drawable/ic_dialpad.xml
new file mode 100644
index 0000000..33ba1d9
--- /dev/null
+++ b/merchant-terminal/src/main/res/drawable/ic_dialpad.xml
@@ -0,0 +1,25 @@
+<!--
+  ~ This file is part of GNU Taler
+  ~ (C) 2023 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/>
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android";
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M12,19c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 
-0.9,-2 -2,-2zM6,1c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 
-2,-2zM6,7c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM6,13c-1.1,0 
-2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,5c1.1,0 2,-0.9 2,-2s-0.9,-2 
-2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,13c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 
-0.9,-2 -2,-2zM18,13c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 
-2,-2zM18,7c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0 [...]
+</vector>
diff --git a/merchant-terminal/src/main/res/layout/fragment_custom_dialog.xml 
b/merchant-terminal/src/main/res/layout/fragment_custom_dialog.xml
new file mode 100644
index 0000000..8da50ad
--- /dev/null
+++ b/merchant-terminal/src/main/res/layout/fragment_custom_dialog.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ This file is part of GNU Taler
+  ~ (C) 2023 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/>
+  -->
+
+<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android";
+    xmlns:app="http://schemas.android.com/apk/res-auto";
+    xmlns:tools="http://schemas.android.com/tools";
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <TextView
+        android:id="@+id/titleView"
+        style="@style/TextAppearance.Material3.TitleMedium"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:layout_marginTop="16dp"
+        android:layout_marginEnd="16dp"
+        android:text="@string/order_custom"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <com.google.android.material.textfield.TextInputLayout
+        android:id="@+id/productNameLayout"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:layout_marginTop="16dp"
+        android:layout_marginEnd="16dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/titleView">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="@string/order_custom_product"
+            android:inputType="textShortMessage"
+            android:singleLine="true"
+            android:text="@string/order_custom_product_default" />
+    </com.google.android.material.textfield.TextInputLayout>
+
+    <com.google.android.material.textfield.TextInputLayout
+        android:id="@+id/amountLayout"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:layout_marginTop="16dp"
+        android:layout_marginEnd="8dp"
+        android:minEms="5"
+        app:layout_constraintEnd_toStartOf="@+id/currencyView"
+        app:layout_constraintHorizontal_bias="1.0"
+        app:layout_constraintHorizontal_chainStyle="packed"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/productNameLayout">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="@string/refund_amount"
+            android:inputType="numberDecimal">
+
+            <requestFocus />
+        </com.google.android.material.textfield.TextInputEditText>
+    </com.google.android.material.textfield.TextInputLayout>
+
+    <TextView
+        android:id="@+id/currencyView"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="16dp"
+        app:layout_constraintBottom_toBottomOf="@+id/amountLayout"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.5"
+        app:layout_constraintStart_toEndOf="@+id/amountLayout"
+        app:layout_constraintTop_toTopOf="@+id/amountLayout"
+        tools:text="TESTKUDOS" />
+
+    <Button
+        android:id="@+id/addButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="16dp"
+        android:layout_marginEnd="16dp"
+        android:layout_marginBottom="16dp"
+        android:text="@string/order_custom_add_button"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/amountLayout"
+        app:layout_constraintVertical_bias="0.0" />
+
+    <Button
+        android:id="@+id/cancelButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:layout_marginTop="16dp"
+        android:layout_marginEnd="16dp"
+        android:text="@android:string/cancel"
+        app:layout_constraintEnd_toStartOf="@+id/addButton"
+        app:layout_constraintHorizontal_bias="1.0"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/amountLayout" />
+</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/merchant-terminal/src/main/res/layout/fragment_order.xml 
b/merchant-terminal/src/main/res/layout/fragment_order.xml
index dc49db1..45f1aee 100644
--- a/merchant-terminal/src/main/res/layout/fragment_order.xml
+++ b/merchant-terminal/src/main/res/layout/fragment_order.xml
@@ -121,6 +121,17 @@
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintStart_toEndOf="@+id/prevButton" />
 
+    <ImageButton
+        android:id="@+id/customButton"
+        android:layout_width="48dp"
+        android:layout_height="48dp"
+        android:layout_marginStart="16dp"
+        android:backgroundTint="?colorPrimary"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toEndOf="@+id/nextButton"
+        app:srcCompat="@drawable/ic_dialpad"
+        android:contentDescription="@string/order_custom" />
+
     <Button
         android:id="@+id/completeButton"
         android:layout_width="wrap_content"
@@ -132,6 +143,6 @@
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintHorizontal_bias="1.0"
-        app:layout_constraintStart_toEndOf="@+id/nextButton" />
+        app:layout_constraintStart_toEndOf="@+id/customButton" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/merchant-terminal/src/main/res/values/strings.xml 
b/merchant-terminal/src/main/res/values/strings.xml
index f06866d..3cd2043 100644
--- a/merchant-terminal/src/main/res/values/strings.xml
+++ b/merchant-terminal/src/main/res/values/strings.xml
@@ -14,7 +14,11 @@
     <string name="order_undo">Undo</string>
     <string name="order_previous">Prev</string>
     <string name="order_next">Next</string>
+    <string name="order_custom">Add custom product</string>
     <string name="order_complete">Complete</string>
+    <string name="order_custom_product">Custom product name</string>
+    <string name="order_custom_product_default">Tip</string>
+    <string name="order_custom_add_button">Add</string>
 
     <string name="config_label">Merchant settings</string>
     <string name="config_url">Configuration URL</string>

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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