ability to add and link barcodeless products

This commit is contained in:
leca 2024-10-23 02:21:35 +03:00
parent 6e32545b9d
commit 6e497323c0
12 changed files with 145 additions and 18 deletions

View File

@ -44,6 +44,10 @@
android:name=".activities.ExpiryCalendarGroupActivity" android:name=".activities.ExpiryCalendarGroupActivity"
android:exported="false" android:exported="false"
android:theme="@style/Theme.BarcodeScannerForEmployees"/> android:theme="@style/Theme.BarcodeScannerForEmployees"/>
<activity
android:name=".activities.FindBarcodelessAbstractProduct"
android:exported="false"
android:theme="@style/Theme.BarcodeScannerForEmployees"/>
<activity <activity
android:name=".activities.FullscreenActivity" android:name=".activities.FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize" android:configChanges="orientation|keyboardHidden|screenSize"
@ -57,7 +61,7 @@
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
android:authorities="com.google.firebase.components.activities.MainActivity.provider;com.google.firebase.components.activities.FullscreenActivity.provider;com.google.firebase.components.activities.AddAbstractProductActivity.provider;com.google.firebase.components.activities.AddProductActivity.provider;com.google.firebase.components.activities.ExpiryCalendarActivity.provider;com.google.firebase.components.activities.ExpiryCalendarGroupActivity.provider" android:authorities="com.google.firebase.components.activities.MainActivity.provider;com.google.firebase.components.activities.FullscreenActivity.provider;com.google.firebase.components.activities.AddAbstractProductActivity.provider;com.google.firebase.components.activities.AddProductActivity.provider;com.google.firebase.components.activities.ExpiryCalendarActivity.provider;com.google.firebase.components.activities.FindBarcodelessAbstractProduct.provider;com.google.firebase.components.activities.ExpiryCalendarGroupActivity.provider"
android:exported="false" android:exported="false"
android:grantUriPermissions="true"> android:grantUriPermissions="true">
<meta-data <meta-data

View File

@ -32,6 +32,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
private lateinit var scanButton: Button private lateinit var scanButton: Button
private lateinit var barcodeText: EditText private lateinit var barcodeText: EditText
private lateinit var noBarcodeCheckBox: CheckBox
private lateinit var productNameText: TextView private lateinit var productNameText: TextView
private lateinit var netWeightText: TextView private lateinit var netWeightText: TextView
private lateinit var unitTypeSpinner: Spinner private lateinit var unitTypeSpinner: Spinner
@ -63,6 +64,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
scanButton = findViewById(R.id.scan_button) scanButton = findViewById(R.id.scan_button)
barcodeText = findViewById(R.id.barcodeTextEdit) barcodeText = findViewById(R.id.barcodeTextEdit)
noBarcodeCheckBox = findViewById(R.id.noBarcodeCheckBox)
productNameText = findViewById(R.id.productName) productNameText = findViewById(R.id.productName)
netWeightText = findViewById(R.id.netWeight) netWeightText = findViewById(R.id.netWeight)
unitTypeSpinner = findViewById(R.id.unitTypeSpinner) unitTypeSpinner = findViewById(R.id.unitTypeSpinner)
@ -72,6 +74,12 @@ class AddAbstractProductActivity : AppCompatActivity() {
fillupCategorySpinner() fillupCategorySpinner()
fillupUnitsSpinner() fillupUnitsSpinner()
noBarcodeCheckBox.setOnClickListener {
if (noBarcodeCheckBox.isChecked) {
barcodeText.setText("")
}
}
barcodeText.addTextChangedListener { barcodeText.addTextChangedListener {
this.barcode = barcodeText.text.toString() this.barcode = barcodeText.text.toString()
} }
@ -108,7 +116,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
return@setOnClickListener return@setOnClickListener
} }
if (barcode == "") { if (barcode == "" && !noBarcodeCheckBox.isChecked) {
Toast.makeText(this, getString(R.string.product_barcode_request), Toast.LENGTH_SHORT).show() Toast.makeText(this, getString(R.string.product_barcode_request), Toast.LENGTH_SHORT).show()
return@setOnClickListener return@setOnClickListener
} }

View File

@ -1,5 +1,6 @@
package org.foxarmy.barcodescannerforemployees.activities package org.foxarmy.barcodescannerforemployees.activities
import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -25,6 +26,7 @@ import java.util.*
class AddProductActivity : AppCompatActivity() { class AddProductActivity : AppCompatActivity() {
private lateinit var scanButton: Button private lateinit var scanButton: Button
private lateinit var noBarcodeButton: Button
private lateinit var abstractProductView: AbstractProductView private lateinit var abstractProductView: AbstractProductView
private lateinit var expiryDateRadioButton: RadioButton private lateinit var expiryDateRadioButton: RadioButton
private lateinit var shelfLifeRadioButton: RadioButton private lateinit var shelfLifeRadioButton: RadioButton
@ -49,6 +51,7 @@ class AddProductActivity : AppCompatActivity() {
setContentView(R.layout.fragment_add_product) setContentView(R.layout.fragment_add_product)
scanButton = findViewById(R.id.scanButton) scanButton = findViewById(R.id.scanButton)
noBarcodeButton = findViewById(R.id.noBarcodeButton)
abstractProductView = findViewById(R.id.abstractProductView) abstractProductView = findViewById(R.id.abstractProductView)
expiryDateRadioButton = findViewById(R.id.expiryDateRadio) expiryDateRadioButton = findViewById(R.id.expiryDateRadio)
shelfLifeRadioButton = findViewById(R.id.shelfLifeRadio) shelfLifeRadioButton = findViewById(R.id.shelfLifeRadio)
@ -83,6 +86,10 @@ class AddProductActivity : AppCompatActivity() {
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA) requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
} }
noBarcodeButton.setOnClickListener {
intentLauncher.launch(Intent(this, FindBarcodelessAbstractProduct::class.java))
}
expiryDateRadioButton.setOnClickListener { expiryDateRadioButton.setOnClickListener {
expiryDateOverShelfLife = true expiryDateOverShelfLife = true
update() update()
@ -157,6 +164,16 @@ class AddProductActivity : AppCompatActivity() {
expiryDatePicker.updateDate(today[2].toInt(), today[1].toInt(), today[0].toInt()) expiryDatePicker.updateDate(today[2].toInt(), today[1].toInt(), today[0].toInt())
} }
private val intentLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val selectedAbstractProduct = (result.data?.extras!!.getParcelable("abstractProduct") as AbstractProduct?)!!
product!!.abstractProductId = selectedAbstractProduct.id
abstractProduct = selectedAbstractProduct
displayAbstractProduct(selectedAbstractProduct, "")
}
}
private fun update () { private fun update () {
if (expiryDateOverShelfLife == true) { if (expiryDateOverShelfLife == true) {
expiryDatePicker.visibility = View.VISIBLE expiryDatePicker.visibility = View.VISIBLE

View File

@ -0,0 +1,34 @@
package org.foxarmy.barcodescannerforemployees.activities
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import org.foxarmy.barcodescannerforemployees.R
import org.foxarmy.barcodescannerforemployees.databinding.ActivityFindBarcodelessAbstractProductBinding
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
import org.foxarmy.barcodescannerforemployees.fragments.StorageFragment
class FindBarcodelessAbstractProduct() : AppCompatActivity() {
private lateinit var binding: ActivityFindBarcodelessAbstractProductBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityFindBarcodelessAbstractProductBinding.inflate(layoutInflater)
val ft = supportFragmentManager.beginTransaction()
val fragment = StorageFragment.newInstance("barcodeless", arrayOf(""))
ft.replace(R.id.content, fragment)
ft.commit()
setContentView(binding.root)
}
fun selected(abstractProduct: AbstractProduct) {
val data = Intent()
data.putExtra("abstractProduct", abstractProduct)
setResult(Activity.RESULT_OK, data)
finish()
}
}

View File

@ -77,7 +77,7 @@ class MainActivity : AppCompatActivity() {
private fun setupViewPager(viewpager: ViewPager) { private fun setupViewPager(viewpager: ViewPager) {
adapter = ViewPagerAdapter(supportFragmentManager) adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(StorageFragment(), getString(R.string.storage_title)) adapter.addFragment(StorageFragment.newInstance("", arrayOf("")), getString(R.string.storage_title))
adapter.addFragment(ShelfFragment(), getString(R.string.shelf_title)) adapter.addFragment(ShelfFragment(), getString(R.string.shelf_title))
adapter.addFragment(CategoriesFragment(), getString(R.string.categories_title)) adapter.addFragment(CategoriesFragment(), getString(R.string.categories_title))

View File

@ -6,10 +6,7 @@ import android.provider.BaseColumns
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.AdapterView import android.widget.*
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.Toast
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.children import androidx.core.view.children
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -17,6 +14,7 @@ import org.foxarmy.barcodescannerforemployees.AbstractProductContract
import org.foxarmy.barcodescannerforemployees.DBStorageController import org.foxarmy.barcodescannerforemployees.DBStorageController
import org.foxarmy.barcodescannerforemployees.R import org.foxarmy.barcodescannerforemployees.R
import org.foxarmy.barcodescannerforemployees.activities.AddAbstractProductActivity import org.foxarmy.barcodescannerforemployees.activities.AddAbstractProductActivity
import org.foxarmy.barcodescannerforemployees.activities.FindBarcodelessAbstractProduct
import org.foxarmy.barcodescannerforemployees.databinding.FragmentStorageBinding import org.foxarmy.barcodescannerforemployees.databinding.FragmentStorageBinding
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
import org.foxarmy.barcodescannerforemployees.generateThumbnailForImage import org.foxarmy.barcodescannerforemployees.generateThumbnailForImage
@ -26,7 +24,8 @@ import kotlin.concurrent.thread
class StorageFragment : Fragment() { class StorageFragment : Fragment() {
private lateinit var binding: FragmentStorageBinding private lateinit var binding: FragmentStorageBinding
private var filterByCategory = "" private var filterBy = ""
private lateinit var filter: Array<String>
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
@ -46,10 +45,13 @@ class StorageFragment : Fragment() {
} }
binding.dropFiltersButton.setOnClickListener { binding.dropFiltersButton.setOnClickListener {
filterByCategory = "" filterBy = ""
updateContent() updateContent()
} }
filterBy = arguments?.getString("filterBy")!!
filter = arguments?.getStringArray("filter")!!
return binding.root return binding.root
} }
@ -137,11 +139,18 @@ class StorageFragment : Fragment() {
var selection = "" var selection = ""
var selectionArgs: Array<String>? = null var selectionArgs: Array<String>? = null
if (filterByCategory != "") { when (filterBy) {
selection = "${AbstractProductContract.AbstractProductEntry.CATEGORY} = ?" "category" -> {
selectionArgs = arrayOf(filterByCategory) selection = "${AbstractProductContract.AbstractProductEntry.CATEGORY} = ?"
selectionArgs = filter
}
"barcodeless" -> {
selection = "${AbstractProductContract.AbstractProductEntry.BARCODE} = '' "
selectionArgs = null
}
} }
val cursor = db.query(AbstractProductContract.AbstractProductEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, orderBy) val cursor = db.query(AbstractProductContract.AbstractProductEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, orderBy)
with (cursor) { with (cursor) {
@ -164,6 +173,16 @@ class StorageFragment : Fragment() {
product product
) )
if (filterBy == "barcodeless") {
abstractProduct.setOnClickListener {
(activity as FindBarcodelessAbstractProduct).selected(abstractProduct.abstractProduct)
}
abstractProduct.findViewById<TextView>(R.id.productNameView).setOnClickListener {
(activity as FindBarcodelessAbstractProduct).selected(abstractProduct.abstractProduct)
}
}
activity!!.runOnUiThread{ activity!!.runOnUiThread{
grv.addView(abstractProduct) grv.addView(abstractProduct)
} }
@ -179,8 +198,20 @@ class StorageFragment : Fragment() {
} }
fun filterByCategory(id: Int) { fun filterByCategory(id: Int) {
// filterByCategory = DBStorageController(context!!).getCategoryNameById(DBStorageController(context!!).readableDatabase, id) filterBy = "category"
filterByCategory = "$id" filter = arrayOf("$id")
updateContent() updateContent()
} }
companion object {
fun newInstance(filterBy: String, filter: Array<String>):StorageFragment = StorageFragment().apply {
val fragment = StorageFragment()
val args = Bundle()
args.putString("filterBy", filterBy)
args.putStringArray("filter", filter)
fragment.setArguments(args)
return fragment
}
}
} }

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.ShelfFragment"
android:id="@+id/content">
</androidx.core.widget.NestedScrollView>

View File

@ -61,9 +61,16 @@
android:inputType="text" android:inputType="text"
android:ems="10" android:ems="10"
android:id="@+id/barcodeTextEdit" app:layout_constraintTop_toBottomOf="@+id/imageView" android:id="@+id/barcodeTextEdit" app:layout_constraintTop_toBottomOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="8dp" android:hint="Barcode" android:textColorHint="#737373" android:layout_marginTop="8dp" android:hint="Barcode" android:textColorHint="#737373"
android:layout_marginStart="5dp" android:layout_marginEnd="5dp"/> android:layout_marginStart="5dp"/>
<CheckBox
android:text="@string/no_barcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/noBarcodeCheckBox"
app:layout_constraintStart_toEndOf="@+id/barcodeTextEdit"
app:layout_constraintTop_toBottomOf="@+id/imageView" android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView <TextView
android:text="@string/category" android:text="@string/category"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -21,8 +21,15 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/scanButton" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/scanButton" android:layout_weight="1"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/abstractProductView" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/abstractProductView" android:layout_marginTop="16dp"/> android:layout_marginStart="32dp"/>
<Button
android:text="@string/no_barcode_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/noBarcodeButton"
app:layout_constraintTop_toBottomOf="@+id/abstractProductView"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"/>
<TextView <TextView
android:text="@string/date_of_production" android:text="@string/date_of_production"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.core.widget.NestedScrollView>

View File

@ -87,4 +87,6 @@
ошибка сканирования или введите данные вручную ошибка сканирования или введите данные вручную
</string> </string>
<string name="abstract_product_request">Пожалуйста, отсканируйте штрихкод, чтобы добавить продукт</string> <string name="abstract_product_request">Пожалуйста, отсканируйте штрихкод, чтобы добавить продукт</string>
<string name="no_barcode">No barcode present</string>
<string name="no_barcode_button">No barcode</string>
</resources> </resources>

View File

@ -85,4 +85,6 @@
wrongly or type manually wrongly or type manually
</string> </string>
<string name="abstract_product_request">Please, scan a barcode in order to add product</string> <string name="abstract_product_request">Please, scan a barcode in order to add product</string>
<string name="no_barcode">No barcode present</string>
<string name="no_barcode_button">No barcode</string>
</resources> </resources>