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

Commit 3c990bf

Browse files
Fixes for transparent theme and setup
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 9a79029 commit 3c990bf

File tree

10 files changed

+187
-109
lines changed

10 files changed

+187
-109
lines changed

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

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.widget.CheckBox;
2323
import android.widget.EditText;
2424
import android.widget.LinearLayout;
25+
import android.widget.RadioGroup;
2526
import android.widget.TextView;
2627
import android.widget.Toast;
2728

@@ -116,20 +117,20 @@ protected void onCreate(Bundle savedInstanceState) {
116117
URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory);
117118
} catch (
118119
Error e) {
119-
Log.e(TAG, "Failed to install Cronet URLStreamHandlerFactory", e);
120+
Log.e(TAG, "Failed to install Cronet URLStreamHandlerFactory");
120121
}
121122
urlFactoryInstalled = true;
122123
} catch (
123124
Throwable t) {
124-
Log.e(TAG, "Failed to install CronetURLStreamHandlerFactory", t);
125+
Log.e(TAG, "Failed to install CronetURLStreamHandlerFactory - other");
125126
}
126127
}
127128
if (doSetupRestarting) {
128129
doSetupRestarting = false;
129130
}
130131
BackgroundUpdateChecker.onMainActivityCreate(this);
131132
super.onCreate(savedInstanceState);
132-
if (!MainApplication.getSharedPreferences().getBoolean("first_run", true)) {
133+
if (!MainApplication.getSharedPreferences().getBoolean("first_time_user", true)) {
133134
this.setActionBarExtraMenuButton(R.drawable.ic_baseline_settings_24, v -> {
134135
IntentHelper.startActivity(this, SettingsActivity.class);
135136
return true;
@@ -735,10 +736,10 @@ private void ensurePermissions() {
735736
@SuppressLint({"InflateParams", "RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref"})
736737
private void checkShowInitialSetup() {
737738
if (BuildConfig.DEBUG)
738-
Log.i("SetupWizard", "Do setup now");
739+
Log.i("SetupWizard", "Checking if we need to run setup");
739740
// Check if this is the first launch
740741
SharedPreferences prefs = MainApplication.getSharedPreferences();
741-
boolean firstLaunch = prefs.getBoolean("first_launch", true);
742+
boolean firstLaunch = prefs.getBoolean("first_time_user", true);
742743
if (BuildConfig.DEBUG)
743744
Log.i("SetupWizard", "First launch: " + firstLaunch);
744745
if (firstLaunch) {
@@ -759,31 +760,72 @@ private void checkShowInitialSetup() {
759760
// Repos are a little harder, as the enabled_repos build config is an arraylist
760761
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_androidacy_repo))).setChecked(BuildConfig.ENABLED_REPOS.contains("androidacy_repo"));
761762
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_magisk_alt_repo))).setChecked(BuildConfig.ENABLED_REPOS.contains("magisk_alt_repo"));
763+
// On debug builds, log when a switch is toggled
764+
if (BuildConfig.DEBUG) {
765+
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_background_update_check))).setOnCheckedChangeListener((buttonView, isChecked) -> Log.i("SetupWizard", "Background Update Check: " + isChecked));
766+
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_crash_reporting))).setOnCheckedChangeListener((buttonView, isChecked) -> Log.i("SetupWizard", "Crash Reporting: " + isChecked));
767+
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_androidacy_repo))).setOnCheckedChangeListener((buttonView, isChecked) -> Log.i("SetupWizard", "Androidacy Repo: " + isChecked));
768+
((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_magisk_alt_repo))).setOnCheckedChangeListener((buttonView, isChecked) -> Log.i("SetupWizard", "Magisk Alt Repo: " + isChecked));
769+
}
762770
// Set up the buttons
763771
// Cancel button
764772
MaterialButton cancelButton = view.findViewById(R.id.setup_cancel);
765773
cancelButton.setText(R.string.cancel);
766774
cancelButton.setOnClickListener(v -> {
767775
// Set first launch to false and finish the activity
768-
prefs.edit().putBoolean("first_launch", false).commit();
776+
prefs.edit().putBoolean("first_time_user", false).commit();
769777
finish();
778+
startActivity(getIntent());
770779
});
771780
// Setup button
772781
MaterialButton setupButton = view.findViewById(R.id.setup_continue);
773-
setupButton.setText(R.string.setup_button);
774782
setupButton.setOnClickListener(v -> {
775783
// Set first launch to false
776-
prefs.edit().putBoolean("first_launch", false).commit();
784+
// get instance of editor
785+
SharedPreferences.Editor editor = prefs.edit();
786+
editor.putBoolean("first_time_user", false);
777787
// Set the background update check pref
778-
prefs.edit().putBoolean("pref_background_update_check", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_background_update_check))).isChecked()).commit();
788+
editor.putBoolean("pref_background_update_check", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_background_update_check))).isChecked());
779789
// Set the crash reporting pref
780-
prefs.edit().putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_crash_reporting))).isChecked()).commit();
790+
editor.putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_crash_reporting))).isChecked());
781791
// Set the repos
782792
// first pref_magisk_alt_repo_enabled then pref_androidacy_repo_enabled
783-
prefs.edit().putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit();
784-
prefs.edit().putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_androidacy_repo))).isChecked()).commit();
785-
// Finish the activity
793+
editor.putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_magisk_alt_repo))).isChecked());
794+
editor.putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(view.findViewById(R.id.setup_androidacy_repo))).isChecked());
795+
// Loop through the setup_theme radio group and set the theme pref
796+
RadioGroup themeRadioGroup = view.findViewById(R.id.setup_theme);
797+
int selectedTheme = themeRadioGroup.getCheckedRadioButtonId();
798+
// system, light, dark, black, and transparent_light
799+
if (selectedTheme == R.id.setup_theme_light) {
800+
editor.putString("pref_theme", "light");
801+
} else if (selectedTheme == R.id.setup_theme_dark) {
802+
editor.putString("pref_theme", "dark");
803+
} else if (selectedTheme == R.id.setup_theme_system) {
804+
editor.putString("pref_theme", "system");
805+
} else if (selectedTheme == R.id.setup_theme_black) {
806+
editor.putString("pref_theme", "black");
807+
} else if (selectedTheme == R.id.setup_theme_transparent_light) {
808+
editor.putString("pref_theme", "transparent_light");
809+
}
810+
// Commit the changes
811+
editor.commit();
812+
// Sleep for 1 second to allow the user to see the changes
813+
try {
814+
Thread.sleep(500);
815+
} catch (InterruptedException e) {
816+
e.printStackTrace();
817+
}
818+
// Log the changes if debug
819+
if (BuildConfig.DEBUG) {
820+
Log.i("SetupWizard", "Background update check: " + prefs.getBoolean("pref_background_update_check", false));
821+
Log.i("SetupWizard", "Crash reporting: " + prefs.getBoolean("pref_crash_reporting", false));
822+
Log.i("SetupWizard", "Magisk Alt Repo: " + prefs.getBoolean("pref_magisk_alt_repo_enabled", false));
823+
Log.i("SetupWizard", "Androidacy Repo: " + prefs.getBoolean("pref_androidacy_repo_enabled", false));
824+
}
825+
// Restart the activity
826+
doSetupRestarting = true;
786827
finish();
828+
startActivity(getIntent());
787829
});
788830
} else {
789831
ensurePermissions();

app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void postNotification(Context context, int updateCount) {
7878

7979
public static void onMainActivityCreate(Context context) {
8080
// Refuse to run if first_launch pref is not false
81-
if (MainApplication.getSharedPreferences().getBoolean("first_launch", true))
81+
if (MainApplication.getSharedPreferences().getBoolean("first_time_user", true))
8282
return;
8383
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
8484
notificationManagerCompat.createNotificationChannel(new NotificationChannelCompat.Builder(NOTIFICATION_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_HIGH).setShowBadge(true).setName(context.getString(R.string.notification_update_pref)).build());

app/src/main/java/com/fox2code/mmm/repo/RepoData.java

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@
3030
import java.util.List;
3131

3232
public class RepoData extends XRepo {
33-
private final Object populateLock = new Object();
3433
public final String url;
3534
public final String id;
3635
public final File cacheRoot;
3736
public final SharedPreferences cachedPreferences;
3837
public final File metaDataCache;
3938
public final HashMap<String, RepoModule> moduleHashMap;
39+
private final Object populateLock = new Object();
4040
public long lastUpdate;
41-
protected String defaultName, defaultWebsite,
42-
defaultSupport, defaultDonate, defaultSubmitModule;
4341
public String name, website, support, donate, submitModule;
42+
protected String defaultName, defaultWebsite, defaultSupport, defaultDonate, defaultSubmitModule;
4443
private boolean forceHide, enabled; // Cache for speed
4544

4645
public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences) {
@@ -52,8 +51,7 @@ public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences)
5251
this.moduleHashMap = new HashMap<>();
5352
this.defaultName = url; // Set url as default name
5453
this.forceHide = AppUpdateManager.shouldForceHide(this.id);
55-
this.enabled = (!this.forceHide) && MainApplication.getSharedPreferences()
56-
.getBoolean("pref_" + this.getPreferenceId() + "_enabled", true);
54+
this.enabled = (!this.forceHide) && MainApplication.getSharedPreferences().getBoolean("pref_" + this.getPreferenceId() + "_enabled", true);
5755
this.defaultWebsite = "https://" + Uri.parse(url).getHost() + "/";
5856
if (!this.cacheRoot.isDirectory()) {
5957
boolean mkdirs = this.cacheRoot.mkdirs();
@@ -67,14 +65,14 @@ public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences)
6765
this.lastUpdate = 0; // Don't allow time travel
6866
}
6967
try {
70-
List<RepoModule> modules = this.populate(new JSONObject(
71-
new String(Files.read(this.metaDataCache), StandardCharsets.UTF_8)));
68+
List<RepoModule> modules = this.populate(new JSONObject(new String(Files.read(this.metaDataCache), StandardCharsets.UTF_8)));
7269
for (RepoModule repoModule : modules) {
7370
if (!this.tryLoadMetadata(repoModule)) {
7471
repoModule.moduleInfo.flags &= ~ModuleInfo.FLAG_METADATA_INVALID;
7572
}
7673
}
77-
} catch (Exception e) {
74+
} catch (
75+
Exception e) {
7876
boolean delete = this.metaDataCache.delete();
7977
if (!delete) {
8078
throw new RuntimeException("Failed to delete invalid cache file");
@@ -84,6 +82,10 @@ public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences)
8482
}
8583
}
8684

85+
private static boolean isNonNull(String str) {
86+
return str != null && !str.isEmpty() && !"null".equals(str);
87+
}
88+
8789
protected boolean prepare() throws NoSuchAlgorithmException {
8890
return true;
8991
}
@@ -92,8 +94,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
9294
List<RepoModule> newModules = new ArrayList<>();
9395
synchronized (this.populateLock) {
9496
String name = jsonObject.getString("name").trim();
95-
String nameForModules = name.endsWith(" (Official)") ?
96-
name.substring(0, name.length() - 11) : name;
97+
String nameForModules = name.endsWith(" (Official)") ? name.substring(0, name.length() - 11) : name;
9798
long lastUpdate = jsonObject.getLong("last_update");
9899
for (RepoModule repoModule : this.moduleHashMap.values()) {
99100
repoModule.processed = false;
@@ -104,8 +105,8 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
104105
JSONObject module = array.getJSONObject(i);
105106
String moduleId = module.getString("id");
106107
// Deny remote modules ids shorter than 3 chars or containing null char or space
107-
if (moduleId.length() < 3 || moduleId.indexOf('\0') != -1 ||
108-
moduleId.indexOf(' ') != -1 || "ak3-helper".equals(moduleId)) continue;
108+
if (moduleId.length() < 3 || moduleId.indexOf('\0') != -1 || moduleId.indexOf(' ') != -1 || "ak3-helper".equals(moduleId))
109+
continue;
109110
long moduleLastUpdate = module.getLong("last_update");
110111
String moduleNotesUrl = module.getString("notes_url");
111112
String modulePropsUrl = module.getString("prop_url");
@@ -119,8 +120,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
119120
this.moduleHashMap.put(moduleId, repoModule);
120121
newModules.add(repoModule);
121122
} else {
122-
if (repoModule.lastUpdated < moduleLastUpdate ||
123-
repoModule.moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID)) {
123+
if (repoModule.lastUpdated < moduleLastUpdate || repoModule.moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID)) {
124124
newModules.add(repoModule);
125125
}
126126
}
@@ -135,12 +135,16 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException,
135135
try {
136136
repoModule.qualityValue = Integer.parseInt(moduleStars);
137137
repoModule.qualityText = R.string.module_stars;
138-
} catch (NumberFormatException ignored) {}
138+
} catch (
139+
NumberFormatException ignored) {
140+
}
139141
} else if (!moduleDownloads.isEmpty()) {
140142
try {
141143
repoModule.qualityValue = Integer.parseInt(moduleDownloads);
142144
repoModule.qualityText = R.string.module_downloads;
143-
} catch (NumberFormatException ignored) {}
145+
} catch (
146+
NumberFormatException ignored) {
147+
}
144148
}
145149
}
146150
// Remove no longer existing modules
@@ -173,7 +177,7 @@ public boolean isEnabledByDefault() {
173177
return BuildConfig.ENABLED_REPOS.contains(this.id);
174178
}
175179

176-
public void storeMetadata(RepoModule repoModule,byte[] data) throws IOException {
180+
public void storeMetadata(RepoModule repoModule, byte[] data) throws IOException {
177181
Files.write(new File(this.cacheRoot, repoModule.id + ".prop"), data);
178182
}
179183

@@ -182,14 +186,14 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
182186
if (file.exists()) {
183187
try {
184188
ModuleInfo moduleInfo = repoModule.moduleInfo;
185-
PropUtils.readProperties(moduleInfo, file.getAbsolutePath(),
186-
repoModule.repoName + "/" + moduleInfo.name, false);
189+
PropUtils.readProperties(moduleInfo, file.getAbsolutePath(), repoModule.repoName + "/" + moduleInfo.name, false);
187190
moduleInfo.flags &= ~ModuleInfo.FLAG_METADATA_INVALID;
188191
if (moduleInfo.version == null) {
189192
moduleInfo.version = "v" + moduleInfo.versionCode;
190193
}
191194
return true;
192-
} catch (Exception ignored) {
195+
} catch (
196+
Exception ignored) {
193197
boolean delete = file.delete();
194198
if (!delete) {
195199
throw new RuntimeException("Failed to delete invalid metadata file");
@@ -202,18 +206,24 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
202206

203207
@Override
204208
public boolean isEnabled() {
209+
SharedPreferences preferenceManager = MainApplication.getSharedPreferences();
210+
boolean enabled = preferenceManager.getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault());
211+
if (this.enabled != enabled) {
212+
if (BuildConfig.DEBUG) {
213+
Log.d("NoodleDebug", "Repo " + this.id + " enable mismatch: " + this.enabled + " vs " + enabled);
214+
}
215+
this.enabled = enabled;
216+
}
205217
return this.enabled;
206218
}
207219

208220
@Override
209221
public void setEnabled(boolean enabled) {
210222
this.enabled = enabled && !this.forceHide;
211223
if (BuildConfig.DEBUG) {
212-
Log.i("RepoData",
213-
"Repo " + this.id + " enabled: " + this.enabled + " (forced: " + this.forceHide + ") with preferenceID: " + this.getPreferenceId());
224+
Log.i("RepoData", "Repo " + this.id + " enabled: " + this.enabled + " (forced: " + this.forceHide + ") with preferenceID: " + this.getPreferenceId());
214225
}
215-
MainApplication.getSharedPreferences().edit()
216-
.putBoolean("pref_" + this.getPreferenceId() + "_enabled", enabled).apply();
226+
MainApplication.getSharedPreferences().edit().putBoolean("pref_" + this.getPreferenceId() + "_enabled", enabled).apply();
217227
}
218228

219229
public void updateEnabledState() {
@@ -223,11 +233,9 @@ public void updateEnabledState() {
223233
}
224234
this.forceHide = AppUpdateManager.shouldForceHide(this.id);
225235
if (BuildConfig.DEBUG) {
226-
Log.i("RepoData",
227-
"Repo " + this.id + " update enabled: " + this.enabled + " (forced: " + this.forceHide + ") with preferenceID: " + this.getPreferenceId());
236+
Log.i("RepoData", "Repo " + this.id + " update enabled: " + this.enabled + " (forced: " + this.forceHide + ") with preferenceID: " + this.getPreferenceId());
228237
}
229-
this.enabled = (!this.forceHide) && MainApplication.getSharedPreferences()
230-
.getBoolean("pref_" + this.getPreferenceId() + "_enabled", true);
238+
this.enabled = (!this.forceHide) && MainApplication.getSharedPreferences().getBoolean("pref_" + this.getPreferenceId() + "_enabled", true);
231239
}
232240

233241
public String getUrl() throws NoSuchAlgorithmException {
@@ -238,10 +246,6 @@ public String getPreferenceId() {
238246
return this.id;
239247
}
240248

241-
private static boolean isNonNull(String str) {
242-
return str != null && !str.isEmpty() && !"null".equals(str);
243-
}
244-
245249
// Repo data info getters
246250
@NonNull
247251
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SentryMain {
2727
public static void initialize(final MainApplication mainApplication) {
2828
// If first_launch pref is not false, refuse to initialize Sentry
2929
SharedPreferences sharedPreferences = MainApplication.getSharedPreferences();
30-
if (sharedPreferences.getBoolean("first_launch", true)) {
30+
if (sharedPreferences.getBoolean("first_time_user", true)) {
3131
return;
3232
}
3333
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {

0 commit comments

Comments
 (0)