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.StandardCopyOption
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.math.abs
|
||||
|
||||
class AddAbstractProductActivity : AppCompatActivity() {
|
||||
private lateinit var imageView: ImageView
|
||||
|
@ -128,6 +129,9 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
netWeightText.text = abstractProduct!!.netWeight.toString()
|
||||
categorySpinner.setSelection(abstractProduct!!.category - 1)
|
||||
unitTypeSpinner.setSelection(abstractProduct!!.unit)
|
||||
if (abstractProduct!!.barcode == "" || abstractProduct!!.barcode == " ") {
|
||||
noBarcodeCheckBox.isChecked = true
|
||||
}
|
||||
}
|
||||
|
||||
saveButton.setOnClickListener {
|
||||
|
@ -151,16 +155,22 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
Toast.makeText(this, getString(R.string.product_net_weight_request), Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
val currentGroup: Int
|
||||
val currentGroupString = sharedPreferences.getString("currentGroup", "offline")!!
|
||||
|
||||
lateinit var response: Response
|
||||
val net = Net()
|
||||
|
||||
if (currentGroupString != "offline") {
|
||||
currentGroup = currentGroupString.toInt()
|
||||
|
||||
net.token = sharedPreferences.getString("token", "")!!
|
||||
net.server = sharedPreferences.getString("server", "")!!
|
||||
net.language = sharedPreferences.getString("language", "en-US")!!
|
||||
|
||||
val currentGroup: Int = if (sharedPreferences.getString("currentGroup", "offline")!! == "offline") 0 else sharedPreferences.getString("currentGroup", "")!!.toInt()
|
||||
|
||||
lateinit var response: Response
|
||||
} else {
|
||||
currentGroup = 0
|
||||
}
|
||||
|
||||
abstractProduct = AbstractProduct(
|
||||
if (abstractProduct == null) 0 else abstractProduct!!.id,
|
||||
|
@ -171,16 +181,18 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
categorySpinner.selectedItemPosition + 1,
|
||||
unitTypeSpinner.selectedItemPosition
|
||||
)
|
||||
|
||||
val pictureFile = File(File(filesDir, "pictures"), "${abstractProduct!!.imageHash}.png")
|
||||
|
||||
if (action == "update") {
|
||||
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") {
|
||||
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()
|
||||
}
|
||||
|
@ -257,7 +269,8 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
|
||||
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 }
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ class StorageFragment : Fragment() {
|
|||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = FragmentStorageBinding.inflate(inflater)
|
||||
|
||||
sharedPreferences = EncryptedSharedPreferences.create(
|
||||
"sensitive",
|
||||
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
|
||||
|
@ -47,8 +49,6 @@ class StorageFragment : Fragment() {
|
|||
|
||||
prepareDatabaseConnection()
|
||||
|
||||
binding = FragmentStorageBinding.inflate(inflater)
|
||||
|
||||
fillUpSortBySpinner()
|
||||
|
||||
binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
|
|
Loading…
Reference in New Issue