-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes dark mode in the main activity based on the settings
- Loading branch information
1 parent
e0b909c
commit 7181bdf
Showing
7 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
plugins { | ||
id("feature-module") | ||
} | ||
|
||
dependencies { | ||
api(projects.feature.settingsCore) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
30 changes: 30 additions & 0 deletions
30
feature/main/src/main/kotlin/com/mobiledevpro/main/view/state/MainUIState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2023 | Dmitri Chernysh | https://mobile-dev.pro | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.mobiledevpro.main.view.state | ||
|
||
import com.mobiledevpro.settings.core.model.Settings | ||
import com.mobiledevpro.ui.state.UIState | ||
|
||
|
||
sealed interface MainUIState : UIState { | ||
data object Empty : MainUIState | ||
|
||
data class Success( | ||
val settings: Settings | ||
) : MainUIState | ||
} |
49 changes: 49 additions & 0 deletions
49
feature/main/src/main/kotlin/com/mobiledevpro/main/view/vm/MainViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2023 | Dmitri Chernysh | https://mobile-dev.pro | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.mobiledevpro.main.view.vm | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import com.mobiledevpro.main.view.state.MainUIState | ||
import com.mobiledevpro.settings.core.usecase.GetAppSettingsUseCase | ||
import com.mobiledevpro.ui.vm.BaseViewModel | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.launch | ||
import kotlin.onSuccess | ||
|
||
|
||
class MainViewModel( | ||
private val getAppSettingsUseCase: GetAppSettingsUseCase | ||
) : BaseViewModel<MainUIState>() { | ||
|
||
override fun initUIState(): MainUIState = MainUIState.Empty | ||
|
||
init { | ||
observeSettings() | ||
} | ||
|
||
private fun observeSettings() { | ||
viewModelScope.launch { | ||
getAppSettingsUseCase.execute() | ||
.collectLatest { result -> | ||
result.onSuccess { settings -> | ||
_uiState.value = MainUIState.Success(settings) | ||
} | ||
} | ||
} | ||
} | ||
} |