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
|
package io.github.wulkanowy.ui.base
|
||||||
|
|
||||||
|
import android.content.pm.PackageManager.GET_ACTIVITIES
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
|
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
|
||||||
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
|
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
|
||||||
@ -10,6 +11,7 @@ import javax.inject.Inject
|
|||||||
class ThemeManager @Inject constructor(private val preferencesRepository: PreferencesRepository) {
|
class ThemeManager @Inject constructor(private val preferencesRepository: PreferencesRepository) {
|
||||||
|
|
||||||
fun applyTheme(activity: AppCompatActivity) {
|
fun applyTheme(activity: AppCompatActivity) {
|
||||||
|
if (isThemeApplicable(activity)) {
|
||||||
activity.delegate.apply {
|
activity.delegate.apply {
|
||||||
when (preferencesRepository.appTheme) {
|
when (preferencesRepository.appTheme) {
|
||||||
"light" -> setLocalNightMode(MODE_NIGHT_NO)
|
"light" -> setLocalNightMode(MODE_NIGHT_NO)
|
||||||
@ -21,4 +23,11 @@ class ThemeManager @Inject constructor(private val preferencesRepository: Prefer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import android.widget.Toast.LENGTH_LONG
|
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.login.LoginActivity
|
||||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SplashActivity : DaggerAppCompatActivity(), SplashView {
|
class SplashActivity : BaseActivity(), SplashView {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var presenter: SplashPresenter
|
lateinit var presenter: SplashPresenter
|
||||||
@ -29,10 +29,6 @@ class SplashActivity : DaggerAppCompatActivity(), SplashView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun showError(text: String, error: Throwable) {
|
override fun showError(text: String, error: Throwable) {
|
||||||
showMessage(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showMessage(text: String) {
|
|
||||||
Toast.makeText(this, text, LENGTH_LONG).show()
|
Toast.makeText(this, text, LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@
|
|||||||
<string name="pref_view_list">Domyślny widok</string>
|
<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_grade_average_mode">Obliczanie średniej końcoworocznej</string>
|
||||||
<string name="pref_view_present">Pokazuj obecność we frekwencji</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_expand_grade">Rozwiń oceny</string>
|
||||||
<string name="pref_view_grade_color_scheme">Schemat kolorów ocen</string>
|
<string name="pref_view_grade_color_scheme">Schemat kolorów ocen</string>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user