info about deleting an item is sent to the server now
This commit is contained in:
parent
cd299477d4
commit
7cc0467967
|
@ -573,4 +573,61 @@ class Net {
|
||||||
}
|
}
|
||||||
}.join()
|
}.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteCategory(groupId: Int, localId: Int): Response {
|
||||||
|
lateinit var response: Response
|
||||||
|
|
||||||
|
thread {
|
||||||
|
val client = OkHttpClient()
|
||||||
|
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url("https://$server/api/category/$groupId/$localId")
|
||||||
|
.delete()
|
||||||
|
.addHeader("Authorization", "Bearer $token")
|
||||||
|
.addHeader("accept-language", language)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
response = client.newCall(request).execute()
|
||||||
|
}.join()
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteAbstractProduct(groupId: Int, localId: Int): Response {
|
||||||
|
lateinit var response: Response
|
||||||
|
|
||||||
|
thread {
|
||||||
|
val client = OkHttpClient()
|
||||||
|
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url("https://$server/api/abstractproduct/$groupId/$localId")
|
||||||
|
.delete()
|
||||||
|
.addHeader("Authorization", "Bearer $token")
|
||||||
|
.addHeader("accept-language", language)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
response = client.newCall(request).execute()
|
||||||
|
}.join()
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteProduct(groupId: Int, localId: Int): Response {
|
||||||
|
lateinit var response: Response
|
||||||
|
|
||||||
|
thread {
|
||||||
|
val client = OkHttpClient()
|
||||||
|
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url("https://$server/api/product/$groupId/$localId")
|
||||||
|
.delete()
|
||||||
|
.addHeader("Authorization", "Bearer $token")
|
||||||
|
.addHeader("accept-language", language)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
response = client.newCall(request).execute()
|
||||||
|
}.join()
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ class FindBarcodelessAbstractProduct() : AppCompatActivity() {
|
||||||
binding = ActivityFindBarcodelessAbstractProductBinding.inflate(layoutInflater)
|
binding = ActivityFindBarcodelessAbstractProductBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
val ft = supportFragmentManager.beginTransaction()
|
val ft = supportFragmentManager.beginTransaction()
|
||||||
val fragment = StorageFragment.newInstance("barcodeless", arrayOf(""))
|
val fragment = StorageFragment.newInstance("barcodeless", arrayOf("", " "))
|
||||||
ft.replace(R.id.content, fragment)
|
ft.replace(R.id.content, fragment)
|
||||||
ft.commit()
|
ft.commit()
|
||||||
|
|
||||||
|
|
|
@ -308,8 +308,8 @@ class AbstractProductDAO(private val dbHelper: DBStorageController) {
|
||||||
}
|
}
|
||||||
|
|
||||||
"barcodeless" -> {
|
"barcodeless" -> {
|
||||||
selection = "${AbstractProductContract.AbstractProductEntry.BARCODE} = '' "
|
selection = "${AbstractProductContract.AbstractProductEntry.BARCODE} = ? OR ${AbstractProductContract.AbstractProductEntry.BARCODE} = ?"
|
||||||
selectionArgs = null
|
selectionArgs = filter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import androidx.core.view.children
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.security.crypto.EncryptedSharedPreferences
|
import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKeys
|
import androidx.security.crypto.MasterKeys
|
||||||
|
import org.foxarmy.barcodescannerforemployees.Net
|
||||||
import org.foxarmy.barcodescannerforemployees.R
|
import org.foxarmy.barcodescannerforemployees.R
|
||||||
import org.foxarmy.barcodescannerforemployees.activities.AddCategoryActivity
|
import org.foxarmy.barcodescannerforemployees.activities.AddCategoryActivity
|
||||||
import org.foxarmy.barcodescannerforemployees.database.CategoryDAO
|
import org.foxarmy.barcodescannerforemployees.database.CategoryDAO
|
||||||
|
@ -58,7 +59,18 @@ class CategoriesFragment : Fragment() {
|
||||||
var deleted = false
|
var deleted = false
|
||||||
for (view: CategoryView in layout?.children!!.iterator() as Iterator<CategoryView>) {
|
for (view: CategoryView in layout?.children!!.iterator() as Iterator<CategoryView>) {
|
||||||
if (view.isCategorySelected) {
|
if (view.isCategorySelected) {
|
||||||
|
val net = Net()
|
||||||
|
net.token = sharedPreferences.getString("token", "")!!
|
||||||
|
net.server = sharedPreferences.getString("server", "")!!
|
||||||
|
net.language = sharedPreferences.getString("language", "en-US")!!
|
||||||
|
val currentGroup = sharedPreferences.getString("currentGroup", "")!!.toInt()
|
||||||
|
|
||||||
categoryDAO.eraseCategory(view.category.id, requireContext())
|
categoryDAO.eraseCategory(view.category.id, requireContext())
|
||||||
|
val response = net.deleteCategory(currentGroup, view.category.id)
|
||||||
|
activity!!.runOnUiThread{
|
||||||
|
Toast.makeText(context, response.body!!.string(), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
deleted = true
|
deleted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.gridlayout.widget.GridLayout
|
import androidx.gridlayout.widget.GridLayout
|
||||||
import androidx.security.crypto.EncryptedSharedPreferences
|
import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKeys
|
import androidx.security.crypto.MasterKeys
|
||||||
|
import org.foxarmy.barcodescannerforemployees.Net
|
||||||
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
||||||
import org.foxarmy.barcodescannerforemployees.R
|
import org.foxarmy.barcodescannerforemployees.R
|
||||||
import org.foxarmy.barcodescannerforemployees.activities.AddProductActivity
|
import org.foxarmy.barcodescannerforemployees.activities.AddProductActivity
|
||||||
|
@ -151,7 +152,18 @@ class ShelfFragment : Fragment() {
|
||||||
view.findViewById<ImageView>(R.id.productPicture).setImageURI(null)
|
view.findViewById<ImageView>(R.id.productPicture).setImageURI(null)
|
||||||
}
|
}
|
||||||
if (view.isProductSelected) {
|
if (view.isProductSelected) {
|
||||||
|
val net = Net()
|
||||||
|
net.token = sharedPreferences.getString("token", "")!!
|
||||||
|
net.server = sharedPreferences.getString("server", "")!!
|
||||||
|
net.language = sharedPreferences.getString("language", "en-US")!!
|
||||||
|
val currentGroup = sharedPreferences.getString("currentGroup", "")!!.toInt()
|
||||||
|
|
||||||
productDAO.eraseProduct(view.product.id)
|
productDAO.eraseProduct(view.product.id)
|
||||||
|
val response = net.deleteProduct(currentGroup, view.product.id)
|
||||||
|
activity!!.runOnUiThread{
|
||||||
|
Toast.makeText(context, response.body!!.string(), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
deleted = true
|
deleted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import androidx.core.view.children
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.security.crypto.EncryptedSharedPreferences
|
import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKeys
|
import androidx.security.crypto.MasterKeys
|
||||||
|
import org.foxarmy.barcodescannerforemployees.Net
|
||||||
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
import org.foxarmy.barcodescannerforemployees.database.DBStorageController
|
||||||
import org.foxarmy.barcodescannerforemployees.R
|
import org.foxarmy.barcodescannerforemployees.R
|
||||||
import org.foxarmy.barcodescannerforemployees.activities.AddAbstractProductActivity
|
import org.foxarmy.barcodescannerforemployees.activities.AddAbstractProductActivity
|
||||||
|
@ -95,7 +96,18 @@ class StorageFragment : Fragment() {
|
||||||
view.findViewById<ImageView>(R.id.productPicture).setImageURI(null)
|
view.findViewById<ImageView>(R.id.productPicture).setImageURI(null)
|
||||||
}
|
}
|
||||||
if (view.isProductSelected) {
|
if (view.isProductSelected) {
|
||||||
|
val net = Net()
|
||||||
|
net.token = sharedPreferences.getString("token", "")!!
|
||||||
|
net.server = sharedPreferences.getString("server", "")!!
|
||||||
|
net.language = sharedPreferences.getString("language", "en-US")!!
|
||||||
|
val currentGroup = sharedPreferences.getString("currentGroup", "")!!.toInt()
|
||||||
|
|
||||||
abstractProductDAO.eraseAbstractProduct(view.abstractProduct.id, requireContext())
|
abstractProductDAO.eraseAbstractProduct(view.abstractProduct.id, requireContext())
|
||||||
|
val response = net.deleteAbstractProduct(currentGroup, view.abstractProduct.id)
|
||||||
|
activity!!.runOnUiThread{
|
||||||
|
Toast.makeText(context, response.body!!.string(), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
deleted = true
|
deleted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +160,6 @@ class StorageFragment : Fragment() {
|
||||||
}
|
}
|
||||||
abstractProductView.findViewById<TextView>(R.id.productNameView).setOnClickListener {
|
abstractProductView.findViewById<TextView>(R.id.productNameView).setOnClickListener {
|
||||||
(activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
|
(activity as FindBarcodelessAbstractProduct).selected(abstractProductView.abstractProduct)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue