From 270fb1d2c62a410baa8ec38e04d554696d722e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf-Martell=20Montw=C3=A9?= Date: Mon, 6 May 2024 17:57:07 +0200 Subject: [PATCH] Change FolderIconProvider and K9Drawer to reference drawables directly --- .../src/main/java/com/fsck/k9/ui/K9Drawer.kt | 14 +------ .../fsck/k9/ui/folders/FolderIconProvider.kt | 40 +++++-------------- .../java/com/fsck/k9/ui/folders/KoinModule.kt | 3 +- 3 files changed, 12 insertions(+), 45 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt index 3f72bca02..6bffaddb8 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt @@ -7,7 +7,6 @@ import android.graphics.PorterDuff import android.graphics.drawable.Drawable import android.net.Uri import android.os.Bundle -import android.util.TypedValue import android.widget.ImageView import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout @@ -71,6 +70,7 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K private val resources: Resources by inject() private val messagingController: MessagingController by inject() private val accountImageLoader: AccountImageLoader by inject() + private val folderIconProvider: FolderIconProvider by inject() private val drawer: DrawerLayout = parent.findViewById(R.id.drawerLayout) private val sliderView: MaterialDrawerSliderView = parent.findViewById(R.id.material_drawer_slider) @@ -79,7 +79,6 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K dividerBelowHeader = false displayBadgesOnCurrentProfileImage = false } - private val folderIconProvider: FolderIconProvider = FolderIconProvider(parent.theme) private val swipeRefreshLayout: SwipeRefreshLayout private val userFolderDrawerIds = ArrayList() @@ -288,22 +287,13 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K sliderView.addStickyFooterItem( PrimaryDrawerItem().apply { nameRes = R.string.preferences_action - iconRes = getResId(R.attr.iconActionSettings) + iconRes = R.drawable.ic_cog identifier = DRAWER_ID_PREFERENCES isSelectable = false }, ) } - private fun getResId(resAttribute: Int): Int { - val typedValue = TypedValue() - val found = parent.theme.resolveAttribute(resAttribute, typedValue, true) - if (!found) { - throw AssertionError("Couldn't find resource with attribute $resAttribute") - } - return typedValue.resourceId - } - private fun getFolderDisplayName(folder: Folder): String { return folderNameFormatter.displayName(folder) } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/FolderIconProvider.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/FolderIconProvider.kt index 40625b974..15076dbe0 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/FolderIconProvider.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/FolderIconProvider.kt @@ -1,39 +1,17 @@ package com.fsck.k9.ui.folders -import android.content.res.Resources -import android.util.TypedValue import com.fsck.k9.mailstore.FolderType import com.fsck.k9.ui.R -class FolderIconProvider(private val theme: Resources.Theme) { - private val iconFolderInboxResId: Int - private val iconFolderOutboxResId: Int - private val iconFolderSentResId: Int - private val iconFolderTrashResId: Int - private val iconFolderDraftsResId: Int - private val iconFolderArchiveResId: Int - private val iconFolderSpamResId: Int - var iconFolderResId: Int - - init { - iconFolderInboxResId = getResId(R.attr.iconFolderInbox) - iconFolderOutboxResId = getResId(R.attr.iconFolderOutbox) - iconFolderSentResId = getResId(R.attr.iconFolderSent) - iconFolderTrashResId = getResId(R.attr.iconFolderTrash) - iconFolderDraftsResId = getResId(R.attr.iconFolderDrafts) - iconFolderArchiveResId = getResId(R.attr.iconFolderArchive) - iconFolderSpamResId = getResId(R.attr.iconFolderSpam) - iconFolderResId = getResId(R.attr.iconFolder) - } - - private fun getResId(resAttribute: Int): Int { - val typedValue = TypedValue() - val found = theme.resolveAttribute(resAttribute, typedValue, true) - if (!found) { - throw AssertionError("Couldn't find resource with attribute $resAttribute") - } - return typedValue.resourceId - } +class FolderIconProvider { + private val iconFolderInboxResId: Int = R.drawable.ic_inbox + private val iconFolderOutboxResId: Int = R.drawable.ic_outbox + private val iconFolderSentResId: Int = R.drawable.ic_send + private val iconFolderTrashResId: Int = R.drawable.ic_trash_can + private val iconFolderDraftsResId: Int = R.drawable.ic_drafts_folder + private val iconFolderArchiveResId: Int = R.drawable.ic_archive + private val iconFolderSpamResId: Int = R.drawable.ic_alert_octagon + var iconFolderResId: Int = R.drawable.ic_folder fun getFolderIcon(type: FolderType): Int = when (type) { FolderType.INBOX -> iconFolderInboxResId diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/KoinModule.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/KoinModule.kt index 30fb5814f..835f93b2b 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/KoinModule.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/folders/KoinModule.kt @@ -1,11 +1,10 @@ package com.fsck.k9.ui.folders -import android.content.res.Resources.Theme import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.dsl.module val foldersUiModule = module { factory { FolderNameFormatter(resources = get()) } viewModel { FoldersViewModel(folderRepository = get(), messageCountsProvider = get()) } - factory { (theme: Theme) -> FolderIconProvider(theme) } + factory { FolderIconProvider() } }