add room infra

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/89/head
androidacy-user 1 year ago
parent a030dfe2b0
commit 1e8e7da065

3
.gitattributes vendored

@ -0,0 +1,3 @@
# assets/*.db are binary
*.db binary

Binary file not shown.

@ -20,7 +20,6 @@ import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import com.fox2code.foxcompat.app.FoxActivity
import com.fox2code.mmm.databinding.ActivitySetupBinding
import com.fox2code.mmm.repo.RepoManager
import com.fox2code.mmm.utils.IntentHelper
import com.fox2code.mmm.utils.realm.ReposList
import com.fox2code.rosettax.LanguageActivity
@ -346,91 +345,9 @@ class SetupActivity : FoxActivity(), LanguageActivity {
}
}
// creates the realm database
private fun createRealmDatabase() {
if (realmDatabasesCreated) {
Timber.d("Realm databases already created")
return
}
Timber.d("Creating Realm databases")
val startTime = System.currentTimeMillis()
// create encryption key
Timber.d("Creating encryption key")
val key = MainApplication.INSTANCE!!.key
// create the realm database for ReposList
// create the realm configuration
val config = RealmConfiguration.Builder().name("ReposList.realm")
.directory(MainApplication.INSTANCE!!.getDataDirWithPath("realms")).schemaVersion(1)
.encryptionKey(key).build()
// get the instance
Realm.getInstanceAsync(config, object : Realm.Callback() {
override fun onSuccess(realm: Realm) {
Timber.d("Realm instance: %s", realm)
realm.beginTransaction()
// create the ReposList realm database
Timber.d("Creating ReposList realm database")
if (realm.where(ReposList::class.java).equalTo("id", "androidacy_repo")
.findFirst() == null
) {
Timber.d("Creating androidacyRepo")
// create the androidacyRepo row
// cant use createObject because it crashes because reasons. use copyToRealm instead
val androidacyRepo =
realm.createObject(ReposList::class.java, "androidacy_repo")
Timber.d("Created androidacyRepo object")
androidacyRepo.name = "Androidacy Repo"
Timber.d("Set androidacyRepo name")
androidacyRepo.donate =
"https://www.androidacy.com/membership-account/membership-join/?utm_source=fox-app&utm_medium=app&utm_campaign=app"
Timber.d("Set androidacyRepo donate")
androidacyRepo.support = "https://t.me/androidacy_discussions"
Timber.d("Set androidacyRepo support")
androidacyRepo.submitModule =
"https://www.androidacy.com/module-repository-applications/?utm_source=fox-app&utm_medium=app&utm_campaign=app"
Timber.d("Set androidacyRepo submit module")
androidacyRepo.url = RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT
Timber.d("Set androidacyRepo url")
androidacyRepo.isEnabled = true
Timber.d("Set androidacyRepo enabled")
androidacyRepo.lastUpdate = 0
Timber.d("Set androidacyRepo last update")
androidacyRepo.website = RepoManager.ANDROIDACY_MAGISK_REPO_HOMEPAGE
Timber.d("Set androidacyRepo website")
// now copy the data from the data class to the realm object using copyToRealmOrUpdate
Timber.d("Copying data to realm object")
realm.copyToRealmOrUpdate(androidacyRepo)
Timber.d("Created androidacyRepo")
}
// create magiskAltRepo
if (realm.where(ReposList::class.java).equalTo("id", "magisk_alt_repo")
.findFirst() == null
) {
Timber.d("Creating magiskAltRepo")
val magiskAltRepo =
realm.createObject(ReposList::class.java, "magisk_alt_repo")
Timber.d("Created magiskAltRepo object")
magiskAltRepo.name = "Magisk Alt Repo"
magiskAltRepo.donate = null
magiskAltRepo.website = RepoManager.MAGISK_ALT_REPO_HOMEPAGE
magiskAltRepo.support = null
magiskAltRepo.isEnabled = true
magiskAltRepo.url = RepoManager.MAGISK_ALT_REPO_JSDELIVR
magiskAltRepo.submitModule =
"${RepoManager.MAGISK_ALT_REPO_HOMEPAGE}/submission"
magiskAltRepo.lastUpdate = 0
// commit the changes
Timber.d("Copying data to realm object")
realm.copyToRealmOrUpdate(magiskAltRepo)
Timber.d("Created magiskAltRepo")
}
realm.commitTransaction()
realm.close()
realmDatabasesCreated = true
Timber.d("Realm transaction finished")
val endTime = System.currentTimeMillis()
Timber.d("Realm databases created in %d ms", endTime - startTime)
}
})
// creates the room database
private fun createDatabases() {
val appContext = MainApplication.INSTANCE!!.applicationContext
}
private fun createFiles() {
@ -457,7 +374,7 @@ class SetupActivity : FoxActivity(), LanguageActivity {
} catch (e: IOException) {
Timber.e(e)
}
createRealmDatabase()
createDatabases()
}
@Suppress("KotlinConstantConditions")

@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 to present Androidacy and contributors. Names, logos, icons, and the Androidacy name are all trademarks of Androidacy and may not be used without license. See LICENSE for more information.
*/
package com.fox2code.mmm.utils.room
import androidx.room.Entity
@Suppress("unused")
@Entity(tableName = "modulelistcache")
class ModuleListCache (
var codename: String,
var version: String,
var versionCode: Int,
var author: String,
var description: String,
var minApi: Int,
var maxApi: Int,
var minMagisk: Int,
var needRamdisk: Boolean,
var support: String,
var donate: String,
var config: String,
var changeBoot: Boolean,
var mmtReborn: Boolean,
var repoId: String,
var lastUpdate: Long
) {
// functions:
// getAll(): List<ModuleListCache>
// getByCodename(codename: String): ModuleListCache
// insert(moduleListCache: ModuleListCache)
// update(moduleListCache: ModuleListCache)
// delete(moduleListCache: ModuleListCache)
// deleteAll()
// count(): Int
// get fun
// getVersion(codename: String): String
// getVersionCode(codename: String): Int
// getAuthor(codename: String): String
// getDescription(codename: String): String
// getMinApi(codename: String): Int
// getMaxApi(codename: String): Int
// getMinMagisk(codename: String): Int
// getNeedRamdisk(codename: String): Boolean
// getSupport(codename: String): String
// getDonate(codename: String): String
// getConfig(codename: String): String
// getChangeBoot(codename: String): Boolean
// getMmtReborn(codename: String): Boolean
// getRepoId(codename: String): String
// getLastUpdate(codename: String): Long
}

@ -0,0 +1,173 @@
/*
* Copyright (c) 2023 to present Androidacy and contributors. Names, logos, icons, and the Androidacy name are all trademarks of Androidacy and may not be used without license. See LICENSE for more information.
*/
package com.fox2code.mmm.utils.room
import androidx.room.Dao
import androidx.room.Query
// contains
// codename (string, primary), version (string), versionCode (int), author (string), description (string), minApi (int), maxApi (int), minMagisk (int), needRamdisk (boolean), support (string), donate (string), config (string), changeBoot (bool), mmtReborn (bool), repoId (string), lastUpdate (bigint)
@Suppress("unused")
@Dao
interface ModuleListCacheDao {
// functions:
// getAll(): List<ModuleListCache>
// getByRepoId(repoId: String): List<ModuleListCache>
// getByCodename(codename: String): ModuleListCache
// insert(moduleListCache: ModuleListCache)
// update(moduleListCache: ModuleListCache)
// delete(moduleListCache: ModuleListCache)
// deleteAll()
// count(): Int
// get fun
// getVersion(codename: String): String
// getVersionCode(codename: String): Int
// getAuthor(codename: String): String
// getDescription(codename: String): String
// getMinApi(codename: String): Int
// getMaxApi(codename: String): Int
// getMinMagisk(codename: String): Int
// getNeedRamdisk(codename: String): Boolean
// getSupport(codename: String): String
// getDonate(codename: String): String
// getConfig(codename: String): String
// getChangeBoot(codename: String): Boolean
// getMmtReborn(codename: String): Boolean
// getRepoId(codename: String): String
// getLastUpdate(codename: String): Long
// set fun
// setVersion(codename: String, version: String)
// setVersionCode(codename: String, versionCode: Int)
// setAuthor(codename: String, author: String)
// setDescription(codename: String, description: String)
// setMinApi(codename: String, minApi: Int)
// setMaxApi(codename: String, maxApi: Int)
// setMinMagisk(codename: String, minMagisk: Int)
// setNeedRamdisk(codename: String, needRamdisk: Boolean)
// setSupport(codename: String, support: String)
// setDonate(codename: String, donate: String)
// setConfig(codename: String, config: String)
// setChangeBoot(codename: String, changeBoot: Boolean)
// setMmtReborn(codename: String, mmtReborn: Boolean)
// setRepoId(codename: String, repoId: String)
// setLastUpdate(codename: String, lastUpdate: Long)
@Query("SELECT * FROM modulelistcache")
fun getAll(): List<ModuleListCache>
@Query("SELECT * FROM modulelistcache WHERE repoId = :repoId")
fun getByRepoId(repoId: String): List<ModuleListCache>
@Query("SELECT * FROM modulelistcache WHERE codename = :codename")
fun getByCodename(codename: String): ModuleListCache
@Query("INSERT INTO modulelistcache VALUES (:codename, :version, :versionCode, :author, :description, :minApi, :maxApi, :minMagisk, :needRamdisk, :support, :donate, :config, :changeBoot, :mmtReborn, :repoId, :lastUpdate)")
fun insert(codename: String, version: String, versionCode: Int, author: String, description: String, minApi: Int, maxApi: Int, minMagisk: Int, needRamdisk: Boolean, support: String, donate: String, config: String, changeBoot: Boolean, mmtReborn: Boolean, repoId: String, lastUpdate: Long)
@Query("UPDATE modulelistcache SET version = :version WHERE codename = :codename")
fun setVersion(codename: String, version: String)
@Query("UPDATE modulelistcache SET versionCode = :versionCode WHERE codename = :codename")
fun setVersionCode(codename: String, versionCode: Int)
@Query("UPDATE modulelistcache SET author = :author WHERE codename = :codename")
fun setAuthor(codename: String, author: String)
@Query("UPDATE modulelistcache SET description = :description WHERE codename = :codename")
fun setDescription(codename: String, description: String)
@Query("UPDATE modulelistcache SET minApi = :minApi WHERE codename = :codename")
fun setMinApi(codename: String, minApi: Int)
@Query("UPDATE modulelistcache SET maxApi = :maxApi WHERE codename = :codename")
fun setMaxApi(codename: String, maxApi: Int)
@Query("UPDATE modulelistcache SET minMagisk = :minMagisk WHERE codename = :codename")
fun setMinMagisk(codename: String, minMagisk: Int)
@Query("UPDATE modulelistcache SET needRamdisk = :needRamdisk WHERE codename = :codename")
fun setNeedRamdisk(codename: String, needRamdisk: Boolean)
@Query("UPDATE modulelistcache SET support = :support WHERE codename = :codename")
fun setSupport(codename: String, support: String)
@Query("UPDATE modulelistcache SET donate = :donate WHERE codename = :codename")
fun setDonate(codename: String, donate: String)
@Query("UPDATE modulelistcache SET config = :config WHERE codename = :codename")
fun setConfig(codename: String, config: String)
@Query("UPDATE modulelistcache SET changeBoot = :changeBoot WHERE codename = :codename")
fun setChangeBoot(codename: String, changeBoot: Boolean)
@Query("UPDATE modulelistcache SET mmtReborn = :mmtReborn WHERE codename = :codename")
fun setMmtReborn(codename: String, mmtReborn: Boolean)
@Query("UPDATE modulelistcache SET repoId = :repoId WHERE codename = :codename")
fun setRepoId(codename: String, repoId: String)
@Query("UPDATE modulelistcache SET lastUpdate = :lastUpdate WHERE codename = :codename")
fun setLastUpdate(codename: String, lastUpdate: Long)
@Query("DELETE FROM modulelistcache WHERE codename = :codename")
fun delete(codename: String)
@Query("DELETE FROM modulelistcache")
fun deleteAll()
@Query("SELECT COUNT(*) FROM modulelistcache")
fun count(): Int
@Query("SELECT version FROM modulelistcache WHERE codename = :codename")
fun getVersion(codename: String): String
@Query("SELECT versionCode FROM modulelistcache WHERE codename = :codename")
fun getVersionCode(codename: String): Int
@Query("SELECT author FROM modulelistcache WHERE codename = :codename")
fun getAuthor(codename: String): String
@Query("SELECT description FROM modulelistcache WHERE codename = :codename")
fun getDescription(codename: String): String
@Query("SELECT minApi FROM modulelistcache WHERE codename = :codename")
fun getMinApi(codename: String): Int
@Query("SELECT maxApi FROM modulelistcache WHERE codename = :codename")
fun getMaxApi(codename: String): Int
@Query("SELECT minMagisk FROM modulelistcache WHERE codename = :codename")
fun getMinMagisk(codename: String): Int
@Query("SELECT needRamdisk FROM modulelistcache WHERE codename = :codename")
fun getNeedRamdisk(codename: String): Boolean
@Query("SELECT support FROM modulelistcache WHERE codename = :codename")
fun getSupport(codename: String): String
@Query("SELECT donate FROM modulelistcache WHERE codename = :codename")
fun getDonate(codename: String): String
@Query("SELECT config FROM modulelistcache WHERE codename = :codename")
fun getConfig(codename: String): String
@Query("SELECT changeBoot FROM modulelistcache WHERE codename = :codename")
fun getChangeBoot(codename: String): Boolean
@Query("SELECT mmtReborn FROM modulelistcache WHERE codename = :codename")
fun getMmtReborn(codename: String): Boolean
@Query("SELECT repoId FROM modulelistcache WHERE codename = :codename")
fun getRepoId(codename: String): String
@Query("SELECT lastUpdate FROM modulelistcache WHERE codename = :codename")
fun getLastUpdate(codename: String): Long
@Query("SELECT * FROM modulelistcache WHERE codename = :codename")
fun get(codename: String): ModuleListCache
}

@ -0,0 +1,13 @@
/*
* Copyright (c) 2023 to present Androidacy and contributors. Names, logos, icons, and the Androidacy name are all trademarks of Androidacy and may not be used without license. See LICENSE for more information.
*/
package com.fox2code.mmm.utils.room
import androidx.room.Database
@Suppress("unused")
@Database(entities = [ModuleListCache::class], version = 1)
abstract class ModuleListCacheDatabase {
abstract fun moduleListCacheDao(): ModuleListCacheDao
}

@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 to present Androidacy and contributors. Names, logos, icons, and the Androidacy name are all trademarks of Androidacy and may not be used without license. See LICENSE for more information.
*/
package com.fox2code.mmm.utils.room
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "ReposList")
data class ReposList(
@PrimaryKey var id: String,
var url: String,
var enabled: Boolean,
var donate: String,
var support: String,
var submitModule: String,
var lastUpdate: Long,
var name: String,
var website: String
)

@ -0,0 +1,93 @@
/*
* Copyright (c) 2023 to present Androidacy and contributors. Names, logos, icons, and the Androidacy name are all trademarks of Androidacy and may not be used without license. See LICENSE for more information.
*/
package com.fox2code.mmm.utils.room
import androidx.room.Dao
import androidx.room.Query
@Suppress("unused")
@Dao
interface ReposListDao {
// contains
// id (string, primary), url (string), enabled (boolean), donate (string), support (string), submitMoulde (string), lastUpdate (bigint), name (string) and website (string)
// functions:
// getAll(): List<ReposList>
// getById(id: String): ReposList
// insert(reposList: ReposList)
// update(reposList: ReposList)
// delete(reposList: ReposList)
@Query("SELECT * FROM ReposList")
fun getAll(): List<ReposList>
@Query("SELECT * FROM ReposList WHERE id = :id")
fun getById(id: String): ReposList
@Query("INSERT INTO ReposList VALUES (:id, :url, :enabled, :donate, :support, :submitModule, :lastUpdate, :name, :website)")
fun insert(id: String, url: String, enabled: Boolean, donate: String, support: String, submitModule: String, lastUpdate: Long, name: String, website: String)
@Query("UPDATE ReposList SET url = :url, enabled = :enabled, donate = :donate, support = :support, submitModule = :submitModule, lastUpdate = :lastUpdate, name = :name, website = :website WHERE id = :id")
fun update(id: String, url: String, enabled: Boolean, donate: String, support: String, submitModule: String, lastUpdate: Long, name: String, website: String)
@Query("DELETE FROM ReposList WHERE id = :id")
fun delete(id: String)
@Query("DELETE FROM ReposList")
fun deleteAll()
@Query("SELECT COUNT(*) FROM ReposList")
fun count(): Int
// get fun
@Query("SELECT url FROM ReposList WHERE id = :id")
fun getUrl(id: String): String
@Query("SELECT enabled FROM ReposList WHERE id = :id")
fun getEnabled(id: String): Boolean
@Query("SELECT donate FROM ReposList WHERE id = :id")
fun getDonate(id: String): String
@Query("SELECT support FROM ReposList WHERE id = :id")
fun getSupport(id: String): String
@Query("SELECT submitModule FROM ReposList WHERE id = :id")
fun getSubmitModule(id: String): String
@Query("SELECT lastUpdate FROM ReposList WHERE id = :id")
fun getLastUpdate(id: String): Long
@Query("SELECT name FROM ReposList WHERE id = :id")
fun getName(id: String): String
@Query("SELECT website FROM ReposList WHERE id = :id")
fun getWebsite(id: String): String
// set fun
@Query("UPDATE ReposList SET url = :url WHERE id = :id")
fun setUrl(id: String, url: String)
@Query("UPDATE ReposList SET enabled = :enabled WHERE id = :id")
fun setEnabled(id: String, enabled: Boolean)
@Query("UPDATE ReposList SET donate = :donate WHERE id = :id")
fun setDonate(id: String, donate: String)
@Query("UPDATE ReposList SET support = :support WHERE id = :id")
fun setSupport(id: String, support: String)
@Query("UPDATE ReposList SET submitModule = :submitModule WHERE id = :id")
fun setSubmitModule(id: String, submitModule: String)
@Query("UPDATE ReposList SET lastUpdate = :lastUpdate WHERE id = :id")
fun setLastUpdate(id: String, lastUpdate: Long)
@Query("UPDATE ReposList SET name = :name WHERE id = :id")
fun setName(id: String, name: String)
@Query("UPDATE ReposList SET website = :website WHERE id = :id")
fun setWebsite(id: String, website: String)
}

@ -0,0 +1,14 @@
/*
* Copyright (c) 2023 to present Androidacy and contributors. Names, logos, icons, and the Androidacy name are all trademarks of Androidacy and may not be used without license. See LICENSE for more information.
*/
package com.fox2code.mmm.utils.room
import androidx.room.Database
import androidx.room.RoomDatabase
@Suppress("unused")
@Database(entities = [ReposList::class], version = 1)
abstract class ReposListDatabase : RoomDatabase() {
abstract fun reposListDao(): ReposListDao
}
Loading…
Cancel
Save