fix theme

This commit is contained in:
Bnyro 2022-07-06 16:57:47 +02:00
parent a1b5975c40
commit d024908a5c
2 changed files with 28 additions and 6 deletions

View File

@ -47,7 +47,23 @@ class MainActivity : AppCompatActivity() {
private var startFragmentId = R.id.homeFragment private var startFragmentId = R.id.homeFragment
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
/**
* apply dynamic colors if enabled
*/
val materialColorsEnabled = PreferenceHelper
.getString(this, "accent_color", "purple") == "my"
if (materialColorsEnabled) {
// apply dynamic colors to the current activity
DynamicColors.applyToActivityIfAvailable(this) DynamicColors.applyToActivityIfAvailable(this)
// apply dynamic colors to the all other activities
DynamicColors.applyToActivitiesIfAvailable(application)
}
// set the theme
ThemeHelper.updateTheme(applicationContext)
// set the language
LocaleHelper.updateLanguage(applicationContext)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// start service that gets called on closure // start service that gets called on closure
@ -69,9 +85,6 @@ class MainActivity : AppCompatActivity() {
RetrofitInstance.url RetrofitInstance.url
} }
ThemeHelper.updateTheme(this)
LocaleHelper.updateLanguage(this)
// show noInternet Activity if no internet available on app startup // show noInternet Activity if no internet available on app startup
if (!ConnectionHelper.isNetworkAvailable(this)) { if (!ConnectionHelper.isNetworkAvailable(this)) {
val noInternetIntent = Intent(this, NoInternetActivity::class.java) val noInternetIntent = Intent(this, NoInternetActivity::class.java)

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.databinding.ActivityNointernetBinding import com.github.libretube.databinding.ActivityNointernetBinding
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
import com.google.android.material.color.DynamicColors import com.google.android.material.color.DynamicColors
@ -14,8 +15,16 @@ class NoInternetActivity : AppCompatActivity() {
private lateinit var binding: ActivityNointernetBinding private lateinit var binding: ActivityNointernetBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
/**
* apply dynamic colors if enabled
*/
val materialColorsEnabled = PreferenceHelper
.getString(this, "accent_color", "purple") == "my"
if (materialColorsEnabled) {
DynamicColors.applyToActivityIfAvailable(this) DynamicColors.applyToActivityIfAvailable(this)
ThemeHelper.updateTheme(this) }
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityNointernetBinding.inflate(layoutInflater) binding = ActivityNointernetBinding.inflate(layoutInflater)