From f920acafe2c2853ed74d4cca80e26c89061b720d Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Mon, 18 Jul 2022 11:38:17 +0600 Subject: [PATCH 1/7] add flash feature for iOS, Android --- .../home/custom-camera/custom-camera.page.html | 5 +++++ .../home/custom-camera/custom-camera.page.scss | 6 ++++++ .../home/custom-camera/custom-camera.page.ts | 17 +++++++++++++++++ .../home/custom-camera/custom-camera.service.ts | 10 ++++++++++ 4 files changed, 38 insertions(+) diff --git a/src/app/features/home/custom-camera/custom-camera.page.html b/src/app/features/home/custom-camera/custom-camera.page.html index 0e7d2a6ed..aa169603f 100644 --- a/src/app/features/home/custom-camera/custom-camera.page.html +++ b/src/app/features/home/custom-camera/custom-camera.page.html @@ -5,6 +5,11 @@ >
+ + + {{ isFlashOn ? 'flash_on' : 'flash_off' }} + +
(this.captureVideoFinishedListener = listener)); this.startPreviewCamera(); + + this.isTorchOn().then(value => { + console.log(`isFlashOn: ${value.result}`); + + return (this.isFlashOn = value.result); + }); } async ionViewDidEnter() { @@ -167,6 +175,15 @@ export class CustomCameraPage implements OnInit, OnDestroy { this.leaveCustomCamera(); } + async isTorchOn() { + return this.customCameraService.isTorchOn(); + } + + async enableTorch() { + await this.customCameraService.enableTorch(!this.isFlashOn); + this.isFlashOn = (await this.customCameraService.isTorchOn()).result; + } + async leaveCustomCamera() { return this.location.back(); } diff --git a/src/app/features/home/custom-camera/custom-camera.service.ts b/src/app/features/home/custom-camera/custom-camera.service.ts index 2bce4eebe..a1ea82c23 100644 --- a/src/app/features/home/custom-camera/custom-camera.service.ts +++ b/src/app/features/home/custom-camera/custom-camera.service.ts @@ -98,6 +98,16 @@ export class CustomCameraService { await this.filesystemPlugin.deleteFile({ path: filePath }); } + // eslint-disable-next-line class-methods-use-this + async isTorchOn() { + return await PreviewCamera.isTorchOn(); + } + + // eslint-disable-next-line class-methods-use-this + async enableTorch(enable: boolean) { + return await PreviewCamera.enableTorch({ enable }); + } + private changeGlobalCSSBackgroundToTransparent() { document.querySelector('body')?.classList.add(this.globalCSSClass); document.querySelector('ion-app')?.classList.add(this.globalCSSClass); From f2e55bfa8adfd1243211addbcfdd42c9766af4ce Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Tue, 19 Jul 2022 10:10:57 +0600 Subject: [PATCH 2/7] install latest custom camera plugin --- package-lock.json | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 87527e8f4..5f43e9c10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ "@ngx-formly/core": "^5.10.22", "@ngx-formly/material": "^5.10.22", "@ngx-formly/schematics": "^5.10.22", - "@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera#release-0.0.2-auto-rotate-fix", + "@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera", "@numbersprotocol/preview-video": "github:numbersprotocol/preview-video", "@techiediaries/ngx-qrcode": "^9.1.0", "async-mutex": "^0.3.2", @@ -4157,8 +4157,8 @@ } }, "node_modules/@numbersprotocol/preview-camera": { - "version": "0.0.2", - "resolved": "git+ssh://git@github.com/numbersprotocol/preview-camera.git#2ce3dc63f83780c4c8e7afe8291238b9c838eb5c", + "version": "0.0.3", + "resolved": "git+ssh://git@github.com/numbersprotocol/preview-camera.git#cc4a7d544220040e4fad9730dbdd2251458390c3", "license": "MIT", "peerDependencies": { "@capacitor/core": "^3.0.0" @@ -28525,8 +28525,8 @@ } }, "@numbersprotocol/preview-camera": { - "version": "git+ssh://git@github.com/numbersprotocol/preview-camera.git#2ce3dc63f83780c4c8e7afe8291238b9c838eb5c", - "from": "@numbersprotocol/preview-camera@github:numbersprotocol/preview-camera#release-0.0.2-auto-rotate-fix", + "version": "git+ssh://git@github.com/numbersprotocol/preview-camera.git#cc4a7d544220040e4fad9730dbdd2251458390c3", + "from": "@numbersprotocol/preview-camera@github:numbersprotocol/preview-camera", "requires": {} }, "@numbersprotocol/preview-video": { diff --git a/package.json b/package.json index 825908e70..ef0a656e3 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@ngx-formly/core": "^5.10.22", "@ngx-formly/material": "^5.10.22", "@ngx-formly/schematics": "^5.10.22", - "@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera#release-0.0.2-auto-rotate-fix", + "@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera", "@numbersprotocol/preview-video": "github:numbersprotocol/preview-video", "@techiediaries/ngx-qrcode": "^9.1.0", "async-mutex": "^0.3.2", From dd3f88a0f4bc22c1ca9019e813b1d58e02bcfb0a Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Tue, 19 Jul 2022 10:19:04 +0600 Subject: [PATCH 3/7] fix(custom-camera.service): call plugin methods on native platforms only --- .../custom-camera/custom-camera.service.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/app/features/home/custom-camera/custom-camera.service.ts b/src/app/features/home/custom-camera/custom-camera.service.ts index a1ea82c23..9fb84450f 100644 --- a/src/app/features/home/custom-camera/custom-camera.service.ts +++ b/src/app/features/home/custom-camera/custom-camera.service.ts @@ -3,6 +3,7 @@ import { Inject, Injectable } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { Capacitor } from '@capacitor/core'; import { FilesystemPlugin } from '@capacitor/filesystem'; +import { Platform } from '@ionic/angular'; import { TranslocoService } from '@ngneat/transloco'; import { PreviewCamera } from '@numbersprotocol/preview-camera'; import { BehaviorSubject } from 'rxjs'; @@ -31,7 +32,8 @@ export class CustomCameraService { private readonly errorService: ErrorService, private readonly translocoService: TranslocoService, @Inject(FILESYSTEM_PLUGIN) - private readonly filesystemPlugin: FilesystemPlugin + private readonly filesystemPlugin: FilesystemPlugin, + private readonly platform: Platform ) {} private mediaItemFromFilePath( @@ -98,14 +100,21 @@ export class CustomCameraService { await this.filesystemPlugin.deleteFile({ path: filePath }); } - // eslint-disable-next-line class-methods-use-this async isTorchOn() { - return await PreviewCamera.isTorchOn(); + if (this.isNativePlatform) { + return await PreviewCamera.isTorchOn(); + } + return { result: false }; } - // eslint-disable-next-line class-methods-use-this - async enableTorch(enable: boolean) { - return await PreviewCamera.enableTorch({ enable }); + async enableTorch(enable: boolean): Promise { + if (this.isNativePlatform) { + return await PreviewCamera.enableTorch({ enable }); + } + } + + private get isNativePlatform() { + return this.platform.is('ios') || this.platform.is('android'); } private changeGlobalCSSBackgroundToTransparent() { From 746d8c8f004cb083d784bf9d6caed417207878dc Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Tue, 19 Jul 2022 10:19:21 +0600 Subject: [PATCH 4/7] fix(custom-camera.service.spec) --- .../custom-camera.service.spec.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/app/features/home/custom-camera/custom-camera.service.spec.ts b/src/app/features/home/custom-camera/custom-camera.service.spec.ts index 288da8ca1..383e6e88c 100644 --- a/src/app/features/home/custom-camera/custom-camera.service.spec.ts +++ b/src/app/features/home/custom-camera/custom-camera.service.spec.ts @@ -1,14 +1,30 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed, waitForAsync } from '@angular/core/testing'; +import { Platform } from '@ionic/angular'; import { SharedTestingModule } from '../../../shared/shared-testing.module'; import { CustomCameraService } from './custom-camera.service'; describe('CustomCameraService', () => { let service: CustomCameraService; + let platformReadySpy: Promise; + let platformIsSpy: boolean | undefined; + let platformSpy: Platform; - beforeEach(() => { - TestBed.configureTestingModule({ imports: [SharedTestingModule] }); - service = TestBed.inject(CustomCameraService); - }); + beforeEach( + waitForAsync(() => { + platformReadySpy = Promise.resolve(); + platformIsSpy = false; + platformSpy = jasmine.createSpyObj('Platform', { + ready: platformReadySpy, + is: platformIsSpy, + }); + + TestBed.configureTestingModule({ + imports: [SharedTestingModule], + providers: [{ provide: Platform, useValue: platformSpy }], + }).compileComponents(); + service = TestBed.inject(CustomCameraService); + }) + ); it('should be created', () => { expect(service).toBeTruthy(); From 58f6baf5e964abf202e8f7e93c9af818f82eb739 Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Mon, 18 Jul 2022 16:22:58 +0600 Subject: [PATCH 5/7] fix(custom-camera): make sure confirm button works properly --- src/app/features/home/custom-camera/custom-camera.page.ts | 5 ++--- src/app/features/home/custom-camera/custom-camera.service.ts | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/features/home/custom-camera/custom-camera.page.ts b/src/app/features/home/custom-camera/custom-camera.page.ts index a5637af78..d7cb6a597 100644 --- a/src/app/features/home/custom-camera/custom-camera.page.ts +++ b/src/app/features/home/custom-camera/custom-camera.page.ts @@ -166,13 +166,12 @@ export class CustomCameraPage implements OnInit, OnDestroy { async confirmCurrentCapture() { if (this.curCaptureFilePath && this.curCaptureType) { - await this.customCameraService.uploadToCapture( + this.customCameraService.uploadToCapture( this.curCaptureFilePath, this.curCaptureType ); - this.removeCurrentCapture(); + this.leaveCustomCamera(); } - this.leaveCustomCamera(); } async isTorchOn() { diff --git a/src/app/features/home/custom-camera/custom-camera.service.ts b/src/app/features/home/custom-camera/custom-camera.service.ts index 9fb84450f..d9adab50d 100644 --- a/src/app/features/home/custom-camera/custom-camera.service.ts +++ b/src/app/features/home/custom-camera/custom-camera.service.ts @@ -58,6 +58,7 @@ export class CustomCameraService { const base64 = await blobToBase64(itemBlob); const mimeType = itemToUpload.mimeType; await this.captureService.capture({ base64, mimeType }); + await this.removeFile(filePath); } catch (error) { const errMsg = this.translocoService.translate(`error.internetError`); await this.errorService.toastError$(errMsg).toPromise(); From d9afc0e7d24bb233565b779a3051104e6fc4bd3c Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Tue, 19 Jul 2022 11:59:17 +0600 Subject: [PATCH 6/7] fix(custom-camera.service): else case for enable torch --- src/app/features/home/custom-camera/custom-camera.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/features/home/custom-camera/custom-camera.service.ts b/src/app/features/home/custom-camera/custom-camera.service.ts index 9fb84450f..0eac621fb 100644 --- a/src/app/features/home/custom-camera/custom-camera.service.ts +++ b/src/app/features/home/custom-camera/custom-camera.service.ts @@ -111,6 +111,7 @@ export class CustomCameraService { if (this.isNativePlatform) { return await PreviewCamera.enableTorch({ enable }); } + return Promise.resolve(); } private get isNativePlatform() { From d5f497824aef3b887c2a6db4e6f802e8fd077f7c Mon Sep 17 00:00:00 2001 From: sultanmyrza Date: Tue, 19 Jul 2022 12:50:28 +0600 Subject: [PATCH 7/7] build: bump to 0.61.1 --- CHANGELOG.md | 11 +++++++++++ android/app/build.gradle | 4 ++-- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f9f3b900..a8b38a66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.61.1 - 2022-07-19 + +### Added + +- Camera flash light + +### Fixed + +- Capture flow, confirm button work smoothly +- Use high resolution as default camera settings + ## 0.60.2 - 2022-07-07 ### Changed diff --git a/android/app/build.gradle b/android/app/build.gradle index f0e663a23..dedafb6f7 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "io.numbersprotocol.capturelite" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 430 - versionName "0.61.0" + versionCode 431 + versionName "0.61.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildFeatures { diff --git a/package-lock.json b/package-lock.json index 5f43e9c10..41c99a1a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "capture-lite", - "version": "0.61.0", + "version": "0.61.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "capture-lite", - "version": "0.61.0", + "version": "0.61.1", "dependencies": { "@angular/animations": "^12.2.4", "@angular/cdk": "^12.2.4", diff --git a/package.json b/package.json index ef0a656e3..e74d7901b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "capture-lite", - "version": "0.61.0", + "version": "0.61.1", "author": "numbersprotocol", "homepage": "https://numbersprotocol.io/", "scripts": {