updating abstract products are now uploaded
This commit is contained in:
parent
3e5150754a
commit
94d309c491
|
@ -116,7 +116,7 @@ class Net {
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeUsername( newUsername: String): Response {
|
fun changeUsername(newUsername: String): Response {
|
||||||
|
|
||||||
lateinit var response: Response
|
lateinit var response: Response
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ class Net {
|
||||||
return responseText
|
return responseText
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGroupName(id: Int) : String {
|
fun getGroupName(id: Int): String {
|
||||||
lateinit var response: Response
|
lateinit var response: Response
|
||||||
|
|
||||||
thread {
|
thread {
|
||||||
|
@ -352,4 +352,35 @@ class Net {
|
||||||
|
|
||||||
return response
|
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,22 +157,23 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
val currentGroup = sharedPreferences.getString("currentGroup", "")!!
|
val currentGroup = sharedPreferences.getString("currentGroup", "")!!
|
||||||
|
|
||||||
lateinit var response: Response
|
lateinit var response: Response
|
||||||
|
|
||||||
|
abstractProduct = AbstractProduct(
|
||||||
|
if(abstractProduct == null) 0 else abstractProduct!!.id,
|
||||||
|
barcode,
|
||||||
|
productName,
|
||||||
|
netWeight.toString().toDouble(),
|
||||||
|
pictureFile.nameWithoutExtension,
|
||||||
|
categorySpinner.selectedItemPosition,
|
||||||
|
unitTypeSpinner.selectedItemPosition
|
||||||
|
)
|
||||||
|
val pictureFile = File(File(filesDir, "pictures"), "${abstractProduct!!.imageHash}.png")
|
||||||
|
|
||||||
if (action == "update") {
|
if (action == "update") {
|
||||||
DAO.updateAbstractProduct(abstractProduct!!, this)
|
DAO.updateAbstractProduct(abstractProduct!!)
|
||||||
|
response = net.updateAbstractProduct(currentGroup.toInt(), abstractProduct!!, pictureFile)
|
||||||
} else if (action == "new" || action == "new_from_barcode") {
|
} else if (action == "new" || action == "new_from_barcode") {
|
||||||
|
|
||||||
abstractProduct = AbstractProduct(
|
|
||||||
0,
|
|
||||||
barcode,
|
|
||||||
productName,
|
|
||||||
netWeight.toString().toDouble(),
|
|
||||||
pictureFile.nameWithoutExtension,
|
|
||||||
categorySpinner.selectedItemPosition,
|
|
||||||
unitTypeSpinner.selectedItemPosition
|
|
||||||
)
|
|
||||||
|
|
||||||
abstractProduct!!.id = DAO.addAbstractProduct(abstractProduct!!).toInt()
|
abstractProduct!!.id = DAO.addAbstractProduct(abstractProduct!!).toInt()
|
||||||
val pictureFile = File(File(filesDir, "pictures"), "${abstractProduct!!.imageHash}.png")
|
|
||||||
response = net.uploadAbstractProduct(currentGroup.toInt(), abstractProduct!!, pictureFile);
|
response = net.uploadAbstractProduct(currentGroup.toInt(), abstractProduct!!, pictureFile);
|
||||||
}
|
}
|
||||||
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
|
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
|
||||||
|
|
|
@ -244,7 +244,7 @@ class AbstractProductDAO(private val dbHelper: DBStorageController) {
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAbstractProduct(abstractProduct: AbstractProduct, context: Context) {
|
fun updateAbstractProduct(abstractProduct: AbstractProduct) {
|
||||||
|
|
||||||
val db = dbHelper.writableDatabase
|
val db = dbHelper.writableDatabase
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue