From 6f67f54f0e2f5c182f05e158beb451bfbb7fced8 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sun, 31 May 2026 13:47:28 +0200 Subject: [PATCH] fix: Move color implementation #2541 --- .../keepass/activities/EntryActivity.kt | 14 +++++++++- .../keepass/viewmodels/EntryViewModel.kt | 26 +++---------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt index 856755f93..d218bb017 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt @@ -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) diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt index 7fbac3eee..bad2d3c68 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt @@ -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) }