more improvements

- prepare repo list db
- remove prism4j for good as it's not compatible with java 11
- various fixes

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/277/head
androidacy-user 1 year ago
parent e3734e15d6
commit cdd4092bbf

@ -278,6 +278,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.10'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.10'
// Chromium cronet from androidacy
// TODO: bump to 109.0.5414.75
implementation 'com.androidacy:cronet-common:108.0.5359.125'
implementation 'com.androidacy:cronet-native:108.0.5359.125'
// Force prefer our own version of Cronet
@ -292,7 +293,6 @@ dependencies {
implementation "io.noties.markwon:image:4.6.2"
implementation "io.noties.markwon:syntax-highlight:4.6.2"
implementation 'com.google.net.cronet:cronet-okhttp:0.1.0'
kapt "io.noties:prism4j-bundler:2.0.0"
implementation "com.caverock:androidsvg:1.4"
// Icons
// implementation "com.mikepenz:iconics-core:3.2.5"
@ -321,6 +321,18 @@ android {
buildFeatures {
viewBinding true
}
kotlinOptions {
jvmTarget=JavaVersion.VERSION_11
}
}
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(11)) // "8"
}
}
// Safeguard (Do not remove)

@ -8,10 +8,8 @@ import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.SystemClock;
import android.text.SpannableStringBuilder;
import android.util.Log;
import android.widget.Toast;
@ -47,15 +45,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.html.HtmlPlugin;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler;
import io.noties.markwon.syntax.Prism4jTheme;
import io.noties.markwon.syntax.Prism4jThemeDarkula;
import io.noties.markwon.syntax.Prism4jThemeDefault;
import io.noties.markwon.syntax.SyntaxHighlightPlugin;
import io.noties.prism4j.Prism4j;
import io.noties.prism4j.annotations.PrismBundle;
import io.realm.Realm;
@PrismBundle(includeAll = true, grammarLocatorClassName = ".Prism4jGrammarLocator")
public class MainApplication extends FoxApplication implements androidx.work.Configuration.Provider {
private static final String timeFormatString = "dd MMM yyyy"; // Example: 13 july 2001
private static final Shell.Builder shellBuilder;
@ -64,6 +55,9 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
// Use FoxProcess wrapper helper.
private static final boolean wrapped = !FoxProcessExt.isRootLoader();
public static boolean isOfficial = false;
// Warning! Locales that are't exist will crash the app
// Anything that is commented out is supported but the translation is not complete to at least 60%
public static HashSet<String> supportedLocales = new HashSet<>();
private static Locale timeFormatLocale = Resources.getSystem().getConfiguration().locale;
private static SimpleDateFormat timeFormat = new SimpleDateFormat(timeFormatString, timeFormatLocale);
private static SharedPreferences bootSharedPreferences;
@ -82,10 +76,6 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
private FoxThemeWrapper markwonThemeContext;
private Markwon markwon;
// Warning! Locales that are't exist will crash the app
// Anything that is commented out is supported but the translation is not complete to at least 60%
public static HashSet<String> supportedLocales = new HashSet<>();
public MainApplication() {
if (INSTANCE != null && INSTANCE != this)
throw new IllegalStateException("Duplicate application instance!");
@ -210,7 +200,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
if (contextThemeWrapper == null) {
contextThemeWrapper = this.markwonThemeContext = new FoxThemeWrapper(this, this.managerThemeResId);
}
Markwon markwon = Markwon.builder(contextThemeWrapper).usePlugin(HtmlPlugin.create()).usePlugin(SyntaxHighlightPlugin.create(new Prism4j(new Prism4jGrammarLocator()), new Prism4jSwitchTheme())).usePlugin(ImagesPlugin.create().addSchemeHandler(OkHttpNetworkSchemeHandler.create(Http.getHttpClientWithCache()))).build();
Markwon markwon = Markwon.builder(contextThemeWrapper).usePlugin(HtmlPlugin.create()).usePlugin(ImagesPlugin.create().addSchemeHandler(OkHttpNetworkSchemeHandler.create(Http.getHttpClientWithCache()))).build();
return this.markwon = markwon;
}
@ -451,30 +441,4 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
}
}
private class Prism4jSwitchTheme implements Prism4jTheme {
private final Prism4jTheme light = new Prism4jThemeDefault(Color.TRANSPARENT);
private final Prism4jTheme dark = new Prism4jThemeDarkula(Color.TRANSPARENT);
// Black theme
private final Prism4jTheme black = new Prism4jThemeDefault(Color.BLACK);
private Prism4jTheme getTheme() {
// isLightTheme() means light, isDarkTheme() means dark, and isBlackTheme() means black
return isLightTheme() ? light : isDarkTheme() ? dark : black;
}
@Override
public int background() {
return this.getTheme().background();
}
@Override
public int textColor() {
return this.getTheme().textColor();
}
@Override
public void apply(@NonNull String language, @NonNull Prism4j.Syntax syntax, @NonNull SpannableStringBuilder builder, int start, int end) {
this.getTheme().apply(language, syntax, builder, start, end);
}
}
}

@ -245,6 +245,9 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
// creates the realm database
private void createRealmDatabase() {
if (BuildConfig.DEBUG) {
Log.d("Realm", "Creating Realm databases");
}
// create the realm database for ModuleListCache
RealmConfiguration config = new RealmConfiguration.Builder().name("ModuleListCache.realm").schemaVersion(1).allowWritesOnUiThread(true).allowQueriesOnUiThread(true).build();
Realm.setDefaultConfiguration(config);
@ -253,5 +256,16 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
realm.executeTransaction(r -> {
});
realm.close();
// next, create the realm database for ReposList
config = new RealmConfiguration.Builder().name("ReposList.realm").schemaVersion(1).allowWritesOnUiThread(true).allowQueriesOnUiThread(true).build();
Realm.setDefaultConfiguration(config);
// do a dummy write to create the database
realm = Realm.getDefaultInstance();
realm.executeTransaction(r -> {
});
realm.close();
if (BuildConfig.DEBUG) {
Log.d("Realm", "Realm databases created");
}
}
}

@ -1,10 +1,15 @@
package com.fox2code.mmm.utils.realm;
import org.json.JSONException;
import org.json.JSONObject;
import io.realm.Realm;
import io.realm.RealmObject;
import io.realm.RealmResults;
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.Required;
@SuppressWarnings({"FieldCanBeLocal", "unused"})
@SuppressWarnings("unused")
public class ModuleListCache extends RealmObject {
// supported properties for a module
//id=<string>
@ -72,4 +77,191 @@ public class ModuleListCache extends RealmObject {
public ModuleListCache() {
}
// get all modules from a repo as a json object
public static JSONObject getRepoModulesAsJson(String repoId) {
Realm realm = Realm.getDefaultInstance();
RealmResults<ModuleListCache> modules = realm.where(ModuleListCache.class).equalTo("repoId", repoId).findAll();
JSONObject jsonObject = new JSONObject();
for (ModuleListCache module : modules) {
try {
jsonObject.put(module.getId(), module.toJson());
} catch (
JSONException e) {
e.printStackTrace();
}
}
realm.close();
return jsonObject;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getVersionCode() {
return versionCode;
}
public void setVersionCode(int versionCode) {
this.versionCode = versionCode;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getSupport() {
return support;
}
public void setSupport(String support) {
this.support = support;
}
public String getDonate() {
return donate;
}
public void setDonate(String donate) {
this.donate = donate;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public boolean isChangeBoot() {
return changeBoot;
}
public void setChangeBoot(boolean changeBoot) {
this.changeBoot = changeBoot;
}
public boolean isMmtReborn() {
return mmtReborn;
}
public void setMmtReborn(boolean mmtReborn) {
this.mmtReborn = mmtReborn;
}
public String getRepoId() {
return repoId;
}
public void setRepoId(String repoId) {
this.repoId = repoId;
}
public boolean isInstalled() {
return installed;
}
public void setInstalled(boolean installed) {
this.installed = installed;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public int getMinApi() {
return minApi;
}
public void setMinApi(int minApi) {
this.minApi = minApi;
}
public int getMaxApi() {
return maxApi;
}
public void setMaxApi(int maxApi) {
this.maxApi = maxApi;
}
public int getMinMagisk() {
return minMagisk;
}
public void setMinMagisk(int minMagisk) {
this.minMagisk = minMagisk;
}
public boolean isNeedRamdisk() {
return needRamdisk;
}
public void setNeedRamdisk(boolean needRamdisk) {
this.needRamdisk = needRamdisk;
}
public int getInstalledVersionCode() {
return installedVersionCode;
}
public void setInstalledVersionCode(int installedVersionCode) {
this.installedVersionCode = installedVersionCode;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
private JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("name", name);
jsonObject.put("version", version);
jsonObject.put("versionCode", versionCode);
jsonObject.put("author", author);
jsonObject.put("description", description);
jsonObject.put("minApi", minApi);
jsonObject.put("maxApi", maxApi);
jsonObject.put("minMagisk", minMagisk);
jsonObject.put("needRamdisk", needRamdisk);
jsonObject.put("support", support);
jsonObject.put("donate", donate);
jsonObject.put("config", config);
jsonObject.put("changeBoot", changeBoot);
jsonObject.put("mmtReborn", mmtReborn);
jsonObject.put("repoId", repoId);
jsonObject.put("installed", installed);
jsonObject.put("installedVersionCode", installedVersionCode);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject;
}
}

@ -0,0 +1,69 @@
package com.fox2code.mmm.utils.realm;
import io.realm.RealmObject;
import io.realm.annotations.Required;
@SuppressWarnings("unused")
public class ReposList extends RealmObject {
// Each repo is identified by its id, has a url field, and an enabled field
// there's also an optional donate and support field
@Required
private String id;
@Required
private String url;
private boolean enabled;
private String donate;
private String support;
public ReposList(String id, String url, boolean enabled, String donate, String support) {
this.id = id;
this.url = url;
this.enabled = enabled;
this.donate = donate;
this.support = support;
}
public ReposList() {
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDonate() {
return donate;
}
public void setDonate(String donate) {
this.donate = donate;
}
public String getSupport() {
return support;
}
public void setSupport(String support) {
this.support = support;
}
}

@ -297,5 +297,5 @@
<string name="save_logs">Save logs to storage and share</string>
<string name="error_saving_logs">Could not save logs</string>
<string name="share_logs">Share FoxMMM logs</string>
<string name="not_official_build">Caution: You are running an unofficial and therefore unsupported FoxMMM build.</string>
<string name="not_official_build">This app is an unofficial FoxMMM build.</string>
</resources>

Loading…
Cancel
Save