Skip to content

Commit 1e8e7da

Browse files
add room infra
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent a030dfe commit 1e8e7da

9 files changed

Lines changed: 375 additions & 87 deletions

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# assets/*.db are binary
2+
3+
*.db binary

app/src/main/assets/repos.db

28 KB
Binary file not shown.

app/src/main/kotlin/com/fox2code/mmm/SetupActivity.kt

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import android.widget.Toast
2020
import androidx.fragment.app.FragmentActivity
2121
import com.fox2code.foxcompat.app.FoxActivity
2222
import com.fox2code.mmm.databinding.ActivitySetupBinding
23-
import com.fox2code.mmm.repo.RepoManager
2423
import com.fox2code.mmm.utils.IntentHelper
2524
import com.fox2code.mmm.utils.realm.ReposList
2625
import com.fox2code.rosettax.LanguageActivity
@@ -346,91 +345,9 @@ class SetupActivity : FoxActivity(), LanguageActivity {
346345
}
347346
}
348347

349-
// creates the realm database
350-
private fun createRealmDatabase() {
351-
if (realmDatabasesCreated) {
352-
Timber.d("Realm databases already created")
353-
return
354-
}
355-
Timber.d("Creating Realm databases")
356-
val startTime = System.currentTimeMillis()
357-
// create encryption key
358-
Timber.d("Creating encryption key")
359-
val key = MainApplication.INSTANCE!!.key
360-
// create the realm database for ReposList
361-
// create the realm configuration
362-
val config = RealmConfiguration.Builder().name("ReposList.realm")
363-
.directory(MainApplication.INSTANCE!!.getDataDirWithPath("realms")).schemaVersion(1)
364-
.encryptionKey(key).build()
365-
// get the instance
366-
Realm.getInstanceAsync(config, object : Realm.Callback() {
367-
override fun onSuccess(realm: Realm) {
368-
Timber.d("Realm instance: %s", realm)
369-
realm.beginTransaction()
370-
// create the ReposList realm database
371-
Timber.d("Creating ReposList realm database")
372-
if (realm.where(ReposList::class.java).equalTo("id", "androidacy_repo")
373-
.findFirst() == null
374-
) {
375-
Timber.d("Creating androidacyRepo")
376-
// create the androidacyRepo row
377-
// cant use createObject because it crashes because reasons. use copyToRealm instead
378-
val androidacyRepo =
379-
realm.createObject(ReposList::class.java, "androidacy_repo")
380-
Timber.d("Created androidacyRepo object")
381-
androidacyRepo.name = "Androidacy Repo"
382-
Timber.d("Set androidacyRepo name")
383-
androidacyRepo.donate =
384-
"https://www.androidacy.com/membership-account/membership-join/?utm_source=fox-app&utm_medium=app&utm_campaign=app"
385-
Timber.d("Set androidacyRepo donate")
386-
androidacyRepo.support = "https://t.me/androidacy_discussions"
387-
Timber.d("Set androidacyRepo support")
388-
androidacyRepo.submitModule =
389-
"https://www.androidacy.com/module-repository-applications/?utm_source=fox-app&utm_medium=app&utm_campaign=app"
390-
Timber.d("Set androidacyRepo submit module")
391-
androidacyRepo.url = RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT
392-
Timber.d("Set androidacyRepo url")
393-
androidacyRepo.isEnabled = true
394-
Timber.d("Set androidacyRepo enabled")
395-
androidacyRepo.lastUpdate = 0
396-
Timber.d("Set androidacyRepo last update")
397-
androidacyRepo.website = RepoManager.ANDROIDACY_MAGISK_REPO_HOMEPAGE
398-
Timber.d("Set androidacyRepo website")
399-
// now copy the data from the data class to the realm object using copyToRealmOrUpdate
400-
Timber.d("Copying data to realm object")
401-
realm.copyToRealmOrUpdate(androidacyRepo)
402-
Timber.d("Created androidacyRepo")
403-
}
404-
// create magiskAltRepo
405-
if (realm.where(ReposList::class.java).equalTo("id", "magisk_alt_repo")
406-
.findFirst() == null
407-
) {
408-
Timber.d("Creating magiskAltRepo")
409-
val magiskAltRepo =
410-
realm.createObject(ReposList::class.java, "magisk_alt_repo")
411-
Timber.d("Created magiskAltRepo object")
412-
magiskAltRepo.name = "Magisk Alt Repo"
413-
magiskAltRepo.donate = null
414-
magiskAltRepo.website = RepoManager.MAGISK_ALT_REPO_HOMEPAGE
415-
magiskAltRepo.support = null
416-
magiskAltRepo.isEnabled = true
417-
magiskAltRepo.url = RepoManager.MAGISK_ALT_REPO_JSDELIVR
418-
magiskAltRepo.submitModule =
419-
"${RepoManager.MAGISK_ALT_REPO_HOMEPAGE}/submission"
420-
magiskAltRepo.lastUpdate = 0
421-
// commit the changes
422-
Timber.d("Copying data to realm object")
423-
realm.copyToRealmOrUpdate(magiskAltRepo)
424-
Timber.d("Created magiskAltRepo")
425-
}
426-
realm.commitTransaction()
427-
realm.close()
428-
realmDatabasesCreated = true
429-
Timber.d("Realm transaction finished")
430-
val endTime = System.currentTimeMillis()
431-
Timber.d("Realm databases created in %d ms", endTime - startTime)
432-
}
433-
})
348+
// creates the room database
349+
private fun createDatabases() {
350+
val appContext = MainApplication.INSTANCE!!.applicationContext
434351
}
435352

436353
private fun createFiles() {
@@ -457,7 +374,7 @@ class SetupActivity : FoxActivity(), LanguageActivity {
457374
} catch (e: IOException) {
458375
Timber.e(e)
459376
}
460-
createRealmDatabase()
377+
createDatabases()
461378
}
462379

463380
@Suppress("KotlinConstantConditions")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* 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.
3+
*/
4+
5+
package com.fox2code.mmm.utils.room
6+
7+
import androidx.room.Entity
8+
9+
@Suppress("unused")
10+
@Entity(tableName = "modulelistcache")
11+
class ModuleListCache (
12+
var codename: String,
13+
var version: String,
14+
var versionCode: Int,
15+
var author: String,
16+
var description: String,
17+
var minApi: Int,
18+
var maxApi: Int,
19+
var minMagisk: Int,
20+
var needRamdisk: Boolean,
21+
var support: String,
22+
var donate: String,
23+
var config: String,
24+
var changeBoot: Boolean,
25+
var mmtReborn: Boolean,
26+
var repoId: String,
27+
var lastUpdate: Long
28+
) {
29+
// functions:
30+
// getAll(): List<ModuleListCache>
31+
// getByCodename(codename: String): ModuleListCache
32+
// insert(moduleListCache: ModuleListCache)
33+
// update(moduleListCache: ModuleListCache)
34+
// delete(moduleListCache: ModuleListCache)
35+
// deleteAll()
36+
// count(): Int
37+
38+
// get fun
39+
// getVersion(codename: String): String
40+
// getVersionCode(codename: String): Int
41+
// getAuthor(codename: String): String
42+
// getDescription(codename: String): String
43+
// getMinApi(codename: String): Int
44+
// getMaxApi(codename: String): Int
45+
// getMinMagisk(codename: String): Int
46+
// getNeedRamdisk(codename: String): Boolean
47+
// getSupport(codename: String): String
48+
// getDonate(codename: String): String
49+
// getConfig(codename: String): String
50+
// getChangeBoot(codename: String): Boolean
51+
// getMmtReborn(codename: String): Boolean
52+
// getRepoId(codename: String): String
53+
// getLastUpdate(codename: String): Long
54+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* 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.
3+
*/
4+
5+
package com.fox2code.mmm.utils.room
6+
7+
import androidx.room.Dao
8+
import androidx.room.Query
9+
10+
11+
// contains
12+
// 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)
13+
@Suppress("unused")
14+
@Dao
15+
interface ModuleListCacheDao {
16+
// functions:
17+
// getAll(): List<ModuleListCache>
18+
// getByRepoId(repoId: String): List<ModuleListCache>
19+
// getByCodename(codename: String): ModuleListCache
20+
// insert(moduleListCache: ModuleListCache)
21+
// update(moduleListCache: ModuleListCache)
22+
// delete(moduleListCache: ModuleListCache)
23+
// deleteAll()
24+
// count(): Int
25+
26+
// get fun
27+
// getVersion(codename: String): String
28+
// getVersionCode(codename: String): Int
29+
// getAuthor(codename: String): String
30+
// getDescription(codename: String): String
31+
// getMinApi(codename: String): Int
32+
// getMaxApi(codename: String): Int
33+
// getMinMagisk(codename: String): Int
34+
// getNeedRamdisk(codename: String): Boolean
35+
// getSupport(codename: String): String
36+
// getDonate(codename: String): String
37+
// getConfig(codename: String): String
38+
// getChangeBoot(codename: String): Boolean
39+
// getMmtReborn(codename: String): Boolean
40+
// getRepoId(codename: String): String
41+
// getLastUpdate(codename: String): Long
42+
43+
// set fun
44+
// setVersion(codename: String, version: String)
45+
// setVersionCode(codename: String, versionCode: Int)
46+
// setAuthor(codename: String, author: String)
47+
// setDescription(codename: String, description: String)
48+
// setMinApi(codename: String, minApi: Int)
49+
// setMaxApi(codename: String, maxApi: Int)
50+
// setMinMagisk(codename: String, minMagisk: Int)
51+
// setNeedRamdisk(codename: String, needRamdisk: Boolean)
52+
// setSupport(codename: String, support: String)
53+
// setDonate(codename: String, donate: String)
54+
// setConfig(codename: String, config: String)
55+
// setChangeBoot(codename: String, changeBoot: Boolean)
56+
// setMmtReborn(codename: String, mmtReborn: Boolean)
57+
// setRepoId(codename: String, repoId: String)
58+
// setLastUpdate(codename: String, lastUpdate: Long)
59+
60+
@Query("SELECT * FROM modulelistcache")
61+
fun getAll(): List<ModuleListCache>
62+
63+
@Query("SELECT * FROM modulelistcache WHERE repoId = :repoId")
64+
fun getByRepoId(repoId: String): List<ModuleListCache>
65+
66+
@Query("SELECT * FROM modulelistcache WHERE codename = :codename")
67+
fun getByCodename(codename: String): ModuleListCache
68+
69+
@Query("INSERT INTO modulelistcache VALUES (:codename, :version, :versionCode, :author, :description, :minApi, :maxApi, :minMagisk, :needRamdisk, :support, :donate, :config, :changeBoot, :mmtReborn, :repoId, :lastUpdate)")
70+
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)
71+
72+
@Query("UPDATE modulelistcache SET version = :version WHERE codename = :codename")
73+
fun setVersion(codename: String, version: String)
74+
75+
@Query("UPDATE modulelistcache SET versionCode = :versionCode WHERE codename = :codename")
76+
fun setVersionCode(codename: String, versionCode: Int)
77+
78+
@Query("UPDATE modulelistcache SET author = :author WHERE codename = :codename")
79+
fun setAuthor(codename: String, author: String)
80+
81+
@Query("UPDATE modulelistcache SET description = :description WHERE codename = :codename")
82+
fun setDescription(codename: String, description: String)
83+
84+
@Query("UPDATE modulelistcache SET minApi = :minApi WHERE codename = :codename")
85+
fun setMinApi(codename: String, minApi: Int)
86+
87+
@Query("UPDATE modulelistcache SET maxApi = :maxApi WHERE codename = :codename")
88+
fun setMaxApi(codename: String, maxApi: Int)
89+
90+
@Query("UPDATE modulelistcache SET minMagisk = :minMagisk WHERE codename = :codename")
91+
fun setMinMagisk(codename: String, minMagisk: Int)
92+
93+
@Query("UPDATE modulelistcache SET needRamdisk = :needRamdisk WHERE codename = :codename")
94+
fun setNeedRamdisk(codename: String, needRamdisk: Boolean)
95+
96+
@Query("UPDATE modulelistcache SET support = :support WHERE codename = :codename")
97+
fun setSupport(codename: String, support: String)
98+
99+
@Query("UPDATE modulelistcache SET donate = :donate WHERE codename = :codename")
100+
fun setDonate(codename: String, donate: String)
101+
102+
@Query("UPDATE modulelistcache SET config = :config WHERE codename = :codename")
103+
fun setConfig(codename: String, config: String)
104+
105+
@Query("UPDATE modulelistcache SET changeBoot = :changeBoot WHERE codename = :codename")
106+
fun setChangeBoot(codename: String, changeBoot: Boolean)
107+
108+
@Query("UPDATE modulelistcache SET mmtReborn = :mmtReborn WHERE codename = :codename")
109+
fun setMmtReborn(codename: String, mmtReborn: Boolean)
110+
111+
@Query("UPDATE modulelistcache SET repoId = :repoId WHERE codename = :codename")
112+
fun setRepoId(codename: String, repoId: String)
113+
114+
@Query("UPDATE modulelistcache SET lastUpdate = :lastUpdate WHERE codename = :codename")
115+
fun setLastUpdate(codename: String, lastUpdate: Long)
116+
117+
@Query("DELETE FROM modulelistcache WHERE codename = :codename")
118+
fun delete(codename: String)
119+
120+
@Query("DELETE FROM modulelistcache")
121+
fun deleteAll()
122+
123+
@Query("SELECT COUNT(*) FROM modulelistcache")
124+
fun count(): Int
125+
126+
@Query("SELECT version FROM modulelistcache WHERE codename = :codename")
127+
fun getVersion(codename: String): String
128+
129+
@Query("SELECT versionCode FROM modulelistcache WHERE codename = :codename")
130+
fun getVersionCode(codename: String): Int
131+
132+
@Query("SELECT author FROM modulelistcache WHERE codename = :codename")
133+
fun getAuthor(codename: String): String
134+
135+
@Query("SELECT description FROM modulelistcache WHERE codename = :codename")
136+
fun getDescription(codename: String): String
137+
138+
@Query("SELECT minApi FROM modulelistcache WHERE codename = :codename")
139+
fun getMinApi(codename: String): Int
140+
141+
@Query("SELECT maxApi FROM modulelistcache WHERE codename = :codename")
142+
fun getMaxApi(codename: String): Int
143+
144+
@Query("SELECT minMagisk FROM modulelistcache WHERE codename = :codename")
145+
fun getMinMagisk(codename: String): Int
146+
147+
@Query("SELECT needRamdisk FROM modulelistcache WHERE codename = :codename")
148+
fun getNeedRamdisk(codename: String): Boolean
149+
150+
@Query("SELECT support FROM modulelistcache WHERE codename = :codename")
151+
fun getSupport(codename: String): String
152+
153+
@Query("SELECT donate FROM modulelistcache WHERE codename = :codename")
154+
fun getDonate(codename: String): String
155+
156+
@Query("SELECT config FROM modulelistcache WHERE codename = :codename")
157+
fun getConfig(codename: String): String
158+
159+
@Query("SELECT changeBoot FROM modulelistcache WHERE codename = :codename")
160+
fun getChangeBoot(codename: String): Boolean
161+
162+
@Query("SELECT mmtReborn FROM modulelistcache WHERE codename = :codename")
163+
fun getMmtReborn(codename: String): Boolean
164+
165+
@Query("SELECT repoId FROM modulelistcache WHERE codename = :codename")
166+
fun getRepoId(codename: String): String
167+
168+
@Query("SELECT lastUpdate FROM modulelistcache WHERE codename = :codename")
169+
fun getLastUpdate(codename: String): Long
170+
171+
@Query("SELECT * FROM modulelistcache WHERE codename = :codename")
172+
fun get(codename: String): ModuleListCache
173+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* 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.
3+
*/
4+
5+
package com.fox2code.mmm.utils.room
6+
7+
import androidx.room.Database
8+
9+
@Suppress("unused")
10+
@Database(entities = [ModuleListCache::class], version = 1)
11+
abstract class ModuleListCacheDatabase {
12+
abstract fun moduleListCacheDao(): ModuleListCacheDao
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* 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.
3+
*/
4+
5+
package com.fox2code.mmm.utils.room
6+
7+
import androidx.room.Entity
8+
import androidx.room.PrimaryKey
9+
10+
@Entity(tableName = "ReposList")
11+
data class ReposList(
12+
@PrimaryKey var id: String,
13+
var url: String,
14+
var enabled: Boolean,
15+
var donate: String,
16+
var support: String,
17+
var submitModule: String,
18+
var lastUpdate: Long,
19+
var name: String,
20+
var website: String
21+
)

0 commit comments

Comments
 (0)