Skip to content

Commit

Permalink
Merge pull request #1835 from numbersprotocol/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bafu committed Jul 19, 2022
2 parents 6961ad8 + 08bde1e commit 8427b98
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 20 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "capture-lite",
"version": "0.61.0",
"version": "0.61.1",
"author": "numbersprotocol",
"homepage": "https://numbersprotocol.io/",
"scripts": {
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/app/features/home/custom-camera/custom-camera.page.html
Expand Up @@ -5,6 +5,11 @@
>
<ng-container *ngIf="(mode$ | ngrxPush) === 'capture'">
<div id="camera-flash-placeholder"></div>

<mat-icon class="flash-camera-button" (click)="enableTorch()">
{{ isFlashOn ? 'flash_on' : 'flash_off' }}
</mat-icon>

<div
class="select-from-go-pro-camera-button"
*ngIf="lastConnectedGoProDevice$ | ngrxPush"
Expand Down
6 changes: 6 additions & 0 deletions src/app/features/home/custom-camera/custom-camera.page.scss
Expand Up @@ -13,6 +13,12 @@ mat-icon {
width: 36px;
}

mat-icon.flash-camera-button {
position: absolute;
top: 16px;
left: 16px;
}

mat-icon.close-camera-button {
position: absolute;
top: 16px;
Expand Down
22 changes: 19 additions & 3 deletions src/app/features/home/custom-camera/custom-camera.page.ts
Expand Up @@ -41,6 +41,8 @@ export class CustomCameraPage implements OnInit, OnDestroy {
curCaptureType?: 'image' | 'video' = 'image';
curCaptureSrc?: string;

isFlashOn = false;

readonly lastConnectedGoProDevice$ =
this.goProBluetoothService.lastConnectedDevice$;

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

this.startPreviewCamera();

this.isTorchOn().then(value => {
console.log(`isFlashOn: ${value.result}`);

return (this.isFlashOn = value.result);
});
}

async ionViewDidEnter() {
Expand Down Expand Up @@ -158,13 +166,21 @@ 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() {
return this.customCameraService.isTorchOn();
}

async enableTorch() {
await this.customCameraService.enableTorch(!this.isFlashOn);
this.isFlashOn = (await this.customCameraService.isTorchOn()).result;
}

async leaveCustomCamera() {
Expand Down
26 changes: 21 additions & 5 deletions 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<void>;
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();
Expand Down
23 changes: 22 additions & 1 deletion src/app/features/home/custom-camera/custom-camera.service.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand All @@ -56,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();
Expand Down Expand Up @@ -98,6 +101,24 @@ export class CustomCameraService {
await this.filesystemPlugin.deleteFile({ path: filePath });
}

async isTorchOn() {
if (this.isNativePlatform) {
return await PreviewCamera.isTorchOn();
}
return { result: false };
}

async enableTorch(enable: boolean): Promise<void> {
if (this.isNativePlatform) {
return await PreviewCamera.enableTorch({ enable });
}
return Promise.resolve();
}

private get isNativePlatform() {
return this.platform.is('ios') || this.platform.is('android');
}

private changeGlobalCSSBackgroundToTransparent() {
document.querySelector('body')?.classList.add(this.globalCSSClass);
document.querySelector('ion-app')?.classList.add(this.globalCSSClass);
Expand Down

0 comments on commit 8427b98

Please sign in to comment.