Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ enum class DetailFetch {
* the whole design of this screen: the catalogue already carries the description, the summary, the
* scope, the collaborators and the newest release *with its APK*, so the page can paint — and be
* installed from — before any request is made, and a failed request costs the README rather than
* the page.
* the page. The exception is an entry the site has corrected since the mirror's snapshot: it names
* its version and carries no release, so that page installs once its record has arrived.
*/
data class RepoDetailsState(
val module: OnlineModule? = null,
Expand Down
37 changes: 19 additions & 18 deletions manager-ui/src/main/kotlin/org/matrix/vector/ui/store/RepoModels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import com.google.gson.annotations.SerializedName
/**
* The module repository's JSON, as types.
*
* These mirror what the server actually sends, measured against a live `modules.json` of 809
* entries. Two things shape the file:
* These mirror what the server sends. Two things shape the file:
*
* **Nullability is not decoration here.** `scope` is null on 506 of the 809 entries, `sourceUrl` on
* 369 and `summary` on 121. Gson constructs through `Unsafe` and runs neither Kotlin's
* default-argument logic nor its null checks, so a non-null type on a field the server omits yields
* a `null` that only explodes at the first dereference, far from the parse. Every field the payload
* does not guarantee is therefore declared optional.
* **Nullability is not decoration here.** Many entries leave `scope`, `sourceUrl` or `summary`
* null. Gson constructs through `Unsafe` and runs neither Kotlin's default-argument logic nor its
* null checks, so a non-null type on a field the server omits yields a `null` that only explodes at
* the first dereference, far from the parse. Every field the payload does not guarantee is
* therefore declared optional.
*
* **The list payload is nearly a detail payload.** Each list entry already carries exactly one
* release — the newest — with its `.apk` asset and download URL. Installing the current version of
* a module needs no second request, which is what lets the Store work on a bad connection.
*
* **Except where the list is the site's.** An entry from `module-list/<n>.json` names its
* `latestRelease` and carries no release, scope or collaborators at all, so `releases` being empty
* means "ask for the detail record", not "nothing was ever published".
*/
data class OnlineModule(
@SerializedName("name") val name: String,
Expand Down Expand Up @@ -58,8 +61,8 @@ data class Collaborator(
/**
* Someone credited beyond the repository's collaborators.
*
* An object, not a bare name, though the field reads like a list of names: the 49 entries that
* carry one hold `{type, name, link}`. Typed as a list of strings it makes Gson throw `Expected a
* An object, not a bare name, though the field reads like a list of names: an entry that carries
* one holds `{type, name, link}`. Typed as a list of strings it makes Gson throw `Expected a
* string but was BEGIN_OBJECT`, which takes the whole catalogue parse — and with it the entire
* Store — rather than the one module.
*/
Expand Down Expand Up @@ -88,11 +91,11 @@ data class Release(
/**
* A stable identity for a lazy list.
*
* Release *names* are not unique in real data: `com.rww.wetypeswipe` currently publishes two
* releases both named `1.11.4`, under tags `43-` and `42-`. `LazyColumn` throws
* `IllegalArgumentException` on a duplicate key, so identity comes from `id`, which is unique
* by construction, with the tag as fallback and the index as last resort — a malformed payload
* then degrades into an odd-looking list rather than a crash.
* Release *names* are not unique in real data: a module can publish two releases under one name
* and different tags. `LazyColumn` throws `IllegalArgumentException` on a duplicate key, so
* identity comes from `id`, which is unique by construction, with the tag as fallback and the
* index as last resort — a malformed payload then degrades into an odd-looking list rather than
* a crash.
*/
fun key(index: Int): String = id ?: tagName ?: "release:$index"

Expand All @@ -116,10 +119,8 @@ data class ReleaseAsset(
/**
* Whether this asset is an APK.
*
* Judged on the declared content type *and* the filename: 923 of the 946 assets in the
* catalogue declare `application/vnd.android.package-archive`, but a few authors upload theirs
* as `application/octet-stream`, and trusting the type alone would hide the only download those
* modules have.
* Judged on the declared content type *and* the filename: an APK uploaded under a generic
* content type is still the only download its module has, and the type alone would hide it.
*/
val isApk: Boolean
get() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Check
import androidx.compose.material.icons.rounded.CloudOff
Expand All @@ -46,6 +47,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -124,8 +126,24 @@ fun RepoScreen(
return@Column
}

// A list holds its first visible row where it is when rows arrive above it, and rows do:
// the mirror's catalogue is shown before the site has corrected it, and what the site
// adds is the newest releases. A reader who has not scrolled is at the top to see what
// is newest, so the top is where they stay.
val listState = rememberLazyListState()
// Read out here on purpose: the rows are otherwise read only inside the list's own
// content, so a new first row would not recompose this scope and the effect, which is
// what has to run before the list is measured again, would not run at all.
val firstRow = entries.firstOrNull()?.module?.name
SideEffect {
if (firstRow != null && !listState.canScrollBackward) {
listState.requestScrollToItem(0)
}
}

PullToRefreshBox(isRefreshing = refreshing, onRefresh = viewModel::refresh) {
LazyColumn(
state = listState,
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(bottom = 20.dp),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ enum class StoreSort {
/**
* Which releases count.
*
* Two options, not three. Of the 809 modules in the catalogue 14 publish a beta and **none**
* publishes a snapshot, so a snapshot channel would have no data behind it at all — and a control
* that can never change anything is a control that lies.
* Two options, not three. The payload carries a beta release list and nothing a snapshot channel
* could select from, so such a channel would have no data behind it — and a control that can never
* change anything is a control that lies.
*/
enum class StoreChannel(val preference: String) {
Stable("stable"),
Expand All @@ -54,27 +54,28 @@ enum class StoreChannel(val preference: String) {
/**
* Every release the chosen channel admits, newest first.
*
* **A beta is not a flagged element of `releases`; it is a different array.** In the live catalogue
* not one entry of any module's `releases` carries `isPrerelease`, and each of the 14 modules that
* publish a beta keeps it exclusively in `betaReleases`. Selecting the prerelease channel by
* filtering `releases` on `isPrerelease` therefore matches nothing at all, and the install bar
* takes the newest release with an APK straight off this list.
* **Where a beta lives depends on the payload.** In the catalogue it is not a flagged element of
* `releases` but a different array: not one list entry's `releases` carries `isPrerelease`, and
* each module that publishes a beta keeps it exclusively in `betaReleases`. In a detail record it
* is the reverse: there is no `betaReleases`, and the betas sit in `releases` with `isPrerelease`
* set. Both shapes are read here, because the install bar takes the newest release with an APK
* straight off this list whichever payload it came from.
*
* Merged, the order has to come from the version code rather than from either array's position,
* because the two are sorted independently and a beta is not automatically newer: of today's 14,
* `com.luoshui.paycardeditor` publishes beta code 1 against stable code 8.
* On the prerelease channel the order has to come from the version code rather than from position
* in either shape. The two arrays are sorted independently, a detail record is sorted by date, and
* a beta is not automatically newer: a module's newest beta can carry a lower code than its newest
* stable release. [latestOn] names the highest code, so the first element here has to be that
* release.
*/
public fun OnlineModule.releasesOn(channel: StoreChannel): List<Release> {
val published = releases.orEmpty().filter { it.isDraft != true }
if (channel == StoreChannel.Prerelease) {
val beta = betaReleases.orEmpty().filter { it.isDraft != true }
if (beta.isEmpty()) return published
return (published + beta)
.distinctBy { it.tagName ?: it.id ?: it.name }
.sortedByDescending { it.version?.versionCode ?: Long.MIN_VALUE }
}
// Defensive rather than load-bearing, and it stays because the mirror's shape is not ours to
// promise: a module that has only ever prereleased still has releases worth listing.
// A module that has only ever prereleased still has releases worth listing.
val stable = published.filter { it.isPrerelease != true }
return stable.ifEmpty { published }
}
Expand All @@ -83,8 +84,8 @@ public fun OnlineModule.releasesOn(channel: StoreChannel): List<Release> {
* The version the channel says is current — which is what every "Update to …" label states.
*
* On the prerelease channel that is whichever of the two channels is genuinely newer, not the beta
* unconditionally. Advertising `latestBetaRelease` on its own offers `paycardeditor`'s readers a
* downgrade from code 8 to code 1 and calls it an update.
* unconditionally. Advertising `latestBetaRelease` on its own would offer a reader whose newest
* beta is older than their stable release a downgrade, and call it an update.
*/
public fun OnlineModule.latestOn(channel: StoreChannel): RepoVersion? {
val stable = RepoVersion.parse(latestRelease)
Expand Down Expand Up @@ -138,7 +139,7 @@ class RepoViewModel(
* Every catalogue entry paired with what this device has, before any filtering.
*
* Shared rather than recomputed per consumer: both the list and the "n updates" count need it,
* and it walks 809 entries.
* and it walks the whole catalogue.
*/
private val allEntries: StateFlow<List<StoreEntry>> =
combine(
Expand All @@ -165,8 +166,8 @@ class RepoViewModel(
entries.filter { it.matches(query) }.sortedWith(comparatorFor(view))
}
// Off the main thread, for the reason ModulesViewModel records: stateIn on its own
// collects on Dispatchers.Main.immediate, which would put a filter and a sort over 809
// entries on the UI thread on every keystroke.
// collects on Dispatchers.Main.immediate, which would put a filter and a sort over the
// whole catalogue on the UI thread on every keystroke.
.flowOn(Dispatchers.Default)
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())

Expand Down
Loading
Loading