Compare commits
3
Commits
1.9.0
..
dcae63056c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcae63056c | ||
|
|
98b23bac48 | ||
|
|
c440fc5024 |
No files matched your search
@@ -28,7 +28,6 @@ import com.example.research.common.ui.theme.ReSearchTheme
|
|||||||
import com.example.research.core.domain.model.AppTheme
|
import com.example.research.core.domain.model.AppTheme
|
||||||
import com.example.research.core.domain.model.SearchBarPosition
|
import com.example.research.core.domain.model.SearchBarPosition
|
||||||
import com.example.research.data.local.preferences.SectionExpansionStates
|
import com.example.research.data.local.preferences.SectionExpansionStates
|
||||||
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.navigation.AppNavigation
|
import com.example.research.ui.navigation.AppNavigation
|
||||||
import com.example.research.ui.settings.SettingsViewModel
|
import com.example.research.ui.settings.SettingsViewModel
|
||||||
@@ -144,7 +143,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
val text = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT)
|
val text = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT)
|
||||||
?: intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT_READONLY)
|
?: intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT_READONLY)
|
||||||
text?.toString()?.let {
|
text?.toString()?.let {
|
||||||
searchViewModel.onAction(SearchAction.QueryChanged(it))
|
searchViewModel.injectExternalQuery(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.*
|
|||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
class DictionaryImportManager(
|
class DictionaryImportManager(
|
||||||
private val application: Application
|
private val application: Application
|
||||||
@@ -19,6 +20,10 @@ class DictionaryImportManager(
|
|||||||
private val mutableImportState = MutableStateFlow<ImportState>(ImportState.Idle)
|
private val mutableImportState = MutableStateFlow<ImportState>(ImportState.Idle)
|
||||||
val importState: StateFlow<ImportState> = mutableImportState.asStateFlow()
|
val importState: StateFlow<ImportState> = mutableImportState.asStateFlow()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TERMINAL_STATE_DURATION = 2.seconds
|
||||||
|
}
|
||||||
|
|
||||||
private val managerScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
private val managerScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||||
private var importJob: Job? = null
|
private var importJob: Job? = null
|
||||||
private val importedFiles = Collections.synchronizedList(mutableListOf<File>())
|
private val importedFiles = Collections.synchronizedList(mutableListOf<File>())
|
||||||
@@ -130,6 +135,9 @@ class DictionaryImportManager(
|
|||||||
)
|
)
|
||||||
mutableImportState.value = terminalState
|
mutableImportState.value = terminalState
|
||||||
onTerminal?.invoke(terminalState)
|
onTerminal?.invoke(terminalState)
|
||||||
|
if (terminalState is ImportState.Error) {
|
||||||
|
expireErrorStateToIdle(terminalState)
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
cleanupImportedFiles()
|
cleanupImportedFiles()
|
||||||
@@ -141,6 +149,14 @@ class DictionaryImportManager(
|
|||||||
)
|
)
|
||||||
mutableImportState.value = errorState
|
mutableImportState.value = errorState
|
||||||
onTerminal?.invoke(errorState)
|
onTerminal?.invoke(errorState)
|
||||||
|
expireErrorStateToIdle(errorState)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun expireErrorStateToIdle(errorState: ImportState.Error) {
|
||||||
|
delay(TERMINAL_STATE_DURATION)
|
||||||
|
if (mutableImportState.value === errorState) {
|
||||||
|
mutableImportState.value = ImportState.Idle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ class SearchViewModel(
|
|||||||
)
|
)
|
||||||
val searchQuery: StateFlow<String> = mutableSearchQuery.asStateFlow()
|
val searchQuery: StateFlow<String> = mutableSearchQuery.asStateFlow()
|
||||||
|
|
||||||
|
private val mutableQueryInjection = MutableSharedFlow<String>(extraBufferCapacity = 1)
|
||||||
|
val queryInjection: SharedFlow<String> = mutableQueryInjection.asSharedFlow()
|
||||||
|
|
||||||
private val mutableSelectedArticle = MutableStateFlow<ArticleState?>(null)
|
private val mutableSelectedArticle = MutableStateFlow<ArticleState?>(null)
|
||||||
val selectedArticle: StateFlow<ArticleState?> = mutableSelectedArticle.asStateFlow()
|
val selectedArticle: StateFlow<ArticleState?> = mutableSelectedArticle.asStateFlow()
|
||||||
|
|
||||||
@@ -157,6 +160,12 @@ class SearchViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun injectExternalQuery(query: String) {
|
||||||
|
val sanitized = query.sanitizeQuery().trim()
|
||||||
|
mutableQueryInjection.tryEmit(sanitized)
|
||||||
|
onSearchQueryChanged(sanitized)
|
||||||
|
}
|
||||||
|
|
||||||
private fun warmupIndexesInBackground() {
|
private fun warmupIndexesInBackground() {
|
||||||
indexWarmupJob?.cancel()
|
indexWarmupJob?.cancel()
|
||||||
indexWarmupJob = viewModelScope.launch(Dispatchers.Default) {
|
indexWarmupJob = viewModelScope.launch(Dispatchers.Default) {
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ fun MainRoute(
|
|||||||
val searchHistory by searchViewModel.searchHistory.collectAsStateWithLifecycle()
|
val searchHistory by searchViewModel.searchHistory.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val settingsState by settingsViewModel.uiState.collectAsStateWithLifecycle()
|
val settingsState by settingsViewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val searchQuery by searchViewModel.searchQuery.collectAsStateWithLifecycle()
|
|
||||||
val isSearchBarAtBottom = settingsState.searchBarPosition == SearchBarPosition.BOTTOM
|
val isSearchBarAtBottom = settingsState.searchBarPosition == SearchBarPosition.BOTTOM
|
||||||
|
|
||||||
val scrollPosition = remember(searchViewModel) {
|
val scrollPosition = remember(searchViewModel) {
|
||||||
@@ -53,9 +52,9 @@ fun MainRoute(
|
|||||||
TextFieldState(initialText = searchViewModel.searchQuery.value)
|
TextFieldState(initialText = searchViewModel.searchQuery.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(searchState, searchQuery) {
|
LaunchedEffect(searchViewModel) {
|
||||||
if (searchState.text.toString() != searchQuery) {
|
searchViewModel.queryInjection.collect { query ->
|
||||||
searchState.edit { replace(0, length, searchQuery) }
|
searchState.edit { replace(0, length, query) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,12 +94,11 @@ fun MainRoute(
|
|||||||
MainAction.ClearError -> searchViewModel.clearError()
|
MainAction.ClearError -> searchViewModel.clearError()
|
||||||
is MainAction.SaveScrollPosition ->
|
is MainAction.SaveScrollPosition ->
|
||||||
searchViewModel.saveScrollPosition(action.index, action.offset)
|
searchViewModel.saveScrollPosition(action.index, action.offset)
|
||||||
is MainAction.HistoryEntryClicked ->
|
is MainAction.HistoryEntryClicked -> {
|
||||||
|
searchState.edit { replace(0, length, action.query) }
|
||||||
if (isWide) {
|
if (isWide) {
|
||||||
searchViewModel.onSearchQueryChanged(action.query)
|
|
||||||
searchViewModel.onAction(SearchAction.SearchAndLoadArticle(action.query))
|
searchViewModel.onAction(SearchAction.SearchAndLoadArticle(action.query))
|
||||||
} else {
|
}
|
||||||
searchViewModel.onSearchQueryChanged(action.query)
|
|
||||||
}
|
}
|
||||||
is MainAction.RemoveHistoryEntry ->
|
is MainAction.RemoveHistoryEntry ->
|
||||||
searchViewModel.removeSearchHistoryEntry(action.query)
|
searchViewModel.removeSearchHistoryEntry(action.query)
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ internal fun SearchResultsPane(
|
|||||||
|
|
||||||
SideEffect {
|
SideEffect {
|
||||||
val loaded = results.itemSnapshotList.items
|
val loaded = results.itemSnapshotList.items
|
||||||
if (results.loadState.refresh is LoadState.NotLoading && loaded.isNotEmpty()) {
|
if (results.loadState.refresh is LoadState.NotLoading) {
|
||||||
staleEntries = loaded
|
staleEntries = if (loaded.isNotEmpty()) loaded else emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val pendingReload = results.itemCount == 0 &&
|
val pendingReload = results.itemCount == 0 &&
|
||||||
|
|||||||
Reference in new issue
Block a user