forked from github/wulkanowy-mirror
Change background color of navigation and notification bars (#1120)
This commit is contained in:
parent
4fceb854b3
commit
ff425d6d2b
@ -56,7 +56,7 @@
|
||||
android:name=".ui.modules.login.LoginActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/login_title"
|
||||
android:theme="@style/WulkanowyTheme.NoActionBar"
|
||||
android:theme="@style/WulkanowyTheme.Login"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
<activity
|
||||
android:name=".ui.modules.main.MainActivity"
|
||||
@ -68,7 +68,7 @@
|
||||
android:name=".ui.modules.message.send.SendMessageActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/send_message_title"
|
||||
android:theme="@style/WulkanowyTheme.NoActionBar"
|
||||
android:theme="@style/WulkanowyTheme.MessageSend"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
<activity
|
||||
android:name=".ui.modules.timetablewidget.TimetableWidgetConfigureActivity"
|
||||
|
@ -8,6 +8,9 @@ import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
|
||||
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.message.send.SendMessageActivity
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@ -17,7 +20,13 @@ class ThemeManager @Inject constructor(private val preferencesRepository: Prefer
|
||||
fun applyActivityTheme(activity: AppCompatActivity) {
|
||||
if (isThemeApplicable(activity)) {
|
||||
applyDefaultTheme()
|
||||
if (preferencesRepository.appTheme == "black") activity.setTheme(R.style.WulkanowyTheme_Black)
|
||||
if (preferencesRepository.appTheme == "black") {
|
||||
when (activity) {
|
||||
is MainActivity -> activity.setTheme(R.style.WulkanowyTheme_Black)
|
||||
is LoginActivity -> activity.setTheme(R.style.WulkanowyTheme_Login_Black)
|
||||
is SendMessageActivity -> activity.setTheme(R.style.WulkanowyTheme_MessageSend_Black)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,8 +42,13 @@ 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::class.java.canonicalName }?.theme
|
||||
.let { it == R.style.WulkanowyTheme_Black || it == R.style.WulkanowyTheme_NoActionBar }
|
||||
return activity.packageManager
|
||||
.getPackageInfo(activity.packageName, GET_ACTIVITIES)
|
||||
.activities.singleOrNull { it.name == activity::class.java.canonicalName }
|
||||
?.theme.let {
|
||||
it == R.style.WulkanowyTheme_Black || it == R.style.WulkanowyTheme_NoActionBar
|
||||
|| it == R.style.WulkanowyTheme_Login || it == R.style.WulkanowyTheme_Login_Black
|
||||
|| it == R.style.WulkanowyTheme_MessageSend || it == R.style.WulkanowyTheme_MessageSend_Black
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.Build.VERSION_CODES.LOLLIPOP
|
||||
import android.os.Build.VERSION_CODES.P
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@ -194,6 +195,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
return true
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun initView() {
|
||||
with(binding.mainToolbar) {
|
||||
if (SDK_INT >= LOLLIPOP) stateListAnimator = null
|
||||
@ -233,12 +235,18 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
|
||||
with(navController) {
|
||||
setOnViewChangeListener { section, name ->
|
||||
binding.mainBottomNav.visibility =
|
||||
if (section == MainView.Section.ACCOUNT || section == MainView.Section.STUDENT_INFO) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
if (section == MainView.Section.ACCOUNT || section == MainView.Section.STUDENT_INFO) {
|
||||
binding.mainBottomNav.visibility = View.GONE
|
||||
if (appInfo.systemVersion >= P) {
|
||||
window.navigationBarColor = getThemeAttrColor(R.attr.colorSurface)
|
||||
}
|
||||
} else {
|
||||
binding.mainBottomNav.visibility = View.VISIBLE
|
||||
if (appInfo.systemVersion >= P) {
|
||||
window.navigationBarColor =
|
||||
getThemeAttrColor(android.R.attr.navigationBarColor)
|
||||
}
|
||||
}
|
||||
|
||||
analytics.setCurrentScreen(this@MainActivity, name)
|
||||
presenter.onViewChange(section)
|
||||
|
@ -10,14 +10,43 @@
|
||||
<item name="colorSwipeRefresh">@color/colorSwipeRefreshDark</item>
|
||||
<item name="android:windowBackground">?colorSurface</item>
|
||||
<item name="android:textColor">?android:textColorPrimary</item>
|
||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/black
|
||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">
|
||||
@color/colorNavigationBarLight
|
||||
</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">
|
||||
@color/colorStatusBarLight
|
||||
</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/black</item>
|
||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
|
||||
<item name="mdtp_theme_dark">true</item>
|
||||
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.Black" parent="WulkanowyTheme.NoActionBar">
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">
|
||||
@color/colorNavigationBarBlack
|
||||
</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/black</item>
|
||||
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.Login" parent="WulkanowyTheme.NoActionBar">
|
||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">?colorSurface</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">?colorSurface</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.Login.Black" parent="WulkanowyTheme.Black">
|
||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">?colorSurface</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">?colorSurface</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.MessageSend" parent="WulkanowyTheme.NoActionBar">
|
||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">?colorSurface</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">#1C1C1C</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.MessageSend.Black" parent="WulkanowyTheme.Black">
|
||||
<item name="android:navigationBarColor" tools:targetApi="lollipop">?colorSurface</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/black</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
14
app/src/main/res/values-v23/styles.xml
Normal file
14
app/src/main/res/values-v23/styles.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="WulkanowyTheme" parent="BaseWulkanowyTheme">
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
<item name="android:statusBarColor">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.SplashScreen" parent="WulkanowyTheme.NoActionBar">
|
||||
<item name="android:windowBackground">@drawable/layer_splash_background</item>
|
||||
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
</style>
|
||||
</resources>
|
15
app/src/main/res/values-v26/styles.xml
Normal file
15
app/src/main/res/values-v26/styles.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<resources>
|
||||
|
||||
<style name="WulkanowyTheme" parent="BaseWulkanowyTheme">
|
||||
<item name="android:navigationBarColor">@android:color/black</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="android:statusBarColor">@android:color/darker_gray</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.SplashScreen" parent="WulkanowyTheme.NoActionBar">
|
||||
<item name="android:windowBackground">@drawable/layer_splash_background</item>
|
||||
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
</style>
|
||||
</resources>
|
@ -1,9 +1,10 @@
|
||||
<resources>
|
||||
|
||||
<style name="WulkanowyTheme" parent="BaseWulkanowyTheme">
|
||||
<item name="android:statusBarColor">@android:color/darker_gray</item>
|
||||
<item name="android:navigationBarColor">@android:color/white</item>
|
||||
<item name="android:windowLightNavigationBar">true</item>
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
<item name="android:statusBarColor">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.SplashScreen" parent="WulkanowyTheme.NoActionBar">
|
||||
@ -11,5 +12,6 @@
|
||||
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:windowLightNavigationBar">false</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
</style>
|
||||
</resources>
|
17
app/src/main/res/values-v29/styles.xml
Normal file
17
app/src/main/res/values-v29/styles.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<resources>
|
||||
|
||||
<style name="WulkanowyTheme" parent="BaseWulkanowyTheme">
|
||||
<item name="android:navigationBarColor">@android:color/white</item>
|
||||
<item name="android:windowLightNavigationBar">true</item>
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
<item name="android:statusBarColor">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="WulkanowyTheme.SplashScreen" parent="WulkanowyTheme.NoActionBar">
|
||||
<item name="android:windowBackground">@drawable/layer_splash_background</item>
|
||||
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
|
||||
<item name="android:windowLightNavigationBar">false</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
</style>
|
||||
</resources>
|
@ -6,6 +6,11 @@
|
||||
<color name="colorError">#ff5722</color>
|
||||
<color name="colorErrorLight">#e84853</color>
|
||||
|
||||
<color name="colorNavigationBarLight">#2E2E2E</color>
|
||||
<color name="colorNavigationBarBlack">#1E1E1E</color>
|
||||
|
||||
<color name="colorStatusBarLight">#1C1C1C</color>
|
||||
|
||||
<color name="timetable_change_light">#ffd54f</color>
|
||||
<color name="timetable_change_dark">#ff8f00</color>
|
||||
|
||||
|
@ -34,4 +34,8 @@
|
||||
</style>
|
||||
|
||||
<style name="mdtp_ActionButton.Text" parent="Widget.MaterialComponents.Button.TextButton.Dialog" />
|
||||
|
||||
<style name="WulkanowyTheme.Login" parent="WulkanowyTheme.NoActionBar" />
|
||||
|
||||
<style name="WulkanowyTheme.MessageSend" parent="WulkanowyTheme.NoActionBar" />
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user