Skip to content

Commit

Permalink
Merge pull request #2671 from numbersprotocol/feat-v230310-sprint-2-u…
Browse files Browse the repository at this point in the history
…pload-image

Feat v230310 sprint 2 upload image
  • Loading branch information
bafu authored Apr 2, 2023
2 parents 0fb04af + 8adab01 commit 73d13d8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/app/features/home/custom-camera/custom-camera.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@
</div>
</div>
<div class="footer-camera-buttons">
<mat-icon class="temporarily-hidden" id="gallery-icon">
video_collection
</mat-icon>
<mat-icon (click)="pickImage()"> imagesmode </mat-icon>

<circle-progress
(click)="onPress()"
Expand Down
4 changes: 0 additions & 4 deletions src/app/features/home/custom-camera/custom-camera.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ mat-icon.close-camera-button {
right: 16px;
}

mat-icon.temporarily-hidden {
visibility: hidden;
}

// mat-icon
.select-from-go-pro-camera-button {
position: absolute;
Expand Down
16 changes: 16 additions & 0 deletions src/app/features/home/custom-camera/custom-camera.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ export class CustomCameraPage implements OnInit, OnDestroy {
this.customCameraService.stopPreviewCamera();
}

async pickImage() {
try {
const image = await this.customCameraService.pickImage();
await this.prePublish(
{ filePath: image.path },
'image',
CameraSource.Photos
);
} catch (error) {
/**
* Error mighght happen if user didn't pick photo or video,
* we'll handle such error quietly without notifying user.
*/
}
}

async flipCamera() {
await this.customCameraService.flipCamera();
await this.syncCameraState();
Expand Down
8 changes: 7 additions & 1 deletion src/app/features/home/custom-camera/custom-camera.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Platform } from '@ionic/angular';
import { TranslocoService } from '@ngneat/transloco';
import { PreviewCamera } from '@numbersprotocol/preview-camera';
import { BehaviorSubject } from 'rxjs';
import { CameraService } from '../../../shared/camera/camera.service';
import { FILESYSTEM_PLUGIN } from '../../../shared/capacitor-plugins/capacitor-plugins.module';
import { CaptureService } from '../../../shared/capture/capture.service';
import { ErrorService } from '../../../shared/error/error.service';
Expand All @@ -34,7 +35,8 @@ export class CustomCameraService {
private readonly translocoService: TranslocoService,
@Inject(FILESYSTEM_PLUGIN)
private readonly filesystemPlugin: FilesystemPlugin,
private readonly platform: Platform
private readonly platform: Platform,
private readonly cameraService: CameraService
) {}

private mediaItemFromFilePath(
Expand Down Expand Up @@ -81,6 +83,10 @@ export class CustomCameraService {
return PreviewCamera.stopPreview().catch(() => ({}));
}

async pickImage() {
return this.cameraService.pickPhoto();
}

// eslint-disable-next-line class-methods-use-this
async flipCamera() {
return PreviewCamera.flipCamera().catch(() => ({}));
Expand Down
13 changes: 11 additions & 2 deletions src/app/shared/camera/camera.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Inject, Injectable } from '@angular/core';
import { AppPlugin } from '@capacitor/app';
import {
Photo as CameraPhoto,
CameraPlugin,
CameraResultType,
CameraSource,
Photo as CameraPhoto,
} from '@capacitor/camera';
import { Subject } from 'rxjs';
import { blobToBase64 } from '../../utils/encoding/encoding';
import { fromExtension, MimeType } from '../../utils/mime-type';
import { MimeType, fromExtension } from '../../utils/mime-type';
import {
APP_PLUGIN,
CAMERA_PLUGIN,
Expand Down Expand Up @@ -51,6 +51,15 @@ export class CameraService {
return cameraPhotoToPhoto(cameraPhoto);
}

async pickPhoto(): Promise<CameraPhoto> {
return this.cameraPlugin.getPhoto({
resultType: CameraResultType.Uri,
source: CameraSource.Photos,
quality: 100,
allowEditing: false,
});
}

// eslint-disable-next-line class-methods-use-this
async recordVideo(): Promise<Media> {
return new Promise<Media>((resolve, reject) => {
Expand Down

0 comments on commit 73d13d8

Please sign in to comment.