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:
1 parent
c7f658dd94
commit
35f2ded634
7 files changed
+17
-16
No files matched your search
@@ -181,7 +181,7 @@ class MainActivity : ComponentActivity() {
|
||||
runBlocking {
|
||||
app.preferencesManager.hadNoDictionaries.first()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -62,7 +62,7 @@ class DictionaryPipelineCoordinator(
|
||||
pipelineJob?.cancel()
|
||||
pipelineJob = scope.launch(launchDispatcher) {
|
||||
val dir = File(dictionaryPath())
|
||||
val filesBeforeReindex = dir?.listFiles()?.map { it.name }?.toSet() ?: emptySet()
|
||||
val filesBeforeReindex = dir.listFiles()?.map { it.name }?.toSet() ?: emptySet()
|
||||
try {
|
||||
triggerReindexing(isImport)
|
||||
if (isImport) {
|
||||
@@ -85,7 +85,7 @@ class DictionaryPipelineCoordinator(
|
||||
}
|
||||
cleanupOrphanedFiles(dir)
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
ui.showError()
|
||||
} finally {
|
||||
finishService()
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class DictionaryProgressPresenter(
|
||||
private val scope: CoroutineScope,
|
||||
scope: CoroutineScope,
|
||||
private val progressSnapshot: StateFlow<DictionaryProgressModel.Snapshot?>,
|
||||
private val notifications: NotificationPort,
|
||||
mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
|
||||
|
||||
@@ -41,9 +41,10 @@ import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.platform.LocalWindowInfo
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -351,7 +352,9 @@ private fun LicenseDialog(
|
||||
this.alpha = alpha
|
||||
}
|
||||
) {
|
||||
val maxHeight = LocalConfiguration.current.screenHeightDp.dp - 96.dp
|
||||
val maxHeight = with(LocalDensity.current) {
|
||||
LocalWindowInfo.current.containerSize.height.toDp()
|
||||
} - 96.dp
|
||||
Surface(
|
||||
shape = AlertDialogDefaults.shape,
|
||||
color = AlertDialogDefaults.containerColor,
|
||||
|
||||
@@ -80,8 +80,8 @@ internal fun SearchResultsPane(
|
||||
}
|
||||
}
|
||||
|
||||
val loaded = results.itemSnapshotList.items.filterNotNull()
|
||||
SideEffect {
|
||||
val loaded = results.itemSnapshotList.items
|
||||
if (results.loadState.refresh is LoadState.NotLoading && loaded.isNotEmpty()) {
|
||||
staleEntries = loaded
|
||||
}
|
||||
|
||||
@@ -242,7 +242,6 @@ class SettingsViewModel(
|
||||
refreshDictionaryStatus()
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
SettingsUiState(
|
||||
|
||||
+7
-8
@@ -33,7 +33,7 @@ import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
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.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
@@ -88,12 +88,11 @@ fun DictionaryManagement(
|
||||
derivedStateOf { importState is ImportState.Importing || importState is ImportState.Extracting }
|
||||
}
|
||||
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,
|
||||
// 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.
|
||||
val isMutationsBlockedState = rememberUpdatedState(isBlockingMutations)
|
||||
val isMutationsBlockedState = rememberUpdatedState(isInProgress)
|
||||
val isDeleteBlocked = remember { { isMutationsBlockedState.value } }
|
||||
|
||||
SectionCard(
|
||||
@@ -149,13 +148,13 @@ fun DictionaryManagement(
|
||||
|
||||
// Disable accessibility on background content during import to improve performance.
|
||||
// The progress dialog remains accessible for cancellation.
|
||||
val backgroundModifier = if (isBlockingMutations) {
|
||||
Modifier.semantics { invisibleToUser() }
|
||||
val backgroundModifier = if (isInProgress) {
|
||||
Modifier.semantics { hideFromAccessibility() }
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
|
||||
if (dictionaries.isEmpty() && !isBlockingMutations) {
|
||||
if (dictionaries.isEmpty() && !isInProgress) {
|
||||
Column(
|
||||
modifier = backgroundModifier
|
||||
.fillMaxWidth()
|
||||
@@ -177,7 +176,7 @@ fun DictionaryManagement(
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if (dictionaryStatus is DictionaryStatus.NeedsUpdate && !isBlockingMutations && hasEnabledSources) {
|
||||
if (dictionaryStatus is DictionaryStatus.NeedsUpdate && !isInProgress && hasEnabledSources) {
|
||||
DictionaryUpdateCard(
|
||||
onStartDownload = onStartDownload,
|
||||
modifier = backgroundModifier
|
||||
@@ -194,7 +193,7 @@ fun DictionaryManagement(
|
||||
isDeleteBlocked = isDeleteBlocked
|
||||
)
|
||||
|
||||
if (!isBlockingMutations) {
|
||||
if (!isInProgress) {
|
||||
DictionaryActionButtons(
|
||||
onAddSource = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)
|
||||
|
||||
Reference in new issue
Block a user