forked from github/wulkanowy-mirror
Fix configure activity's theme (#325)
This commit is contained in:
parent
72a35481e5
commit
4464812651
@ -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 }
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@
|
||||
<string name="pref_view_list">Domyślny widok</string>
|
||||
<string name="pref_view_grade_average_mode">Obliczanie średniej końcoworocznej</string>
|
||||
<string name="pref_view_present">Pokazuj obecność we frekwencji</string>
|
||||
<string name="pref_view_app_theme">Motyw apliakcji</string>
|
||||
<string name="pref_view_app_theme">Motyw aplikacji</string>
|
||||
<string name="pref_view_expand_grade">Rozwiń oceny</string>
|
||||
<string name="pref_view_grade_color_scheme">Schemat kolorów ocen</string>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user