refactor: clean up redundant calls and replace deprecated APIs

Unnecessary safe call on a non-null File receiver; unused catch parameters renamed to _; constructor parameter used only in init no longer held as a property; deprecated Configuration.screenHeightDp replaced with LocalWindowInfo.containerSize; redundant filterNotNull on Paging items; deprecated invisibleToUser() replaced with hideFromAccessibility(); redundant alias variable inlined; redundant else in an exhaustive when removed; paging snapshot read moved into the SideEffect that consumes it.
This commit is contained in:
OneWay committed 2026-09-26 08:17:09 +08:00
1 parent c7f658dd94
commit 35f2ded634
7 files changed
+17 -16

No files matched your search

@@ -181,7 +181,7 @@ class MainActivity : ComponentActivity() {
runBlocking { runBlocking {
app.preferencesManager.hadNoDictionaries.first() app.preferencesManager.hadNoDictionaries.first()
} }
} catch (e: Exception) { } catch (_: Exception) {
true true
} }
} }
@@ -62,7 +62,7 @@ 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 = dir.listFiles()?.map { it.name }?.toSet() ?: emptySet()
try { try {
triggerReindexing(isImport) triggerReindexing(isImport)
if (isImport) { if (isImport) {
@@ -85,7 +85,7 @@ class DictionaryPipelineCoordinator(
} }
cleanupOrphanedFiles(dir) cleanupOrphanedFiles(dir)
throw e throw e
} catch (e: Exception) { } catch (_: Exception) {
ui.showError() ui.showError()
} finally { } finally {
finishService() finishService()
@@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class DictionaryProgressPresenter( class DictionaryProgressPresenter(
private val scope: CoroutineScope, scope: CoroutineScope,
private val progressSnapshot: StateFlow<DictionaryProgressModel.Snapshot?>, private val progressSnapshot: StateFlow<DictionaryProgressModel.Snapshot?>,
private val notifications: NotificationPort, private val notifications: NotificationPort,
mainDispatcher: CoroutineDispatcher = Dispatchers.Main, mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
@@ -41,9 +41,10 @@ import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@@ -351,7 +352,9 @@ private fun LicenseDialog(
this.alpha = alpha this.alpha = alpha
} }
) { ) {
val maxHeight = LocalConfiguration.current.screenHeightDp.dp - 96.dp val maxHeight = with(LocalDensity.current) {
LocalWindowInfo.current.containerSize.height.toDp()
} - 96.dp
Surface( Surface(
shape = AlertDialogDefaults.shape, shape = AlertDialogDefaults.shape,
color = AlertDialogDefaults.containerColor, color = AlertDialogDefaults.containerColor,
@@ -80,8 +80,8 @@ internal fun SearchResultsPane(
} }
} }
val loaded = results.itemSnapshotList.items.filterNotNull()
SideEffect { SideEffect {
val loaded = results.itemSnapshotList.items
if (results.loadState.refresh is LoadState.NotLoading && loaded.isNotEmpty()) { if (results.loadState.refresh is LoadState.NotLoading && loaded.isNotEmpty()) {
staleEntries = loaded staleEntries = loaded
} }
@@ -242,7 +242,6 @@ class SettingsViewModel(
refreshDictionaryStatus() refreshDictionaryStatus()
} }
} }
else -> {}
} }
SettingsUiState( SettingsUiState(
@@ -33,7 +33,7 @@ import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.invisibleToUser import androidx.compose.ui.semantics.hideFromAccessibility
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -88,12 +88,11 @@ fun DictionaryManagement(
derivedStateOf { importState is ImportState.Importing || importState is ImportState.Extracting } derivedStateOf { importState is ImportState.Importing || importState is ImportState.Extracting }
} }
val hasEnabledSources by remember(sources) { derivedStateOf { sources.any { it.isEnabled } } } val hasEnabledSources by remember(sources) { derivedStateOf { sources.any { it.isEnabled } } }
val isBlockingMutations = isInProgress
// Invariant: the mutation-block flag is read only at state-read/gesture time (derivedStateOf, // Invariant: the mutation-block flag is read only at state-read/gesture time (derivedStateOf,
// snapshotFlow, pointerInput callbacks), never at row composition time. A composition-time read // snapshotFlow, pointerInput callbacks), never at row composition time. A composition-time read
// (e.g. Modifier.alpha(if (isDeleteBlocked()) ...)) would invalidate every row on each flip. // (e.g. Modifier.alpha(if (isDeleteBlocked()) ...)) would invalidate every row on each flip.
val isMutationsBlockedState = rememberUpdatedState(isBlockingMutations) val isMutationsBlockedState = rememberUpdatedState(isInProgress)
val isDeleteBlocked = remember { { isMutationsBlockedState.value } } val isDeleteBlocked = remember { { isMutationsBlockedState.value } }
SectionCard( SectionCard(
@@ -149,13 +148,13 @@ fun DictionaryManagement(
// Disable accessibility on background content during import to improve performance. // Disable accessibility on background content during import to improve performance.
// The progress dialog remains accessible for cancellation. // The progress dialog remains accessible for cancellation.
val backgroundModifier = if (isBlockingMutations) { val backgroundModifier = if (isInProgress) {
Modifier.semantics { invisibleToUser() } Modifier.semantics { hideFromAccessibility() }
} else { } else {
Modifier Modifier
} }
if (dictionaries.isEmpty() && !isBlockingMutations) { if (dictionaries.isEmpty() && !isInProgress) {
Column( Column(
modifier = backgroundModifier modifier = backgroundModifier
.fillMaxWidth() .fillMaxWidth()
@@ -177,7 +176,7 @@ fun DictionaryManagement(
) )
} }
} else { } else {
if (dictionaryStatus is DictionaryStatus.NeedsUpdate && !isBlockingMutations && hasEnabledSources) { if (dictionaryStatus is DictionaryStatus.NeedsUpdate && !isInProgress && hasEnabledSources) {
DictionaryUpdateCard( DictionaryUpdateCard(
onStartDownload = onStartDownload, onStartDownload = onStartDownload,
modifier = backgroundModifier modifier = backgroundModifier
@@ -194,7 +193,7 @@ fun DictionaryManagement(
isDeleteBlocked = isDeleteBlocked isDeleteBlocked = isDeleteBlocked
) )
if (!isBlockingMutations) { if (!isInProgress) {
DictionaryActionButtons( DictionaryActionButtons(
onAddSource = { onAddSource = {
haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove) haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)