Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edf6a6074e | ||
|
|
8319973161 | ||
|
|
1631e5384c | ||
|
|
1d4990e5b7 | ||
|
|
8c6e43f3db | ||
|
|
2f22144d19 | ||
|
|
9807a0cf27 | ||
|
|
de27eecd9e | ||
|
|
c4b3a57ccb | ||
|
|
d96fad9cab |
No files matched your search
@@ -26,6 +26,7 @@ import com.example.research.common.ui.AppLocaleProvider
|
|||||||
import com.example.research.common.ui.BackgroundTextMeasurementProvider
|
import com.example.research.common.ui.BackgroundTextMeasurementProvider
|
||||||
import com.example.research.common.ui.theme.ReSearchTheme
|
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.data.local.preferences.SectionExpansionStates
|
||||||
import com.example.research.feature.search.SearchAction
|
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
|
||||||
@@ -51,6 +52,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var initialSectionExpansion: SectionExpansionStates? = null
|
||||||
|
|
||||||
private val settingsViewModel: SettingsViewModel by viewModels {
|
private val settingsViewModel: SettingsViewModel by viewModels {
|
||||||
val app = application as ReSearchApplication
|
val app = application as ReSearchApplication
|
||||||
val versionName = try {
|
val versionName = try {
|
||||||
@@ -69,6 +72,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
app.dictionaryImportManager,
|
app.dictionaryImportManager,
|
||||||
app.dictionaryProgressStateHolder,
|
app.dictionaryProgressStateHolder,
|
||||||
versionName,
|
versionName,
|
||||||
|
initialSectionExpansion ?: SectionExpansionStates(
|
||||||
|
isThemeExpanded = false,
|
||||||
|
isLanguageExpanded = false,
|
||||||
|
isDictionariesExpanded = true,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,6 +92,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
val initialTheme = loadInitialTheme(app)
|
val initialTheme = loadInitialTheme(app)
|
||||||
val initialLanguage = loadInitialLanguage(app)
|
val initialLanguage = loadInitialLanguage(app)
|
||||||
val initialHadNoDictionaries = loadInitialHadNoDictionaries(app)
|
val initialHadNoDictionaries = loadInitialHadNoDictionaries(app)
|
||||||
|
initialSectionExpansion = loadInitialSectionExpansion(app)
|
||||||
|
|
||||||
handleIntent(intent)
|
handleIntent(intent)
|
||||||
setContent {
|
setContent {
|
||||||
@@ -177,6 +186,21 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadInitialSectionExpansion(app: ReSearchApplication): SectionExpansionStates {
|
||||||
|
return try {
|
||||||
|
runBlocking {
|
||||||
|
app.preferencesManager.sectionExpansionStates()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
android.util.Log.e("MainActivity", "Failed to load section expansion states: ${e.message}")
|
||||||
|
SectionExpansionStates(
|
||||||
|
isThemeExpanded = false,
|
||||||
|
isLanguageExpanded = false,
|
||||||
|
isDictionariesExpanded = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
handleIntent(intent)
|
handleIntent(intent)
|
||||||
|
|||||||
@@ -10,12 +10,19 @@ import androidx.datastore.preferences.core.stringSetPreferencesKey
|
|||||||
import androidx.datastore.preferences.preferencesDataStore
|
import androidx.datastore.preferences.preferencesDataStore
|
||||||
import com.example.research.core.domain.model.DictionarySource
|
import com.example.research.core.domain.model.DictionarySource
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
|
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
|
||||||
|
|
||||||
|
data class SectionExpansionStates(
|
||||||
|
val isThemeExpanded: Boolean,
|
||||||
|
val isLanguageExpanded: Boolean,
|
||||||
|
val isDictionariesExpanded: Boolean,
|
||||||
|
)
|
||||||
|
|
||||||
class PreferencesManager(private val context: Context) {
|
class PreferencesManager(private val context: Context) {
|
||||||
private object PreferencesKeys {
|
private object PreferencesKeys {
|
||||||
val THEME_MODE = stringPreferencesKey("theme_mode")
|
val THEME_MODE = stringPreferencesKey("theme_mode")
|
||||||
@@ -79,6 +86,15 @@ class PreferencesManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun sectionExpansionStates(): SectionExpansionStates =
|
||||||
|
context.dataStore.data.first().let { preferences ->
|
||||||
|
SectionExpansionStates(
|
||||||
|
isThemeExpanded = preferences[PreferencesKeys.IS_THEME_EXPANDED] ?: false,
|
||||||
|
isLanguageExpanded = preferences[PreferencesKeys.IS_LANGUAGE_EXPANDED] ?: false,
|
||||||
|
isDictionariesExpanded = preferences[PreferencesKeys.IS_DICTIONARIES_EXPANDED] ?: true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun setDictionaryActive(path: String, isActive: Boolean) {
|
suspend fun setDictionaryActive(path: String, isActive: Boolean) {
|
||||||
context.dataStore.edit { preferences ->
|
context.dataStore.edit { preferences ->
|
||||||
val disabledPaths = preferences[PreferencesKeys.DISABLED_DICTIONARY_PATHS]
|
val disabledPaths = preferences[PreferencesKeys.DISABLED_DICTIONARY_PATHS]
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.example.research.core.domain.usecase.DictionarySourceValidator
|
|||||||
import com.example.research.core.domain.usecase.ManageDictionarySourcesUseCase
|
import com.example.research.core.domain.usecase.ManageDictionarySourcesUseCase
|
||||||
import com.example.research.core.util.OperationResult
|
import com.example.research.core.util.OperationResult
|
||||||
import com.example.research.data.local.preferences.PreferencesManager
|
import com.example.research.data.local.preferences.PreferencesManager
|
||||||
|
import com.example.research.data.local.preferences.SectionExpansionStates
|
||||||
import com.example.research.data.repository.LocalDictionaryRepository
|
import com.example.research.data.repository.LocalDictionaryRepository
|
||||||
import com.example.research.feature.download.DownloadManager
|
import com.example.research.feature.download.DownloadManager
|
||||||
import com.example.research.feature.download.model.DownloadState
|
import com.example.research.feature.download.model.DownloadState
|
||||||
@@ -61,6 +62,7 @@ class SettingsViewModel(
|
|||||||
private val dictionaryImportManager: DictionaryImportManager,
|
private val dictionaryImportManager: DictionaryImportManager,
|
||||||
progressStateHolder: DictionaryProgressStateHolder,
|
progressStateHolder: DictionaryProgressStateHolder,
|
||||||
appVersion: String,
|
appVersion: String,
|
||||||
|
initialSectionExpansion: SectionExpansionStates,
|
||||||
) : AndroidViewModel(application) {
|
) : AndroidViewModel(application) {
|
||||||
|
|
||||||
private val manageDictionarySourcesUseCase = ManageDictionarySourcesUseCase(
|
private val manageDictionarySourcesUseCase = ManageDictionarySourcesUseCase(
|
||||||
@@ -68,7 +70,14 @@ class SettingsViewModel(
|
|||||||
validator = DictionarySourceValidator(),
|
validator = DictionarySourceValidator(),
|
||||||
)
|
)
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow(SettingsUiState(appVersion = appVersion))
|
private val _uiState = MutableStateFlow(
|
||||||
|
SettingsUiState(
|
||||||
|
appVersion = appVersion,
|
||||||
|
isThemeExpanded = initialSectionExpansion.isThemeExpanded,
|
||||||
|
isLanguageExpanded = initialSectionExpansion.isLanguageExpanded,
|
||||||
|
isDictionariesExpanded = initialSectionExpansion.isDictionariesExpanded,
|
||||||
|
)
|
||||||
|
)
|
||||||
val uiState: StateFlow<SettingsUiState> = _uiState.asStateFlow()
|
val uiState: StateFlow<SettingsUiState> = _uiState.asStateFlow()
|
||||||
|
|
||||||
val progressSnapshot = progressStateHolder.progressSnapshot
|
val progressSnapshot = progressStateHolder.progressSnapshot
|
||||||
|
|||||||
Reference in new issue
Block a user