diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d45c6f1..942defe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,6 +36,14 @@ android:name=".activities.AddAbstractProductActivity" android:exported="false" android:theme="@style/Theme.BarcodeScannerForEmployees"/> + + { + val dates: MutableSet = mutableSetOf() + + val projection = arrayOf( + ProductContract.ProductEntry.EXPIRY_DATE + ) + + val orderBy = "${ProductContract.ProductEntry.EXPIRY_DATE} ASC" + + val cursor = db.query(ProductContract.ProductEntry.TABLE_NAME, projection, null, null, null, null, orderBy) + + with(cursor) { + while (moveToNext()) { + dates.add(getLong(getColumnIndexOrThrow(ProductContract.ProductEntry.EXPIRY_DATE))) + } + } + + return dates + } + fun findAbstractProductByBarcode (db: SQLiteDatabase, barcode: String) : AbstractProduct? { var abstractProduct: AbstractProduct? = null val projection = arrayOf( diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt index f7e3649..c88ff69 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt @@ -77,7 +77,6 @@ class AddProductActivity : AppCompatActivity() { update() } else { product = Product(0, 0, 0, 0, 0) - abstractProduct = AbstractProduct(0, "", "", 0.0, "", 0, 0) } scanButton.setOnClickListener { @@ -111,6 +110,11 @@ class AddProductActivity : AppCompatActivity() { } saveProductButton.setOnClickListener { + if (abstractProduct == null) { + Toast.makeText(this, getString(R.string.abstract_product_request), Toast.LENGTH_SHORT).show() + return@setOnClickListener + } + if (expiryDateOverShelfLife == null) { Toast.makeText(this, getString(R.string.shell_life_or_expiry_date_request), Toast.LENGTH_SHORT).show() return@setOnClickListener @@ -145,6 +149,12 @@ class AddProductActivity : AppCompatActivity() { finish() } update() + + val today = SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().time).split(".") + + + dateOfProductionDatePicker.updateDate(today[2].toInt(), today[1].toInt(), today[0].toInt()) + expiryDatePicker.updateDate(today[2].toInt(), today[1].toInt(), today[0].toInt()) } private fun update () { @@ -158,14 +168,6 @@ class AddProductActivity : AppCompatActivity() { shelfLifeTextEdit.visibility = View.VISIBLE } - val dateOfProduction = SimpleDateFormat("dd.MM.yyyy").format(product!!.dateOfProduction * 1000).split(".") - - dateOfProductionDatePicker.updateDate(dateOfProduction[2].toInt(), dateOfProduction[1].toInt(), dateOfProduction[0].toInt()) - - val expiryDate = SimpleDateFormat("dd.MM.yyyy").format(product!!.dateOfExpiry * 1000).split(".") - - expiryDatePicker.updateDate(expiryDate[2].toInt(), expiryDate[1].toInt(), expiryDate[0].toInt()) - if (amountTextEdit.text.toString() == "") { amountTextEdit.setText(product!!.amount.toString()) } else { diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ExpiryCalendarActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ExpiryCalendarActivity.kt new file mode 100644 index 0000000..2dd2b72 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ExpiryCalendarActivity.kt @@ -0,0 +1,33 @@ +package org.foxarmy.barcodescannerforemployees.activities + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +import org.foxarmy.barcodescannerforemployees.databinding.ActivityExpiryCalendarBinding + +class ExpiryCalendarActivity : AppCompatActivity() { + private lateinit var binding: ActivityExpiryCalendarBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = ActivityExpiryCalendarBinding.inflate(layoutInflater) + setContentView(binding.root) + + } + + fun displayDate(date:Long) { + val expiryCalendarGroupActivityIntent = Intent(this, ExpiryCalendarGroupActivity::class.java) + val extras = Bundle() + extras.putLong("date", date) + expiryCalendarGroupActivityIntent.putExtras(extras) + ContextCompat.startActivity(this, expiryCalendarGroupActivityIntent, extras) + +// val shelfFragment = ShelfFragment.newInstance(date) +// val ft = supportFragmentManager.beginTransaction() +// ft.replace(R.id.include_content, shelfFragment) +// ft.commit() +// ft.addToBackStack(null) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ExpiryCalendarGroupActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ExpiryCalendarGroupActivity.kt new file mode 100644 index 0000000..6d18b4d --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/ExpiryCalendarGroupActivity.kt @@ -0,0 +1,26 @@ +package org.foxarmy.barcodescannerforemployees.activities + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import org.foxarmy.barcodescannerforemployees.R +import org.foxarmy.barcodescannerforemployees.databinding.ActivityExpiryCalendarGroupBinding +import org.foxarmy.barcodescannerforemployees.fragments.ShelfFragment + +class ExpiryCalendarGroupActivity : AppCompatActivity() { + private lateinit var binding: ActivityExpiryCalendarGroupBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = ActivityExpiryCalendarGroupBinding.inflate(layoutInflater) + + val date = intent.extras!!.getLong("date") + +// binding.root.addView(ShelfFragment.newInstance(date).view!!.rootView) + val ft = supportFragmentManager.beginTransaction() + ft.replace(R.id.content, ShelfFragment.newInstance(date)) + ft.commit() + setContentView(binding.root) + + } +} \ 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 dcaf3d7..7e68a86 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt @@ -32,6 +32,13 @@ class MainActivity : AppCompatActivity() { setupViewPager(binding.tabViewpager) binding.tabTablayout.setupWithViewPager(binding.tabViewpager) + binding.expiryCalendarFab.setOnClickListener { _ -> + val expiryCalendarIntent = Intent(this, ExpiryCalendarActivity::class.java) + val extras = Bundle() + expiryCalendarIntent.putExtras(extras) + ContextCompat.startActivity(this, expiryCalendarIntent, extras) + } + binding.newElementFab.setOnClickListener { view -> val currentPosition = binding.tabTablayout.selectedTabPosition val fragment = adapter.getItem(currentPosition) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddAbstractProductFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddAbstractProductFragment.kt index 9270f55..2a4d1b9 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddAbstractProductFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddAbstractProductFragment.kt @@ -5,7 +5,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import org.foxarmy.barcodescannerforemployees.R import org.foxarmy.barcodescannerforemployees.databinding.FragmentAddAbstractProductBinding class AddAbstractProductFragment : Fragment() { @@ -16,6 +15,6 @@ class AddAbstractProductFragment : Fragment() { savedInstanceState: Bundle? ): View { binding = FragmentAddAbstractProductBinding.inflate(layoutInflater) - return inflater.inflate(R.layout.fragment_add_abstract_product, container, false) + return binding.root } } \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddProductFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddProductFragment.kt index a4f327d..574c9a8 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddProductFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/AddProductFragment.kt @@ -5,7 +5,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import org.foxarmy.barcodescannerforemployees.R import org.foxarmy.barcodescannerforemployees.databinding.FragmentAddProductBinding class AddProductFragment : Fragment() { @@ -16,6 +15,6 @@ class AddProductFragment : Fragment() { savedInstanceState: Bundle? ): View { binding = FragmentAddProductBinding.inflate(layoutInflater) - return inflater.inflate(R.layout.fragment_add_product, container, false) + return binding.root } } \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ExpiryDatesFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ExpiryDatesFragment.kt new file mode 100644 index 0000000..1e07125 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ExpiryDatesFragment.kt @@ -0,0 +1,37 @@ +package org.foxarmy.barcodescannerforemployees.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import org.foxarmy.barcodescannerforemployees.DBStorageController +import org.foxarmy.barcodescannerforemployees.databinding.FragmentExpiryDatesBinding +import org.foxarmy.barcodescannerforemployees.views.ExpiryGroupView + +class ExpiryDatesFragment : Fragment() { + private lateinit var binding: FragmentExpiryDatesBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = FragmentExpiryDatesBinding.inflate(layoutInflater) + + fillUp() + + return binding.root + } + + + private fun fillUp() { + val dates = DBStorageController(requireContext()).findAllExpiryDates(DBStorageController(requireContext()).readableDatabase) + + val container = binding.datesLinearLayout + + dates.forEach { date -> + val newDate = ExpiryGroupView(requireActivity(), requireContext(), date) + container.addView(newDate) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt index 8181905..4442805 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/fragments/ShelfFragment.kt @@ -1,5 +1,6 @@ package org.foxarmy.barcodescannerforemployees.fragments +import android.content.Context import android.content.Intent import android.os.Bundle import android.provider.BaseColumns @@ -28,6 +29,8 @@ class ShelfFragment : Fragment() { private lateinit var binding: FragmentShelfBinding private var updateInProgress = false + private var filterBy = "" + private var filter = "" override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -37,6 +40,12 @@ class ShelfFragment : Fragment() { fillUpSortBySpinner() + val filterByDate = arguments?.getLong("filterByExpiryDate") as Long? + if (filterByDate != null) { + filter = filterByDate.toString() + filterBy = "expiryDate" + } + binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onNothingSelected(parent: AdapterView<*>?) { updateContent() @@ -135,7 +144,20 @@ class ShelfFragment : Fragment() { } } - val cursor = db.query(ProductContract.ProductEntry.TABLE_NAME, projection, null, null, null, null, orderBy) + var selection: String? = null + var selectionArgs: Array? = null + + when (filterBy) { + "expiryDate" -> { + selection = "${ProductContract.ProductEntry.EXPIRY_DATE} = ?" + selectionArgs = arrayOf(filter) + } + + "" -> {} + } + + + val cursor = db.query(ProductContract.ProductEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, orderBy) val products = mutableListOf() @@ -206,4 +228,16 @@ class ShelfFragment : Fragment() { updateContent() } } + + companion object { + + fun newInstance(date: Long):ShelfFragment = ShelfFragment().apply { + val fragment = ShelfFragment() + val args = Bundle() + args.putLong("filterByExpiryDate", date) + fragment.setArguments(args) + + return fragment + } + } } \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt index 4b481bc..800a2a4 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt @@ -9,6 +9,7 @@ import android.view.LayoutInflater import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView +import android.widget.Toast import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat.startActivity @@ -71,6 +72,10 @@ class AbstractProductView: LinearLayout { this.background = ContextCompat.getDrawable(context, if (isProductSelected) R.drawable.outline_selected else R.drawable.outline) true } + + productNameField!!.setOnClickListener { + Toast.makeText(activity, productNameField!!.text, Toast.LENGTH_SHORT).show() + } } fun update() { diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ExpiryGroupView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ExpiryGroupView.kt new file mode 100644 index 0000000..8cb3f53 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ExpiryGroupView.kt @@ -0,0 +1,37 @@ +package org.foxarmy.barcodescannerforemployees.views + +import android.app.Activity +import android.content.Context +import android.view.LayoutInflater +import android.widget.LinearLayout +import android.widget.TextView +import androidx.core.content.ContextCompat +import org.foxarmy.barcodescannerforemployees.DBStorageController +import org.foxarmy.barcodescannerforemployees.R +import org.foxarmy.barcodescannerforemployees.activities.ExpiryCalendarActivity +import java.text.SimpleDateFormat + +class ExpiryGroupView : LinearLayout { + + private var representingDate: Long? = null + + constructor(activity: Activity, context: Context, representingDate: Long) : super(context) { + + val inflater: LayoutInflater = activity.layoutInflater + inflater.inflate(R.layout.expiry_group_view, this) + + this.representingDate = representingDate + + this.background = ContextCompat.getDrawable(context,R.drawable.outline) + + var amount = DBStorageController(context).findAmountOfProductsWithExpiryDate(DBStorageController(context).readableDatabase, representingDate) + + findViewById(R.id.representingDateTextView).text = SimpleDateFormat("dd.MM.yyyy").format(representingDate * 1000) + findViewById(R.id.amountTextView).text = amount.toString() + + setOnClickListener { + (activity as ExpiryCalendarActivity).displayDate(representingDate) +// (activity as MainActivity).filterAbstractProductsByCategory(category.id) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt index fb1e9f2..93d5cdd 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt @@ -88,7 +88,11 @@ class ProductView: LinearLayout { @RequiresApi(Build.VERSION_CODES.O) fun update () { - val linkedAbstractProduct: AbstractProduct = DBStorageController(activity).findAbstractProductById(DBStorageController(activity).readableDatabase, product.abstractProductId)!! + val linkedAbstractProduct: AbstractProduct? = DBStorageController(activity).findAbstractProductById(DBStorageController(activity).readableDatabase, product.abstractProductId) + + if(linkedAbstractProduct == null) { + return + } val thumbnailsDir = File(activity.cacheDir, "thumbnails") thumbnailsDir.mkdirs() diff --git a/app/src/main/res/layout/activity_expiry_calendar.xml b/app/src/main/res/layout/activity_expiry_calendar.xml new file mode 100644 index 0000000..2f37de1 --- /dev/null +++ b/app/src/main/res/layout/activity_expiry_calendar.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_expiry_calendar_group.xml b/app/src/main/res/layout/activity_expiry_calendar_group.xml new file mode 100644 index 0000000..ad84073 --- /dev/null +++ b/app/src/main/res/layout/activity_expiry_calendar_group.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index eddf761..97d9609 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -50,5 +50,12 @@ android:layout_marginEnd="@dimen/fab_margin" android:layout_marginBottom="16dp" app:srcCompat="@android:drawable/ic_input_add"/> + \ No newline at end of file diff --git a/app/src/main/res/layout/content_expiry_calendar.xml b/app/src/main/res/layout/content_expiry_calendar.xml new file mode 100644 index 0000000..3744aa7 --- /dev/null +++ b/app/src/main/res/layout/content_expiry_calendar.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/expiry_group_view.xml b/app/src/main/res/layout/expiry_group_view.xml new file mode 100644 index 0000000..55a2c04 --- /dev/null +++ b/app/src/main/res/layout/expiry_group_view.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_add_product.xml b/app/src/main/res/layout/fragment_add_product.xml index 25b4d81..54c7cac 100644 --- a/app/src/main/res/layout/fragment_add_product.xml +++ b/app/src/main/res/layout/fragment_add_product.xml @@ -48,7 +48,7 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_shelf.xml b/app/src/main/res/layout/fragment_shelf.xml index 8ec6216..eef1d0e 100644 --- a/app/src/main/res/layout/fragment_shelf.xml +++ b/app/src/main/res/layout/fragment_shelf.xml @@ -1,7 +1,8 @@ + android:layout_height="match_parent" + android:background="#141218"> + + + + \ 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 5376dec..a709cb9 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -86,4 +86,5 @@ Продукт не найден в онлайн базе данных. Попробуйте снова, если это ошибка сканирования или введите данные вручную + Пожалуйста, отсканируйте штрихкод, чтобы добавить продукт \ 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 8f27dbe..94c593f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -84,4 +84,5 @@ Product not found. Please, try again if you beleive barcode scanned wrongly or type manually + Please, scan a barcode in order to add product \ No newline at end of file