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:
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.ui.appended
|
||||
import eu.llembas.android.ui.chat.composerPhoto
|
||||
import eu.llembas.android.update.Updater
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
/** What the third review of the app found and fixed, each as the rule it now follows. */
|
||||
class ThirdReviewTest {
|
||||
// --- The updater compares versions as the rest of the app does ------------------------------
|
||||
|
||||
@Test
|
||||
fun aBetaIsOfferedTheReleaseItWasATestOf() {
|
||||
// What the website's manifest names is a release; the app asking may be one of its betas.
|
||||
assertTrue(Updater.newer("1.0.0", "1.0.0-beta.17"))
|
||||
assertTrue(Updater.newer("1.0.0", "1.0.0-beta.2"))
|
||||
assertFalse(Updater.newer("1.0.0-beta.17", "1.0.0"))
|
||||
assertFalse(Updater.newer("1.0.0", "1.0.0"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun betasCompareByTheirNumberAndPatchesByTheirs() {
|
||||
assertTrue(Updater.newer("1.0.0-beta.10", "1.0.0-beta.9"))
|
||||
assertFalse(Updater.newer("1.0.0-beta.9", "1.0.0-beta.10"))
|
||||
assertTrue(Updater.newer("1.0.1", "1.0.0"))
|
||||
// The beta of a later patch is later than the release before it.
|
||||
assertTrue(Updater.newer("1.0.1-beta.1", "1.0.0"))
|
||||
assertFalse(Updater.newer("1.0.0", "1.0.1-beta.1"))
|
||||
assertTrue(Updater.newer("v1.2.0", "1.1.9"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aVersionThatCannotBeReadIsNeverLater() {
|
||||
assertFalse(Updater.newer("", "1.0.0"))
|
||||
assertFalse(Updater.newer("newest", "1.0.0"))
|
||||
assertFalse(Updater.newer("2.0", "1.0.0"))
|
||||
assertFalse(Updater.newer("1.0.1", "unknown"))
|
||||
}
|
||||
|
||||
// --- A list read a page at a time never holds a row twice -----------------------------------
|
||||
|
||||
@Test
|
||||
fun aPageThatArrivesTwiceAddsItsRowsOnce() {
|
||||
val held = listOf("a", "b")
|
||||
val once = appended(held, listOf("c", "d")) { it }
|
||||
assertEquals(listOf("a", "b", "c", "d"), once)
|
||||
// The same page again -- asked for twice while the first answer was on its way.
|
||||
assertEquals(once, appended(once, listOf("c", "d")) { it })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aPageThatOverlapsTheListAddsOnlyWhatIsNew() {
|
||||
// The list was read again meanwhile and already holds part of the page.
|
||||
assertEquals(listOf("a", "b", "c", "d"), appended(listOf("a", "b", "c"), listOf("b", "c", "d")) { it })
|
||||
// A page that names a row twice itself.
|
||||
assertEquals(listOf("a", "b"), appended(listOf("a"), listOf("b", "b")) { it })
|
||||
assertEquals(listOf("a"), appended(listOf("a"), emptyList()) { it })
|
||||
assertEquals(listOf("a"), appended(emptyList(), listOf("a")) { it })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rowsAreToldApartByTheirIdNotByWhatElseTheyHold() {
|
||||
val held = listOf("1" to "old title")
|
||||
val page = listOf("1" to "new title", "2" to "another")
|
||||
// The row held stays as it is; only the one not held is added.
|
||||
assertEquals(listOf("1" to "old title", "2" to "another"), appended(held, page) { it.first })
|
||||
}
|
||||
|
||||
// --- Only the camera's photo is read with the app's own rights ------------------------------
|
||||
|
||||
@Test
|
||||
fun thePhotoTakenForTheComposerIsTheAppsOwn() {
|
||||
val own = "eu.example.app.files"
|
||||
assertTrue(composerPhoto(own, listOf("camera", "photo-1.jpg"), own))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nothingElseOfTheAppsOwnProviderIsAPhoto() {
|
||||
val own = "eu.example.app.files"
|
||||
// A copy of one of the account's files, held for another app.
|
||||
assertFalse(composerPhoto(own, listOf("shared", "1234", "notes.md"), own))
|
||||
assertFalse(composerPhoto(own, listOf("shared", "camera"), own))
|
||||
// Deeper than the folder, or the folder alone.
|
||||
assertFalse(composerPhoto(own, listOf("camera", "more", "photo-1.jpg"), own))
|
||||
assertFalse(composerPhoto(own, listOf("camera"), own))
|
||||
assertFalse(composerPhoto(own, emptyList(), own))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anotherAppsAddressIsNeverThePhoto() {
|
||||
val own = "eu.example.app.files"
|
||||
assertFalse(composerPhoto("com.example.gallery", listOf("camera", "photo-1.jpg"), own))
|
||||
assertFalse(composerPhoto(null, listOf("camera", "photo-1.jpg"), own))
|
||||
// An authority is compared whole: one that merely ends like the app's is another's.
|
||||
assertFalse(composerPhoto("x.$own", listOf("camera", "photo-1.jpg"), own))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user