Skip to content

Commit

Permalink
Merge pull request #428 from anandwana001/default-theme
Browse files Browse the repository at this point in the history
Fix #425: using setDefaultNightMode
  • Loading branch information
takahirom authored May 3, 2021
2 parents 33960c6 + 645eedb commit b7a0a14
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions android/src/main/java/io/github/droidkaigi/feeder/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@ package io.github.droidkaigi.feeder

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import io.github.droidkaigi.feeder.viewmodel.ProvideViewModels
import io.github.droidkaigi.feeder.viewmodel.RealAppViewModel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
private val appViewModel by viewModels<RealAppViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setup()
appViewModel.state
.onEach {
AppCompatDelegate.setDefaultNightMode(
when (it.theme) {
Theme.SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
Theme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
Theme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
null -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}
.launchIn(lifecycleScope)
}

private fun setup() {
Expand Down

0 comments on commit b7a0a14

Please sign in to comment.