diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 942defe..9bd8fd7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -44,6 +44,10 @@
android:name=".activities.ExpiryCalendarGroupActivity"
android:exported="false"
android:theme="@style/Theme.BarcodeScannerForEmployees"/>
+
+ 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 () {
if (expiryDateOverShelfLife == true) {
expiryDatePicker.visibility = View.VISIBLE
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/FindBarcodelessAbstractProduct.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/FindBarcodelessAbstractProduct.kt
new file mode 100644
index 0000000..38c199e
--- /dev/null
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/FindBarcodelessAbstractProduct.kt
@@ -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()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt
index 7e68a86..900a1b9 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt
@@ -77,7 +77,7 @@ class MainActivity : AppCompatActivity() {
private fun setupViewPager(viewpager: ViewPager) {
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(CategoriesFragment(), getString(R.string.categories_title))
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt
index 29068c1..f331f7f 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/StorageFragment.kt
@@ -6,10 +6,7 @@ import android.provider.BaseColumns
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import android.widget.AdapterView
-import android.widget.ArrayAdapter
-import android.widget.ImageView
-import android.widget.Toast
+import android.widget.*
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.fragment.app.Fragment
@@ -17,6 +14,7 @@ import org.foxarmy.barcodescannerforemployees.AbstractProductContract
import org.foxarmy.barcodescannerforemployees.DBStorageController
import org.foxarmy.barcodescannerforemployees.R
import org.foxarmy.barcodescannerforemployees.activities.AddAbstractProductActivity
+import org.foxarmy.barcodescannerforemployees.activities.FindBarcodelessAbstractProduct
import org.foxarmy.barcodescannerforemployees.databinding.FragmentStorageBinding
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
import org.foxarmy.barcodescannerforemployees.generateThumbnailForImage
@@ -26,7 +24,8 @@ import kotlin.concurrent.thread
class StorageFragment : Fragment() {
private lateinit var binding: FragmentStorageBinding
- private var filterByCategory = ""
+ private var filterBy = ""
+ private lateinit var filter: Array
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@@ -46,10 +45,13 @@ class StorageFragment : Fragment() {
}
binding.dropFiltersButton.setOnClickListener {
- filterByCategory = ""
+ filterBy = ""
updateContent()
}
+ filterBy = arguments?.getString("filterBy")!!
+ filter = arguments?.getStringArray("filter")!!
+
return binding.root
}
@@ -137,11 +139,18 @@ class StorageFragment : Fragment() {
var selection = ""
var selectionArgs: Array? = null
- if (filterByCategory != "") {
- selection = "${AbstractProductContract.AbstractProductEntry.CATEGORY} = ?"
- selectionArgs = arrayOf(filterByCategory)
+ when (filterBy) {
+ "category" -> {
+ 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)
with (cursor) {
@@ -164,6 +173,16 @@ class StorageFragment : Fragment() {
product
)
+ if (filterBy == "barcodeless") {
+ abstractProduct.setOnClickListener {
+ (activity as FindBarcodelessAbstractProduct).selected(abstractProduct.abstractProduct)
+ }
+ abstractProduct.findViewById(R.id.productNameView).setOnClickListener {
+ (activity as FindBarcodelessAbstractProduct).selected(abstractProduct.abstractProduct)
+
+ }
+ }
+
activity!!.runOnUiThread{
grv.addView(abstractProduct)
}
@@ -179,8 +198,20 @@ class StorageFragment : Fragment() {
}
fun filterByCategory(id: Int) {
-// filterByCategory = DBStorageController(context!!).getCategoryNameById(DBStorageController(context!!).readableDatabase, id)
- filterByCategory = "$id"
+ filterBy = "category"
+ filter = arrayOf("$id")
updateContent()
}
+ companion object {
+
+ fun newInstance(filterBy: String, filter: Array):StorageFragment = StorageFragment().apply {
+ val fragment = StorageFragment()
+ val args = Bundle()
+ args.putString("filterBy", filterBy)
+ args.putStringArray("filter", filter)
+ fragment.setArguments(args)
+
+ return fragment
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_find_barcodeless_abstract_product.xml b/app/src/main/res/layout/activity_find_barcodeless_abstract_product.xml
new file mode 100644
index 0000000..ad84073
--- /dev/null
+++ b/app/src/main/res/layout/activity_find_barcodeless_abstract_product.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_add_abstract_product.xml b/app/src/main/res/layout/fragment_add_abstract_product.xml
index 5ab8641..81845ce 100644
--- a/app/src/main/res/layout/fragment_add_abstract_product.xml
+++ b/app/src/main/res/layout/fragment_add_abstract_product.xml
@@ -61,9 +61,16 @@
android:inputType="text"
android:ems="10"
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_marginStart="5dp" android:layout_marginEnd="5dp"/>
+ android:layout_marginStart="5dp"/>
+
+ app:layout_constraintTop_toBottomOf="@+id/abstractProductView" android:layout_marginTop="16dp"
+ android:layout_marginStart="32dp"/>
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index a709cb9..31709c9 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -87,4 +87,6 @@
ошибка сканирования или введите данные вручную
Пожалуйста, отсканируйте штрихкод, чтобы добавить продукт
+ No barcode present
+ No barcode
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 94c593f..4d895a1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -85,4 +85,6 @@
wrongly or type manually
Please, scan a barcode in order to add product
+ No barcode present
+ No barcode
\ No newline at end of file