fixes and stuff

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 3 years ago
parent 589eab5124
commit ee4ad76b43

@ -47,13 +47,11 @@ import com.fox2code.mmm.manager.ModuleManager;
import com.fox2code.mmm.module.ModuleViewAdapter; import com.fox2code.mmm.module.ModuleViewAdapter;
import com.fox2code.mmm.module.ModuleViewListBuilder; import com.fox2code.mmm.module.ModuleViewListBuilder;
import com.fox2code.mmm.repo.RepoManager; import com.fox2code.mmm.repo.RepoManager;
import com.fox2code.mmm.sentry.SentryMain;
import com.fox2code.mmm.settings.SettingsActivity; import com.fox2code.mmm.settings.SettingsActivity;
import com.fox2code.mmm.utils.BlurUtils; import com.fox2code.mmm.utils.BlurUtils;
import com.fox2code.mmm.utils.ExternalHelper; import com.fox2code.mmm.utils.ExternalHelper;
import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.IntentHelper;
import com.fox2code.mmm.utils.ProcessHelper;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.materialswitch.MaterialSwitch; import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.progressindicator.LinearProgressIndicator; import com.google.android.material.progressindicator.LinearProgressIndicator;
@ -73,6 +71,7 @@ import eightbitlab.com.blurview.BlurView;
public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRefreshListener, SearchView.OnQueryTextListener, SearchView.OnCloseListener, OverScrollManager.OverScrollHelper { public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRefreshListener, SearchView.OnQueryTextListener, SearchView.OnCloseListener, OverScrollManager.OverScrollHelper {
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
private static final int PRECISION = 10000; private static final int PRECISION = 10000;
public static boolean doSetupNowRunning = true;
public final ModuleViewListBuilder moduleViewListBuilder; public final ModuleViewListBuilder moduleViewListBuilder;
public LinearProgressIndicator progressIndicator; public LinearProgressIndicator progressIndicator;
private ModuleViewAdapter moduleViewAdapter; private ModuleViewAdapter moduleViewAdapter;
@ -89,7 +88,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
private CardView searchCard; private CardView searchCard;
private SearchView searchView; private SearchView searchView;
private boolean initMode; private boolean initMode;
private boolean doSetupNowRunning;
private boolean doSetupRestarting; private boolean doSetupRestarting;
private boolean urlFactoryInstalled = false; private boolean urlFactoryInstalled = false;
@ -115,11 +113,13 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
CronetURLStreamHandlerFactory cronetURLStreamHandlerFactory = new CronetURLStreamHandlerFactory(cronetEngine); CronetURLStreamHandlerFactory cronetURLStreamHandlerFactory = new CronetURLStreamHandlerFactory(cronetEngine);
try { try {
URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory); URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory);
} catch (Error e) { } catch (
Error e) {
Log.e(TAG, "Failed to install Cronet URLStreamHandlerFactory", 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);
} }
} }
@ -158,6 +158,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.actionBarBlur.setBackground(this.actionBarBackground); this.actionBarBlur.setBackground(this.actionBarBackground);
BlurUtils.setupBlur(this.actionBarBlur, this, R.id.blur_frame); BlurUtils.setupBlur(this.actionBarBlur, this, R.id.blur_frame);
this.updateBlurState(); this.updateBlurState();
checkShowInitialSetup();
this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() { this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
@ -183,7 +185,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.cardIconifyUpdate(); this.cardIconifyUpdate();
this.updateScreenInsets(this.getResources().getConfiguration()); this.updateScreenInsets(this.getResources().getConfiguration());
checkShowInitialSetup();
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() { InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@Override @Override
public void onPathReceived(String path) { public void onPathReceived(String path) {
@ -209,10 +210,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
if (waitInitialSetupFinished()) { if (waitInitialSetupFinished()) {
return; return;
} }
/*if (BuildConfig.DEBUG) {
SharedPreferences prefs = MainApplication.getSharedPreferences();
if (BuildConfig.DEBUG) 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)));
}*/
swipeRefreshBlocker = System.currentTimeMillis() + 5_000L; swipeRefreshBlocker = System.currentTimeMillis() + 5_000L;
if (MainApplication.isShowcaseMode()) if (MainApplication.isShowcaseMode())
moduleViewListBuilder.addNotification(NotificationType.SHOWCASE_MODE); moduleViewListBuilder.addNotification(NotificationType.SHOWCASE_MODE);
@ -233,25 +230,20 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
MainApplication.getSharedPreferences().registerOnSharedPreferenceChangeListener((prefs, key) -> Log.i("PrefsListener", "onSharedPreferenceChanged: " + key + " = " + prefs.getAll().get(key))); MainApplication.getSharedPreferences().registerOnSharedPreferenceChangeListener((prefs, key) -> Log.i("PrefsListener", "onSharedPreferenceChanged: " + key + " = " + prefs.getAll().get(key)));
} }
Log.i(TAG, "Scanning for modules!"); Log.i(TAG, "Scanning for modules!");
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Initialize Update"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Initialize Update");
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount(); final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) { if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
Log.w(TAG, "Need update on create?"); Log.w(TAG, "Need update on create?");
} }
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Check Update Compat"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Check Update Compat");
AppUpdateManager.getAppUpdateManager().checkUpdateCompat(); AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
/*if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG)
SharedPreferences prefs = MainApplication.getSharedPreferences(); Log.d("NoodleDebug", "Check Update");
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)));
}*/
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Check Update");
RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true))); RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true)));
NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder); NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder);
/*if (BuildConfig.DEBUG) {
SharedPreferences prefs = MainApplication.getSharedPreferences();
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)));
}*/
if (!NotificationType.NO_INTERNET.shouldRemove()) { if (!NotificationType.NO_INTERNET.shouldRemove()) {
moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET); moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
} else if (!NotificationType.REPO_UPDATE_FAILED.shouldRemove()) { } else if (!NotificationType.REPO_UPDATE_FAILED.shouldRemove()) {
@ -259,24 +251,24 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} else { } else {
// Compatibility data still needs to be updated // Compatibility data still needs to be updated
AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager(); AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager();
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Check App Update"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Check App Update");
if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true)) if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true))
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE); moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Check Json Update"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Check Json Update");
if (max != 0) { if (max != 0) {
/*if (BuildConfig.DEBUG) {
SharedPreferences prefs = MainApplication.getSharedPreferences();
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)));
}*/
int current = 0; int current = 0;
// noodleDebug.push(""); // noodleDebug.push("");
for (LocalModuleInfo localModuleInfo : ModuleManager.getINSTANCE().getModules().values()) { for (LocalModuleInfo localModuleInfo : ModuleManager.getINSTANCE().getModules().values()) {
if (localModuleInfo.updateJson != null) { if (localModuleInfo.updateJson != null) {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", localModuleInfo.id); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", localModuleInfo.id);
try { try {
localModuleInfo.checkModuleUpdate(); localModuleInfo.checkModuleUpdate();
} catch (Exception e) { } catch (
Exception e) {
Log.e("MainActivity", "Failed to fetch update of: " + localModuleInfo.id, e); Log.e("MainActivity", "Failed to fetch update of: " + localModuleInfo.id, e);
} }
current++; current++;
@ -293,13 +285,10 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
setActionBarBackground(null); setActionBarBackground(null);
updateScreenInsets(getResources().getConfiguration()); updateScreenInsets(getResources().getConfiguration());
}); });
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Apply"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Apply");
RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules);
/*if (BuildConfig.DEBUG) {
SharedPreferences prefs = MainApplication.getSharedPreferences();
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)));
}*/
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter); moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
Log.i(TAG, "Finished app opening state!"); Log.i(TAG, "Finished app opening state!");
// noodleDebug.unbind(); // noodleDebug.unbind();
@ -312,10 +301,12 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
if (MainApplication.isCrashReportingEnabled() && !BuildConfig.SENTRY_TOKEN.isEmpty()) { if (MainApplication.isCrashReportingEnabled() && !BuildConfig.SENTRY_TOKEN.isEmpty()) {
SharedPreferences preferences = getSharedPreferences("sentry", MODE_PRIVATE); SharedPreferences preferences = getSharedPreferences("sentry", MODE_PRIVATE);
String lastExitReason = preferences.getString("lastExitReason", ""); String lastExitReason = preferences.getString("lastExitReason", "");
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Last Exit Reason: " + lastExitReason); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Last Exit Reason: " + lastExitReason);
if (lastExitReason.equals("crash")) { if (lastExitReason.equals("crash")) {
String lastEventId = preferences.getString("lastEventId", ""); String lastEventId = preferences.getString("lastEventId", "");
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Last Event ID: " + lastEventId); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Last Event ID: " + lastEventId);
if (!lastEventId.equals("")) { if (!lastEventId.equals("")) {
// Three edit texts for the user to enter their email, name and a description of the issue // Three edit texts for the user to enter their email, name and a description of the issue
EditText email = new EditText(this); EditText email = new EditText(this);
@ -354,8 +345,10 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// Setups the JSON body // Setups the JSON body
String nameString = name.getText().toString(); String nameString = name.getText().toString();
String emailString = email.getText().toString(); String emailString = email.getText().toString();
if (nameString.equals("")) nameString = "Anonymous"; if (nameString.equals(""))
if (emailString.equals("")) emailString = "Anonymous"; nameString = "Anonymous";
if (emailString.equals(""))
emailString = "Anonymous";
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("event_id", lastEventId); body.put("event_id", lastEventId);
body.put("name", nameString); body.put("name", nameString);
@ -375,7 +368,9 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} else { } else {
runOnUiThread(() -> Toast.makeText(this, R.string.sentry_dialogue_failed_toast, Toast.LENGTH_LONG).show()); runOnUiThread(() -> Toast.makeText(this, R.string.sentry_dialogue_failed_toast, Toast.LENGTH_LONG).show());
} }
} catch (IOException | JSONException ignored) { } catch (
IOException |
JSONException ignored) {
// Show a toast if the user feedback could not be submitted // Show a toast if the user feedback could not be submitted
runOnUiThread(() -> Toast.makeText(this, R.string.sentry_dialogue_failed_toast, Toast.LENGTH_LONG).show()); runOnUiThread(() -> Toast.makeText(this, R.string.sentry_dialogue_failed_toast, Toast.LENGTH_LONG).show());
} }
@ -428,7 +423,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
int colorBackground; int colorBackground;
try { try {
colorBackground = this.getColorCompat(android.R.attr.windowBackground); colorBackground = this.getColorCompat(android.R.attr.windowBackground);
} catch (Resources.NotFoundException e) { } catch (
Resources.NotFoundException e) {
colorBackground = this.getColorCompat(isLightMode ? R.color.white : R.color.black); colorBackground = this.getColorCompat(isLightMode ? R.color.white : R.color.black);
} }
if (MainApplication.isBlurEnabled()) { if (MainApplication.isBlurEnabled()) {
@ -445,7 +441,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public void refreshUI() { public void refreshUI() {
super.refreshUI(); super.refreshUI();
if (this.initMode) return; if (this.initMode)
return;
this.initMode = true; this.initMode = true;
Log.i(TAG, "Item Before"); Log.i(TAG, "Item Before");
this.searchView.setQuery("", false); this.searchView.setQuery("", false);
@ -460,6 +457,16 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() { InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@Override @Override
public void onPathReceived(String path) { public void onPathReceived(String path) {
checkShowInitialSetup();
// Wait for doSetupNow to finish
while (doSetupNowRunning) {
try {
//noinspection BusyWait
Thread.sleep(100);
} catch (
InterruptedException ignored) {
}
}
if (InstallerInitializer.peekMagiskVersion() < Constants.MAGISK_VER_CODE_INSTALL_COMMAND) if (InstallerInitializer.peekMagiskVersion() < Constants.MAGISK_VER_CODE_INSTALL_COMMAND)
moduleViewListBuilder.addNotification(NotificationType.MAGISK_OUTDATED); moduleViewListBuilder.addNotification(NotificationType.MAGISK_OUTDATED);
if (!MainApplication.isShowcaseMode()) if (!MainApplication.isShowcaseMode())
@ -490,14 +497,16 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
progressIndicator.setIndeterminate(false); progressIndicator.setIndeterminate(false);
progressIndicator.setMax(PRECISION); progressIndicator.setMax(PRECISION);
}); });
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Check Update"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Check Update");
RepoManager.getINSTANCE().update(value -> runOnUiThread(() -> progressIndicator.setProgressCompat((int) (value * PRECISION), true))); RepoManager.getINSTANCE().update(value -> runOnUiThread(() -> progressIndicator.setProgressCompat((int) (value * PRECISION), true)));
runOnUiThread(() -> { runOnUiThread(() -> {
progressIndicator.setProgressCompat(PRECISION, true); progressIndicator.setProgressCompat(PRECISION, true);
progressIndicator.setVisibility(View.GONE); progressIndicator.setVisibility(View.GONE);
}); });
} }
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Apply"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Apply");
RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules);
Log.i(TAG, "Common Before applyTo"); Log.i(TAG, "Common Before applyTo");
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter); moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
@ -514,14 +523,12 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public void onRefresh() { public void onRefresh() {
if (this.swipeRefreshBlocker > System.currentTimeMillis() || if (this.swipeRefreshBlocker > System.currentTimeMillis() || this.initMode || this.progressIndicator == null || this.progressIndicator.getVisibility() == View.VISIBLE || doSetupNowRunning) {
this.initMode || this.progressIndicator == null ||
this.progressIndicator.getVisibility() == View.VISIBLE ||
this.doSetupNowRunning) {
this.swipeRefreshLayout.setRefreshing(false); this.swipeRefreshLayout.setRefreshing(false);
return; // Do not double scan return; // Do not double scan
} }
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Refresh"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Refresh");
this.progressIndicator.setVisibility(View.VISIBLE); this.progressIndicator.setVisibility(View.VISIBLE);
this.progressIndicator.setProgressCompat(0, false); this.progressIndicator.setProgressCompat(0, false);
this.swipeRefreshBlocker = System.currentTimeMillis() + 5_000L; this.swipeRefreshBlocker = System.currentTimeMillis() + 5_000L;
@ -539,18 +546,22 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} else { } else {
// Compatibility data still needs to be updated // Compatibility data still needs to be updated
AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager(); AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager();
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Check App Update"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Check App Update");
if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true)) if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true))
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE); moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Check Json Update"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Check Json Update");
if (max != 0) { if (max != 0) {
int current = 0; int current = 0;
for (LocalModuleInfo localModuleInfo : ModuleManager.getINSTANCE().getModules().values()) { for (LocalModuleInfo localModuleInfo : ModuleManager.getINSTANCE().getModules().values()) {
if (localModuleInfo.updateJson != null) { if (localModuleInfo.updateJson != null) {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", localModuleInfo.id); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", localModuleInfo.id);
try { try {
localModuleInfo.checkModuleUpdate(); localModuleInfo.checkModuleUpdate();
} catch (Exception e) { } catch (
Exception e) {
Log.e("MainActivity", "Failed to fetch update of: " + localModuleInfo.id, e); Log.e("MainActivity", "Failed to fetch update of: " + localModuleInfo.id, e);
} }
current++; current++;
@ -560,7 +571,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
} }
} }
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Apply"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Apply");
runOnUiThread(() -> { runOnUiThread(() -> {
this.progressIndicator.setVisibility(View.GONE); this.progressIndicator.setVisibility(View.GONE);
this.swipeRefreshLayout.setRefreshing(false); this.swipeRefreshLayout.setRefreshing(false);
@ -578,7 +590,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public boolean onQueryTextSubmit(final String query) { public boolean onQueryTextSubmit(final String query) {
this.searchView.clearFocus(); this.searchView.clearFocus();
if (this.initMode) return false; if (this.initMode)
return false;
if (this.moduleViewListBuilder.setQueryChange(query)) { if (this.moduleViewListBuilder.setQueryChange(query)) {
new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start(); new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start();
} }
@ -587,7 +600,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public boolean onQueryTextChange(String query) { public boolean onQueryTextChange(String query) {
if (this.initMode) return false; if (this.initMode)
return false;
if (this.moduleViewListBuilder.setQueryChange(query)) { if (this.moduleViewListBuilder.setQueryChange(query)) {
new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start(); new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start();
} }
@ -596,7 +610,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public boolean onClose() { public boolean onClose() {
if (this.initMode) return false; if (this.initMode)
return false;
if (this.moduleViewListBuilder.setQueryChange(null)) { if (this.moduleViewListBuilder.setQueryChange(null)) {
new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start(); new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start();
} }
@ -615,11 +630,13 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private void ensurePermissions() { private void ensurePermissions() {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Ensure Permissions"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Ensure Permissions");
// First, check if user has said don't ask again by checking if pref_dont_ask_again_notification_permission is true // First, check if user has said don't ask again by checking if pref_dont_ask_again_notification_permission is true
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_dont_ask_again_notification_permission", false)) { if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_dont_ask_again_notification_permission", false)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Request Notification Permission"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Request Notification Permission");
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.POST_NOTIFICATIONS)) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.POST_NOTIFICATIONS)) {
// Show a dialog explaining why we need this permission, which is to show // Show a dialog explaining why we need this permission, which is to show
// notifications for updates // notifications for updates
@ -651,7 +668,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
}); });
} else { } else {
// Request the permission // Request the permission
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Request Notification Permission"); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Request Notification Permission");
this.requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 0); this.requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 0);
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
// Log if granted via onRequestPermissionsResult // Log if granted via onRequestPermissionsResult
@ -702,11 +720,13 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// Method to show a setup box on first launch // Method to show a setup box on first launch
@SuppressLint({"InflateParams", "RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref"}) @SuppressLint({"InflateParams", "RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref"})
private void checkShowInitialSetup() { private void checkShowInitialSetup() {
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 = prefs.getBoolean("first_launch", true); boolean firstLaunch = prefs.getBoolean("first_launch", true);
if (BuildConfig.DEBUG) Log.d("Noodle", "First launch: " + firstLaunch); if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "First launch: " + firstLaunch);
if (firstLaunch) { if (firstLaunch) {
doSetupNowRunning = true; doSetupNowRunning = true;
// Show setup box // Show setup box
@ -721,29 +741,25 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// 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 and pref_first_launch to false // Set the preferences and pref_first_launch to false
prefs.edit().putBoolean("first_launch", false) prefs.edit().putBoolean("first_launch", false).putBoolean("pref_background_update_check", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked()).putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked()).putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit();
.putBoolean("pref_background_update_check", ((MaterialSwitch)
Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked())
.putBoolean("pref_crash_reporting",
((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked())
.putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch)
Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked())
.putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch)
Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).apply();
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Log.d("MainActivity", String.format("Background update check: %s, Crash reporting: %s, Androidacy repo: %s, Magisk alt repo: %s", Log.d("NoodleDebug", String.format("Setup: 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)));
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)));
} }
// Only for sentry switching we need to restart I think? // Sleep for 100ms. Who knows, it might fix it?
if (SentryMain.isSentryEnabled() != MainApplication.isCrashReportingEnabled()) { try {
doSetupRestarting = true; Thread.sleep(500);
ProcessHelper.restartApplicationProcess(this); } catch (InterruptedException e) {
e.printStackTrace();
} }
ensurePermissions(); doSetupRestarting = true;
// Restart the app
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(intent);
}); });
builder.setNegativeButton(R.string.setup_button_skip, (dialog, which) -> { builder.setNegativeButton(R.string.setup_button_skip, (dialog, which) -> {
MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).apply(); MainApplication.getSharedPreferences().edit().putBoolean("first_launch", false).commit();
dialog.dismiss(); dialog.dismiss();
ensurePermissions(); ensurePermissions();
}); });
@ -764,15 +780,18 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
* @return true if the load workflow must be stopped. * @return true if the load workflow must be stopped.
*/ */
private boolean waitInitialSetupFinished() { private boolean waitInitialSetupFinished() {
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "waitInitialSetupFinished"); if (BuildConfig.DEBUG)
if (doSetupNowRunning) updateScreenInsets(); // Fix an edge case Log.d("NoodleDebug", "waitInitialSetupFinished");
if (doSetupNowRunning)
updateScreenInsets(); // Fix an edge case
try { try {
// Wait for doSetupNow to finish // Wait for doSetupNow to finish
while (doSetupNowRunning) { while (doSetupNowRunning) {
//noinspection BusyWait //noinspection BusyWait
Thread.sleep(50); Thread.sleep(50);
} }
} catch (InterruptedException e) { } catch (
InterruptedException e) {
return true; return true;
} }
return doSetupRestarting; return doSetupRestarting;

@ -30,7 +30,7 @@ import com.fox2code.mmm.manager.ModuleManager;
import com.fox2code.mmm.repo.RepoModule; import com.fox2code.mmm.repo.RepoModule;
import com.google.android.material.chip.Chip; import com.google.android.material.chip.Chip;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.switchmaterial.SwitchMaterial; import com.google.android.material.materialswitch.MaterialSwitch;
import com.topjohnwu.superuser.internal.UiThreadHandler; import com.topjohnwu.superuser.internal.UiThreadHandler;
import java.util.ArrayList; import java.util.ArrayList;
@ -72,7 +72,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
private final CardView cardView; private final CardView cardView;
private final Chip invalidPropsChip; private final Chip invalidPropsChip;
private final ImageButton buttonAction; private final ImageButton buttonAction;
private final SwitchMaterial switchMaterial; private final MaterialSwitch switchMaterial;
private final TextView titleText; private final TextView titleText;
private final TextView creditText; private final TextView creditText;
private final TextView descriptionText; private final TextView descriptionText;

@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
import com.fox2code.mmm.AppUpdateManager; import com.fox2code.mmm.AppUpdateManager;
import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.BuildConfig;
import com.fox2code.mmm.MainActivity;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.R; import com.fox2code.mmm.R;
import com.fox2code.mmm.XRepo; import com.fox2code.mmm.XRepo;
@ -201,7 +202,7 @@ public class RepoData extends XRepo {
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
return this.enabled; return MainApplication.getSharedPreferences().getBoolean("pref_" + this.getPreferenceId() + "_enabled", this.isEnabledByDefault());
} }
@Override @Override
@ -216,6 +217,10 @@ public class RepoData extends XRepo {
} }
public void updateEnabledState() { public void updateEnabledState() {
// Make sure first_launch preference is set to false
if (MainActivity.doSetupNowRunning) {
return;
}
this.forceHide = AppUpdateManager.shouldForceHide(this.id); this.forceHide = AppUpdateManager.shouldForceHide(this.id);
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Log.d("RepoData", Log.d("RepoData",

@ -11,6 +11,7 @@ import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.BuildConfig;
import com.fox2code.mmm.MainActivity;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.R; import com.fox2code.mmm.R;
import com.fox2code.mmm.XHooks; import com.fox2code.mmm.XHooks;
@ -29,6 +30,7 @@ import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -218,6 +220,10 @@ public final class RepoManager extends SyncManager {
@SuppressLint("StringFormatInvalid") @SuppressLint("StringFormatInvalid")
protected void scanInternal(@NonNull UpdateListener updateListener) { protected void scanInternal(@NonNull UpdateListener updateListener) {
// Refuse to start if first_launch is not false in shared preferences
if (MainActivity.doSetupNowRunning) {
return;
}
this.modules.clear(); this.modules.clear();
updateListener.update(0D); updateListener.update(0D);
// Using LinkedHashSet to deduplicate Androidacy entry. // Using LinkedHashSet to deduplicate Androidacy entry.
@ -239,13 +245,19 @@ public final class RepoManager extends SyncManager {
if (!repoUpdaters[i].repoData.isEnabled()) { if (!repoUpdaters[i].repoData.isEnabled()) {
if (BuildConfig.DEBUG) Log.d("RepoManager", if (BuildConfig.DEBUG) Log.d("RepoManager",
"Skipping disabled repo: " + repoUpdaters[i].repoData.getName()); "Skipping disabled repo: " + repoUpdaters[i].repoData.getName());
// Remove the repo from the list
try {
this.repoData.remove(repoUpdaters[i].repoData.getUrl());
} catch (
NoSuchAlgorithmException e) {
e.printStackTrace();
}
continue; continue;
} }
List<RepoModule> repoModules = repoUpdaters[i].toUpdate(); List<RepoModule> repoModules = repoUpdaters[i].toUpdate();
RepoData repoData = repoDatas[i]; RepoData repoData = repoDatas[i];
if (BuildConfig.DEBUG) Log.d("RepoManager", "Registering " + repoData.getName()); if (BuildConfig.DEBUG) Log.d("RepoManager", "Registering " + repoData.getName());
for (RepoModule repoModule : repoModules) { for (RepoModule repoModule : repoModules) {
if (BuildConfig.DEBUG) Log.d("RepoManager", "Fetching module: " + repoModule.id);
try { try {
if (repoModule.propUrl != null && if (repoModule.propUrl != null &&
!repoModule.propUrl.isEmpty()) { !repoModule.propUrl.isEmpty()) {

@ -63,7 +63,7 @@
android:textAppearance="?attr/textAppearanceTitleMedium" android:textAppearance="?attr/textAppearanceTitleMedium"
/> />
<com.google.android.material.switchmaterial.SwitchMaterial <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/switch_action" android:id="@+id/switch_action"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="35dp" /> android:layout_height="35dp" />

Loading…
Cancel
Save