Skip to content

Commit 0ac7808

Browse files
Alexander-Bliznyukabliznyuk
authored and
abliznyuk
committed
fix(android): make dialog color options take effect and update API calls
1 parent c9bf329 commit 0ac7808

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/dialogs/dialogs.android.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,20 @@ function createAlertDialogBuilder(options?: DialogOptions & MDCAlertControlerOpt
8282
}
8383

8484
function showDialog(dlg: androidx.appcompat.app.AlertDialog, options: DialogOptions & MDCAlertControlerOptions, resolve?: Function) {
85+
dlg.show();
86+
87+
const packageName = dlg.getContext().getPackageName();
88+
8589
if (options.titleColor) {
86-
const textViewId = dlg.getContext().getResources().getIdentifier('android:id/alertTitle', null, null);
90+
const textViewId = dlg.getContext().getResources().getIdentifier('alertTitle', 'id', packageName);
8791
if (textViewId) {
8892
const tv = <android.widget.TextView>dlg.findViewById(textViewId);
8993
if (tv) {
9094
tv.setTextColor(options.titleColor.android);
9195
}
9296
}
9397
if (options.messageColor) {
94-
const messageTextViewId = dlg.getContext().getResources().getIdentifier('android:id/message', null, null);
98+
const messageTextViewId = dlg.getContext().getResources().getIdentifier('message', 'id', packageName);
9599
if (messageTextViewId) {
96100
const messageTextView = <android.widget.TextView>dlg.findViewById(messageTextViewId);
97101
if (messageTextView) {
@@ -128,22 +132,18 @@ function showDialog(dlg: androidx.appcompat.app.AlertDialog, options: DialogOpti
128132
// let { color, backgroundColor } = getButtonColors();
129133

130134
if (options.buttonInkColor || options.buttonTitleColor) {
131-
let buttons: android.widget.Button[] = [];
132-
for (let i = 0; i < 3; i++) {
133-
let id = dlg
134-
.getContext()
135-
.getResources()
136-
.getIdentifier('android:id/button' + i, null, null);
137-
buttons[i] = <android.widget.Button>dlg.findViewById(id);
138-
}
135+
let buttons: android.widget.Button[] = [
136+
dlg.getButton(android.content.DialogInterface.BUTTON_POSITIVE),
137+
dlg.getButton(android.content.DialogInterface.BUTTON_NEGATIVE),
138+
dlg.getButton(android.content.DialogInterface.BUTTON_NEUTRAL)
139+
];
139140

140141
buttons.forEach((button) => {
141142
if (button) {
142143
button.setTextColor((options.buttonInkColor || options.buttonTitleColor).android);
143144
}
144145
});
145146
}
146-
dlg.show();
147147
return dlg;
148148
}
149149

@@ -203,7 +203,6 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
203203
dlg.setButton(
204204
android.content.DialogInterface.BUTTON_POSITIVE,
205205
options.okButtonText,
206-
null,
207206
new android.content.DialogInterface.OnClickListener({
208207
onClick: function (dialog: android.content.DialogInterface, id: number) {
209208
onDone(true, dialog);
@@ -219,7 +218,6 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
219218
dlg.setButton(
220219
android.content.DialogInterface.BUTTON_NEGATIVE,
221220
options.cancelButtonText,
222-
null,
223221
new android.content.DialogInterface.OnClickListener({
224222
onClick: function (dialog: android.content.DialogInterface, id: number) {
225223
onDone(false, dialog);
@@ -240,7 +238,6 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
240238
dlg.setButton(
241239
android.content.DialogInterface.BUTTON_NEUTRAL,
242240
options.neutralButtonText,
243-
null,
244241
new android.content.DialogInterface.OnClickListener({
245242
onClick: function (dialog: android.content.DialogInterface, id: number) {
246243
onDone(undefined, dialog);

0 commit comments

Comments
 (0)