From e3734e15d6c6c4c088479f5e7843c4c1b9b3840f Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Fri, 13 Jan 2023 21:35:18 -0500 Subject: [PATCH] onto a new Realm ....realm database, anyway Signed-off-by: androidacy-user --- app/build.gradle | 11 ++- .../com/fox2code/mmm/MainApplication.java | 10 ++- .../java/com/fox2code/mmm/SetupActivity.java | 16 ++++ .../mmm/utils/realm/ModuleListCache.java | 75 +++++++++++++++++++ app/src/main/res/values/strings.xml | 20 ++++- build.gradle | 1 + 6 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java diff --git a/app/build.gradle b/app/build.gradle index 808ec7b..e1419f3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,8 +3,12 @@ plugins { id "io.sentry.android.gradle" version "3.4.0" id 'com.android.application' id 'com.mikepenz.aboutlibraries.plugin' + id 'org.jetbrains.kotlin.android' + id 'org.jetbrains.kotlin.kapt' } +apply plugin: "realm-android" + android { namespace "com.fox2code.mmm" compileSdk 33 @@ -35,11 +39,6 @@ android { versionName "1.2.1" signingConfig signingConfigs.release archivesBaseName = "FoxMMM-v$versionName" - javaCompileOptions { - annotationProcessorOptions { - arguments += ["room.schemaLocation": "$projectDir/schemas".toString()] - } - } } splits { @@ -293,7 +292,7 @@ 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' - annotationProcessor "io.noties:prism4j-bundler:2.0.0" + kapt "io.noties:prism4j-bundler:2.0.0" implementation "com.caverock:androidsvg:1.4" // Icons // implementation "com.mikepenz:iconics-core:3.2.5" diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index cdc9f58..7fca26a 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -53,6 +53,7 @@ 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 { @@ -313,10 +314,17 @@ public class MainApplication extends FoxApplication implements androidx.work.Con if (INSTANCE == null) INSTANCE = this; relPackageName = this.getPackageName(); - super.onCreate(); if (BuildConfig.DEBUG) { Log.d("MainApplication", "Starting FoxMMM version " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + "), commit " + BuildConfig.COMMIT_HASH); } + super.onCreate(); + if (BuildConfig.DEBUG) { + Log.d("MainApplication", "FoxMMM is running in debug mode"); + } + if (BuildConfig.DEBUG) { + Log.d("MainApplication", "Initializing Realm"); + } + Realm.init(this); // Determine if this is an official build based on the signature try { // Get the signature of the key used to sign the app diff --git a/app/src/main/java/com/fox2code/mmm/SetupActivity.java b/app/src/main/java/com/fox2code/mmm/SetupActivity.java index 920b63d..e7d9fc0 100644 --- a/app/src/main/java/com/fox2code/mmm/SetupActivity.java +++ b/app/src/main/java/com/fox2code/mmm/SetupActivity.java @@ -25,6 +25,9 @@ import com.topjohnwu.superuser.internal.UiThreadHandler; import java.util.Objects; +import io.realm.Realm; +import io.realm.RealmConfiguration; + public class SetupActivity extends FoxActivity implements LanguageActivity { @SuppressLint({"ApplySharedPref", "RestrictedApi"}) @@ -43,6 +46,7 @@ public class SetupActivity extends FoxActivity implements LanguageActivity { actionBar.show(); } this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, 0); + createRealmDatabase(); // Set theme SharedPreferences prefs = MainApplication.getSharedPreferences(); switch (prefs.getString("theme", "system")) { @@ -238,4 +242,16 @@ public class SetupActivity extends FoxActivity implements LanguageActivity { startActivity(intent); }); } + + // creates the realm database + private void createRealmDatabase() { + // create the realm database for ModuleListCache + RealmConfiguration config = new RealmConfiguration.Builder().name("ModuleListCache.realm").schemaVersion(1).allowWritesOnUiThread(true).allowQueriesOnUiThread(true).build(); + Realm.setDefaultConfiguration(config); + // do a dummy write to create the database + Realm realm = Realm.getDefaultInstance(); + realm.executeTransaction(r -> { + }); + realm.close(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java b/app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java new file mode 100644 index 0000000..0a567db --- /dev/null +++ b/app/src/main/java/com/fox2code/mmm/utils/realm/ModuleListCache.java @@ -0,0 +1,75 @@ +package com.fox2code.mmm.utils.realm; + +import io.realm.RealmObject; +import io.realm.annotations.PrimaryKey; +import io.realm.annotations.Required; + +@SuppressWarnings({"FieldCanBeLocal", "unused"}) +public class ModuleListCache extends RealmObject { + // supported properties for a module + //id= + //name= + //version= + //versionCode= + //author= + //description= + //minApi= + //maxApi= + //minMagisk= + //needRamdisk= + //support= + //donate= + //config= + //changeBoot= + //mmtReborn= + // extra properties only useful for the database + //repoId= + //installed= + //installedVersionCode= (only if installed) + + // for compatibility, only id is required + @PrimaryKey + @Required + private String id; + private String name; + private String version; + private int versionCode; + private String author; + private String description; + private int minApi; + private int maxApi; + private int minMagisk; + private boolean needRamdisk; + private String support; + private String donate; + private String config; + private boolean changeBoot; + private boolean mmtReborn; + private String repoId; + private boolean installed; + private int installedVersionCode; + + public ModuleListCache(String id, String name, String version, int versionCode, String author, String description, int minApi, int maxApi, int minMagisk, boolean needRamdisk, String support, String donate, String config, boolean changeBoot, boolean mmtReborn, String repoId, boolean installed, int installedVersionCode) { + this.id = id; + this.name = name; + this.version = version; + this.versionCode = versionCode; + this.author = author; + this.description = description; + this.minApi = minApi; + this.maxApi = maxApi; + this.minMagisk = minMagisk; + this.needRamdisk = needRamdisk; + this.support = support; + this.donate = donate; + this.config = config; + this.changeBoot = changeBoot; + this.mmtReborn = mmtReborn; + this.repoId = repoId; + this.installed = installed; + this.installedVersionCode = installedVersionCode; + } + + public ModuleListCache() { + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7012228..1f423ce 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -243,7 +243,8 @@ This repo has less restrictions and reviews, which may lead to lower quality modules. Pretty barebones but has a lot of modules. You are about to reboot your device. If you\'ve saved your work, hit OK to continue. Otherwise, hit cancel. Package %s is missing for module config, so we cannot launch it. - Clear app dataClear app data? + Clear app data + Clear app data? You\'re about to clear the app data. Please confirm this action. This is a debug build. Expect some bugs and worse performance. Androidacy Repo @@ -267,7 +268,9 @@ Light This app is outdated. Please update the app to the latest version. - Your webview is outdated! Please update it.Don\'t see your language?Help us by translating it! Tap here to find out more. + Your webview is outdated! Please update it. + Don\'t see your language? + Help us by translating it! Tap here to find out more. Commit %1$s @ %2$s No file was provided when trying to open zip. Could not load the zip file @@ -283,5 +286,16 @@ Choose theme Choose language Setup Wizard - SettingsThe following repos have failed to update:\\n\\n%sReset API keysUpgrade to premiumUpgrading to premium will remove ads, captchas, and downloads for the Androidacy Repository, and support Androidacy and the module authors.ContributorsFox2Code is the original creator of the app. Without him, this would have never been possible.Created by Fox2CodeSave logs to storage and shareCould not save logsShare FoxMMM logsCaution: You are running an unofficial and unsupported FoxMMM build. + Settings + The following repos have failed to update:\\n\\n%s + Reset API keys + Upgrade to premium + Upgrading to premium will remove ads, captchas, and downloads for the Androidacy Repository, and support Androidacy and the module authors. + Contributors + Fox2Code is the original creator of the app. Without him, this would have never been possible. + Created by Fox2Code + Save logs to storage and share + Could not save logs + Share FoxMMM logs + Caution: You are running an unofficial and therefore unsupported FoxMMM build. diff --git a/build.gradle b/build.gradle index dd420ca..6771cf9 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,7 @@ buildscript { // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "io.realm:realm-gradle-plugin:10.11.1" } }