Add dark and light theme with corresponding settings activity and BaseActivity class

This commit is contained in:
2020-05-20 00:06:30 +03:00
parent da14a31c78
commit 7855b7e658
15 changed files with 166 additions and 18 deletions
@@ -0,0 +1,40 @@
package com.illusionware.npsbrowser.activities
import android.content.SharedPreferences
import android.content.res.Configuration
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceManager
import com.illusionware.npsbrowser.R
open class BaseActivity : AppCompatActivity() {
private lateinit var sharedPreferences : SharedPreferences
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PreferenceManager.setDefaultValues(this, R.xml.root_preferences, false)
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
val decor: View = window.decorView
AppCompatDelegate.setDefaultNightMode(when ((sharedPreferences.getString("app_theme", "2")?.toInt())) {
0 -> {
decor.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
AppCompatDelegate.MODE_NIGHT_NO
}
1 -> {
decor.systemUiVisibility = 0;
AppCompatDelegate.MODE_NIGHT_YES
}
2 -> {
decor.systemUiVisibility = if (resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
else -> AppCompatDelegate.MODE_NIGHT_UNSPECIFIED
})
}
}