Close scan activity if camera permission is denied

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2023-01-24 16:03:44 +01:00
parent f6094ae343
commit 0f51646d3c
No known key found for this signature in database
GPG key ID: 2585783189A62105
3 changed files with 20 additions and 7 deletions

View file

@ -152,7 +152,7 @@ class DocumentScanActivity : ToolbarActivity(), Injectable {
}
}
}
DocumentScanViewModel.UIState.DoneState -> {
DocumentScanViewModel.UIState.DoneState, DocumentScanViewModel.UIState.CanceledState -> {
finish()
}
}

View file

@ -72,6 +72,7 @@ class DocumentScanViewModel @Inject constructor(
) : BaseState(pageList)
object DoneState : UIState
object CanceledState : UIState
}
private var uploadFolder: String? = null
@ -95,13 +96,13 @@ class DocumentScanViewModel @Inject constructor(
val pageList = state.pageList.toMutableList()
pageList.add(newPath)
_uiState.postValue(UIState.NormalState(pageList))
} else {
// result == null means cancellation or error
if (state.isEmpty) {
// close only if no pages have been added yet
_uiState.postValue(UIState.CanceledState)
}
}
if (result != null) {
val pageList = (uiState.value as UIState.NormalState).pageList.toMutableList()
pageList.add(result)
_uiState.value = UIState.NormalState(pageList)
}
}

View file

@ -24,6 +24,7 @@ package com.nextcloud.appscan
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import com.zynksoftware.documentscanner.ScanActivity
import com.zynksoftware.documentscanner.model.DocumentScannerErrorModel
@ -40,6 +41,7 @@ class AppScanActivity : ScanActivity() {
override fun onError(error: DocumentScannerErrorModel) {
// TODO pass this from app somehow?
println(error)
}
override fun onSuccess(scannerResults: ScannerResults) {
@ -55,9 +57,19 @@ class AppScanActivity : ScanActivity() {
}
override fun onClose() {
setResult(Activity.RESULT_CANCELED)
finish()
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (permissions.contains(android.Manifest.permission.CAMERA) &&
(grantResults.isEmpty() || grantResults[0] == PackageManager.PERMISSION_DENIED)
) {
onClose()
}
}
companion object {
@JvmStatic
val enabled: Boolean = true