Skip to content

Commit 312b6dc

Browse files
feat: Use modern style settings dialogs (#5109)
Co-authored-by: LisoUseInAIKyrios <[email protected]>
1 parent 442f5f5 commit 312b6dc

File tree

99 files changed

+2344
-1325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2344
-1325
lines changed

extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import android.annotation.SuppressLint;
77
import android.app.Activity;
8-
import android.app.AlertDialog;
8+
import android.app.Dialog;
99
import android.app.SearchManager;
1010
import android.content.Context;
1111
import android.content.DialogInterface;
@@ -15,6 +15,8 @@
1515
import android.os.Build;
1616
import android.os.PowerManager;
1717
import android.provider.Settings;
18+
import android.util.Pair;
19+
import android.widget.LinearLayout;
1820

1921
import androidx.annotation.Nullable;
2022
import androidx.annotation.RequiresApi;
@@ -26,6 +28,7 @@
2628

2729
import app.revanced.extension.shared.requests.Requester;
2830
import app.revanced.extension.shared.requests.Route;
31+
import app.revanced.extension.shared.Utils;
2932

3033
@SuppressWarnings("unused")
3134
public class GmsCoreSupport {
@@ -78,13 +81,27 @@ private static void showBatteryOptimizationDialog(Activity context,
7881
// Use a delay to allow the activity to finish initializing.
7982
// Otherwise, if device is in dark mode the dialog is shown with wrong color scheme.
8083
Utils.runOnMainThreadDelayed(() -> {
84+
// Create the custom dialog.
85+
Pair<Dialog, LinearLayout> dialogPair = Utils.createCustomDialog(
86+
context,
87+
str("gms_core_dialog_title"), // Title.
88+
str(dialogMessageRef), // Message.
89+
null, // No EditText.
90+
str(positiveButtonTextRef), // OK button text.
91+
() -> onPositiveClickListener.onClick(null, 0), // Convert DialogInterface.OnClickListener to Runnable.
92+
null, // No Cancel button action.
93+
null, // No Neutral button text.
94+
null, // No Neutral button action.
95+
true // Dismiss dialog when onNeutralClick.
96+
);
97+
98+
Dialog dialog = dialogPair.first;
99+
81100
// Do not set cancelable to false, to allow using back button to skip the action,
82101
// just in case the battery change can never be satisfied.
83-
var dialog = new AlertDialog.Builder(context)
84-
.setTitle(str("gms_core_dialog_title"))
85-
.setMessage(str(dialogMessageRef))
86-
.setPositiveButton(str(positiveButtonTextRef), onPositiveClickListener)
87-
.create();
102+
dialog.setCancelable(true);
103+
104+
// Show the dialog
88105
Utils.showDialog(context, dialog);
89106
}, 100);
90107
}

0 commit comments

Comments
 (0)