From 033eabbc535ac4ad5f528eceba68ba874798e1a1 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 2 Jun 2023 19:19:43 +0930 Subject: [PATCH] Utilise dialog dsl in SettingsDialog --- .../securesms/permissions/Permissions.java | 18 +++------------- .../securesms/permissions/SettingsDialog.kt | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/permissions/Permissions.java b/app/src/main/java/org/thoughtcrime/securesms/permissions/Permissions.java index 8cda4ab95b..88ee67cb4d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/permissions/Permissions.java +++ b/app/src/main/java/org/thoughtcrime/securesms/permissions/Permissions.java @@ -255,7 +255,7 @@ public class Permissions { resultListener.onResult(permissions, grantResults, shouldShowRationaleDialog); } - private static Intent getApplicationSettingsIntent(@NonNull Context context) { + static Intent getApplicationSettingsIntent(@NonNull Context context) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", context.getPackageName(), null); @@ -352,20 +352,8 @@ public class Permissions { @Override public void run() { Context context = this.context.get(); - - if (context != null) { - AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.ThemeOverlay_Session_AlertDialog) - .setTitle(R.string.Permissions_permission_required) - .setMessage(message) - .setPositiveButton(R.string.Permissions_continue, (dialog, which) -> context.startActivity(getApplicationSettingsIntent(context))) - .setNegativeButton(android.R.string.cancel, null) - .create(); - Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); - if (positiveButton != null) { - positiveButton.setContentDescription(context.getString(R.string.AccessibilityId_continue)); - } - alertDialog.show(); - } + if (context == null) return; + SettingsDialog.show(context, message); } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt new file mode 100644 index 0000000000..a4efd8d870 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt @@ -0,0 +1,21 @@ +package org.thoughtcrime.securesms.permissions + +import android.content.Context +import network.loki.messenger.R +import org.thoughtcrime.securesms.showSessionDialog + +class SettingsDialog { + companion object { + @JvmStatic + fun show(context: Context, message: String) { + context.showSessionDialog { + title(R.string.Permissions_permission_required) + text(message) + button(R.string.Permissions_continue, R.string.AccessibilityId_continue) { + context.startActivity(Permissions.getApplicationSettingsIntent(context)) + } + cancelButton() + } + } + } +}