diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/DBStorageController.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/DBStorageController.kt index a612c42..872e4f0 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/DBStorageController.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/DBStorageController.kt @@ -1,6 +1,7 @@ package org.foxarmy.barcodescannerforemployees import android.content.Context +import android.database.DatabaseUtils import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper import android.provider.BaseColumns @@ -121,6 +122,9 @@ class DBStorageController(context: Context) : SQLiteOpenHelper(context, DATABASE return result } + fun getAmountOfAbstractProductsInCategory(db:SQLiteDatabase, id: Int) : Int { + return DatabaseUtils.longForQuery(db, "SELECT COUNT(*) FROM ${ProductContract.ProductEntry.TABLE_NAME} WHERE ${ProductContract.ProductEntry.CATEGORY} = ?", arrayOf(id.toString())).toInt() + } fun eraseAbstractProduct(db: SQLiteDatabase, id: Int, context: Context) { val projection = arrayOf( ProductContract.ProductEntry.IMAGE_FILENAME diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt index aabdb57..883fdc6 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/CategoryView.kt @@ -7,6 +7,7 @@ import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.ContextCompat import org.foxarmy.barcodescannerforemployees.Category +import org.foxarmy.barcodescannerforemployees.DBStorageController import org.foxarmy.barcodescannerforemployees.R class CategoryView : LinearLayout { @@ -14,8 +15,6 @@ class CategoryView : LinearLayout { val categoryName: TextView val amountOfProducts: TextView var isCategorySelected = false -// val updateButton: Button -// val deleteButton: Button constructor(activity: Activity, context: Context, category: Category) : super(context) { this.category = category @@ -27,37 +26,14 @@ class CategoryView : LinearLayout { categoryName = findViewById(R.id.categoryNameTextView) amountOfProducts = findViewById(R.id.amountOfProducts) -// updateButton = findViewById(R.id.updateButton) -// deleteButton = findViewById(R.id.deleteButton) categoryName.text = category.name + amountOfProducts.text = DBStorageController(context).getAmountOfAbstractProductsInCategory(DBStorageController(context).readableDatabase, category.id).toString() setOnLongClickListener { isCategorySelected = !isCategorySelected this.background = ContextCompat.getDrawable(context, if (isCategorySelected) R.drawable.outline_selected else R.drawable.outline) true } - -// updateButton.setOnClickListener { -// val addCategoryIntent = Intent(context, AddCategoryActivity::class.java) -// val extras = Bundle() -// extras.putInt("categoryid", category.id) -// extras.putString("categoryname", category.name) -// addCategoryIntent.putExtras(extras) -// ContextCompat.startActivity(context, addCategoryIntent, extras) -// } -// -// deleteButton.setOnClickListener { -// val builder = AlertDialog.Builder(context) -// .setMessage("Deleting this category will also delete ALL the products, that belong to that category. Do you want to proceed?") -// .setPositiveButton("Yes") { _: DialogInterface, _: Int -> -// val db = DBStorageController(context).writableDatabase -// DBStorageController(context).eraseCategory(db, category.id, context) -// -// } -// .setNegativeButton("No") { _: DialogInterface, _: Int -> -// -// }.show() -// } } } \ No newline at end of file