Change FolderIconProvider and K9Drawer to reference drawables directly

This commit is contained in:
Wolf-Martell Montwé 2024-05-06 17:57:07 +02:00
parent 75e315e61a
commit 270fb1d2c6
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
3 changed files with 12 additions and 45 deletions

View file

@ -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<Long>()
@ -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)
}

View file

@ -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

View file

@ -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() }
}