From d024908a5c933e38125e7f886e20528647756edc Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 6 Jul 2022 16:57:47 +0200 Subject: [PATCH] fix theme --- .../libretube/activities/MainActivity.kt | 21 +++++++++++++++---- .../activities/NoInternetActivity.kt | 13 ++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index a214973a9..e0e2522d6 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -47,7 +47,23 @@ class MainActivity : AppCompatActivity() { private var startFragmentId = R.id.homeFragment override fun onCreate(savedInstanceState: Bundle?) { - DynamicColors.applyToActivityIfAvailable(this) + /** + * 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) + // 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) // start service that gets called on closure @@ -69,9 +85,6 @@ class MainActivity : AppCompatActivity() { RetrofitInstance.url } - ThemeHelper.updateTheme(this) - LocaleHelper.updateLanguage(this) - // show noInternet Activity if no internet available on app startup if (!ConnectionHelper.isNetworkAvailable(this)) { val noInternetIntent = Intent(this, NoInternetActivity::class.java) diff --git a/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt b/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt index a2e4d9e4d..bd626a2c1 100644 --- a/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt @@ -5,6 +5,7 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.github.libretube.R import com.github.libretube.databinding.ActivityNointernetBinding +import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.ThemeHelper import com.google.android.material.color.DynamicColors @@ -14,8 +15,16 @@ class NoInternetActivity : AppCompatActivity() { private lateinit var binding: ActivityNointernetBinding override fun onCreate(savedInstanceState: Bundle?) { - DynamicColors.applyToActivityIfAvailable(this) - ThemeHelper.updateTheme(this) + + /** + * apply dynamic colors if enabled + */ + val materialColorsEnabled = PreferenceHelper + .getString(this, "accent_color", "purple") == "my" + if (materialColorsEnabled) { + DynamicColors.applyToActivityIfAvailable(this) + } + super.onCreate(savedInstanceState) binding = ActivityNointernetBinding.inflate(layoutInflater)