mirror of
https://github.com/nextcloud/android.git
synced 2024-11-21 20:55:31 +03:00
Close scan activity if camera permission is denied
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
f6094ae343
commit
0f51646d3c
3 changed files with 20 additions and 7 deletions
|
@ -152,7 +152,7 @@ class DocumentScanActivity : ToolbarActivity(), Injectable {
|
|||
}
|
||||
}
|
||||
}
|
||||
DocumentScanViewModel.UIState.DoneState -> {
|
||||
DocumentScanViewModel.UIState.DoneState, DocumentScanViewModel.UIState.CanceledState -> {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue