Fix the beta-to-release update, lists that could hold a row twice, one instance's list under another

- The full build's own installer compared versions with a third rule of its
  own, by which 1.0.0 was not newer than 1.0.0-beta.N: a beta would have
  answered "This is the newest version" to the release. It now uses the one
  rule (olderThan). A failure there is said in the app's words, not a
  library's.
- The drawer's chats, the archived chats and a schedule's runs ask for their
  next page whenever the list's end comes into view; while a page was on its
  way a second request for the same page could start, and the same rows twice
  end the app (duplicate keys). One read at a time, and no row twice.
- The drawer's list was one for the whole activity: after a switch of
  instance it showed the other instance's chats and badge until its read
  answered (for good, if that failed), and an instance refused as too old
  left the next one refused too. One list per instance.
- A photo taken with the phone turned was dropped when the screen was made
  again on the way back: where it was taken to is kept.
- The sign-in page scrolls, so a long sentence, large type and the keyboard
  cannot push Continue out of reach.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-12-02 20:43:58 +00:00
1 parent 81f255bd94
commit f84551c65e
9 files changed
+153 -22

No files matched your search

@@ -233,7 +233,9 @@ class MainActivity : ComponentActivity() {
val nav = rememberNavController()
val drawer = rememberDrawerState(DrawerValue.Closed)
val scope = rememberCoroutineScope()
val chats: ChatsViewModel = viewModel()
// One list per instance: what was read of one instance (its chats, its badge, whether it
// was refused as too old) is never shown, or held against, another after a switch.
val chats: ChatsViewModel = viewModel(key = "chats:" + instance.id)
val list by chats.state.collectAsStateWithLifecycle()
val instances by lembas.instances.instances.collectAsState(initial = emptyList())
val defaultInstance by lembas.instances.defaultInstance.collectAsState(initial = null)
@@ -0,0 +1,13 @@
package eu.llembas.android.ui
/**
* A list with its next [page] put after it, no row twice. A list that is read a page at a time
* asks for the next one whenever its end comes into view, and the end can come into view again
* while that page is still on its way (the list was read again meanwhile, a row was added at its
* head): the same page then arrives twice. The rows are keyed by [id], and a key drawn twice
* ends the app -- so a row [held] already, or named twice by the page itself, is not added.
*/
fun <T> appended(held: List<T>, page: List<T>, id: (T) -> String): List<T> {
val have = held.mapTo(HashSet()) { id(it) }
return held + page.filter { have.add(id(it)) }
}
@@ -163,7 +163,9 @@ fun Composer(state: ChatState, actions: ChatActions, agent: Boolean, onTune: ()
var text by rememberSaveable { mutableStateOf(initial) }
var attachMenu by remember { mutableStateOf(false) }
var listening by remember { mutableStateOf(false) }
var photo by remember { mutableStateOf<Uri?>(null) }
// Kept across the screen being made again: the camera is held sideways as often as not, and
// the photo that comes back then must still know where it was taken to.
var photo by rememberSaveable { mutableStateOf<Uri?>(null) }
val recorder = remember { Recorder(scope) }
val phone = remember { PhoneRecognizer(context) }
// What was typed before the phone's recogniser began: its words go after it as they come.
@@ -40,8 +40,10 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import eu.llembas.android.R
import eu.llembas.android.api.Chat
import eu.llembas.android.lembas
import eu.llembas.android.ui.appended
import eu.llembas.android.ui.explain
import eu.llembas.android.ui.theme.LocalPalette
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
@@ -67,13 +69,17 @@ class ArchivedViewModel(app: Application) : AndroidViewModel(app) {
}
}
private var moreRead: Job? = null
/** The page after the last row: one read at a time, and no chat twice ([appended]). */
fun more() {
if (moreRead?.isActive == true) return
val last = _state.value.chats.lastOrNull() ?: return
viewModelScope.launch {
moreRead = viewModelScope.launch {
try {
val api = getApplication<Application>().lembas.instances.client() ?: return@launch
val page = api.chats(archived = true, before = last.id)
_state.update { it.copy(chats = it.chats + page.chats, more = page.more) }
_state.update { it.copy(chats = appended(it.chats, page.chats) { chat -> chat.id }, more = page.more) }
} catch (e: Exception) {
_state.update { it.copy(error = getApplication<Application>().explain(e)) }
}
@@ -92,6 +92,7 @@ import eu.llembas.android.api.ReportsFrame
import eu.llembas.android.api.SearchHit
import eu.llembas.android.auth.Instance
import eu.llembas.android.lembas
import eu.llembas.android.ui.appended
import eu.llembas.android.ui.explain
import eu.llembas.android.ui.signin.unfit
import eu.llembas.android.ui.theme.LocalPalette
@@ -368,13 +369,17 @@ class ChatsViewModel(app: Application) : AndroidViewModel(app) {
/** How many `reports` frames have come: a list read that began before the last one is older than it. */
private var reportsTold = 0
private var moreRead: Job? = null
/** The page after the last row. One read at a time, and no chat twice ([appended]): the list asks again whenever its end comes into view. */
fun more() {
if (moreRead?.isActive == true) return
val last = _state.value.chats.lastOrNull() ?: return
viewModelScope.launch {
moreRead = viewModelScope.launch {
try {
val api = getApplication<Application>().lembas.instances.client() ?: return@launch
val page = api.chats(before = last.id)
_state.update { it.copy(chats = it.chats + page.chats, more = page.more) }
_state.update { it.copy(chats = appended(it.chats, page.chats) { chat -> chat.id }, more = page.more) }
} catch (e: Exception) {
_state.update { it.copy(error = getApplication<Application>().explain(e)) }
}
@@ -106,6 +106,7 @@ import eu.llembas.android.api.saidWithConnection
import eu.llembas.android.api.titleAmong
import eu.llembas.android.lembas
import eu.llembas.android.ui.DirectoryPicker
import eu.llembas.android.ui.appended
import eu.llembas.android.ui.explain
import eu.llembas.android.ui.progressLineOf
import eu.llembas.android.ui.theme.LocalPalette
@@ -424,12 +425,16 @@ class ScheduleViewModel(app: Application) : AndroidViewModel(app) {
}
}
private var moreRead: Job? = null
/** The runs before the last row: one read at a time, and no run twice ([appended]). */
fun more() {
if (moreRead?.isActive == true) return
val schedule = _state.value.schedule ?: return
val last = _state.value.runs.lastOrNull() ?: return
viewModelScope.launch {
moreRead = viewModelScope.launch {
runCatching { getApplication<Application>().api().scheduleRuns(schedule.id, last.id) }
.onSuccess { page -> _state.update { it.copy(runs = it.runs + page.runs, more = page.more) } }
.onSuccess { page -> _state.update { it.copy(runs = appended(it.runs, page.runs) { row -> row.id }, more = page.more) } }
}
}
@@ -244,7 +244,8 @@ fun SignInScreen(onDone: () -> Unit = {}, onCancel: (() -> Unit)? = null, model:
val knownBases by context.lembas.instances.instances.collectAsState(initial = emptyList())
val distinctBases = knownBases.map { it.base }.distinct()
Column(
modifier = Modifier.fillMaxSize().safeDrawingPadding().imePadding().padding(24.dp),
// It scrolls: a long sentence about a certificate, large type and the keyboard up must not push Continue out of reach.
modifier = Modifier.fillMaxSize().safeDrawingPadding().imePadding().verticalScroll(rememberScrollState()).padding(24.dp),
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
@@ -14,6 +14,7 @@ import eu.llembas.android.api.AppRelease
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.SharedHttp
import eu.llembas.android.api.await
import eu.llembas.android.api.olderThan
import eu.llembas.android.lembas
import eu.llembas.android.notify.NotificationAccess
import kotlinx.coroutines.Dispatchers
@@ -98,8 +99,9 @@ class Updater(private val context: Context) {
}
install(apk)
context.getString(R.string.update_installing, latest.version)
} catch (e: Exception) {
e.message ?: context.getString(R.string.update_unreachable)
} catch (_: Exception) {
// Never a library's own words on the screen: the manifest or the file did not come.
context.getString(R.string.update_unreachable)
}
}
@@ -146,17 +148,12 @@ class Updater(private val context: Context) {
companion object {
const val MANIFEST = "https://llembas.eu/android/latest.json"
/** Whether `a` is a later x.y.z than `b`. */
fun newer(a: String, b: String): Boolean {
val left = a.split(".").map { it.toIntOrNull() ?: 0 }
val right = b.split(".").map { it.toIntOrNull() ?: 0 }
for (i in 0 until maxOf(left.size, right.size)) {
val l = left.getOrElse(i) { 0 }
val r = right.getOrElse(i) { 0 }
if (l != r) return l > r
}
return false
}
/**
* Whether the version `a` is later than `b`, by the one rule the app compares versions
* with ([olderThan]): a release is later than every beta of itself, so a beta is offered
* the release it was a test of. A version that cannot be read is never later.
*/
fun newer(a: String, b: String): Boolean = olderThan(b, a)
}
}