Skip to content

Commit ea9cd55

Browse files
committed
Step 14.15: Use the getPicture method into messages-attachment.ts
1 parent 12fb8b7 commit ea9cd55

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/pages/messages/messages-attachments.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { ModalController, ViewController } from 'ionic-angular';
2+
import { AlertController, ModalController, Platform, ViewController } from 'ionic-angular';
33
import { NewLocationMessageComponent } from './location-message';
44
import { MessageType } from 'api/models';
55
import { PictureService } from '../../services/picture';
@@ -12,16 +12,26 @@ export class MessagesAttachmentsComponent {
1212
constructor(
1313
private viewCtrl: ViewController,
1414
private modelCtrl: ModalController,
15-
private pictureService: PictureService
15+
private pictureService: PictureService,
16+
private platform: Platform,
17+
private alertCtrl: AlertController
1618
) {}
1719

18-
sendPicture(): void {
19-
this.pictureService.select().then((file: File) => {
20-
this.viewCtrl.dismiss({
21-
messageType: MessageType.PICTURE,
22-
selectedPicture: file
20+
sendPicture(camera: boolean): void {
21+
if (camera && !this.platform.is('cordova')) {
22+
return console.warn('Device must run cordova in order to take pictures');
23+
}
24+
25+
this.pictureService.getPicture(camera, false)
26+
.then((blob: File) => {
27+
this.viewCtrl.dismiss({
28+
messageType: MessageType.PICTURE,
29+
selectedPicture: blob
30+
});
31+
})
32+
.catch((e) => {
33+
this.handleError(e);
2334
});
24-
});
2535
}
2636

2737
sendLocation(): void {
@@ -41,4 +51,16 @@ export class MessagesAttachmentsComponent {
4151

4252
locationModal.present();
4353
}
54+
55+
handleError(e: Error): void {
56+
console.error(e);
57+
58+
const alert = this.alertCtrl.create({
59+
title: 'Oops!',
60+
message: e.message,
61+
buttons: ['OK']
62+
});
63+
64+
alert.present();
65+
}
4466
}

0 commit comments

Comments
 (0)