Skip to content
Snippets Groups Projects
Commit fcecf77f authored by Rinaldy Adin's avatar Rinaldy Adin
Browse files

Merge branch 'fix/no-network-upload-gallery' into 'dev'

fix: pressing back from gallery causes take photo to lock and move no network...

See merge request !21
parents 18389bf9 0a6783f0
1 merge request!21fix: pressing back from gallery causes take photo to lock and move no network...
......@@ -112,14 +112,11 @@ class ScannerFragment : Fragment(), UploadResultCallback {
val imageUri = result.data?.data
if (imageUri != null) {
val imageFile = uriToFile(imageUri)
isProcessingPhoto = true
attemptUpload(imageFile)
val msg = "Uploading photo, please wait"
Toast.makeText(requireContext(), msg, Toast.LENGTH_SHORT).show()
} else {
val msg = "Failed to fetch image from gallery"
Toast.makeText(requireContext(), msg, Toast.LENGTH_SHORT).show()
isProcessingPhoto = false
}
}
}
......@@ -199,12 +196,22 @@ class ScannerFragment : Fragment(), UploadResultCallback {
}
private fun attemptUpload(imageFile: File) {
val activity = activity as MainActivity
if (!isConnected(activity.getNetworkState())) {
binding.scanLayout.visibility = View.GONE
binding.noNetworkLayout.visibility = View.VISIBLE
isProcessingPhoto = false
return
}
lifecycleScope.launch {
val retrofit = Retrofit()
val token = (activity as MainActivity).preferenceDataStoreHelper.getFirstPreference(
PreferenceDataStoreConstants.TOKEN,
""
)
val msg = "Uploading photo, please wait"
Toast.makeText(requireContext(), msg, Toast.LENGTH_LONG).show()
retrofit.upload(token, imageFile, this@ScannerFragment)
}
}
......@@ -226,26 +233,14 @@ class ScannerFragment : Fragment(), UploadResultCallback {
val cancelButton = dialog.findViewById<Button>(R.id.cancel_button)
confirmButton.setOnClickListener {
val activity = activity as MainActivity
if (!isConnected(activity.getNetworkState())) {
val filePath = imageUri.path
if (filePath != null) {
val imageFile = File(filePath)
attemptUpload(imageFile)
dialog.dismiss()
binding.scanLayout.visibility = View.GONE
binding.noNetworkLayout.visibility = View.VISIBLE
isProcessingPhoto = false
} else {
val filePath = imageUri.path
if (filePath != null) {
val imageFile = File(filePath)
attemptUpload(imageFile)
val msg = "Uploading photo, please wait"
Toast.makeText(requireContext(), msg, Toast.LENGTH_LONG).show()
dialog.dismiss()
} else {
isProcessingPhoto = false
dialog.dismiss()
}
isProcessingPhoto = false
dialog.dismiss()
}
}
......@@ -411,7 +406,6 @@ class ScannerFragment : Fragment(), UploadResultCallback {
val intent = Intent(Intent.ACTION_PICK)
intent.type = "image/*"
isProcessingPhoto = true
openGalleryLauncher.launch(intent)
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment