From 4464812651d2f714c62cd6c506a0a76e2e048048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Mon, 22 Apr 2019 09:27:25 +0200 Subject: [PATCH] Fix configure activity's theme (#325) --- .../github/wulkanowy/ui/base/ThemeManager.kt | 23 +++++++++++++------ .../ui/modules/splash/SplashActivity.kt | 8 ++----- app/src/main/res/values-pl/strings.xml | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/base/ThemeManager.kt b/app/src/main/java/io/github/wulkanowy/ui/base/ThemeManager.kt index becb923c..bf16ac49 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/base/ThemeManager.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/base/ThemeManager.kt @@ -1,5 +1,6 @@ package io.github.wulkanowy.ui.base +import android.content.pm.PackageManager.GET_ACTIVITIES import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES @@ -10,15 +11,23 @@ import javax.inject.Inject class ThemeManager @Inject constructor(private val preferencesRepository: PreferencesRepository) { fun applyTheme(activity: AppCompatActivity) { - activity.delegate.apply { - when (preferencesRepository.appTheme) { - "light" -> setLocalNightMode(MODE_NIGHT_NO) - "dark" -> setLocalNightMode(MODE_NIGHT_YES) - "black" -> { - setLocalNightMode(MODE_NIGHT_YES) - activity.setTheme(R.style.WulkanowyTheme_Black) + if (isThemeApplicable(activity)) { + activity.delegate.apply { + when (preferencesRepository.appTheme) { + "light" -> setLocalNightMode(MODE_NIGHT_NO) + "dark" -> setLocalNightMode(MODE_NIGHT_YES) + "black" -> { + setLocalNightMode(MODE_NIGHT_YES) + activity.setTheme(R.style.WulkanowyTheme_Black) + } } } } } + + private fun isThemeApplicable(activity: AppCompatActivity): Boolean { + return activity.packageManager.getPackageInfo(activity.packageName, GET_ACTIVITIES) + .activities.singleOrNull { it.name == activity.localClassName }?.theme + .let { it == R.style.WulkanowyTheme_Black || it == R.style.WulkanowyTheme_NoActionBar } + } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/splash/SplashActivity.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/splash/SplashActivity.kt index 36d7af50..2bd62533 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/splash/SplashActivity.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/splash/SplashActivity.kt @@ -3,12 +3,12 @@ package io.github.wulkanowy.ui.modules.splash import android.os.Bundle import android.widget.Toast import android.widget.Toast.LENGTH_LONG -import dagger.android.support.DaggerAppCompatActivity +import io.github.wulkanowy.ui.base.BaseActivity import io.github.wulkanowy.ui.modules.login.LoginActivity import io.github.wulkanowy.ui.modules.main.MainActivity import javax.inject.Inject -class SplashActivity : DaggerAppCompatActivity(), SplashView { +class SplashActivity : BaseActivity(), SplashView { @Inject lateinit var presenter: SplashPresenter @@ -29,10 +29,6 @@ class SplashActivity : DaggerAppCompatActivity(), SplashView { } override fun showError(text: String, error: Throwable) { - showMessage(text) - } - - override fun showMessage(text: String) { Toast.makeText(this, text, LENGTH_LONG).show() } diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 268ec2cb..c1a5f2bc 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -242,7 +242,7 @@ Domyślny widok Obliczanie średniej końcoworocznej Pokazuj obecność we frekwencji - Motyw apliakcji + Motyw aplikacji Rozwiń oceny Schemat kolorów ocen