fixed using network in offline mode
This commit is contained in:
parent
2676d8083e
commit
2ebcfff51a
|
@ -33,6 +33,7 @@ import java.io.FileOutputStream
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
class AddAbstractProductActivity : AppCompatActivity() {
|
class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
private lateinit var imageView: ImageView
|
private lateinit var imageView: ImageView
|
||||||
|
@ -128,6 +129,9 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
netWeightText.text = abstractProduct!!.netWeight.toString()
|
netWeightText.text = abstractProduct!!.netWeight.toString()
|
||||||
categorySpinner.setSelection(abstractProduct!!.category - 1)
|
categorySpinner.setSelection(abstractProduct!!.category - 1)
|
||||||
unitTypeSpinner.setSelection(abstractProduct!!.unit)
|
unitTypeSpinner.setSelection(abstractProduct!!.unit)
|
||||||
|
if (abstractProduct!!.barcode == "" || abstractProduct!!.barcode == " ") {
|
||||||
|
noBarcodeCheckBox.isChecked = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveButton.setOnClickListener {
|
saveButton.setOnClickListener {
|
||||||
|
@ -151,16 +155,22 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
Toast.makeText(this, getString(R.string.product_net_weight_request), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, getString(R.string.product_net_weight_request), Toast.LENGTH_SHORT).show()
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
val currentGroup: Int
|
||||||
|
val currentGroupString = sharedPreferences.getString("currentGroup", "offline")!!
|
||||||
|
|
||||||
|
lateinit var response: Response
|
||||||
val net = Net()
|
val net = Net()
|
||||||
|
|
||||||
|
if (currentGroupString != "offline") {
|
||||||
|
currentGroup = currentGroupString.toInt()
|
||||||
|
|
||||||
net.token = sharedPreferences.getString("token", "")!!
|
net.token = sharedPreferences.getString("token", "")!!
|
||||||
net.server = sharedPreferences.getString("server", "")!!
|
net.server = sharedPreferences.getString("server", "")!!
|
||||||
net.language = sharedPreferences.getString("language", "en-US")!!
|
net.language = sharedPreferences.getString("language", "en-US")!!
|
||||||
|
|
||||||
val currentGroup: Int = if (sharedPreferences.getString("currentGroup", "offline")!! == "offline") 0 else sharedPreferences.getString("currentGroup", "")!!.toInt()
|
} else {
|
||||||
|
currentGroup = 0
|
||||||
lateinit var response: Response
|
}
|
||||||
|
|
||||||
abstractProduct = AbstractProduct(
|
abstractProduct = AbstractProduct(
|
||||||
if (abstractProduct == null) 0 else abstractProduct!!.id,
|
if (abstractProduct == null) 0 else abstractProduct!!.id,
|
||||||
|
@ -171,16 +181,18 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
categorySpinner.selectedItemPosition + 1,
|
categorySpinner.selectedItemPosition + 1,
|
||||||
unitTypeSpinner.selectedItemPosition
|
unitTypeSpinner.selectedItemPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
val pictureFile = File(File(filesDir, "pictures"), "${abstractProduct!!.imageHash}.png")
|
val pictureFile = File(File(filesDir, "pictures"), "${abstractProduct!!.imageHash}.png")
|
||||||
|
|
||||||
if (action == "update") {
|
if (action == "update") {
|
||||||
DAO.updateAbstractProduct(abstractProduct!!)
|
DAO.updateAbstractProduct(abstractProduct!!)
|
||||||
response = net.updateAbstractProduct(currentGroup, abstractProduct!!, pictureFile)
|
if (currentGroup > 0) response = net.updateAbstractProduct(currentGroup, abstractProduct!!, pictureFile)
|
||||||
} else if (action == "new" || action == "new_from_barcode") {
|
} else if (action == "new" || action == "new_from_barcode") {
|
||||||
abstractProduct!!.id = DAO.addAbstractProduct(abstractProduct!!).toInt()
|
abstractProduct!!.id = DAO.addAbstractProduct(abstractProduct!!).toInt()
|
||||||
response = net.uploadAbstractProduct(currentGroup, abstractProduct!!, pictureFile);
|
if (currentGroup > 0) response =
|
||||||
|
net.uploadAbstractProduct(currentGroup, abstractProduct!!, pictureFile)
|
||||||
}
|
}
|
||||||
Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
|
if (currentGroup > 0) Toast.makeText(this, response.body!!.string(), Toast.LENGTH_LONG).show()
|
||||||
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
@ -257,7 +269,8 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
|
|
||||||
fun fillupCategorySpinner() {
|
fun fillupCategorySpinner() {
|
||||||
|
|
||||||
val categoriesDAO = CategoryDAO(DBStorageController(this, sharedPreferences.getString("currentGroup", "database")!!))
|
val categoriesDAO =
|
||||||
|
CategoryDAO(DBStorageController(this, sharedPreferences.getString("currentGroup", "database")!!))
|
||||||
|
|
||||||
val categories = categoriesDAO.getAllCategories().map { category -> category.name }
|
val categories = categoriesDAO.getAllCategories().map { category -> category.name }
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ class StorageFragment : Fragment() {
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
|
binding = FragmentStorageBinding.inflate(inflater)
|
||||||
|
|
||||||
sharedPreferences = EncryptedSharedPreferences.create(
|
sharedPreferences = EncryptedSharedPreferences.create(
|
||||||
"sensitive",
|
"sensitive",
|
||||||
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
|
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
|
||||||
|
@ -47,8 +49,6 @@ class StorageFragment : Fragment() {
|
||||||
|
|
||||||
prepareDatabaseConnection()
|
prepareDatabaseConnection()
|
||||||
|
|
||||||
binding = FragmentStorageBinding.inflate(inflater)
|
|
||||||
|
|
||||||
fillUpSortBySpinner()
|
fillUpSortBySpinner()
|
||||||
|
|
||||||
binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
|
Loading…
Reference in New Issue