7
7
Output ,
8
8
ViewChild ,
9
9
} from '@angular/core' ;
10
- import { FilesystemPlugin } from '@capacitor/filesystem' ;
11
- import { AlertController } from '@ionic/angular' ;
10
+ import { Directory , FilesystemPlugin } from '@capacitor/filesystem' ;
11
+ import { AlertController , Platform } from '@ionic/angular' ;
12
12
import { TranslocoService } from '@ngneat/transloco' ;
13
13
import { ColorMatrix , getEditorDefaults } from '@pqina/pintura' ;
14
14
import {
@@ -62,6 +62,8 @@ export class PrePublishModeComponent {
62
62
63
63
readonly curCaptureFilePath$ = new ReplaySubject < string > ( 1 ) ;
64
64
65
+ readonly curCaptureFileName$ = new ReplaySubject < string > ( 1 ) ;
66
+
65
67
readonly curCaptureMimeType$ = new ReplaySubject < CaptureMimeType > ( 1 ) ;
66
68
67
69
readonly curCaptureSrc$ = new ReplaySubject < string > ( 1 ) ;
@@ -108,6 +110,11 @@ export class PrePublishModeComponent {
108
110
if ( value ) this . curCaptureFilePath$ . next ( value ) ;
109
111
}
110
112
113
+ @Input ( )
114
+ set curCaptureFileName ( value : string | undefined ) {
115
+ if ( value ) this . curCaptureFileName$ . next ( value ) ;
116
+ }
117
+
111
118
@Input ( )
112
119
set curCaptureMimeType ( value : CaptureMimeType | undefined ) {
113
120
if ( value ) this . curCaptureMimeType$ . next ( value ) ;
@@ -129,7 +136,8 @@ export class PrePublishModeComponent {
129
136
private readonly filesystemPlugin : FilesystemPlugin ,
130
137
private readonly errorService : ErrorService ,
131
138
private readonly alertController : AlertController ,
132
- private readonly translocoService : TranslocoService
139
+ private readonly translocoService : TranslocoService ,
140
+ private readonly platform : Platform
133
141
) { }
134
142
135
143
handleEditorUpdate ( imageState : any ) : void {
@@ -150,12 +158,24 @@ export class PrePublishModeComponent {
150
158
151
159
async handleEditorProcess ( imageWriterResult : any ) : Promise < void > {
152
160
const base64 = await blobToBase64 ( imageWriterResult . dest as File ) ;
153
- combineLatest ( [ this . curCaptureFilePath$ , of ( base64 ) ] )
161
+ combineLatest ( [
162
+ this . curCaptureFilePath$ ,
163
+ of ( base64 ) ,
164
+ this . isImage$ ,
165
+ this . curCaptureFileName$ ,
166
+ ] )
154
167
. pipe (
155
168
first ( ) ,
156
- switchMap ( ( [ path , data ] ) =>
157
- this . filesystemPlugin . writeFile ( { path, data } )
158
- ) ,
169
+ switchMap ( ( [ path , data , isImage , fileName ] ) => {
170
+ if ( this . platform . is ( 'android' ) && isImage ) {
171
+ return this . filesystemPlugin . writeFile ( {
172
+ path : fileName ,
173
+ data : data ,
174
+ directory : Directory . Cache ,
175
+ } ) ;
176
+ }
177
+ return this . filesystemPlugin . writeFile ( { path, data } ) ;
178
+ } ) ,
159
179
tap ( ( ) => this . isProcessingImage$ . next ( false ) ) ,
160
180
tap ( ( ) => this . confirm . emit ( true ) ) ,
161
181
catchError ( ( error : unknown ) => {
0 commit comments