Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit e378f60

Browse files
Fix themes
Material3 is now used regardless of API version. Switches should no longer be invisible for < a12 Oh, and fixed a couple crashes and yes i did pet that kitten Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 6747c11 commit e378f60

File tree

6 files changed

+55
-22
lines changed

6 files changed

+55
-22
lines changed

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ dependencies {
252252
implementation "dev.rikka.rikkax.insets:insets:1.3.0"
253253
implementation 'com.github.Dimezis:BlurView:version-2.0.2'
254254
implementation 'com.github.KieronQuinn:MonetCompat:0.4.1'
255-
implementation 'com.github.Fox2Code:FoxCompat:0.1.7'
255+
implementation 'com.github.Fox2Code:FoxCompat:0.1.8'
256256
// Update the version code in the root build.gradle
257257
implementation "com.mikepenz:aboutlibraries:${latestAboutLibsRelease}"
258258

@@ -261,8 +261,8 @@ dependencies {
261261
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10'
262262
implementation 'com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.10'
263263
// Chromium cronet from androidacy
264-
implementation 'com.androidacy:cronet-common:108.0.5359.95'
265-
implementation 'com.androidacy:cronet-native:108.0.5359.95'
264+
implementation 'com.androidacy:cronet-common:108.0.5359.125'
265+
implementation 'com.androidacy:cronet-native:108.0.5359.125'
266266
// Force prefer our own version of Cronet
267267
implementation 'com.github.topjohnwu.libsu:io:5.0.1'
268268
implementation 'com.github.Fox2Code:RosettaX:1.0.9'

app/src/main/java/com/fox2code/mmm/MainActivity.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ protected void onCreate(Bundle savedInstanceState) {
110110
try {
111111
ExperimentalCronetEngine cronetEngine = new ExperimentalCronetEngine.Builder(this).build();
112112
CronetURLStreamHandlerFactory cronetURLStreamHandlerFactory = new CronetURLStreamHandlerFactory(cronetEngine);
113-
URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory);
113+
try {
114+
URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory);
115+
} catch (Error e) {
116+
Log.e(TAG, "Failed to install Cronet URLStreamHandlerFactory", e);
117+
}
114118
urlFactoryInstalled = true;
115119
} catch (Throwable t) {
116120
Log.e(TAG, "Failed to install CronetURLStreamHandlerFactory", t);
@@ -702,28 +706,31 @@ private void doSetupNow() {
702706
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Do setup now");
703707
// Check if this is the first launch
704708
SharedPreferences prefs = MainApplication.getSharedPreferences();
705-
boolean firstLaunch = MainApplication.getBootSharedPreferences().getBoolean("first_launch", true);
709+
boolean firstLaunch = MainApplication.getSharedPreferences().getBoolean("first_launch", true);
706710
if (BuildConfig.DEBUG) Log.d("Noodle", "First launch: " + firstLaunch);
707711
if (firstLaunch) {
708712
// Show setup box
709713
runOnUiThread(() -> {
710714
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
711715
builder.setCancelable(false);
712716
builder.setTitle(R.string.setup_title);
717+
// Create a view from R.xml.setup_box
713718
View view = getLayoutInflater().inflate(R.layout.setup_box, null);
714719
builder.setView(view);
720+
// For sdk >= 31, use MaterialSwitch instead of MaterialSwitch
715721
// For now, we'll just have the positive button save the preferences and dismiss the dialog
716722
builder.setPositiveButton(R.string.setup_button, (dialog, which) -> {
717723
// Set the preferences
718-
prefs.edit().putBoolean("pref_background_update_check", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).commit();
724+
prefs.edit().putBoolean("pref_background_update_check",
725+
((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).commit();
719726
prefs.edit().putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked()).commit();
720727
prefs.edit().putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked()).commit();
721728
prefs.edit().putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit();
722729
if (BuildConfig.DEBUG) {
723730
Log.d("MainActivity", String.format("Background update check: %s, Crash reporting: %s, Androidacy repo: %s, Magisk alt repo: %s", prefs.getBoolean("pref_background_update_check", false), prefs.getBoolean("pref_crash_reporting", false), prefs.getBoolean("pref_androidacy_repo_enabled", false), prefs.getBoolean("pref_magisk_alt_repo_enabled", false)));
724731
}
725732
// Set pref_first_launch to false
726-
MainApplication.getBootSharedPreferences().edit().putBoolean("first_launch", false).commit();
733+
MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).commit();
727734
// Restart the app
728735
Intent intent = new Intent(this, MainActivity.class);
729736
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -732,7 +739,7 @@ private void doSetupNow() {
732739
ensurePermissions();
733740
});
734741
builder.setNegativeButton(R.string.setup_button_skip, (dialog, which) -> {
735-
MainApplication.getBootSharedPreferences().edit().putBoolean("first_launch", false).commit();
742+
MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).commit();
736743
dialog.dismiss();
737744
ensurePermissions();
738745
});

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fox2code.mmm.settings;
22

3+
import static com.fox2code.mmm.settings.SettingsActivity.RepoFragment.applyMaterial3;
34
import static java.lang.Integer.parseInt;
45

56
import android.annotation.SuppressLint;
@@ -35,6 +36,7 @@
3536
import androidx.preference.ListPreference;
3637
import androidx.preference.Preference;
3738
import androidx.preference.PreferenceFragmentCompat;
39+
import androidx.preference.PreferenceGroup;
3840
import androidx.preference.SwitchPreferenceCompat;
3941
import androidx.preference.TwoStatePreference;
4042

@@ -169,6 +171,7 @@ public static class SettingsFragment extends PreferenceFragmentCompat implements
169171
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
170172
getPreferenceManager().setSharedPreferencesName("mmm");
171173
setPreferencesFromResource(R.xml.root_preferences, rootKey);
174+
applyMaterial3(getPreferenceScreen());
172175
findPreference("pref_manage_repos").setOnPreferenceClickListener(p -> {
173176
devModeStep = 0;
174177
openFragment(new RepoFragment(), R.string.manage_repos_pref);
@@ -602,14 +605,18 @@ private int currentLanguageLevel() {
602605
public static class RepoFragment extends PreferenceFragmentCompat {
603606
private static final int CUSTOM_REPO_ENTRIES = 5;
604607

605-
@Override
606-
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
607-
getPreferenceManager().setSharedPreferencesName("mmm");
608-
setPreferencesFromResource(R.xml.repo_preferences, rootKey);
609-
setRepoData(RepoManager.MAGISK_ALT_REPO);
610-
setRepoData(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT);
611-
updateCustomRepoList(true);
612-
onCreatePreferencesAndroidacy();
608+
// *says proudly* I stole it
609+
// namely, from https://github.com/NeoApplications/Neo-Wellbeing/blob/9fca4136263780c022f9ec6433c0b43d159166db/app/src/main/java/org/eu/droid_ng/wellbeing/prefs/SettingsActivity.java#L101
610+
public static void applyMaterial3(Preference p) {
611+
if (p instanceof PreferenceGroup) {
612+
PreferenceGroup pg = (PreferenceGroup) p;
613+
for (int i = 0; i < pg.getPreferenceCount(); i++) {
614+
applyMaterial3(pg.getPreference(i));
615+
}
616+
}
617+
if (p instanceof SwitchPreferenceCompat) {
618+
p.setWidgetLayoutResource(R.layout.preference_material_switch);
619+
}
613620
}
614621

615622
@SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"})
@@ -1038,5 +1045,16 @@ private void hideRepoData(String preferenceName) {
10381045
if (preference == null) return;
10391046
preference.setVisible(false);
10401047
}
1048+
1049+
@Override
1050+
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
1051+
getPreferenceManager().setSharedPreferencesName("mmm");
1052+
setPreferencesFromResource(R.xml.repo_preferences, rootKey);
1053+
applyMaterial3(getPreferenceScreen());
1054+
setRepoData(RepoManager.MAGISK_ALT_REPO);
1055+
setRepoData(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT);
1056+
updateCustomRepoList(true);
1057+
onCreatePreferencesAndroidacy();
1058+
}
10411059
}
10421060
}

app/src/main/java/com/fox2code/mmm/utils/Http.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public class Http {
143143
// init cronet
144144
try {
145145
// Load the cronet library
146-
System.loadLibrary("cronet.108.0.5359.95");
147146
CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication);
148147
builder.enableBrotli(true);
149148
builder.enableHttp2(true);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Shamelessly stolen from https://github.com/NeoApplications/Neo-Wellbeing/blob/master/app/src/main/res/layout/preference_material_switch.xml -->
3+
<com.google.android.material.materialswitch.MaterialSwitch xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:id="@+id/switchWidget"
5+
android:layout_width="wrap_content"
6+
android:layout_height="wrap_content"
7+
android:background="@null"
8+
android:clickable="false"
9+
android:focusable="false" />

app/src/main/res/values/themes.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
2-
<style name="Theme.MagiskModuleManager.Light" parent="Theme.MaterialComponents.Light">
2+
<style name="Theme.MagiskModuleManager.Light" parent="Theme.Material3.Light">
33
<item name="android:isLightTheme"
44
tools:targetApi="q">true</item>
55
<item name="isLightTheme">true</item>
@@ -14,7 +14,7 @@
1414
<!-- Status bar color. -->
1515
<item name="android:statusBarColor">@color/status_bar_color</item>
1616
<item name="android:navigationBarColor">@color/transparent</item>
17-
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
17+
<item name="android:windowLightStatusBar" >true</item>
1818
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
1919
<!-- Customize your theme here. -->
2020
<item name="android:windowActivityTransitions">true</item>
@@ -31,7 +31,7 @@
3131
<item name="chipStyle">@style/Widget.Material.Chip.Choice.Light</item>
3232
</style>
3333

34-
<style name="Widget.Material.Chip.Choice.Light" parent="Widget.MaterialComponents.Chip.Action">
34+
<style name="Widget.Material.Chip.Choice.Light" parent="Widget.Material3.Chip.Choice.Light">
3535
<item name="chipBackgroundColor">@color/light_chipBackgroundColor</item>
3636
<item name="chipStrokeWidth">0dp</item>
3737
<item name="chipIconTint">@color/black</item>
@@ -51,7 +51,7 @@
5151
<item name="windowNoTitle">true</item>
5252
</style>
5353

54-
<style name="Theme.MagiskModuleManager.Dark" parent="Theme.MaterialComponents">
54+
<style name="Theme.MagiskModuleManager.Dark" parent="Theme.Material3.Dark">
5555
<item name="android:isLightTheme"
5656
tools:targetApi="q">false</item>
5757
<item name="isLightTheme">false</item>
@@ -66,7 +66,7 @@
6666
<!-- Status bar color. -->
6767
<item name="android:statusBarColor">@color/status_bar_color</item>
6868
<item name="android:navigationBarColor">@color/transparent</item>
69-
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
69+
<item name="android:windowLightStatusBar" >false</item>
7070
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
7171
<!-- Customize your theme here. -->
7272
<item name="android:windowActivityTransitions">true</item>

0 commit comments

Comments
 (0)