10 Commits
Author SHA1 Message Date
OneWay 8e871c4fe8 fix(search): reset results scroll after query changes 2026-12-01 02:07:57 +08:00
OneWay 4b8645d43f chore(deps): use base lifecycle runtime artifact 2026-12-01 01:45:04 +08:00
OneWay 456dba6b20 chore(deps): bump lifecycle to 2.11.1 2026-11-30 00:09:36 +08:00
OneWay d93596f8c2 chore(deps): bump AGP to 9.5.3 2026-11-30 00:09:17 +08:00
OneWay 9c71ea26be refactor(about): replace FlowRow with FlexBox
FlexBox is the Compose 1.13 successor of FlowRow and covers the
same wrapping layout with explicit wrap and gap configuration.
2026-11-22 18:47:27 +08:00
OneWay f2b90026cd refactor(article): use CapturedAnimatedVisibility for the overlay
CapturedAnimatedVisibility keeps a snapshot of the last frame
while the overlay exits, so the manual lastShownArticle fallback
is no longer needed to prevent flicker on close.
2026-11-22 18:47:27 +08:00
OneWay 983e28fcf4 perf(article): hoist accessibility listener to screen level
Each article block registered its own assistive-accessibility listeners,
so a long article accumulated one listener pair per block. Register the
listeners once per article screen and share the state through a
CompositionLocal so the block count no longer grows the listener set.
2026-11-22 18:47:27 +08:00
OneWay e733a2f3c0 perf(import): resolve imported file names off the main thread
Importing dictionaries queried the content resolver for each file
name on the main thread, blocking the UI while the provider answered.
Resolve the display name on the IO dispatcher so the query no longer
runs on the main thread.
2026-11-22 18:47:27 +08:00
OneWay 27f77f2eba perf(pipeline): remove fixed reindex delay and main-thread file snapshot
The reindex pipeline slept for a fixed second after waiting for
indexing to finish, even though the wait already blocks until the
index is ready, and it listed the dictionary directory on the main
thread. Drop the redundant sleep and take the directory snapshot on
the IO dispatcher so the pipeline no longer stalls the UI thread.
2026-11-22 18:47:27 +08:00
OneWay ec32b84ac9 chore(deps): bump Compose to 1.13 and compileSdk to 37.1 2026-11-22 18:47:27 +08:00
12 changed files with 80 additions and 73 deletions

No files matched your search

+4 -3
View File
@@ -86,15 +86,16 @@ The main search screen remains usable as long as at least one indexed dictionary
## Tech Stack ## Tech Stack
- Kotlin 2.4.21 - Kotlin 2.4.21
- Jetpack Compose (BOM 2026.09.00) - Jetpack Compose 1.13 (BOM 2026.11.01)
- Material 3 1.5.0 - Material 3 1.5.0
- Coroutines and Flow 1.11.0 - Coroutines and Flow 1.11.0
- DataStore Preferences 1.3.0 - DataStore Preferences 1.3.0
- Lifecycle 2.11.1
- Paging 3.5.3 - Paging 3.5.3
- OkHttp 5.5.1 - OkHttp 5.5.1
- kotlinx.serialization 1.12.0 - kotlinx.serialization 1.13.0
- AboutLibraries 15.3.0 metadata generation - AboutLibraries 15.3.0 metadata generation
- Android Gradle Plugin 9.5.1 - Android Gradle Plugin 9.5.3
## Build ## Build
+7 -2
View File
@@ -87,7 +87,12 @@ kotlin {
android { android {
namespace = "com.example.research" namespace = "com.example.research"
compileSdk = project.property("compileSdk").toString().toInt() val compileSdkSpec = project.property("compileSdk").toString().split(".").map(String::toInt)
compileSdk {
version = release(compileSdkSpec[0]) {
minorApiLevel = compileSdkSpec.getOrElse(1) { 0 }
}
}
defaultConfig { defaultConfig {
applicationId = "com.example.research" applicationId = "com.example.research"
@@ -174,7 +179,7 @@ dependencies {
implementation(libs.androidx.core) implementation(libs.androidx.core)
implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.runtime.compose) implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.activity.compose) implementation(libs.androidx.activity.compose)
implementation(libs.androidx.documentfile) implementation(libs.androidx.documentfile)
@@ -8,11 +8,9 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import kotlin.time.Duration.Companion.seconds
class DictionaryPipelineCoordinator( class DictionaryPipelineCoordinator(
private val scope: CoroutineScope, private val scope: CoroutineScope,
@@ -62,7 +60,9 @@ class DictionaryPipelineCoordinator(
pipelineJob?.cancel() pipelineJob?.cancel()
pipelineJob = scope.launch(launchDispatcher) { pipelineJob = scope.launch(launchDispatcher) {
val dir = File(dictionaryPath()) val dir = File(dictionaryPath())
val filesBeforeReindex = dir.listFiles()?.map { it.name }?.toSet() ?: emptySet() val filesBeforeReindex = withContext(ioDispatcher) {
dir.listFiles()?.map { it.name }?.toSet() ?: emptySet()
}
try { try {
triggerReindexing(isImport) triggerReindexing(isImport)
if (isImport) { if (isImport) {
@@ -95,7 +95,6 @@ class DictionaryPipelineCoordinator(
private suspend fun triggerReindexing(isImport: Boolean) = withContext(ioDispatcher) { private suspend fun triggerReindexing(isImport: Boolean) = withContext(ioDispatcher) {
steps.waitForIndexingCompletion() steps.waitForIndexingCompletion()
delay(1.seconds)
val path = dictionaryPath() val path = dictionaryPath()
if (isImport) { if (isImport) {
@@ -55,7 +55,7 @@ class DictionaryImportManager(
try { try {
for ((index, uri) in uris.withIndex()) { for ((index, uri) in uris.withIndex()) {
currentCoroutineContext().ensureActive() currentCoroutineContext().ensureActive()
val fileName = getFileName(uri) ?: continue val fileName = withContext(Dispatchers.IO) { getFileName(uri) } ?: continue
if (SafeFileName.validate(fileName) == null) { if (SafeFileName.validate(fileName) == null) {
deferredErrors += context.getString(R.string.import_invalid_file_name, fileName) deferredErrors += context.getString(R.string.import_invalid_file_name, fileName)
continue continue
@@ -5,7 +5,8 @@ import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.FlexBox
import androidx.compose.foundation.layout.FlexWrap
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -259,9 +260,11 @@ private fun AboutLibraryRow(
} }
if (library.licenses.isNotEmpty()) { if (library.licenses.isNotEmpty()) {
FlowRow( FlexBox(
horizontalArrangement = Arrangement.spacedBy(6.dp), config = {
verticalArrangement = Arrangement.spacedBy(6.dp) wrap(FlexWrap.Wrap)
gap(6.dp)
}
) { ) {
library.licenses.forEach { licenseId -> library.licenses.forEach { licenseId ->
val license = licenses[licenseId] ?: return@forEach val license = licenses[licenseId] ?: return@forEach
@@ -278,13 +281,15 @@ private fun AboutLibraryRow(
} }
if (expanded && (website != null || source != null)) { if (expanded && (website != null || source != null)) {
FlowRow( FlexBox(
modifier = Modifier modifier = Modifier
.padding(top = 2.dp) .padding(top = 2.dp)
.testTag("about_library_expanded_actions") .testTag("about_library_expanded_actions")
.semantics { testTagsAsResourceId = true }, .semantics { testTagsAsResourceId = true },
horizontalArrangement = Arrangement.spacedBy(8.dp), config = {
verticalArrangement = Arrangement.spacedBy(8.dp) wrap(FlexWrap.Wrap)
gap(8.dp)
}
) { ) {
source?.let { url -> source?.let { url ->
OutlinedChoiceButton( OutlinedChoiceButton(
@@ -31,6 +31,8 @@ import com.example.research.BuildConfig
internal val LocalForceStockArticleLinks = compositionLocalOf { false } internal val LocalForceStockArticleLinks = compositionLocalOf { false }
internal val LocalAssistiveAccessibilityEnabled = compositionLocalOf { false }
internal val ArticleReferenceAtOffsetAction = internal val ArticleReferenceAtOffsetAction =
SemanticsPropertyKey<(Int) -> Boolean>("ArticleReferenceAtOffsetAction") SemanticsPropertyKey<(Int) -> Boolean>("ArticleReferenceAtOffsetAction")
@@ -58,7 +60,7 @@ internal fun ArticleLinkText(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
preferDirectHitTesting: Boolean = false, preferDirectHitTesting: Boolean = false,
) { ) {
val accessibilityEnabled = rememberAssistiveAccessibilityEnabled() val accessibilityEnabled = LocalAssistiveAccessibilityEnabled.current
val inputMode = LocalInputModeManager.current.inputMode val inputMode = LocalInputModeManager.current.inputMode
val forceStockLinks = LocalForceStockArticleLinks.current val forceStockLinks = LocalForceStockArticleLinks.current
val useDirectLinkHitTesting = val useDirectLinkHitTesting =
@@ -136,7 +138,7 @@ internal fun ArticleLinkText(
} }
@Composable @Composable
private fun rememberAssistiveAccessibilityEnabled(): Boolean { internal fun rememberAssistiveAccessibilityEnabled(): Boolean {
val context = LocalContext.current val context = LocalContext.current
val manager = remember(context) { context.getSystemService<AccessibilityManager>() } val manager = remember(context) { context.getSystemService<AccessibilityManager>() }
var enabled by remember(manager) { var enabled by remember(manager) {
@@ -24,6 +24,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.key import androidx.compose.runtime.key
@@ -134,6 +135,7 @@ fun ArticleContent(
} }
} }
val accessibilityEnabled = rememberAssistiveAccessibilityEnabled()
val isHeavyArticle = articleState.isHeavy val isHeavyArticle = articleState.isHeavy
val darkTheme = MaterialTheme.colorScheme.background.luminance() < 0.5f val darkTheme = MaterialTheme.colorScheme.background.luminance() < 0.5f
@@ -193,10 +195,14 @@ fun ArticleContent(
.onSizeChanged { viewportSize = it } .onSizeChanged { viewportSize = it }
.windowInsetsPadding(AppWindowInsets.horizontalSafeDrawing) .windowInsetsPadding(AppWindowInsets.horizontalSafeDrawing)
.padding(end = 16.dp) .padding(end = 16.dp)
if (isHeavyArticle) { CompositionLocalProvider(
articleList(articleListModifier) LocalAssistiveAccessibilityEnabled provides accessibilityEnabled
} else { ) {
SelectionContainer { articleList(articleListModifier) } if (isHeavyArticle) {
articleList(articleListModifier)
} else {
SelectionContainer { articleList(articleListModifier) }
}
} }
} }
is ArticleState.Error -> { is ArticleState.Error -> {
@@ -56,7 +56,6 @@ internal fun SearchResultsPane(
) )
var restoredScrollPosition by remember { mutableStateOf(false) } var restoredScrollPosition by remember { mutableStateOf(false) }
var pendingScrollToTop by remember { mutableStateOf(false) } var pendingScrollToTop by remember { mutableStateOf(false) }
var sawRefreshForPendingScroll by remember { mutableStateOf(false) }
var staleEntries by remember { mutableStateOf(emptyList<IndexEntry>()) } var staleEntries by remember { mutableStateOf(emptyList<IndexEntry>()) }
val imeBottomPadding = with(LocalDensity.current) { val imeBottomPadding = with(LocalDensity.current) {
WindowInsets.ime.getBottom(this).toDp() WindowInsets.ime.getBottom(this).toDp()
@@ -80,7 +79,6 @@ internal fun SearchResultsPane(
.collectLatest { query -> .collectLatest { query ->
restoredScrollPosition = true restoredScrollPosition = true
pendingScrollToTop = query.isNotBlank() pendingScrollToTop = query.isNotBlank()
sawRefreshForPendingScroll = false
if (query.isBlank()) { if (query.isBlank()) {
staleEntries = emptyList() staleEntries = emptyList()
} }
@@ -97,27 +95,15 @@ internal fun SearchResultsPane(
results.loadState.refresh is LoadState.Loading results.loadState.refresh is LoadState.Loading
val shownStale = if (pendingReload && searchState.text.isNotBlank()) staleEntries else emptyList() val shownStale = if (pendingReload && searchState.text.isNotBlank()) staleEntries else emptyList()
LaunchedEffect(results.loadState.refresh, pendingScrollToTop) {
if (pendingScrollToTop && results.loadState.refresh is LoadState.Loading) {
sawRefreshForPendingScroll = true
}
}
LaunchedEffect( LaunchedEffect(
results.itemSnapshotList,
results.loadState.refresh, results.loadState.refresh,
pendingScrollToTop,
sawRefreshForPendingScroll,
listState, listState,
) { ) {
if ( if (pendingScrollToTop && results.loadState.refresh is LoadState.NotLoading) {
pendingScrollToTop &&
sawRefreshForPendingScroll &&
results.loadState.refresh is LoadState.NotLoading
) {
snapshotFlow { listState.isScrollInProgress }.first { isScrollInProgress -> !isScrollInProgress } snapshotFlow { listState.isScrollInProgress }.first { isScrollInProgress -> !isScrollInProgress }
listState.scrollToItem(0) listState.scrollToItem(0)
pendingScrollToTop = false pendingScrollToTop = false
sawRefreshForPendingScroll = false
} }
} }
@@ -2,7 +2,7 @@ package com.example.research.ui.navigation
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.CapturedAnimatedVisibility
import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally import androidx.compose.animation.slideInHorizontally
@@ -23,7 +23,6 @@ import com.example.research.feature.search.SearchAction
import com.example.research.feature.search.SearchViewModel import com.example.research.feature.search.SearchViewModel
import com.example.research.ui.about.AboutScreen import com.example.research.ui.about.AboutScreen
import com.example.research.ui.article.ArticleScreen import com.example.research.ui.article.ArticleScreen
import com.example.research.ui.article.ArticleState
import com.example.research.ui.main.MainRoute import com.example.research.ui.main.MainRoute
import com.example.research.ui.settings.SettingsRoute import com.example.research.ui.settings.SettingsRoute
import com.example.research.ui.settings.SettingsViewModel import com.example.research.ui.settings.SettingsViewModel
@@ -103,10 +102,6 @@ fun AppNavigation(
} }
val articleState by searchViewModel.selectedArticle.collectAsStateWithLifecycle() val articleState by searchViewModel.selectedArticle.collectAsStateWithLifecycle()
var lastShownArticle by remember { mutableStateOf<ArticleState?>(null) }
LaunchedEffect(articleState) {
if (articleState != null) lastShownArticle = articleState
}
val effectiveScreen = when { val effectiveScreen = when {
currentScreen == Screen.About -> Screen.About currentScreen == Screen.About -> Screen.About
@@ -171,31 +166,34 @@ fun AppNavigation(
} }
} }
AnimatedVisibility( CapturedAnimatedVisibility(
visible = currentScreen == Screen.Article && articleState != null, visible = currentScreen == Screen.Article && articleState != null,
enter = fadeIn(tween(180)) + slideInHorizontally(tween(180)) { it / 3 }, enter = fadeIn(tween(180)) + slideInHorizontally(tween(180)) { it / 3 },
exit = fadeOut(tween(180)) + slideOutHorizontally(tween(180)) { it / 3 }, exit = fadeOut(tween(180)) + slideOutHorizontally(tween(180)) { it / 3 },
label = "articleOverlay", label = "articleOverlay",
) { ) {
Surface( val state = articleState
modifier = Modifier.fillMaxSize(), if (state != null) {
color = MaterialTheme.colorScheme.surface Surface(
) { modifier = Modifier.fillMaxSize(),
ArticleScreen( color = MaterialTheme.colorScheme.surface
articleState = articleState ?: lastShownArticle, ) {
onNavigateBack = { ArticleScreen(
if (!searchViewModel.navigateBackFromArticle()) { articleState = state,
searchViewModel.onAction(SearchAction.ClearArticle) onNavigateBack = {
if (screenStack.size > 1) screenStack.removeAt(screenStack.lastIndex) if (!searchViewModel.navigateBackFromArticle()) {
} searchViewModel.onAction(SearchAction.ClearArticle)
}, if (screenStack.size > 1) screenStack.removeAt(screenStack.lastIndex)
onRefClick = { word -> }
searchViewModel.onAction(SearchAction.SearchAndLoadArticle(word)) },
}, onRefClick = { word ->
onScrollPositionChanged = { index, offset -> searchViewModel.onAction(SearchAction.SearchAndLoadArticle(word))
searchViewModel.updateArticleScrollPosition(index, offset) },
}, onScrollPositionChanged = { index, offset ->
) searchViewModel.updateArticleScrollPosition(index, offset)
},
)
}
} }
} }
} }
+6 -1
View File
@@ -5,7 +5,12 @@ plugins {
android { android {
namespace = "com.example.research.baselineprofile" namespace = "com.example.research.baselineprofile"
compileSdk = project.property("compileSdk").toString().toInt() val compileSdkSpec = project.property("compileSdk").toString().split(".").map(String::toInt)
compileSdk {
version = release(compileSdkSpec[0]) {
minorApiLevel = compileSdkSpec.getOrElse(1) { 0 }
}
}
targetProjectPath = ":app" targetProjectPath = ":app"
defaultConfig { defaultConfig {
+1 -1
View File
@@ -41,6 +41,6 @@ kotlin.daemon.jvmargs=-Xmx3g -XX:+UseParallelGC
android.nonTransitiveRClass=true android.nonTransitiveRClass=true
# SDK Versions # SDK Versions
compileSdk=37 compileSdk=37.1
minSdk=31 minSdk=31
targetSdk=37 targetSdk=37
+6 -6
View File
@@ -1,18 +1,18 @@
[versions] [versions]
aboutlibraries = "15.3.0" aboutlibraries = "15.3.0"
activity_compose = "1.13.0" activity_compose = "1.13.0"
agp = "9.5.1" agp = "9.5.3"
baselineprofile = "1.5.0" baselineprofile = "1.5.0"
benchmark_macro = "1.5.0" benchmark_macro = "1.5.0"
compose_bom = "2026.09.00" compose_bom = "2026.11.01"
compose_runtime = "1.13.0-rc01" compose_runtime = "1.13.0"
core = "1.19.1" core = "1.19.1"
datastore_preferences = "1.3.0" datastore_preferences = "1.3.0"
documentfile = "1.1.0" documentfile = "1.1.0"
junit = "1.3.0" junit = "1.3.0"
kotlin = "2.4.21" kotlin = "2.4.21"
lifecycle_runtime_ktx = "2.11.0" lifecycle_runtime_ktx = "2.11.1"
material3 = "1.5.0-rc01" material3 = "1.5.0"
okhttp = "5.5.1" okhttp = "5.5.1"
paging = "3.5.3" paging = "3.5.3"
profileinstaller = "1.4.1" profileinstaller = "1.4.1"
@@ -36,7 +36,7 @@ androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-toolin
androidx-core = { module = "androidx.core:core", version.ref = "core" } androidx-core = { module = "androidx.core:core", version.ref = "core" }
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore_preferences" } androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore_preferences" }
androidx-documentfile = { module = "androidx.documentfile:documentfile", version.ref = "documentfile" } androidx-documentfile = { module = "androidx.documentfile:documentfile", version.ref = "documentfile" }
androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle_runtime_ktx" } androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime", version.ref = "lifecycle_runtime_ktx" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle_runtime_ktx" } androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle_runtime_ktx" }
androidx-paging-runtime = { module = "androidx.paging:paging-runtime", version.ref = "paging" } androidx-paging-runtime = { module = "androidx.paging:paging-runtime", version.ref = "paging" }
androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "paging" } androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "paging" }