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>
pull/27/head
androidacy-user 3 years ago
parent 6747c11b5b
commit e378f604b6

@ -252,7 +252,7 @@ dependencies {
implementation "dev.rikka.rikkax.insets:insets:1.3.0" implementation "dev.rikka.rikkax.insets:insets:1.3.0"
implementation 'com.github.Dimezis:BlurView:version-2.0.2' implementation 'com.github.Dimezis:BlurView:version-2.0.2'
implementation 'com.github.KieronQuinn:MonetCompat:0.4.1' implementation 'com.github.KieronQuinn:MonetCompat:0.4.1'
implementation 'com.github.Fox2Code:FoxCompat:0.1.7' implementation 'com.github.Fox2Code:FoxCompat:0.1.8'
// Update the version code in the root build.gradle // Update the version code in the root build.gradle
implementation "com.mikepenz:aboutlibraries:${latestAboutLibsRelease}" implementation "com.mikepenz:aboutlibraries:${latestAboutLibsRelease}"
@ -261,8 +261,8 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10'
implementation 'com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.10' implementation 'com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.10'
// Chromium cronet from androidacy // Chromium cronet from androidacy
implementation 'com.androidacy:cronet-common:108.0.5359.95' implementation 'com.androidacy:cronet-common:108.0.5359.125'
implementation 'com.androidacy:cronet-native:108.0.5359.95' implementation 'com.androidacy:cronet-native:108.0.5359.125'
// Force prefer our own version of Cronet // Force prefer our own version of Cronet
implementation 'com.github.topjohnwu.libsu:io:5.0.1' implementation 'com.github.topjohnwu.libsu:io:5.0.1'
implementation 'com.github.Fox2Code:RosettaX:1.0.9' implementation 'com.github.Fox2Code:RosettaX:1.0.9'

@ -110,7 +110,11 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
try { try {
ExperimentalCronetEngine cronetEngine = new ExperimentalCronetEngine.Builder(this).build(); ExperimentalCronetEngine cronetEngine = new ExperimentalCronetEngine.Builder(this).build();
CronetURLStreamHandlerFactory cronetURLStreamHandlerFactory = new CronetURLStreamHandlerFactory(cronetEngine); CronetURLStreamHandlerFactory cronetURLStreamHandlerFactory = new CronetURLStreamHandlerFactory(cronetEngine);
try {
URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory); URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory);
} catch (Error e) {
Log.e(TAG, "Failed to install Cronet URLStreamHandlerFactory", e);
}
urlFactoryInstalled = true; urlFactoryInstalled = true;
} catch (Throwable t) { } catch (Throwable t) {
Log.e(TAG, "Failed to install CronetURLStreamHandlerFactory", t); Log.e(TAG, "Failed to install CronetURLStreamHandlerFactory", t);
@ -702,7 +706,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Do setup now"); if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Do setup now");
// Check if this is the first launch // Check if this is the first launch
SharedPreferences prefs = MainApplication.getSharedPreferences(); SharedPreferences prefs = MainApplication.getSharedPreferences();
boolean firstLaunch = MainApplication.getBootSharedPreferences().getBoolean("first_launch", true); boolean firstLaunch = MainApplication.getSharedPreferences().getBoolean("first_launch", true);
if (BuildConfig.DEBUG) Log.d("Noodle", "First launch: " + firstLaunch); if (BuildConfig.DEBUG) Log.d("Noodle", "First launch: " + firstLaunch);
if (firstLaunch) { if (firstLaunch) {
// Show setup box // Show setup box
@ -710,12 +714,15 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
builder.setCancelable(false); builder.setCancelable(false);
builder.setTitle(R.string.setup_title); builder.setTitle(R.string.setup_title);
// Create a view from R.xml.setup_box
View view = getLayoutInflater().inflate(R.layout.setup_box, null); View view = getLayoutInflater().inflate(R.layout.setup_box, null);
builder.setView(view); builder.setView(view);
// For sdk >= 31, use MaterialSwitch instead of MaterialSwitch
// For now, we'll just have the positive button save the preferences and dismiss the dialog // For now, we'll just have the positive button save the preferences and dismiss the dialog
builder.setPositiveButton(R.string.setup_button, (dialog, which) -> { builder.setPositiveButton(R.string.setup_button, (dialog, which) -> {
// Set the preferences // Set the preferences
prefs.edit().putBoolean("pref_background_update_check", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).commit(); prefs.edit().putBoolean("pref_background_update_check",
((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).commit();
prefs.edit().putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked()).commit(); prefs.edit().putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked()).commit();
prefs.edit().putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked()).commit(); prefs.edit().putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked()).commit();
prefs.edit().putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit(); prefs.edit().putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit();
@ -723,7 +730,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
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))); 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)));
} }
// Set pref_first_launch to false // Set pref_first_launch to false
MainApplication.getBootSharedPreferences().edit().putBoolean("first_launch", false).commit(); MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).commit();
// Restart the app // Restart the app
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -732,7 +739,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
ensurePermissions(); ensurePermissions();
}); });
builder.setNegativeButton(R.string.setup_button_skip, (dialog, which) -> { builder.setNegativeButton(R.string.setup_button_skip, (dialog, which) -> {
MainApplication.getBootSharedPreferences().edit().putBoolean("first_launch", false).commit(); MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).commit();
dialog.dismiss(); dialog.dismiss();
ensurePermissions(); ensurePermissions();
}); });

@ -1,5 +1,6 @@
package com.fox2code.mmm.settings; package com.fox2code.mmm.settings;
import static com.fox2code.mmm.settings.SettingsActivity.RepoFragment.applyMaterial3;
import static java.lang.Integer.parseInt; import static java.lang.Integer.parseInt;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -35,6 +36,7 @@ import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceGroup;
import androidx.preference.SwitchPreferenceCompat; import androidx.preference.SwitchPreferenceCompat;
import androidx.preference.TwoStatePreference; import androidx.preference.TwoStatePreference;
@ -169,6 +171,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName("mmm"); getPreferenceManager().setSharedPreferencesName("mmm");
setPreferencesFromResource(R.xml.root_preferences, rootKey); setPreferencesFromResource(R.xml.root_preferences, rootKey);
applyMaterial3(getPreferenceScreen());
findPreference("pref_manage_repos").setOnPreferenceClickListener(p -> { findPreference("pref_manage_repos").setOnPreferenceClickListener(p -> {
devModeStep = 0; devModeStep = 0;
openFragment(new RepoFragment(), R.string.manage_repos_pref); openFragment(new RepoFragment(), R.string.manage_repos_pref);
@ -602,14 +605,18 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
public static class RepoFragment extends PreferenceFragmentCompat { public static class RepoFragment extends PreferenceFragmentCompat {
private static final int CUSTOM_REPO_ENTRIES = 5; private static final int CUSTOM_REPO_ENTRIES = 5;
@Override // *says proudly* I stole it
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { // namely, from https://github.com/NeoApplications/Neo-Wellbeing/blob/9fca4136263780c022f9ec6433c0b43d159166db/app/src/main/java/org/eu/droid_ng/wellbeing/prefs/SettingsActivity.java#L101
getPreferenceManager().setSharedPreferencesName("mmm"); public static void applyMaterial3(Preference p) {
setPreferencesFromResource(R.xml.repo_preferences, rootKey); if (p instanceof PreferenceGroup) {
setRepoData(RepoManager.MAGISK_ALT_REPO); PreferenceGroup pg = (PreferenceGroup) p;
setRepoData(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT); for (int i = 0; i < pg.getPreferenceCount(); i++) {
updateCustomRepoList(true); applyMaterial3(pg.getPreference(i));
onCreatePreferencesAndroidacy(); }
}
if (p instanceof SwitchPreferenceCompat) {
p.setWidgetLayoutResource(R.layout.preference_material_switch);
}
} }
@SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"}) @SuppressLint({"RestrictedApi", "UnspecifiedImmutableFlag"})
@ -1038,5 +1045,16 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
if (preference == null) return; if (preference == null) return;
preference.setVisible(false); preference.setVisible(false);
} }
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName("mmm");
setPreferencesFromResource(R.xml.repo_preferences, rootKey);
applyMaterial3(getPreferenceScreen());
setRepoData(RepoManager.MAGISK_ALT_REPO);
setRepoData(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT);
updateCustomRepoList(true);
onCreatePreferencesAndroidacy();
}
} }
} }

@ -143,7 +143,6 @@ public class Http {
// init cronet // init cronet
try { try {
// Load the cronet library // Load the cronet library
System.loadLibrary("cronet.108.0.5359.95");
CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication); CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication);
builder.enableBrotli(true); builder.enableBrotli(true);
builder.enableHttp2(true); builder.enableHttp2(true);

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Shamelessly stolen from https://github.com/NeoApplications/Neo-Wellbeing/blob/master/app/src/main/res/layout/preference_material_switch.xml -->
<com.google.android.material.materialswitch.MaterialSwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false" />

@ -1,5 +1,5 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.MagiskModuleManager.Light" parent="Theme.MaterialComponents.Light"> <style name="Theme.MagiskModuleManager.Light" parent="Theme.Material3.Light">
<item name="android:isLightTheme" <item name="android:isLightTheme"
tools:targetApi="q">true</item> tools:targetApi="q">true</item>
<item name="isLightTheme">true</item> <item name="isLightTheme">true</item>
@ -14,7 +14,7 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor">@color/status_bar_color</item> <item name="android:statusBarColor">@color/status_bar_color</item>
<item name="android:navigationBarColor">@color/transparent</item> <item name="android:navigationBarColor">@color/transparent</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item> <item name="android:windowLightStatusBar" >true</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item> <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="android:windowActivityTransitions">true</item> <item name="android:windowActivityTransitions">true</item>
@ -31,7 +31,7 @@
<item name="chipStyle">@style/Widget.Material.Chip.Choice.Light</item> <item name="chipStyle">@style/Widget.Material.Chip.Choice.Light</item>
</style> </style>
<style name="Widget.Material.Chip.Choice.Light" parent="Widget.MaterialComponents.Chip.Action"> <style name="Widget.Material.Chip.Choice.Light" parent="Widget.Material3.Chip.Choice.Light">
<item name="chipBackgroundColor">@color/light_chipBackgroundColor</item> <item name="chipBackgroundColor">@color/light_chipBackgroundColor</item>
<item name="chipStrokeWidth">0dp</item> <item name="chipStrokeWidth">0dp</item>
<item name="chipIconTint">@color/black</item> <item name="chipIconTint">@color/black</item>
@ -51,7 +51,7 @@
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
</style> </style>
<style name="Theme.MagiskModuleManager.Dark" parent="Theme.MaterialComponents"> <style name="Theme.MagiskModuleManager.Dark" parent="Theme.Material3.Dark">
<item name="android:isLightTheme" <item name="android:isLightTheme"
tools:targetApi="q">false</item> tools:targetApi="q">false</item>
<item name="isLightTheme">false</item> <item name="isLightTheme">false</item>
@ -66,7 +66,7 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor">@color/status_bar_color</item> <item name="android:statusBarColor">@color/status_bar_color</item>
<item name="android:navigationBarColor">@color/transparent</item> <item name="android:navigationBarColor">@color/transparent</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item> <item name="android:windowLightStatusBar" >false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item> <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="android:windowActivityTransitions">true</item> <item name="android:windowActivityTransitions">true</item>

Loading…
Cancel
Save