updating abstract products are now uploaded
This commit is contained in:
parent
3e5150754a
commit
94d309c491
|
@ -352,4 +352,35 @@ class Net {
|
|||
|
||||
return response
|
||||
}
|
||||
|
||||
fun updateAbstractProduct(groupId: Int, abstractProduct: AbstractProduct, imageFile: File): Response {
|
||||
lateinit var response: Response
|
||||
|
||||
thread {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val body = MultipartBody.Builder()
|
||||
.setType("multipart/form-data".toMediaType())
|
||||
.addFormDataPart("file", imageFile.name, imageFile.asRequestBody("image/png".toMediaTypeOrNull()))
|
||||
.addFormDataPart("groupId", groupId.toString())
|
||||
.addFormDataPart("localId", abstractProduct.id.toString())
|
||||
.addFormDataPart("barcode", abstractProduct.barcode)
|
||||
.addFormDataPart("name", abstractProduct.name)
|
||||
.addFormDataPart("net_weight", abstractProduct.netWeight.toString())
|
||||
.addFormDataPart("category", abstractProduct.category.toString())
|
||||
.addFormDataPart("unit", abstractProduct.unit.toString())
|
||||
.build()
|
||||
|
||||
val request = Request.Builder()
|
||||
.url("https://$server/api/abstractproduct/update")
|
||||
.post(body)
|
||||
.addHeader("Authorization", "Bearer $token")
|
||||
.addHeader("accept-language", language)
|
||||
.build()
|
||||
|
||||
response = client.newCall(request).execute()
|
||||
}.join()
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
|
@ -157,12 +157,9 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
val currentGroup = sharedPreferences.getString("currentGroup", "")!!
|
||||
|
||||
lateinit var response: Response
|
||||
if (action == "update") {
|
||||
DAO.updateAbstractProduct(abstractProduct!!, this)
|
||||
} else if (action == "new" || action == "new_from_barcode") {
|
||||
|
||||
abstractProduct = AbstractProduct(
|
||||
0,
|
||||
if(abstractProduct == null) 0 else abstractProduct!!.id,
|
||||
barcode,
|
||||
productName,
|
||||
netWeight.toString().toDouble(),
|
||||
|
@ -170,9 +167,13 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
categorySpinner.selectedItemPosition,
|
||||
unitTypeSpinner.selectedItemPosition
|
||||
)
|
||||
|
||||
abstractProduct!!.id = DAO.addAbstractProduct(abstractProduct!!).toInt()
|
||||
val pictureFile = File(File(filesDir, "pictures"), "${abstractProduct!!.imageHash}.png")
|
||||
|
||||
if (action == "update") {
|
||||
DAO.updateAbstractProduct(abstractProduct!!)
|
||||
response = net.updateAbstractProduct(currentGroup.toInt(), abstractProduct!!, pictureFile)
|
||||
} else if (action == "new" || action == "new_from_barcode") {
|
||||
abstractProduct!!.id = DAO.addAbstractProduct(abstractProduct!!).toInt()
|
||||
response = net.uploadAbstractProduct(currentGroup.toInt(), abstractProduct!!, pictureFile);
|
||||
}
|
||||
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
|
||||
|
|
|
@ -244,7 +244,7 @@ class AbstractProductDAO(private val dbHelper: DBStorageController) {
|
|||
return id
|
||||
}
|
||||
|
||||
fun updateAbstractProduct(abstractProduct: AbstractProduct, context: Context) {
|
||||
fun updateAbstractProduct(abstractProduct: AbstractProduct) {
|
||||
|
||||
val db = dbHelper.writableDatabase
|
||||
|
||||
|
|
Loading…
Reference in New Issue