Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Optimize ModuleViewModel
Browse files Browse the repository at this point in the history
- Fix `ViewTopBar`
  • Loading branch information
SanmerDev committed Jun 21, 2024
1 parent 4a6c80a commit 00717f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ private fun TopBarContent(
val userPreferences = LocalUserPreferences.current
val repositoryMenu = userPreferences.repositoryMenu

val hasLicense by remember {
val hasLicense by remember(module.metadata) {
derivedStateOf { module.metadata.license.isNotBlank() }
}
val hasDonate by remember {
val hasDonate by remember(module.metadata) {
derivedStateOf { module.metadata.donate.isNotBlank() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ class ModuleViewModel @Inject constructor(

var local: LocalModule? by mutableStateOf(null)
private set
val localVersionCode by lazy {
if (notifyUpdates && installed) local!!.versionCode else Int.MAX_VALUE
}

private val installed get() = local?.let { it.author == online.author } ?: false
var notifyUpdates by mutableStateOf(false)
private set
private val installed by lazy {
local?.let { it.author == online.author } ?: false
}

val localVersionCode get() =
if (notifyUpdates && installed) local!!.versionCode else Int.MAX_VALUE
val versions = mutableStateListOf<Pair<RepoEntity, VersionItem>>()
val updatableSize by derivedStateOf {
versions.count { it.second.versionCode > localVersionCode }
}

val versions = mutableStateListOf<Pair<RepoEntity, VersionItem>>()

init {
Timber.d("ModuleViewModel init: $moduleId")
Expand Down

0 comments on commit 00717f0

Please sign in to comment.