Skip to content

Commit 7403a28

Browse files
code cleanup
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 191bcce commit 7403a28

69 files changed

Lines changed: 50 additions & 2130 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import com.fox2code.mmm.utils.io.net.Http
5151
import com.fox2code.mmm.utils.sentry.SentryBreadcrumb
5252
import com.fox2code.mmm.utils.sentry.SentryMain
5353
import com.google.android.material.bottomnavigation.BottomNavigationItemView
54+
import com.google.android.material.bottomnavigation.BottomNavigationView
5455
import com.google.android.material.dialog.MaterialAlertDialogBuilder
5556
import com.google.android.material.progressindicator.LinearProgressIndicator
5657
import com.topjohnwu.superuser.CallbackList
@@ -162,7 +163,8 @@ class InstallerActivity : FoxActivity() {
162163
val horizontalScroller = findViewById<View>(R.id.install_horizontal_scroller)
163164
var installTerminal: RecyclerView
164165
progressIndicator = findViewById(R.id.progress_bar)
165-
rebootFloatingButton = findViewById(R.id.install_terminal_reboot_fab)
166+
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation)
167+
rebootFloatingButton = bottomNavigationView.findViewById(R.id.install_terminal_reboot_fab)
166168
cancelFloatingButton = findViewById(R.id.back_installer)
167169
val rbtBtn = rebootFloatingButton
168170
val cnlBtn = cancelFloatingButton

app/src/main/kotlin/com/fox2code/mmm/manager/ModuleManager.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,24 @@ class ModuleManager private constructor() : SyncManager() {
6161
if (BuildConfig.DEBUG) Timber.d("Scan")
6262
val modulesList = StringBuilder()
6363
if (modules != null) {
64+
val db = Room.databaseBuilder(
65+
MainApplication.INSTANCE!!,
66+
ModuleListCacheDatabase::class.java,
67+
"ModuleListCache.db"
68+
).allowMainThreadQueries().build()
6469
for (module in modules) {
6570
if (!SuFile("/data/adb/modules/$module").isDirectory) continue // Ignore non directory files inside modules folder
6671
var moduleInfo = moduleInfos[module]
6772
// next, merge the module info with a record from ModuleListCache room db if it exists
6873
// initialize modulelistcache db
69-
val db = Room.databaseBuilder(
70-
MainApplication.INSTANCE!!,
71-
ModuleListCacheDatabase::class.java,
72-
"ModuleListCache"
73-
).allowMainThreadQueries().build()
7474
// get module info from cache
7575
val moduleListCacheDao: ModuleListCacheDao = db.moduleListCacheDao()
76-
Timber.d("Found cache for %s", module)
7776
// get module info from cache
7877
if (moduleInfo == null) {
7978
moduleInfo = LocalModuleInfo(module)
8079
}
8180
if (moduleListCacheDao.exists(module)) {
81+
Timber.d("Found cache for %s", module)
8282
val moduleListCache: ModuleListCache = moduleListCacheDao.getByCodename(module)
8383
moduleInfo.name =
8484
if (moduleListCache.name != "") moduleListCache.name else module
@@ -135,6 +135,7 @@ class ModuleManager private constructor() : SyncManager() {
135135
modulesList.append(moduleInfo.id).append(":").append(moduleInfo.versionCode)
136136
.append(",")
137137
}
138+
db.close()
138139
}
139140
if (modulesList.isNotEmpty()) {
140141
modulesList.deleteCharAt(modulesList.length - 1)

app/src/main/kotlin/com/fox2code/mmm/module/ActionButtonType.kt

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,20 @@ enum class ActionButtonType {
112112
moduleHolder.repoModule?.moduleInfo?.name
113113
}
114114
TrackHelper.track().event("view_update_install", name).with(INSTANCE!!.getTracker())
115-
// if icon is reinstall, we need to uninstall first - warn the user but don't proceed
115+
// if text is reinstall, we need to uninstall first - warn the user but don't proceed
116116
if (moduleHolder.moduleInfo != null) {
117-
// get icon of the button
118-
val icon = button.chipIcon
119-
if (icon != null && icon.constantState != null) {
120-
val reinstallIcon =
121-
button.context.getDrawable(R.drawable.ic_baseline_refresh_24)
122-
if (reinstallIcon != null && reinstallIcon.constantState != null) {
123-
if (icon.constantState == reinstallIcon.constantState) {
124-
MaterialAlertDialogBuilder(button.context)
125-
.setTitle(R.string.reinstall)
126-
.setMessage(R.string.reinstall_warning)
127-
.setPositiveButton(R.string.reinstall, null)
128-
.show()
129-
return
130-
}
131-
}
117+
// get the text
118+
val text = button.text
119+
// if the text is reinstall, warn the user
120+
if (text == button.context.getString(R.string.reinstall)) {
121+
val builder = MaterialAlertDialogBuilder(button.context)
122+
builder.setTitle(R.string.reinstall)
123+
.setMessage(R.string.reinstall_warning)
124+
.setCancelable(true)
125+
// ok button that does nothing
126+
.setPositiveButton(R.string.ok, null)
127+
.show()
128+
return
132129
}
133130
}
134131
val updateZipUrl = moduleHolder.updateZipUrl ?: return

app/src/main/kotlin/com/fox2code/mmm/repo/RepoManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class RepoManager private constructor(mainApplication: MainApplication) : SyncMa
234234
}
235235
if (BuildConfig.DEBUG) Timber.d("Finishing: %s", repoUpdaters[i]!!.repoData.name)
236236
isLastUpdateSuccess = repoUpdaters[i]!!.finish()
237-
if (!isLastUpdateSuccess) {
237+
if (!isLastUpdateSuccess || modules.isEmpty()) {
238238
Timber.e("Failed to update %s", repoUpdaters[i]!!.repoData.name)
239239
// Show snackbar on main looper and add some bottom padding
240240
val context: Activity? = MainApplication.INSTANCE!!.lastCompatActivity

app/src/main/kotlin/com/fox2code/mmm/repo/RepoUpdater.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class RepoUpdater(repoData2: RepoData) {
145145
// this.indexRaw is the raw index file (json)
146146
val modules = JSONObject(String(indexRaw!!, StandardCharsets.UTF_8))
147147
// androidacy repo uses "data" key, others should use "modules" key. Both are JSONArrays
148-
val modulesArray: JSONArray = if (repoData.name == "Androidacy Modules Repo") {
148+
val modulesArray: JSONArray = if (repoData.preferenceId == "androidacy_repo") {
149149
// get modules from "data" key. This is a JSONArray so we need to convert it to a JSONObject
150150
modules.getJSONArray("data")
151151
} else {
@@ -154,7 +154,13 @@ class RepoUpdater(repoData2: RepoData) {
154154
}
155155
val moduleListCacheDao = db.moduleListCacheDao()
156156
moduleListCacheDao.deleteByRepoId(repoData.preferenceId!!)
157-
// iterate over modules. pls don't hate me for this, its ugly but it works
157+
if (modulesArray.length() == 0) {
158+
Timber.w("No modules were found in the index file for %s", repoData.preferenceId)
159+
Timber.d("Finished updating database for %s in %dms", repoData.preferenceId, System.currentTimeMillis() - startTime)
160+
success.set(false)
161+
return@Thread
162+
}
163+
// iterate over modules
158164
for (n in 0 until modulesArray.length()) {
159165
// get module
160166
val module = modulesArray.getJSONObject(n)

app/src/main/res/drawable/baseline_library_add_check_24.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/src/main/res/drawable/baseline_search_24.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/src/main/res/drawable/baseline_upgrade_24.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/src/main/res/drawable/ic_baseline_access_time_24.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/src/main/res/drawable/ic_baseline_chip_24.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)