Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf64986371 | ||
|
|
4d577a6b13 | ||
|
|
d15781a176 | ||
|
|
ee40748b00 | ||
|
|
380e4ca916 | ||
|
|
47b1197a92 | ||
|
|
c1563b8172 | ||
|
|
4a00d8adff | ||
|
|
944d2e6634 | ||
|
|
d7de09a152 |
No files matched your search
@@ -26,7 +26,6 @@ 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
|
||||||
@@ -52,8 +51,6 @@ 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 {
|
||||||
@@ -72,11 +69,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
app.dictionaryImportManager,
|
app.dictionaryImportManager,
|
||||||
app.dictionaryProgressStateHolder,
|
app.dictionaryProgressStateHolder,
|
||||||
versionName,
|
versionName,
|
||||||
initialSectionExpansion ?: SectionExpansionStates(
|
|
||||||
isThemeExpanded = false,
|
|
||||||
isLanguageExpanded = false,
|
|
||||||
isDictionariesExpanded = true,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +84,6 @@ 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 {
|
||||||
@@ -186,21 +177,6 @@ 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,19 +10,12 @@ 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")
|
||||||
@@ -86,15 +79,6 @@ 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,7 +16,6 @@ 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
|
||||||
@@ -62,7 +61,6 @@ 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(
|
||||||
@@ -70,14 +68,7 @@ class SettingsViewModel(
|
|||||||
validator = DictionarySourceValidator(),
|
validator = DictionarySourceValidator(),
|
||||||
)
|
)
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow(
|
private val _uiState = MutableStateFlow(SettingsUiState(appVersion = appVersion))
|
||||||
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