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

Commit

Permalink
Fix LocalItem
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Feb 24, 2024
1 parent 5952f77 commit 6b93ab4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.sanmer.mrepo.utils.extensions.toDateTime
fun OverviewPage(
online: OnlineModule,
item: VersionItem?,
local: LocalModule,
local: LocalModule?,
isProviderAlive: Boolean,
notifyUpdates: Boolean,
setUpdatesTag: (Boolean) -> Unit,
Expand Down Expand Up @@ -78,13 +78,15 @@ fun OverviewPage(
HorizontalDivider(thickness = 0.9.dp)
}

LocalItem(
local = local,
notifyUpdates = notifyUpdates,
setUpdatesTag = setUpdatesTag
)
if (local != null) {
LocalItem(
local = local,
notifyUpdates = notifyUpdates,
setUpdatesTag = setUpdatesTag
)

HorizontalDivider(thickness = 0.9.dp)
HorizontalDivider(thickness = 0.9.dp)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.sanmer.mrepo.database.entity.Repo
import com.sanmer.mrepo.database.entity.toRepo
import com.sanmer.mrepo.model.json.UpdateJson
import com.sanmer.mrepo.model.local.LocalModule
import com.sanmer.mrepo.model.local.example
import com.sanmer.mrepo.model.online.OnlineModule
import com.sanmer.mrepo.model.online.TrackJson
import com.sanmer.mrepo.model.online.VersionItem
Expand Down Expand Up @@ -51,15 +50,15 @@ class ModuleViewModel @Inject constructor(
&& online.track.source.isBlank()
&& online.track.support.isBlank()

var local by mutableStateOf(LocalModule.example())
var local: LocalModule? by mutableStateOf(null)
private set

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

val localVersionCode get() = if (notifyUpdates) local.versionCode else Int.MAX_VALUE
val localVersionCode get() =
if (notifyUpdates && installed) local!!.versionCode else Int.MAX_VALUE
val updatableSize by derivedStateOf {
versions.count { it.second.versionCode > localVersionCode }
}
Expand Down Expand Up @@ -96,7 +95,7 @@ class ModuleViewModel @Inject constructor(
}

if (installed) {
UpdateJson.loadToVersionItem(local.updateJson)?.let {
UpdateJson.loadToVersionItem(local!!.updateJson)?.let {
versions.add(0, "Update Json".toRepo() to it)
}
}
Expand Down

0 comments on commit 6b93ab4

Please sign in to comment.