This commit is contained in:
ivan gomes
2021-11-17 09:48:42 +01:00
44 changed files with 892 additions and 118 deletions
@@ -19,7 +19,6 @@ import { ThemeService } from 'src/app/services/theme.service';
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
import { Filesystem, Directory } from '@capacitor/filesystem';
import { Photos } from './photos';
const IMAGE_DIR = 'stored-images';
@@ -71,11 +70,7 @@ export class NewPublicationPage implements OnInit {
capturedImage: any = '';
capturedImageTitle: any;
// public photos: any[] = [];
public photos: Photos[] = [];
private PHOTO_STORAGE: string = "photos";
private platform: Platform;
public photos: any[] = [];
constructor(
private modalController: ModalController,
@@ -86,7 +81,7 @@ export class NewPublicationPage implements OnInit {
private fileLoaderService: FileLoaderService,
private fileToBase64Service: FileToBase64Service,
public ThemeService: ThemeService,
// private platform: Platform,
private platform: Platform,
private loadingCtrl: LoadingController,
) {
@@ -118,104 +113,17 @@ export class NewPublicationPage implements OnInit {
if (image) {
this.saveImage(image)
}
}
// Little helper
// async presentToast(text) {
// const toast = await this.toastCtrl.create({
// message: text,
// duration: 3000,
// });
// toast.present();
// }
// async selectImage() {
// const image = await Camera.getPhoto({
// quality: 90,
// allowEditing: false,
// resultType: CameraResultType.Uri,
// source: CameraSource.Camera // Camera, Photos or Prompt!
// });
// if (image) {
// this.saveImage(image)
// }
// }
// Create a new file from a capture image
/* async saveImage(photo: Photo) {
const base64Data = await this.readAsBase64(photo);
const fileName = new Date().getTime() + '.jpeg';
const savedFile = await Filesystem.writeFile({
path: `${IMAGE_DIR}/${fileName}`,
data: base64Data,
directory: Directory.Data
});
// Reload the file list
// Improve by only loading for the new image and unshifting array!
this.loadFiles();
} */
// https://ionicframework.com/docs/angular/your-first-app/3-saving-photos
// private async readAsBase64(photo: Photo) {
// if (this.platform.is('hybrid')) {
// const file = await Filesystem.readFile({
// path: photo.path
// });
// return file.data;
// }
// else {
// // Fetch the photo, read as a blob, then convert to base64 format
// const response = await fetch(photo.webPath);
// const blob = await response.blob();
// return await this.convertBlobToBase64(blob) as string;
// }
// }
// Helper function
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});
async startUpload(file: LocalFile) {
// TODO
}
async deleteImage(file: LocalFile) {
// TODO
}
// async takePicture() {
// const capturedImage = await Camera.getPhoto({
// quality: 90,
// // allowEditing: true,
// resultType: CameraResultType.Uri,
// source: CameraSource.Camera
// });
// }
// convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
// const reader = new FileReader;
// reader.onerror = reject;
// reader.onload = () => {
// resolve(reader.result);
// };
// reader.readAsDataURL(blob);
// });
};
reader.readAsDataURL(blob);
});
async laodPicture() {
@@ -291,6 +199,8 @@ private async savePicture(photo: Photo) {
} */
runValidation() {
this.validateFrom = true
}
@@ -519,9 +429,9 @@ private async savePicture(photo: Photo) {
}
}
// // Create a new file from a capture image
async saveImage(photo: Photo) {
const base64Data = await this.readAsBase64(photo);
// Create a new file from a capture image
async saveImage(photo: Photo) {
const base64Data = await this.readAsBase64(photo);
const fileName = new Date().getTime() + '.jpeg';
const savedFile = await Filesystem.writeFile({