@@ -11,27 +11,27 @@ var STRING = "string",
11
11
OK = "OK" ,
12
12
CANCEL = "Cancel" ;
13
13
14
- function createAlertDialog ( options : dialogs . DialogOptions ) : android . app . AlertDialog . Builder {
14
+ function createAlertDialog ( message : string , options : dialogs . DialogOptions ) : android . app . AlertDialog . Builder {
15
15
var alert = new android . app . AlertDialog . Builder ( appmodule . android . foregroundActivity ) ;
16
- alert . setTitle ( options . title ) ;
17
- alert . setMessage ( options . message ) ;
16
+ alert . setTitle ( options && options . title ? options . title : "" ) ;
17
+ alert . setMessage ( message ) ;
18
18
return alert ;
19
19
}
20
20
21
21
function addButtonsToAlertDialog ( alert : android . app . AlertDialog . Builder , options : dialogs . ConfirmOptions ,
22
22
okCallback : Function , cancelCallback ?: Function , neutralCallback ?: Function ) : void {
23
23
24
- if ( options . okButtonName ) {
25
- alert . setPositiveButton ( options . okButtonName , new android . content . DialogInterface . OnClickListener ( {
24
+ if ( options . okButtonText ) {
25
+ alert . setPositiveButton ( options . okButtonText , new android . content . DialogInterface . OnClickListener ( {
26
26
onClick : function ( dialog : android . content . DialogInterface , id : number ) {
27
27
dialog . cancel ( ) ;
28
28
okCallback ( ) ;
29
29
}
30
30
} ) ) ;
31
31
}
32
32
33
- if ( options . cancelButtonName ) {
34
- alert . setNegativeButton ( options . cancelButtonName , new android . content . DialogInterface . OnClickListener ( {
33
+ if ( options . cancelButtonText ) {
34
+ alert . setNegativeButton ( options . cancelButtonText , new android . content . DialogInterface . OnClickListener ( {
35
35
onClick : function ( dialog : android . content . DialogInterface , id : number ) {
36
36
dialog . cancel ( ) ;
37
37
if ( cancelCallback ) {
@@ -41,8 +41,8 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options
41
41
} ) ) ;
42
42
}
43
43
44
- if ( options . otherButtonName ) {
45
- alert . setNeutralButton ( options . otherButtonName , new android . content . DialogInterface . OnClickListener ( {
44
+ if ( options . otherButtonText ) {
45
+ alert . setNeutralButton ( options . otherButtonText , new android . content . DialogInterface . OnClickListener ( {
46
46
onClick : function ( dialog : android . content . DialogInterface , id : number ) {
47
47
dialog . cancel ( ) ;
48
48
if ( neutralCallback ) {
@@ -53,14 +53,12 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options
53
53
}
54
54
}
55
55
56
- export function alert ( arg : any ) : promises . Promise < void > {
56
+ export function alert ( message : string , options = { title : ALERT , buttonText : OK } ) : promises . Promise < void > {
57
57
var d = promises . defer < void > ( ) ;
58
58
try {
59
- var options = typeof arg === STRING ? { message : arg , title : ALERT , buttonName : OK } : arg
59
+ var alert = createAlertDialog ( message , options ) ;
60
60
61
- var alert = createAlertDialog ( options ) ;
62
-
63
- alert . setPositiveButton ( options . buttonName , new android . content . DialogInterface . OnClickListener ( {
61
+ alert . setPositiveButton ( options . buttonText , new android . content . DialogInterface . OnClickListener ( {
64
62
onClick : function ( dialog : android . content . DialogInterface , id : number ) {
65
63
dialog . cancel ( ) ;
66
64
d . resolve ( ) ;
@@ -76,12 +74,10 @@ export function alert(arg: any): promises.Promise<void> {
76
74
return d . promise ( ) ;
77
75
}
78
76
79
- export function confirm ( arg : any ) : promises . Promise < boolean > {
77
+ export function confirm ( message : string , options = { title : ALERT , okButtonText : OK , cancelButtonText : CANCEL } ) : promises . Promise < boolean > {
80
78
var d = promises . defer < boolean > ( ) ;
81
79
try {
82
- var options = typeof arg === STRING ? { message : arg , title : ALERT , okButtonName : OK , cancelButtonName : CANCEL } : arg
83
-
84
- var alert = createAlertDialog ( options ) ;
80
+ var alert = createAlertDialog ( message , options ) ;
85
81
86
82
addButtonsToAlertDialog ( alert , options , function ( ) { d . resolve ( true ) ; } , function ( ) { d . resolve ( false ) ; } , function ( ) { d . resolve ( ) ; } ) ;
87
83
@@ -94,12 +90,10 @@ export function confirm(arg: any): promises.Promise<boolean> {
94
90
return d . promise ( ) ;
95
91
}
96
92
97
- export function prompt ( arg : any ) : promises . Promise < dialogs . PromptResult > {
93
+ export function prompt ( message : string , options = { title : ALERT , okButtonText : OK , cancelButtonText : CANCEL , defaultText : "" } ) : promises . Promise < dialogs . PromptResult > {
98
94
var d = promises . defer < dialogs . PromptResult > ( ) ;
99
95
try {
100
- var options = typeof arg === STRING ? { message : arg , title : ALERT , okButtonName : OK , cancelButtonName : CANCEL } : arg
101
-
102
- var alert = createAlertDialog ( options ) ;
96
+ var alert = createAlertDialog ( message , options ) ;
103
97
104
98
var input = new android . widget . EditText ( appmodule . android . context ) ;
105
99
input . setText ( options . defaultText ? options . defaultText : "" ) ;
0 commit comments