@@ -25,11 +25,14 @@ function isString(value): value is string {
25
25
return typeof value === 'string' ;
26
26
}
27
27
28
- const DialogInterface = android . content . DialogInterface ;
29
- const MaterialAlertDialogBuilder = com . google . android . material . dialog . MaterialAlertDialogBuilder ;
28
+ let DialogInterface : typeof android . content . DialogInterface ;
29
+ let MaterialAlertDialogBuilder : typeof com . google . android . material . dialog . MaterialAlertDialogBuilder ;
30
30
31
31
function createAlertDialogBuilder ( options ?: DialogOptions & MDCAlertControlerOptions ) {
32
32
const activity = Application . android . foregroundActivity || ( Application . android . startActivity as globalAndroid . app . Activity ) ;
33
+ if ( ! MaterialAlertDialogBuilder ) {
34
+ MaterialAlertDialogBuilder = com . google . android . material . dialog . MaterialAlertDialogBuilder ;
35
+ }
33
36
const builder = new MaterialAlertDialogBuilder ( activity ) ;
34
37
builder . setTitle ( options && isString ( options . title ) ? options . title : null ) ;
35
38
builder . setMessage ( options && isString ( options . message ) ? options . message : null ) ;
@@ -38,6 +41,9 @@ function createAlertDialogBuilder(options?: DialogOptions & MDCAlertControlerOpt
38
41
}
39
42
if ( options && options . cancelable === false ) {
40
43
builder . setCancelable ( false ) ;
44
+ if ( ! DialogInterface ) {
45
+ DialogInterface = android . content . DialogInterface ;
46
+ }
41
47
builder . setOnKeyListener (
42
48
new DialogInterface . OnKeyListener ( {
43
49
onKey ( dialog , keyCode , event ) {
@@ -55,8 +61,8 @@ function createAlertDialogBuilder(options?: DialogOptions & MDCAlertControlerOpt
55
61
options . view instanceof View
56
62
? options . view
57
63
: Builder . createViewFromEntry ( {
58
- moduleName : options . view as string
59
- } ) ;
64
+ moduleName : options . view as string
65
+ } ) ;
60
66
61
67
view . cssClasses . add ( CSSUtils . MODAL_ROOT_VIEW_CSS_CLASS ) ;
62
68
const modalRootViewCssClasses = CSSUtils . getSystemCssClasses ( ) ;
@@ -165,7 +171,9 @@ function prepareAndCreateAlertDialog(
165
171
}
166
172
callback && callback ( result ) ;
167
173
} ;
168
-
174
+ if ( ! DialogInterface ) {
175
+ DialogInterface = android . content . DialogInterface ;
176
+ }
169
177
builder . setOnDismissListener (
170
178
new DialogInterface . OnDismissListener ( {
171
179
onDismiss ( ) {
@@ -197,6 +205,9 @@ function prepareAndCreateAlertDialog(
197
205
}
198
206
199
207
if ( options . okButtonText ) {
208
+ if ( ! DialogInterface ) {
209
+ DialogInterface = android . content . DialogInterface ;
210
+ }
200
211
dlg . setButton (
201
212
DialogInterface . BUTTON_POSITIVE ,
202
213
options . okButtonText ,
@@ -213,6 +224,9 @@ function prepareAndCreateAlertDialog(
213
224
}
214
225
215
226
if ( options . cancelButtonText ) {
227
+ if ( ! DialogInterface ) {
228
+ DialogInterface = android . content . DialogInterface ;
229
+ }
216
230
dlg . setButton (
217
231
DialogInterface . BUTTON_NEGATIVE ,
218
232
options . cancelButtonText ,
@@ -234,6 +248,9 @@ function prepareAndCreateAlertDialog(
234
248
}
235
249
236
250
if ( options . neutralButtonText ) {
251
+ if ( ! DialogInterface ) {
252
+ DialogInterface = android . content . DialogInterface ;
253
+ }
237
254
dlg . setButton (
238
255
DialogInterface . BUTTON_NEUTRAL ,
239
256
options . neutralButtonText ,
@@ -306,8 +323,8 @@ export function confirm(arg: any): Promise<boolean> {
306
323
defaultOptions ,
307
324
! isDialogOptions ( arg )
308
325
? {
309
- message : arg + ''
310
- }
326
+ message : arg + ''
327
+ }
311
328
: arg
312
329
) ;
313
330
const alert = createAlertDialogBuilder ( options ) ;
@@ -522,6 +539,9 @@ export function action(arg: any): Promise<string> {
522
539
return new Promise < string > ( ( resolve , reject ) => {
523
540
try {
524
541
const activity = Application . android . foregroundActivity || ( Application . android . startActivity as globalAndroid . app . Activity ) ;
542
+ if ( ! MaterialAlertDialogBuilder ) {
543
+ MaterialAlertDialogBuilder = com . google . android . material . dialog . MaterialAlertDialogBuilder ;
544
+ }
525
545
const alert = new MaterialAlertDialogBuilder ( activity ) ;
526
546
const message = options && isString ( options . message ) ? options . message : '' ;
527
547
const title = options && isString ( options . title ) ? options . title : '' ;
@@ -539,6 +559,9 @@ export function action(arg: any): Promise<string> {
539
559
}
540
560
541
561
if ( options . actions ) {
562
+ if ( ! DialogInterface ) {
563
+ DialogInterface = android . content . DialogInterface ;
564
+ }
542
565
alert . setItems (
543
566
options . actions ,
544
567
new DialogInterface . OnClickListener ( {
0 commit comments