This commit is contained in:
tiago.kayaya
2021-11-09 15:28:40 +01:00
parent f7c8942444
commit 3a46b77e36
6 changed files with 69 additions and 63 deletions
+4
View File
@@ -2,6 +2,10 @@
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" />
<feature name="sqlDB">
<param name="ios-package" value="sqlDB"/>
</feature>
<feature name="SQLitePlugin">
<param name="ios-package" value="SQLitePlugin"/>
</feature>
+3
View File
@@ -9,8 +9,11 @@ install! 'cocoapods', :disable_input_output_paths => true
def capacitor_pods
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app'
pod 'CapacitorCamera', :path => '..\..\node_modules\@capacitor\camera'
pod 'CapacitorFilesystem', :path => '..\..\node_modules\@capacitor\filesystem'
pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics'
pod 'CapacitorPushNotifications', :path => '..\..\node_modules\@capacitor\push-notifications'
pod 'CapacitorVoiceRecorder', :path => '..\..\node_modules\capacitor-voice-recorder'
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
pod 'CordovaPluginsResources', :path => '../capacitor-cordova-ios-plugins'
+63 -62
View File
@@ -2,14 +2,14 @@ import { Injectable } from '@angular/core';
import { FileLoaderService } from '../file/file-loader.service';
import { FileToBase64Service } from '../file/file-to-base64.service';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
//Cordova
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { ChatService } from '../chat.service';
import { ModalController } from '@ionic/angular';
import { SearchPage } from 'src/app/pages/search/search.page';
import { SearchList } from 'src/app/models/search-document';
import { ProcessesService } from '../processes.service';
import { ToastService } from '../toast.service';
import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
@Injectable({
providedIn: 'root'
@@ -22,9 +22,9 @@ export class FileService {
showLoader: boolean;
files: Set<File>;
photos: any[] = [];
constructor(
private camera: Camera,
private fileLoaderService: FileLoaderService,
private fileToBase64Service: FileToBase64Service,
private iab: InAppBrowser,
@@ -34,26 +34,25 @@ export class FileService {
private toastService: ToastService,
) { }
takePicture() {
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
targetWidth: 720,
targetHeight: 720,
}
async takePicture() {
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Camera
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL): m
//let base64Image = 'data:image/jpeg;base64,' + imageData;
this.capturedImage = 'data:image/png;base64,'+imageData;
this.capturedImageTitle = new Date().getTime() + '.jpeg';
}, (err) => {
/* console.log(err); */
});
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
this.photos.unshift({
filepath: "soon...",
webviewPath: capturedImage.webPath
});
this.capturedImage = await this.convertBlobToBase64(blob);
this.capturedImageTitle = new Date().getTime() + '.jpeg';
let data = {
image:this.capturedImage,
name: this.capturedImageTitle
@@ -62,6 +61,15 @@ export class FileService {
return data;
}
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});
loadPicture() {
const input = this.fileLoaderService.createInput({
accept: ['image/apng', 'image/jpeg', 'image/png']
@@ -85,19 +93,24 @@ export class FileService {
};
}
addCameraPictureToChat(roomId){
async addCameraPictureToChat(roomId){
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
targetWidth: 720,
targetHeight: 720,
}
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Camera
this.camera.getPicture(options).then((imageData) => {
this.capturedImage = 'data:image/png;base64,'+imageData;
});
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
this.photos.unshift({
filepath: "soon...",
webviewPath: capturedImage.webPath
});
this.capturedImage = await this.convertBlobToBase64(blob);
this.capturedImageTitle = new Date().getTime() + '.jpeg';
let body = {
@@ -121,29 +134,26 @@ export class FileService {
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
});
}, (err) => {
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
}
async addPictureToChatMobile(roomId) {
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
});
}
addPictureToChatMobile(roomId) {
alert('Here')
const options: CameraOptions = {
quality: 90,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
targetWidth: 720,
targetHeight: 720,
correctOrientation: true
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.capturedImage = imageData;
this.capturedImage = await this.convertBlobToBase64(blob);
this.capturedImageTitle = new Date().getTime() + '.jpeg';
//const loader = this.toastService.loading();
@@ -161,21 +171,12 @@ export class FileService {
}]
}
}
console.log(this.capturedImage)
this.chatService.sendMessage(body).subscribe(res=> {
//loader.remove();
//console.log(res);
},(error) => {
//loader.remove();
});
}, (err) => {
//console.log(err);
});
}
addPictureToChat(roomId) {
@@ -3,7 +3,7 @@
<div class="main-header">
<div class="header-top">
<div class="middle" *ngFor="let users of dmUsers">
<ion-label class="title">{{users.name}}11</ion-label>
<ion-label class="title">{{users.name}}</ion-label>
<span><ion-icon class="{{users.status}}" name="ellipse"></ion-icon></span>
</div>
<div hidden class="right">
@@ -6,7 +6,7 @@
</button>
</div>
<div class="buttons">
<button hidden (click)="takePicture()" full class="btn-ok" shape="round" >Tirar Fotografia</button>
<button (click)="takePicture()" full class="btn-ok" shape="round" >Tirar Fotografia</button>
<button hidden (click)="addFile()" class="btn-ok" shape="round" >Anexar Documento</button>
<button hidden (click)="anexarFoto()" full class="btn-ok" shape="round" >Anexar Fotografia</button>
<button (click)="addDocGestaoDocumental()" class="btn-ok" shape="round" >Gestão Documental</button>
@@ -27,7 +27,6 @@
</div>
</div>
<div class="picture d-flex pb-5 hide-desktop" *ngIf="publication.FileBase64 && capturedImage ==''">
<div class="post-img">
<img src="{{publication.FileBase64}}" alt="image" >
@@ -84,7 +83,6 @@
</ion-content>
<ion-footer class="ion-no-border">
<ion-toolbar class="footer-toolbar width-100 px-20">
<ion-buttons slot="start">