From 487fe4ae6da562a26fc8a10d2888fa49e3524710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 16 Nov 2021 13:07:55 +0100 Subject: [PATCH 1/3] Take picture added to new publications --- .../new-publication/new-publication.page.html | 2 +- .../new-publication/new-publication.page.ts | 119 +++++++++++++++++- 2 files changed, 118 insertions(+), 3 deletions(-) diff --git a/src/app/pages/publications/new-publication/new-publication.page.html b/src/app/pages/publications/new-publication/new-publication.page.html index 8295b9520..253fd8073 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.html +++ b/src/app/pages/publications/new-publication/new-publication.page.html @@ -56,7 +56,7 @@
- +
diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index a82247f04..51aac11b1 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { ModalController, NavParams } from '@ionic/angular'; +import { ModalController, NavParams, Platform, LoadingController } from '@ionic/angular'; /* import {Plugins, CameraResultType, CameraSource} from '@capacitor/core'; */ import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; @@ -18,12 +18,22 @@ import { FileToBase64Service } from 'src/app/services/file/file-to-base64.servic import { ThemeService } from 'src/app/services/theme.service'; import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; + +const IMAGE_DIR = 'stored-images'; + +interface LocalFile { + name: string; + path: string; + data: string; +} @Component({ selector: 'app-new-publication', templateUrl: './new-publication.page.html', styleUrls: ['./new-publication.page.scss'], }) export class NewPublicationPage implements OnInit { + images: LocalFile[] = []; // date picker public date: any; @@ -70,7 +80,9 @@ export class NewPublicationPage implements OnInit { private toastService: ToastService, private fileLoaderService: FileLoaderService, private fileToBase64Service: FileToBase64Service, - public ThemeService: ThemeService + public ThemeService: ThemeService, + private platform: Platform, + private loadingCtrl: LoadingController, ) { this.publicationType = this.navParams.get('publicationType'); @@ -81,6 +93,11 @@ export class NewPublicationPage implements OnInit { ngOnInit() { this.setTitle(); console.log(this.folderId); + Filesystem.mkdir({ + path: IMAGE_DIR, + directory: Directory.Data, + recursive: true + }); // this.takePicture(); } @@ -369,4 +386,102 @@ async takePicture() { this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl)); } */ + + + +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 + }); + + this.loadFiles(); +} + + 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; + } +} + +async loadFiles() { + this.images = []; + + const loading = await this.loadingCtrl.create({ + message: 'Loading data...', + }); + await loading.present(); + + Filesystem.readdir({ + path: IMAGE_DIR, + directory: Directory.Data, + }).then(result => { + console.log('ALL RESULTS', result.files[0]) + let lastphoto = result.files[result.files.length -1] + this.loadFileData(lastphoto); + }, + async (err) => { + console.log('ERROR FILE DOSENT EXIST',err) + // Folder does not yet exists! + await Filesystem.mkdir({ + path: IMAGE_DIR, + directory: Directory.Data, + recursive: true + }); + } + ).then(_ => { + loading.dismiss(); + }); +} + +async loadFileData(fileName: string) { + console.log('ALL PHOTOT FILE', fileName) + // for (let f of fileNames) { + const filePath = `${IMAGE_DIR}/${fileName}`; + + const readFile = await Filesystem.readFile({ + path: filePath, + directory: Directory.Data, + }); + + this.images.push({ + name: fileName, + path: filePath, + data: `data:image/jpeg;base64,${readFile.data}`, + }); + + console.log('ALL IMAGE',this.images) + + this.capturedImage = this.images[0].data + //} +} } From e7c3bbf3ae8078f5e57957387b2f5e74ba6742e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 16 Nov 2021 13:12:25 +0100 Subject: [PATCH 2/3] Bug on synch event edit and delete and added offline synch to event to aprove REver --- src/app/home/home.page.ts | 55 ++++++++++++++++++- .../agenda/view-event/view-event.page.ts | 9 ++- src/app/pages/events/events.page.ts | 30 ++++++++++ .../approve-event/approve-event.page.ts | 8 ++- src/app/services/events.service.ts | 2 + src/app/services/sqlite.service.ts | 6 ++ 6 files changed, 103 insertions(+), 7 deletions(-) diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 2df4678e0..1d0aaa047 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -22,7 +22,9 @@ import { BackgroundService } from 'src/app/services/background.service'; import { OfflineManagerService } from 'src/app/services/offline-manager.service'; import { Storage } from '@ionic/storage'; import { EventsService } from 'src/app/services/events.service'; +import { ProcessesService } from 'src/app/services/processes.service'; import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx'; +import { SqliteService } from 'src/app/services/sqlite.service'; @Component({ selector: 'app-home', @@ -83,7 +85,9 @@ export class HomePage implements OnInit { private offlinemanager: OfflineManagerService, private storage: Storage, private eventservice: EventsService, - private screenOrientation: ScreenOrientation,) { + private processservice: ProcessesService, + private screenOrientation: ScreenOrientation, + private sqliteservice: SqliteService) { /* this.webNotificationPopupService.askNotificationPermission() */ @@ -121,8 +125,7 @@ export class HomePage implements OnInit { this.backgroundservice.online() if (this.platform.is('desktop') || this.platform.is('mobileweb')) { } else { - /* this.notificationsService.onReceviNotification(); */ - this.offlinemanager.synchnize() + this.synchWhenOnline() } }); window.addEventListener('offline', () => { @@ -160,4 +163,50 @@ export class HomePage implements OnInit { } + async synchWhenOnline() { + try { + await this.storage.get('eventEdit').then((req) => { + JSON.parse(req).forEach(element => { + this.eventservice.editEvent(element, 2, 3).subscribe((res) => { + this.storage.remove('eventEdit') + this.sqliteservice.deleteEventTable(); + console.log('eventEdit synchnize', res) + }) + }); + }) + } catch (error) { + console.log('error synch eventedit') + } + + try { + await this.storage.get('eventDelete').then((req) => { + JSON.parse(req).forEach(element => { + console.log('DELETE data SYNC', element) + this.eventservice.deleteEvent(element.eventid, element.eventDeleteType, element.calendarName).subscribe((res) => { + this.storage.remove('eventDelete') + this.sqliteservice.deleteEventTable(); + console.log('eventDelete synchnize', res) + }) + }); + }) + } catch (error) { + console.log('error delete event synch') + } + + try { + await this.storage.get('event-listRever').then((req) => { + JSON.parse(req).forEach(element => { + console.log('REVER data SYNC', element) + this.processservice.PostTaskAction(element).subscribe((res) => { + this.storage.remove('event-listRever') + this.sqliteservice.deleteEventTable(); + console.log('event-listRever synchnize', res) + }) + }); + }) + } catch (error) { + console.log('error event-list rever synch') + } + } + } diff --git a/src/app/pages/agenda/view-event/view-event.page.ts b/src/app/pages/agenda/view-event/view-event.page.ts index ad1989d2b..ea60b28bd 100644 --- a/src/app/pages/agenda/view-event/view-event.page.ts +++ b/src/app/pages/agenda/view-event/view-event.page.ts @@ -171,9 +171,9 @@ export class ViewEventPage implements OnInit { loader.remove() }, (error) => { - console.log('errorstatus',error.status) + console.log('errorstatus ss',error.status) - if (error.status == 0) { + if (error.status === 0) { this.getFromDb(); } else { this.toastService.badRequest('Este evento já não existe na sua agenda') @@ -205,6 +205,8 @@ export class ViewEventPage implements OnInit { () => { loader.remove(); }); + + loader.remove(); } @@ -421,8 +423,9 @@ export class ViewEventPage implements OnInit { const loader = this.toastService.loading(); this.sqliteservice.getEventById(this.eventId).then((event) => { let arrayevent = []; + console.log('EVENT ATTENDEES',event[0].Attendees) let elemet = { - Attendees: JSON.parse(event[0].Attendees) || "", + Attendees: (typeof JSON.parse(event[0].Attendees) === 'undefined') ? "" : JSON.parse(event[0].Attendees), Body: JSON.parse(event[0].Body) || "", CalendarId: event[0].CalendarId, CalendarName: event[0].CalendarName, diff --git a/src/app/pages/events/events.page.ts b/src/app/pages/events/events.page.ts index 709122a83..e9a4177b0 100644 --- a/src/app/pages/events/events.page.ts +++ b/src/app/pages/events/events.page.ts @@ -318,6 +318,36 @@ export class EventsPage implements OnInit { if (list.length > 0) { list.forEach(element => { this.sqliteservice.addEvent(element) + + this.sqliteservice.getAllEvents().then((event: any[]) => { + let todayEvents = new Array() + event.forEach((element) => { + let eventObject = { + AppointmentState: element.AppointmentState, + Attachments: element.Attachments, + Attendees: element.Attendees, + CalendarId: element.CalendarId, + CalendarName: element.CalendarName, + Category: element.Category, + EndDate: element.EndDate, + EventId: element.EventId, + EventRecurrence: element.EventRecurrence, + EventType: element.EventType, + HasAttachments: element.HasAttachments, + HumanDate: element.HumanDate, + IsAllDayEvent: element.IsAllDayEvent, + IsMeeting: element.IsMeeting, + IsRecurring: element.IsRecurring, + Location: element.Location, + Organizer: element.Organizer, + Profile: element.Profile, + StartDate: element.StartDate, + Subject: element.Subject + } + todayEvents.push(eventObject); + }) + console.log('JIFJSOSDJSDONS',todayEvents) + }) }); } } diff --git a/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts b/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts index 1ba7a67a3..6ed90e273 100644 --- a/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts +++ b/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts @@ -17,6 +17,7 @@ import { SqliteService } from '../../../../services/sqlite.service'; import { BackgroundService } from '../../../../services/background.service'; import { Platform } from '@ionic/angular'; import { ThemeService } from 'src/app/services/theme.service' +import { OfflineManagerService } from 'src/app/services/offline-manager.service'; @Component({ @@ -62,6 +63,7 @@ export class ApproveEventPage implements OnInit { private platform: Platform, private backgroundservice: BackgroundService, public ThemeService: ThemeService, + private offlineManager: OfflineManagerService ) { this.activatedRoute.paramMap.subscribe(params => { // console.log(params["params"]); @@ -255,7 +257,11 @@ export class ApproveEventPage implements OnInit { const loader = this.toastService.loading() try { - await this.processes.PostTaskAction(body).toPromise(); + await this.processes.PostTaskAction(body).toPromise() + .catch(() => { + console.log('Send event to approve for revition') + this.offlineManager.storeRequestData('event-listRever', body); + }); this.toastService._successMessage('Pedido enviado'); this.goBack(); } catch (error) { diff --git a/src/app/services/events.service.ts b/src/app/services/events.service.ts index ed264d7ba..c2fd4b9b6 100644 --- a/src/app/services/events.service.ts +++ b/src/app/services/events.service.ts @@ -346,6 +346,7 @@ export class EventsService { return this.http.put(`${puturl}`, event, options).pipe( catchError(err => { + console.log('Event edit saved offline') this.offlinemanager.storeRequestData('eventEdit', arrayReq); throw new Error(err); }) @@ -481,6 +482,7 @@ export class EventsService { return this.http.delete(`${puturl}`, options).pipe( catchError(err => { + console.log('Event edit saved offline') this.offlinemanager.storeRequestData('eventDelete', arrayReq); throw new Error(err); }) diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts index c7ef44e7a..af3ce2dfa 100644 --- a/src/app/services/sqlite.service.ts +++ b/src/app/services/sqlite.service.ts @@ -512,4 +512,10 @@ export class SqliteService { console.log(" Get events by id error", JSON.stringify(e)); }); } + + deleteEventTable() { + this.dbInstance.executeSql("delete from "+ this.events).then((res) => { + console.log('DELETE EVENT TABLE RESULT ', res) + }); + } } From e2ef250521f03d82be26c8a3f3e0653ea6427532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 16 Nov 2021 14:06:30 +0100 Subject: [PATCH 3/3] On new publication add image from gallery added --- .../new-publication/new-publication.page.html | 4 +- .../new-publication/new-publication.page.ts | 247 +++++++++--------- 2 files changed, 121 insertions(+), 130 deletions(-) diff --git a/src/app/pages/publications/new-publication/new-publication.page.html b/src/app/pages/publications/new-publication/new-publication.page.html index 253fd8073..102b43254 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.html +++ b/src/app/pages/publications/new-publication/new-publication.page.html @@ -56,7 +56,7 @@
- +
@@ -69,7 +69,7 @@
- +
diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index 51aac11b1..f9ca5a972 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -16,7 +16,7 @@ import { formatDate } from 'src/plugin/momentG.js' import { FileLoaderService } from 'src/app/services/file/file-loader.service'; import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; import { ThemeService } from 'src/app/services/theme.service'; -import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera'; +import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera'; import { Filesystem, Directory } from '@capacitor/filesystem'; @@ -42,7 +42,7 @@ export class NewPublicationPage implements OnInit { public showSeconds = false; public touchUi = false; public enableMeridian = false; - public minDate = new Date().toISOString().slice(0,10) + public minDate = new Date().toISOString().slice(0, 10) public endMinDate = new Date(new Date().getTime() + 15 * 60000); public stepHour = 1; public stepMinute = 5; @@ -58,18 +58,18 @@ export class NewPublicationPage implements OnInit { folderId: string; image: Image = new Image(); - publicationType:string; - publicationTitle:string; - imgUrl:any; + publicationType: string; + publicationTitle: string; + imgUrl: any; - Defaultimage:any = ''; + Defaultimage: any = ''; photo: SafeResourceUrl; - guestPicture:any; + guestPicture: any; - capturedImage:any = ''; - capturedImageTitle:any; + capturedImage: any = ''; + capturedImageTitle: any; public photos: any[] = []; constructor( @@ -83,12 +83,12 @@ export class NewPublicationPage implements OnInit { public ThemeService: ThemeService, private platform: Platform, private loadingCtrl: LoadingController, - ) { + ) { - this.publicationType = this.navParams.get('publicationType'); - this.folderId = this.navParams.get('folderId'); - this.publicationTitle = 'Nova Publicação'; - } + this.publicationType = this.navParams.get('publicationType'); + this.folderId = this.navParams.get('folderId'); + this.publicationTitle = 'Nova Publicação'; + } ngOnInit() { this.setTitle(); @@ -102,26 +102,17 @@ export class NewPublicationPage implements OnInit { // this.takePicture(); } -async takePicture() { - const capturedImage = await Camera.getPhoto({ - quality: 90, - // allowEditing: true, - resultType: CameraResultType.Uri, - source: CameraSource.Camera - - }); - const response = await fetch(capturedImage.webPath!); - const blob = await response.blob(); - - this.photos.unshift({ - filepath: "soon...", - webviewPath: capturedImage.webPath + async takePicture() { + const image = await Camera.getPhoto({ + quality: 90, + allowEditing: false, + resultType: CameraResultType.Uri, + source: CameraSource.Camera // Camera, Photos or Prompt! }); - this.capturedImage = await this.convertBlobToBase64(blob); - this.capturedImageTitle = new Date().getTime() + '.jpeg'; - - //console.log(this.capturedImage); + if (image) { + this.saveImage(image) + } } @@ -129,7 +120,7 @@ async takePicture() { const reader = new FileReader; reader.onerror = reject; reader.onload = () => { - resolve(reader.result); + resolve(reader.result); }; reader.readAsDataURL(blob); }); @@ -176,7 +167,7 @@ async takePicture() { runValidation() { - this.validateFrom = true + this.validateFrom = true } injectValidation() { @@ -202,18 +193,18 @@ async takePicture() { this.injectValidation() this.runValidation() - if(this.Form.invalid) return false + if (this.Form.invalid) return false - if(this.publicationType == '3') { + if (this.publicationType == '3') { console.log(this.navParams.get('publication')); - if(this.capturedImage != ''){ + if (this.capturedImage != '') { this.publication = { DateIndex: this.publication.DateIndex, - DocumentId:this.publication.DocumentId, - ProcessId:this.publication.ProcessId, + DocumentId: this.publication.DocumentId, + ProcessId: this.publication.ProcessId, Title: this.pub.Title, Message: this.pub.Message, DatePublication: this.publication.DatePublication, @@ -242,8 +233,8 @@ async takePicture() { this.publication = { DateIndex: this.publication.DateIndex, - DocumentId:this.publication.DocumentId, - ProcessId:this.publication.ProcessId, + DocumentId: this.publication.DocumentId, + ProcessId: this.publication.ProcessId, Title: this.pub.Title, Message: this.pub.Message, DatePublication: this.publication.DatePublication, @@ -264,15 +255,15 @@ async takePicture() { this.close(); } catch (error) { this.toastService.badRequest("Publicação não criado") - } finally { + } finally { loader.remove() } - } else { + } else { this.publication = { DateIndex: this.publication.DateIndex, - DocumentId:this.publication.DocumentId, - ProcessId:this.publication.ProcessId, + DocumentId: this.publication.DocumentId, + ProcessId: this.publication.ProcessId, Title: this.pub.Title, Message: this.pub.Message, DatePublication: this.publication.DatePublication, @@ -292,7 +283,7 @@ async takePicture() { this.close(); } catch (error) { this.toastService.badRequest("Publicação não criado") - } finally { + } finally { loader.remove() } @@ -300,15 +291,15 @@ async takePicture() { } else { - const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss') + const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss') console.log(date); console.log(this.folderId); this.publication = { DateIndex: date, - DocumentId:null, - ProcessId:this.folderId, + DocumentId: null, + ProcessId: this.folderId, Title: this.pub.Title, Message: this.pub.Message, DatePublication: date, @@ -329,7 +320,7 @@ async takePicture() { this.close(); } catch (error) { this.toastService.badRequest("Publicação não criado") - } finally { + } finally { loader.remove() } @@ -338,8 +329,8 @@ async takePicture() { close() { - this.modalController.dismiss().then(()=>{ - this.showLoader=true; + this.modalController.dismiss().then(() => { + this.showLoader = true; }); } @@ -348,13 +339,13 @@ async takePicture() { } setTitle() { - if(this.publicationType == '1') { + if (this.publicationType == '1') { this.publicationTitle = 'Nova Publicação Rápida'; } - else if(this.publicationType == '2') { + else if (this.publicationType == '2') { this.publicationTitle = 'Nova Publicação'; } - else if(this.publicationType == '3') { + else if (this.publicationType == '3') { this.publicationTitle = 'Editar Publicação'; this.pub = this.navParams.get('publication'); @@ -374,98 +365,98 @@ async takePicture() { modal.onDidDismiss(); } */ - /* async takePicture(){ - const image = await Plugins.Camera.getPhoto({ - quality: 100, - allowEditing: false, - resultType: CameraResultType.DataUrl, - source: CameraSource.Camera - }); - console.log(image); + /* async takePicture(){ + const image = await Plugins.Camera.getPhoto({ + quality: 100, + allowEditing: false, + resultType: CameraResultType.DataUrl, + source: CameraSource.Camera + }); + console.log(image); - this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl)); - } */ + this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl)); + } */ - -async selectImage() { + + async selectImage() { const image = await Camera.getPhoto({ - quality: 90, - allowEditing: false, - resultType: CameraResultType.Uri, - source: CameraSource.Camera // Camera, Photos or Prompt! + quality: 90, + allowEditing: false, + resultType: CameraResultType.Uri, + source: CameraSource.Photos // Camera, Photos or Prompt! }); - + if (image) { - this.saveImage(image) + this.saveImage(image) } -} - -// Create a new file from a capture image -async saveImage(photo: 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({ - path: `${IMAGE_DIR}/${fileName}`, - data: base64Data, - directory: Directory.Data + path: `${IMAGE_DIR}/${fileName}`, + data: base64Data, + directory: Directory.Data }); - + this.loadFiles(); -} - + } + private async readAsBase64(photo: Photo) { if (this.platform.is('hybrid')) { - const file = await Filesystem.readFile({ - path: photo.path - }); - - return file.data; + 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; + // 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; } -} + } -async loadFiles() { - this.images = []; + async loadFiles() { + this.images = []; - const loading = await this.loadingCtrl.create({ - message: 'Loading data...', - }); - await loading.present(); + const loading = await this.loadingCtrl.create({ + message: 'Loading data...', + }); + await loading.present(); - Filesystem.readdir({ - path: IMAGE_DIR, - directory: Directory.Data, - }).then(result => { - console.log('ALL RESULTS', result.files[0]) - let lastphoto = result.files[result.files.length -1] - this.loadFileData(lastphoto); - }, - async (err) => { - console.log('ERROR FILE DOSENT EXIST',err) - // Folder does not yet exists! - await Filesystem.mkdir({ - path: IMAGE_DIR, - directory: Directory.Data, - recursive: true - }); - } - ).then(_ => { - loading.dismiss(); - }); -} + Filesystem.readdir({ + path: IMAGE_DIR, + directory: Directory.Data, + }).then(result => { + console.log('ALL RESULTS', result.files[0]) + let lastphoto = result.files[result.files.length - 1] + this.loadFileData(lastphoto); + }, + async (err) => { + console.log('ERROR FILE DOSENT EXIST', err) + // Folder does not yet exists! + await Filesystem.mkdir({ + path: IMAGE_DIR, + directory: Directory.Data, + recursive: true + }); + } + ).then(_ => { + loading.dismiss(); + }); + } -async loadFileData(fileName: string) { - console.log('ALL PHOTOT FILE', fileName) - // for (let f of fileNames) { + async loadFileData(fileName: string) { + console.log('ALL PHOTOT FILE', fileName) + // for (let f of fileNames) { const filePath = `${IMAGE_DIR}/${fileName}`; const readFile = await Filesystem.readFile({ @@ -479,9 +470,9 @@ async loadFileData(fileName: string) { data: `data:image/jpeg;base64,${readFile.data}`, }); - console.log('ALL IMAGE',this.images) + console.log('ALL IMAGE', this.images) this.capturedImage = this.images[0].data - //} -} + //} + } }