Skip to content

Commit 8427b98

Browse files
authored
Merge pull request #1835 from numbersprotocol/develop
Develop
2 parents 6961ad8 + 08bde1e commit 8427b98

File tree

9 files changed

+95
-20
lines changed

9 files changed

+95
-20
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.61.1 - 2022-07-19
9+
10+
### Added
11+
12+
- Camera flash light
13+
14+
### Fixed
15+
16+
- Capture flow, confirm button work smoothly
17+
- Use high resolution as default camera settings
18+
819
## 0.60.2 - 2022-07-07
920

1021
### Changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "io.numbersprotocol.capturelite"
77
minSdkVersion rootProject.ext.minSdkVersion
88
targetSdkVersion rootProject.ext.targetSdkVersion
9-
versionCode 430
10-
versionName "0.61.0"
9+
versionCode 431
10+
versionName "0.61.1"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildFeatures {

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "capture-lite",
3-
"version": "0.61.0",
3+
"version": "0.61.1",
44
"author": "numbersprotocol",
55
"homepage": "https://numbersprotocol.io/",
66
"scripts": {
@@ -59,7 +59,7 @@
5959
"@ngx-formly/core": "^5.10.22",
6060
"@ngx-formly/material": "^5.10.22",
6161
"@ngx-formly/schematics": "^5.10.22",
62-
"@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera#release-0.0.2-auto-rotate-fix",
62+
"@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera",
6363
"@numbersprotocol/preview-video": "github:numbersprotocol/preview-video",
6464
"@techiediaries/ngx-qrcode": "^9.1.0",
6565
"async-mutex": "^0.3.2",

src/app/features/home/custom-camera/custom-camera.page.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
>
66
<ng-container *ngIf="(mode$ | ngrxPush) === 'capture'">
77
<div id="camera-flash-placeholder"></div>
8+
9+
<mat-icon class="flash-camera-button" (click)="enableTorch()">
10+
{{ isFlashOn ? 'flash_on' : 'flash_off' }}
11+
</mat-icon>
12+
813
<div
914
class="select-from-go-pro-camera-button"
1015
*ngIf="lastConnectedGoProDevice$ | ngrxPush"

src/app/features/home/custom-camera/custom-camera.page.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ mat-icon {
1313
width: 36px;
1414
}
1515

16+
mat-icon.flash-camera-button {
17+
position: absolute;
18+
top: 16px;
19+
left: 16px;
20+
}
21+
1622
mat-icon.close-camera-button {
1723
position: absolute;
1824
top: 16px;

src/app/features/home/custom-camera/custom-camera.page.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export class CustomCameraPage implements OnInit, OnDestroy {
4141
curCaptureType?: 'image' | 'video' = 'image';
4242
curCaptureSrc?: string;
4343

44+
isFlashOn = false;
45+
4446
readonly lastConnectedGoProDevice$ =
4547
this.goProBluetoothService.lastConnectedDevice$;
4648

@@ -67,6 +69,12 @@ export class CustomCameraPage implements OnInit, OnDestroy {
6769
).then((listener: any) => (this.captureVideoFinishedListener = listener));
6870

6971
this.startPreviewCamera();
72+
73+
this.isTorchOn().then(value => {
74+
console.log(`isFlashOn: ${value.result}`);
75+
76+
return (this.isFlashOn = value.result);
77+
});
7078
}
7179

7280
async ionViewDidEnter() {
@@ -158,13 +166,21 @@ export class CustomCameraPage implements OnInit, OnDestroy {
158166

159167
async confirmCurrentCapture() {
160168
if (this.curCaptureFilePath && this.curCaptureType) {
161-
await this.customCameraService.uploadToCapture(
169+
this.customCameraService.uploadToCapture(
162170
this.curCaptureFilePath,
163171
this.curCaptureType
164172
);
165-
this.removeCurrentCapture();
173+
this.leaveCustomCamera();
166174
}
167-
this.leaveCustomCamera();
175+
}
176+
177+
async isTorchOn() {
178+
return this.customCameraService.isTorchOn();
179+
}
180+
181+
async enableTorch() {
182+
await this.customCameraService.enableTorch(!this.isFlashOn);
183+
this.isFlashOn = (await this.customCameraService.isTorchOn()).result;
168184
}
169185

170186
async leaveCustomCamera() {

src/app/features/home/custom-camera/custom-camera.service.spec.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
import { TestBed } from '@angular/core/testing';
1+
import { TestBed, waitForAsync } from '@angular/core/testing';
2+
import { Platform } from '@ionic/angular';
23
import { SharedTestingModule } from '../../../shared/shared-testing.module';
34
import { CustomCameraService } from './custom-camera.service';
45

56
describe('CustomCameraService', () => {
67
let service: CustomCameraService;
8+
let platformReadySpy: Promise<void>;
9+
let platformIsSpy: boolean | undefined;
10+
let platformSpy: Platform;
711

8-
beforeEach(() => {
9-
TestBed.configureTestingModule({ imports: [SharedTestingModule] });
10-
service = TestBed.inject(CustomCameraService);
11-
});
12+
beforeEach(
13+
waitForAsync(() => {
14+
platformReadySpy = Promise.resolve();
15+
platformIsSpy = false;
16+
platformSpy = jasmine.createSpyObj('Platform', {
17+
ready: platformReadySpy,
18+
is: platformIsSpy,
19+
});
20+
21+
TestBed.configureTestingModule({
22+
imports: [SharedTestingModule],
23+
providers: [{ provide: Platform, useValue: platformSpy }],
24+
}).compileComponents();
25+
service = TestBed.inject(CustomCameraService);
26+
})
27+
);
1228

1329
it('should be created', () => {
1430
expect(service).toBeTruthy();

src/app/features/home/custom-camera/custom-camera.service.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Inject, Injectable } from '@angular/core';
33
import { DomSanitizer } from '@angular/platform-browser';
44
import { Capacitor } from '@capacitor/core';
55
import { FilesystemPlugin } from '@capacitor/filesystem';
6+
import { Platform } from '@ionic/angular';
67
import { TranslocoService } from '@ngneat/transloco';
78
import { PreviewCamera } from '@numbersprotocol/preview-camera';
89
import { BehaviorSubject } from 'rxjs';
@@ -31,7 +32,8 @@ export class CustomCameraService {
3132
private readonly errorService: ErrorService,
3233
private readonly translocoService: TranslocoService,
3334
@Inject(FILESYSTEM_PLUGIN)
34-
private readonly filesystemPlugin: FilesystemPlugin
35+
private readonly filesystemPlugin: FilesystemPlugin,
36+
private readonly platform: Platform
3537
) {}
3638

3739
private mediaItemFromFilePath(
@@ -56,6 +58,7 @@ export class CustomCameraService {
5658
const base64 = await blobToBase64(itemBlob);
5759
const mimeType = itemToUpload.mimeType;
5860
await this.captureService.capture({ base64, mimeType });
61+
await this.removeFile(filePath);
5962
} catch (error) {
6063
const errMsg = this.translocoService.translate(`error.internetError`);
6164
await this.errorService.toastError$(errMsg).toPromise();
@@ -98,6 +101,24 @@ export class CustomCameraService {
98101
await this.filesystemPlugin.deleteFile({ path: filePath });
99102
}
100103

104+
async isTorchOn() {
105+
if (this.isNativePlatform) {
106+
return await PreviewCamera.isTorchOn();
107+
}
108+
return { result: false };
109+
}
110+
111+
async enableTorch(enable: boolean): Promise<void> {
112+
if (this.isNativePlatform) {
113+
return await PreviewCamera.enableTorch({ enable });
114+
}
115+
return Promise.resolve();
116+
}
117+
118+
private get isNativePlatform() {
119+
return this.platform.is('ios') || this.platform.is('android');
120+
}
121+
101122
private changeGlobalCSSBackgroundToTransparent() {
102123
document.querySelector('body')?.classList.add(this.globalCSSClass);
103124
document.querySelector('ion-app')?.classList.add(this.globalCSSClass);

0 commit comments

Comments
 (0)