Skip to content

Commit

Permalink
fix(android): make dialog color options take effect and update API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Bliznyuk authored Jul 11, 2020
1 parent 60706d8 commit e40446f
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/dialogs/dialogs.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,20 @@ function createAlertDialogBuilder(options?: DialogOptions & MDCAlertControlerOpt
}

function showDialog(dlg: androidx.appcompat.app.AlertDialog, options: DialogOptions & MDCAlertControlerOptions, resolve?: Function) {
dlg.show();

const packageName = dlg.getContext().getPackageName();

if (options.titleColor) {
const textViewId = dlg.getContext().getResources().getIdentifier('android:id/alertTitle', null, null);
const textViewId = dlg.getContext().getResources().getIdentifier('alertTitle', 'id', packageName);
if (textViewId) {
const tv = <android.widget.TextView>dlg.findViewById(textViewId);
if (tv) {
tv.setTextColor(options.titleColor.android);
}
}
if (options.messageColor) {
const messageTextViewId = dlg.getContext().getResources().getIdentifier('android:id/message', null, null);
const messageTextViewId = dlg.getContext().getResources().getIdentifier('message', 'id', packageName);
if (messageTextViewId) {
const messageTextView = <android.widget.TextView>dlg.findViewById(messageTextViewId);
if (messageTextView) {
Expand Down Expand Up @@ -128,22 +132,18 @@ function showDialog(dlg: androidx.appcompat.app.AlertDialog, options: DialogOpti
// let { color, backgroundColor } = getButtonColors();

if (options.buttonInkColor || options.buttonTitleColor) {
let buttons: android.widget.Button[] = [];
for (let i = 0; i < 3; i++) {
let id = dlg
.getContext()
.getResources()
.getIdentifier('android:id/button' + i, null, null);
buttons[i] = <android.widget.Button>dlg.findViewById(id);
}
let buttons: android.widget.Button[] = [
dlg.getButton(android.content.DialogInterface.BUTTON_POSITIVE),
dlg.getButton(android.content.DialogInterface.BUTTON_NEGATIVE),
dlg.getButton(android.content.DialogInterface.BUTTON_NEUTRAL)
];

buttons.forEach((button) => {
if (button) {
button.setTextColor((options.buttonInkColor || options.buttonTitleColor).android);
}
});
}
dlg.show();
return dlg;
}

Expand Down Expand Up @@ -203,7 +203,6 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
dlg.setButton(
android.content.DialogInterface.BUTTON_POSITIVE,
options.okButtonText,
null,
new android.content.DialogInterface.OnClickListener({
onClick: function (dialog: android.content.DialogInterface, id: number) {
onDone(true, dialog);
Expand All @@ -219,7 +218,6 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
dlg.setButton(
android.content.DialogInterface.BUTTON_NEGATIVE,
options.cancelButtonText,
null,
new android.content.DialogInterface.OnClickListener({
onClick: function (dialog: android.content.DialogInterface, id: number) {
onDone(false, dialog);
Expand All @@ -240,7 +238,6 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
dlg.setButton(
android.content.DialogInterface.BUTTON_NEUTRAL,
options.neutralButtonText,
null,
new android.content.DialogInterface.OnClickListener({
onClick: function (dialog: android.content.DialogInterface, id: number) {
onDone(undefined, dialog);
Expand Down

0 comments on commit e40446f

Please sign in to comment.