mirror of
https://github.com/twofas/2fas-ios.git
synced 2024-11-22 02:10:19 +01:00
TF-1508 Adding "Camera not available" error to common scanner
This commit is contained in:
parent
3e99ccdf48
commit
4c72d79fbf
@ -81,7 +81,9 @@ public final class Camera {
|
||||
|
||||
extension Camera: CameraControllerDelegate {
|
||||
func cameraDidInitialize() {}
|
||||
func cameraFailedToInitilize(with error: CameraController.CameraError) {}
|
||||
func cameraFailedToInitilize(with error: CameraController.CameraError) {
|
||||
Log("Camera - can't start: \(error)", module: .camera)
|
||||
}
|
||||
func cameraStartedPreview() {
|
||||
delegate?.didStartScanning()
|
||||
}
|
||||
|
@ -161,7 +161,8 @@ final class ModuleInteractorFactory {
|
||||
func cameraScannerModuleInteractor() -> CameraScannerModuleInteracting {
|
||||
CameraScannerModuleInteractor(
|
||||
newCodeInteractor: InteractorFactory.shared.newCodeInteractor(),
|
||||
pushNotificationPermission: InteractorFactory.shared.pushNotificationRegistrationInteractor()
|
||||
pushNotificationPermission: InteractorFactory.shared.pushNotificationRegistrationInteractor(),
|
||||
cameraPermissionInteractor: InteractorFactory.shared.cameraPermissionInteractor()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ protocol CameraScannerFlowControlling: AnyObject {
|
||||
func toPushPermissions(extensionID: ExtensionID)
|
||||
func toRename(currentName: String, secret: String)
|
||||
func toServiceWasCreated(serviceData: ServiceData)
|
||||
func toCameraNotAvailable()
|
||||
}
|
||||
|
||||
final class CameraScannerFlowController: FlowController {
|
||||
@ -189,6 +190,11 @@ extension CameraScannerFlowController: CameraScannerFlowControlling {
|
||||
viewController.present(alert, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func toCameraNotAvailable() {
|
||||
let ac = AlertController.cameraNotAvailable
|
||||
ac.show(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func toPushPermissions(extensionID: ExtensionID) {
|
||||
guard let navi = viewController.navigationController else { return }
|
||||
navi.setNavigationBarHidden(true, animated: false)
|
||||
|
@ -26,6 +26,10 @@ protocol CameraScannerModuleInteracting: AnyObject {
|
||||
var shouldRename: ((String, String) -> Void)? { get set }
|
||||
var wasUserAskedAboutPush: Bool { get }
|
||||
|
||||
func isCameraAvailable() -> Bool
|
||||
func isCameraAllowed() -> Bool
|
||||
func registerCamera(callback: @escaping (Bool) -> Void)
|
||||
|
||||
func addCode(_ code: Code, force: Bool)
|
||||
func codeExists(_ code: Code) -> Bool
|
||||
func filterImportableCodes(_ codes: [Code]) -> [Code]
|
||||
@ -38,19 +42,39 @@ protocol CameraScannerModuleInteracting: AnyObject {
|
||||
final class CameraScannerModuleInteractor {
|
||||
private let newCodeInteractor: NewCodeInteracting
|
||||
private let pushNotificationPermission: PushNotificationRegistrationInteracting
|
||||
private let cameraPermissionInteractor: CameraPermissionInteracting
|
||||
|
||||
var serviceWasCreated: ((ServiceData) -> Void)?
|
||||
var shouldRename: ((String, String) -> Void)?
|
||||
|
||||
init(newCodeInteractor: NewCodeInteracting, pushNotificationPermission: PushNotificationRegistrationInteracting) {
|
||||
init(
|
||||
newCodeInteractor: NewCodeInteracting,
|
||||
pushNotificationPermission: PushNotificationRegistrationInteracting,
|
||||
cameraPermissionInteractor: CameraPermissionInteracting
|
||||
) {
|
||||
self.newCodeInteractor = newCodeInteractor
|
||||
self.pushNotificationPermission = pushNotificationPermission
|
||||
self.cameraPermissionInteractor = cameraPermissionInteractor
|
||||
newCodeInteractor.serviceWasCreated = { [weak self] in self?.serviceWasCreated?($0) }
|
||||
newCodeInteractor.shouldRename = { [weak self] in self?.shouldRename?($0, $1) }
|
||||
}
|
||||
}
|
||||
|
||||
extension CameraScannerModuleInteractor: CameraScannerModuleInteracting {
|
||||
func isCameraAvailable() -> Bool {
|
||||
cameraPermissionInteractor.isCameraAvailable
|
||||
}
|
||||
|
||||
func isCameraAllowed() -> Bool {
|
||||
cameraPermissionInteractor.isCameraAllowed
|
||||
}
|
||||
|
||||
func registerCamera(callback: @escaping (Bool) -> Void) {
|
||||
cameraPermissionInteractor.register { status in
|
||||
callback(status == .granted)
|
||||
}
|
||||
}
|
||||
|
||||
var wasUserAskedAboutPush: Bool {
|
||||
pushNotificationPermission.wasUserAsked
|
||||
}
|
||||
|
@ -39,6 +39,20 @@ final class CameraScannerPresenter {
|
||||
}
|
||||
|
||||
extension CameraScannerPresenter {
|
||||
func viewDidAppear() {
|
||||
if interactor.isCameraAvailable() {
|
||||
if !interactor.isCameraAllowed() {
|
||||
interactor.registerCamera { [weak self] isGranted in
|
||||
if !isGranted {
|
||||
self?.handleCameraNotAvailable()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handleCameraNotAvailable()
|
||||
}
|
||||
}
|
||||
|
||||
func handleOpenGallery() {
|
||||
lockScanning = true
|
||||
flowController.toGallery()
|
||||
@ -137,6 +151,13 @@ extension CameraScannerPresenter {
|
||||
}
|
||||
}
|
||||
|
||||
func handleCameraNotAvailable() {
|
||||
view?.enableOverlay()
|
||||
view?.feedback()
|
||||
|
||||
flowController.toCameraNotAvailable()
|
||||
}
|
||||
|
||||
func handleCameraError(_ str: String) {
|
||||
view?.enableOverlay()
|
||||
view?.feedback()
|
||||
|
@ -66,6 +66,11 @@ final class CameraScannerViewController: UIViewController {
|
||||
navigationController?.setNavigationBarHidden(true, animated: false)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
presenter.viewDidAppear()
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user