From 229941e6de0c46d0a6b5e6bfb26961796f95950d Mon Sep 17 00:00:00 2001 From: leca Date: Wed, 2 Oct 2024 01:38:07 +0300 Subject: [PATCH] Preparing for selection --- .../AbstractProductView.kt | 17 ++++++++++++----- app/src/main/res/drawable/outline.xml | 6 ++++++ app/src/main/res/drawable/outline_selected.xml | 6 ++++++ .../main/res/layout/abstract_product_view.xml | 3 ++- 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/outline.xml create mode 100644 app/src/main/res/drawable/outline_selected.xml diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt index b490195..879690d 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt @@ -10,21 +10,25 @@ import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat.startActivity import java.io.File class AbstractProductView: LinearLayout { + private var productLayout: ConstraintLayout private var productPicture: ImageView private var productNameField: TextView private var netWeightField: TextView private var categoryField: TextView private var unitField: TextView + var isProductSelected = false constructor(activity: Activity, context: Context, productImageHash: String, productName: String, netWeight: Double, category: Int) : super(context) { val inflater:LayoutInflater = activity.layoutInflater inflater.inflate(R.layout.abstract_product_view, this) + productLayout = findViewById(R.id.productLayout) productPicture = findViewById(R.id.productPicture) productNameField = findViewById(R.id.productNameView) netWeightField = findViewById(R.id.productNetWeightView) @@ -46,16 +50,19 @@ class AbstractProductView: LinearLayout { startActivity(context, fullscreenIntent, extras) } + productLayout.setOnClickListener { + + } + productNameField.text = productName netWeightField.text = netWeight.toString() //TODO: category and units - - findViewById(R.id.productLayout).setOnClickListener { - Log.d("QWERTYUIOP", "Clicked layout") + productLayout.setOnLongClickListener { + isProductSelected = !isProductSelected + this.background = ContextCompat.getDrawable(context, if (isProductSelected) R.drawable.outline_selected else R.drawable.outline) + true } - } - } \ No newline at end of file diff --git a/app/src/main/res/drawable/outline.xml b/app/src/main/res/drawable/outline.xml new file mode 100644 index 0000000..6334f0b --- /dev/null +++ b/app/src/main/res/drawable/outline.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/outline_selected.xml b/app/src/main/res/drawable/outline_selected.xml new file mode 100644 index 0000000..2ffc4b5 --- /dev/null +++ b/app/src/main/res/drawable/outline_selected.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/abstract_product_view.xml b/app/src/main/res/layout/abstract_product_view.xml index 25ecef8..e7c669c 100644 --- a/app/src/main/res/layout/abstract_product_view.xml +++ b/app/src/main/res/layout/abstract_product_view.xml @@ -2,7 +2,8 @@ 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="200dp" - android:layout_height="wrap_content" app:barrierMargin="1dp" android:clickable="false"> + android:layout_height="wrap_content" app:barrierMargin="1dp" android:clickable="false" + android:outlineProvider="background" android:background="@drawable/outline">