Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Changing Functionality added #2717

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions androidApp/src/main/kotlin/org/mifos/mobile/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -30,6 +32,7 @@ import kotlinx.coroutines.launch
import org.mifos.mobile.HomeActivityUiState.Success
import org.mifos.mobile.core.data.utils.NetworkMonitor
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
import org.mifos.mobile.feature.settings.ThemeManager
import org.mifos.mobile.navigation.MifosNavGraph.AUTH_GRAPH
import org.mifos.mobile.navigation.MifosNavGraph.PASSCODE_GRAPH
import org.mifos.mobile.navigation.RootNavGraph
Expand All @@ -42,6 +45,9 @@ class HomeActivity : ComponentActivity() {
@Inject
lateinit var networkMonitor: NetworkMonitor

@Inject
lateinit var themeManager: ThemeManager

private val viewModel: HomeActivityViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -72,7 +78,9 @@ class HomeActivity : ComponentActivity() {
val navController = rememberNavController()

val appState = rememberMifosMobileState(networkMonitor = networkMonitor)

val theme by themeManager.themeFlow.collectAsState()
val isDarkMode = themeManager.isDarkTheme(theme) == "DARK" ||
(themeManager.isDarkTheme(theme) == "SYSTEM" && isSystemInDarkTheme())
val navDestination = when (uiState) {
is Success -> if ((uiState as Success).userData.isAuthenticated) {
PASSCODE_GRAPH
Expand All @@ -84,7 +92,7 @@ class HomeActivity : ComponentActivity() {
}

CompositionLocalProvider {
MifosMobileTheme {
MifosMobileTheme(isDarkMode) {
RootNavGraph(
appState = appState,
navHostController = navController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import javax.inject.Inject
@HiltViewModel
internal class SettingsViewModel @Inject constructor(
private val preferencesHelper: PreferencesHelper,
private val themeManager: ThemeManager
) : ViewModel() {

val tenant: StateFlow<String?> = preferencesHelper
Expand Down Expand Up @@ -79,6 +80,7 @@ internal class SettingsViewModel @Inject constructor(
)
preferencesHelper.appTheme = theme.ordinal
preferencesHelper.applyTheme(theme)
themeManager.notifyThemeUpdated(theme)
}
}

Expand Down