fix: Move color implementation #2541

This commit is contained in:
J-Jamet committed 2026-05-31 13:47:28 +02:00
1 parent 6629c7f7d5
commit 6f67f54f0e
2 files changed
+17 -23

No files matched your search

@@ -20,6 +20,7 @@ package com.kunzisoft.keepass.activities
import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.os.Handler
@@ -160,7 +161,18 @@ class EntryActivity : DatabaseLockActivity() {
toolbar?.title = " "
// Set the theme to retrieve the toolbar color
mEntryViewModel.setTheme(theme)
theme.obtainStyledAttributes(intArrayOf(R.attr.colorSecondary)).also { taColorSecondary ->
mEntryViewModel.colorSecondary = taColorSecondary.getColor(0, Color.BLACK)
}.recycle()
theme.obtainStyledAttributes(intArrayOf(R.attr.colorSurface)).also { taColorSurface ->
mEntryViewModel.colorSurface = taColorSurface.getColor(0, Color.BLACK)
}.recycle()
theme.obtainStyledAttributes(intArrayOf(R.attr.colorOnSurface)).also { taColorOnSurface ->
mEntryViewModel.colorOnSurface = taColorOnSurface.getColor(0, Color.BLACK)
}.recycle()
theme.obtainStyledAttributes(intArrayOf(android.R.attr.windowBackground)).also { taColorBackground ->
mEntryViewModel.colorBackground = taColorBackground.getColor(0, Color.BLACK)
}.recycle()
// Init Tags adapter
tagsAdapter = TagsAdapter(this)
@@ -20,13 +20,11 @@
package com.kunzisoft.keepass.viewmodels
import android.app.Application
import android.content.res.Resources
import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.core.graphics.ColorUtils
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.credentialprovider.magikeyboard.MagikeyboardService
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
@@ -67,13 +65,13 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
get() = entryUIState.value.loaded
@ColorInt
private var colorSecondary: Int = 0
var colorSecondary: Int = 0
@ColorInt
private var colorSurface: Int = 0
var colorSurface: Int = 0
@ColorInt
private var colorOnSurface: Int = 0
var colorOnSurface: Int = 0
@ColorInt
private var colorBackground: Int = 0
var colorBackground: Int = 0
@ColorInt
private var backgroundColor: Int? = null
@ColorInt
@@ -127,22 +125,6 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
showEntryColors = PreferencesUtil.showEntryColors(application)
}
fun setTheme(theme: Resources.Theme) {
// Retrieve the textColor to tint the toolbar
theme.obtainStyledAttributes(intArrayOf(R.attr.colorSecondary)).also { taColorSecondary ->
colorSecondary = taColorSecondary.getColor(0, Color.BLACK)
}.recycle()
theme.obtainStyledAttributes(intArrayOf(R.attr.colorSurface)).also { taColorSurface ->
colorSurface = taColorSurface.getColor(0, Color.BLACK)
}.recycle()
theme.obtainStyledAttributes(intArrayOf(R.attr.colorOnSurface)).also { taColorOnSurface ->
colorOnSurface = taColorOnSurface.getColor(0, Color.BLACK)
}.recycle()
theme.obtainStyledAttributes(intArrayOf(android.R.attr.windowBackground)).also { taColorBackground ->
colorBackground = taColorBackground.getColor(0, Color.BLACK)
}.recycle()
}
fun loadDatabase(database: ContextualDatabase?) {
loadEntry(database, mainEntryId, historyPosition)
}