ability to delete a product

This commit is contained in:
leca 2024-10-15 13:26:04 +03:00
parent 6c4f11bcb0
commit 231419eb77
5 changed files with 36 additions and 2 deletions

View File

@ -123,6 +123,10 @@ class MainActivity : AppCompatActivity() {
}.show() }.show()
} }
"ShelfFragment" -> {
val shelfFragment = fragment as ShelfFragment
shelfFragment.removeSelected()
}
} }
true true
} }

View File

@ -5,6 +5,9 @@ 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.ImageView
import android.widget.Toast
import androidx.core.view.children
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.gridlayout.widget.GridLayout import androidx.gridlayout.widget.GridLayout
import org.foxarmy.barcodescannerforemployees.DBStorageController import org.foxarmy.barcodescannerforemployees.DBStorageController
@ -77,4 +80,30 @@ class ShelfFragment : Fragment() {
} }
} }
} }
fun removeSelected() {
thread {
val grv = view?.findViewById<GridLayout>(R.id.contentGridLayout)
val db = DBStorageController(requireContext())
var deleted = false
for (view: ProductView in grv?.children!!.iterator() as Iterator<ProductView>) {
activity!!.runOnUiThread {
view.findViewById<ImageView>(R.id.productPicture).setImageURI(null)
}
if (view.isProductSelected) {
// db.eraseAbstractProduct(db.writableDatabase, view.abstractProduct.id, requireContext())
db.eraseProduct(db.writableDatabase, view.product.id)
deleted = true
}
}
if (!deleted) {
activity!!.runOnUiThread {
Toast.makeText(requireContext(), "Nothing to delete", Toast.LENGTH_SHORT).show()
}
}
updateContent()
}
}
} }

View File

@ -61,6 +61,7 @@ class ProductView: LinearLayout {
productLifeSpan = findViewById(R.id.dateSpan) productLifeSpan = findViewById(R.id.dateSpan)
findViewById<ConstraintLayout>(R.id.productLayout).setOnLongClickListener { findViewById<ConstraintLayout>(R.id.productLayout).setOnLongClickListener {
isProductSelected = !isProductSelected
updateStroke() updateStroke()
true true
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@android:color/transparent" /> <solid android:color="@android:color/transparent" />
<stroke android:width="1dip" android:color="#28283f" android:id="@+id/test"/> <stroke android:width="3dip" android:color="#28283f" android:id="@+id/test"/>
<padding android:bottom="1dp" android:top="1dp" android:left="1dp" android:right="1dp" /> <padding android:bottom="1dp" android:top="1dp" android:left="1dp" android:right="1dp" />
</shape> </shape>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@android:color/transparent" /> <solid android:color="@android:color/transparent" />
<stroke android:width="1dip" android:color="#840d15"/> <stroke android:width="3dip" android:color="#840d15"/>
<padding android:bottom="1dp" android:top="1dp" android:left="1dp" android:right="1dp" /> <padding android:bottom="1dp" android:top="1dp" android:left="1dp" android:right="1dp" />
</shape> </shape>