ability to delete a product
This commit is contained in:
		@@ -123,6 +123,10 @@ class MainActivity : AppCompatActivity() {
 | 
			
		||||
 | 
			
		||||
                            }.show()
 | 
			
		||||
                    }
 | 
			
		||||
                    "ShelfFragment" -> {
 | 
			
		||||
                        val shelfFragment = fragment as ShelfFragment
 | 
			
		||||
                        shelfFragment.removeSelected()
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                true
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,9 @@ import android.provider.BaseColumns
 | 
			
		||||
import android.view.LayoutInflater
 | 
			
		||||
import android.view.View
 | 
			
		||||
import android.view.ViewGroup
 | 
			
		||||
import android.widget.ImageView
 | 
			
		||||
import android.widget.Toast
 | 
			
		||||
import androidx.core.view.children
 | 
			
		||||
import androidx.fragment.app.Fragment
 | 
			
		||||
import androidx.gridlayout.widget.GridLayout
 | 
			
		||||
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()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -61,6 +61,7 @@ class ProductView: LinearLayout {
 | 
			
		||||
        productLifeSpan = findViewById(R.id.dateSpan)
 | 
			
		||||
 | 
			
		||||
        findViewById<ConstraintLayout>(R.id.productLayout).setOnLongClickListener {
 | 
			
		||||
            isProductSelected = !isProductSelected
 | 
			
		||||
            updateStroke()
 | 
			
		||||
            true
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
 | 
			
		||||
    <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" />
 | 
			
		||||
</shape>
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
 | 
			
		||||
    <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" />
 | 
			
		||||
</shape>
 | 
			
		||||
		Reference in New Issue
	
	Block a user