small tweaks

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 2 years ago
parent c9aab40670
commit db94cf2a48

@ -14,7 +14,6 @@ import android.content.res.Resources;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.net.Uri; import android.net.Uri;
import android.net.http.HttpResponseCache;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
@ -54,7 +53,6 @@ import com.google.android.material.progressindicator.LinearProgressIndicator;
import org.chromium.net.CronetEngine; import org.chromium.net.CronetEngine;
import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -103,25 +101,11 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// Ensure HTTP Cache directories are created // Ensure HTTP Cache directories are created
Http.ensureCacheDirs(this); Http.ensureCacheDirs(this);
if (!urlFactoryInstalled) { if (!urlFactoryInstalled) {
try (HttpResponseCache cache = HttpResponseCache.getInstalled()) { urlFactoryInstalled = true;
if (cache == null) { try {
File cacheDir = new File(getCacheDir(), "http"); URL.setURLStreamHandlerFactory(new CronetEngine.Builder(this).build().createURLStreamHandlerFactory());
//noinspection ResultOfMethodCallIgnored } catch (Error ignored) {
cacheDir.mkdirs(); // Ignore
long cacheSize = 10 * 1024 * 1024; // 10 MiB
HttpResponseCache.install(cacheDir, cacheSize);
}
CronetEngine cronetEngine = new CronetEngine.Builder(this).build();
try {
URL.setURLStreamHandlerFactory(cronetEngine.createURLStreamHandlerFactory());
} catch (
Error e) {
Timber.e("Failed to install Cronet URLStreamHandlerFactory");
}
urlFactoryInstalled = true;
} catch (
Exception t) {
Timber.e("Failed to install CronetURLStreamHandlerFactory - other");
} }
} }
if (doSetupRestarting) { if (doSetupRestarting) {
@ -235,8 +219,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
// update the padding of blur_frame to match the new bottom nav height // update the padding of blur_frame to match the new bottom nav height
View blurFrame = findViewById(R.id.blur_frame); View blurFrame = findViewById(R.id.blur_frame);
blurFrame.setPadding(blurFrame.getPaddingLeft(), blurFrame.getPaddingTop(), blurFrame.setPadding(blurFrame.getPaddingLeft(), blurFrame.getPaddingTop(), blurFrame.getPaddingRight(), bottomNavigationView.getHeight());
blurFrame.getPaddingRight(), bottomNavigationView.getHeight());
return true; return true;
}); });
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() { InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@ -302,8 +285,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
Timber.i("Scanning for modules!"); Timber.i("Scanning for modules!");
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Initialize Update");
Timber.i("Initialize Update");
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount(); final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
if (RepoManager.getINSTANCE().getCustomRepoManager() != null && RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) { if (RepoManager.getINSTANCE().getCustomRepoManager() != null && RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
Timber.w("Need update on create"); Timber.w("Need update on create");
@ -311,11 +293,9 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
Timber.w("CustomRepoManager is null"); Timber.w("CustomRepoManager is null");
} }
// update compat metadata // update compat metadata
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Check Update Compat");
Timber.i("Check Update Compat");
AppUpdateManager.getAppUpdateManager().checkUpdateCompat(); AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Check Update");
Timber.i("Check Update");
// update repos // update repos
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)));
// various notifications // various notifications
@ -336,22 +316,18 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
// 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) if (BuildConfig.DEBUG) Timber.i("Check App Update");
Timber.i("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) if (BuildConfig.DEBUG) Timber.i("Check Json Update");
Timber.i("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) if (BuildConfig.DEBUG) Timber.i(localModuleInfo.id);
Timber.i(localModuleInfo.id);
try { try {
localModuleInfo.checkModuleUpdate(); localModuleInfo.checkModuleUpdate();
} catch ( } catch (Exception e) {
Exception e) {
Timber.e(e); Timber.e(e);
} }
current++; current++;
@ -368,8 +344,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
setActionBarBackground(null); setActionBarBackground(null);
updateScreenInsets(getResources().getConfiguration()); updateScreenInsets(getResources().getConfiguration());
}); });
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Apply");
Timber.i("Apply");
RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilderOnline::appendRemoteModules); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilderOnline::appendRemoteModules);
moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline); moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline);
@ -421,8 +396,7 @@ 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 ( } catch (Resources.NotFoundException e) {
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()) {
@ -436,8 +410,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public void refreshUI() { public void refreshUI() {
super.refreshUI(); super.refreshUI();
if (this.initMode) if (this.initMode) return;
return;
this.initMode = true; this.initMode = true;
Timber.i("Item Before"); Timber.i("Item Before");
this.searchView.setQuery("", false); this.searchView.setQuery("", false);
@ -458,8 +431,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
try { try {
//noinspection BusyWait //noinspection BusyWait
Thread.sleep(100); Thread.sleep(100);
} catch ( } catch (InterruptedException ignored) {
InterruptedException ignored) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
@ -492,16 +464,14 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
progressIndicator.setIndeterminate(false); progressIndicator.setIndeterminate(false);
progressIndicator.setMax(PRECISION); progressIndicator.setMax(PRECISION);
}); });
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Check Update");
Timber.i("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) if (BuildConfig.DEBUG) Timber.i("Apply");
Timber.i("Apply");
RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilderOnline::appendRemoteModules); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilderOnline::appendRemoteModules);
Timber.i("Common Before applyTo"); Timber.i("Common Before applyTo");
moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline); moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline);
@ -522,8 +492,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.swipeRefreshLayout.setRefreshing(false); this.swipeRefreshLayout.setRefreshing(false);
return; // Do not double scan return; // Do not double scan
} }
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Refresh");
Timber.i("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;
@ -540,22 +509,18 @@ 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) if (BuildConfig.DEBUG) Timber.i("Check App Update");
Timber.i("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) if (BuildConfig.DEBUG) Timber.i("Check Json Update");
Timber.i("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) if (BuildConfig.DEBUG) Timber.i(localModuleInfo.id);
Timber.i(localModuleInfo.id);
try { try {
localModuleInfo.checkModuleUpdate(); localModuleInfo.checkModuleUpdate();
} catch ( } catch (Exception e) {
Exception e) {
Timber.e(e); Timber.e(e);
} }
current++; current++;
@ -565,8 +530,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
} }
} }
} }
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Apply");
Timber.i("Apply");
runOnUiThread(() -> { runOnUiThread(() -> {
this.progressIndicator.setVisibility(View.GONE); this.progressIndicator.setVisibility(View.GONE);
this.swipeRefreshLayout.setRefreshing(false); this.swipeRefreshLayout.setRefreshing(false);
@ -581,8 +545,7 @@ 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) if (this.initMode) return false;
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();
} }
@ -591,8 +554,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public boolean onQueryTextChange(String query) { public boolean onQueryTextChange(String query) {
if (this.initMode) if (this.initMode) return false;
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();
} }
@ -601,8 +563,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@Override @Override
public boolean onClose() { public boolean onClose() {
if (this.initMode) if (this.initMode) return false;
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();
} }
@ -633,19 +594,16 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private void ensurePermissions() { private void ensurePermissions() {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Ensure Permissions");
Timber.i("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) if (BuildConfig.DEBUG) Timber.i("Request Notification Permission");
Timber.i("Request Notification Permission");
if (FoxActivity.getFoxActivity(this).shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) { if (FoxActivity.getFoxActivity(this).shouldShowRequestPermissionRationale(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
runOnUiThread(() -> { runOnUiThread(() -> {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Show Notification Permission Dialog");
Timber.i("Show Notification Permission Dialog");
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
builder.setTitle(R.string.permission_notification_title); builder.setTitle(R.string.permission_notification_title);
builder.setMessage(R.string.permission_notification_message); builder.setMessage(R.string.permission_notification_message);
@ -668,13 +626,11 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
doSetupNowRunning = false; doSetupNowRunning = false;
}); });
builder.show(); builder.show();
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Show Notification Permission Dialog Done");
Timber.i("Show Notification Permission Dialog Done");
}); });
} else { } else {
// Request the permission // Request the permission
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Request Notification Permission");
Timber.i("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
@ -726,8 +682,7 @@ 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) if (BuildConfig.DEBUG) Timber.i("Checking if we need to run setup");
Timber.i("Checking if we need to run setup");
// Check if this is the first launch using prefs and if doSetupRestarting was passed in the intent // Check if this is the first launch using prefs and if doSetupRestarting was passed in the intent
SharedPreferences prefs = MainApplication.getPreferences("mmm"); SharedPreferences prefs = MainApplication.getPreferences("mmm");
boolean firstLaunch = !Objects.equals(prefs.getString("last_shown_setup", null), "v1"); boolean firstLaunch = !Objects.equals(prefs.getString("last_shown_setup", null), "v1");
@ -743,8 +698,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
if (firstLaunch) { if (firstLaunch) {
doSetupNowRunning = true; doSetupNowRunning = true;
// Launch setup wizard // Launch setup wizard
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Timber.i("Launching setup wizard");
Timber.i("Launching setup wizard");
// Show setup activity // Show setup activity
Intent intent = new Intent(this, SetupActivity.class); Intent intent = new Intent(this, SetupActivity.class);
finish(); finish();
@ -758,18 +712,15 @@ 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) if (BuildConfig.DEBUG) Timber.i("waitInitialSetupFinished");
Timber.i("waitInitialSetupFinished"); if (doSetupNowRunning) updateScreenInsets(); // Fix an edge case
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 ( } catch (InterruptedException e) {
InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return true; return true;
} }

Loading…
Cancel
Save