Simplify SwipeResourceProvider
code that returns the action background color
This commit is contained in:
parent
b95e1655ca
commit
a0edf47b2b
4 changed files with 17 additions and 25 deletions
|
@ -92,10 +92,10 @@ class MessageListSwipeCallback(
|
|||
val swipeThresholdReached = abs(dX) > swipeThreshold
|
||||
if (swipeThresholdReached) {
|
||||
val action = if (dX > 0) swipeRightAction else swipeLeftAction
|
||||
val backgroundColor = resourceProvider.getBackgroundColor(item, action)
|
||||
val backgroundColor = resourceProvider.getBackgroundColor(action)
|
||||
drawBackground(view, backgroundColor)
|
||||
} else {
|
||||
val backgroundColor = resourceProvider.getBackgroundColor(item, SwipeAction.None)
|
||||
val backgroundColor = resourceProvider.getBackgroundColor(SwipeAction.None)
|
||||
drawBackground(view, backgroundColor)
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ class MessageListSwipeCallback(
|
|||
val iconBottom = iconTop + icon.intrinsicHeight
|
||||
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom)
|
||||
|
||||
icon.setTint(resourceProvider.getIconTint(item, swipeRightAction, swipeThresholdReached))
|
||||
icon.setTint(resourceProvider.getIconTint(swipeRightAction, swipeThresholdReached))
|
||||
icon.draw(this)
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ class MessageListSwipeCallback(
|
|||
val iconBottom = iconTop + icon.intrinsicHeight
|
||||
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom)
|
||||
|
||||
icon.setTint(resourceProvider.getIconTint(item, swipeLeftAction, swipeThresholdReached))
|
||||
icon.setTint(resourceProvider.getIconTint(swipeLeftAction, swipeThresholdReached))
|
||||
icon.draw(this)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,20 +23,18 @@ class SwipeResourceProvider(val theme: Theme) {
|
|||
|
||||
private val noActionColor = theme.resolveColorAttribute(R.attr.messageListSwipeDisabledBackgroundColor)
|
||||
private val selectColor = theme.resolveColorAttribute(R.attr.messageListSwipeSelectBackgroundColor)
|
||||
private val markAsReadColor = theme.resolveColorAttribute(R.attr.messageListSwipeMarkAsReadBackgroundColor)
|
||||
private val markAsUnreadColor = theme.resolveColorAttribute(R.attr.messageListSwipeMarkAsUnreadBackgroundColor)
|
||||
private val addStarColor = theme.resolveColorAttribute(R.attr.messageListSwipeAddStarBackgroundColor)
|
||||
private val removeStarColor = theme.resolveColorAttribute(R.attr.messageListSwipeRemoveStarBackgroundColor)
|
||||
private val toggleReadColor = theme.resolveColorAttribute(R.attr.messageListSwipeToggleReadBackgroundColor)
|
||||
private val toggleStarColor = theme.resolveColorAttribute(R.attr.messageListSwipeToggleStarBackgroundColor)
|
||||
private val archiveColor = theme.resolveColorAttribute(R.attr.messageListSwipeArchiveBackgroundColor)
|
||||
private val deleteColor = theme.resolveColorAttribute(R.attr.messageListSwipeDeleteBackgroundColor)
|
||||
private val spamColor = theme.resolveColorAttribute(R.attr.messageListSwipeSpamBackgroundColor)
|
||||
private val moveColor = theme.resolveColorAttribute(R.attr.messageListSwipeMoveBackgroundColor)
|
||||
|
||||
fun getIconTint(item: MessageListItem, action: SwipeAction, swipeThresholdReached: Boolean): Int {
|
||||
fun getIconTint(action: SwipeAction, swipeThresholdReached: Boolean): Int {
|
||||
return if (swipeThresholdReached) {
|
||||
iconTint
|
||||
} else {
|
||||
getBackgroundColor(item, action)
|
||||
getBackgroundColor(action)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,12 +51,12 @@ class SwipeResourceProvider(val theme: Theme) {
|
|||
}
|
||||
}
|
||||
|
||||
fun getBackgroundColor(item: MessageListItem, action: SwipeAction): Int {
|
||||
fun getBackgroundColor(action: SwipeAction): Int {
|
||||
return when (action) {
|
||||
SwipeAction.None -> noActionColor
|
||||
SwipeAction.ToggleSelection -> selectColor
|
||||
SwipeAction.ToggleRead -> if (item.isRead) markAsUnreadColor else markAsReadColor
|
||||
SwipeAction.ToggleStar -> if (item.isStarred) removeStarColor else addStarColor
|
||||
SwipeAction.ToggleRead -> toggleReadColor
|
||||
SwipeAction.ToggleStar -> toggleStarColor
|
||||
SwipeAction.Archive -> archiveColor
|
||||
SwipeAction.Delete -> deleteColor
|
||||
SwipeAction.Spam -> spamColor
|
||||
|
|
|
@ -83,13 +83,11 @@
|
|||
<attr name="messageListSwipeSelectIcon" format="reference"/>
|
||||
<attr name="messageListSwipeSelectBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeMarkAsReadIcon" format="reference"/>
|
||||
<attr name="messageListSwipeMarkAsReadBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeMarkAsUnreadIcon" format="reference"/>
|
||||
<attr name="messageListSwipeMarkAsUnreadBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeToggleReadBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeAddStarIcon" format="reference"/>
|
||||
<attr name="messageListSwipeAddStarBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeRemoveStarIcon" format="reference"/>
|
||||
<attr name="messageListSwipeRemoveStarBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeToggleStarBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeArchiveIcon" format="reference"/>
|
||||
<attr name="messageListSwipeArchiveBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSwipeDeleteIcon" format="reference"/>
|
||||
|
|
|
@ -97,13 +97,11 @@
|
|||
<item name="messageListSwipeSelectIcon">@drawable/ic_import_status</item>
|
||||
<item name="messageListSwipeSelectBackgroundColor">@color/material_blue_600</item>
|
||||
<item name="messageListSwipeMarkAsReadIcon">?attr/iconActionMarkAsRead</item>
|
||||
<item name="messageListSwipeMarkAsReadBackgroundColor">@color/material_blue_600</item>
|
||||
<item name="messageListSwipeMarkAsUnreadIcon">?attr/iconActionMarkAsUnread</item>
|
||||
<item name="messageListSwipeMarkAsUnreadBackgroundColor">@color/material_blue_600</item>
|
||||
<item name="messageListSwipeToggleReadBackgroundColor">@color/material_blue_600</item>
|
||||
<item name="messageListSwipeAddStarIcon">?attr/iconActionFlag</item>
|
||||
<item name="messageListSwipeAddStarBackgroundColor">@color/material_orange_600</item>
|
||||
<item name="messageListSwipeRemoveStarIcon">?attr/iconActionUnflag</item>
|
||||
<item name="messageListSwipeRemoveStarBackgroundColor">@color/material_orange_600</item>
|
||||
<item name="messageListSwipeToggleStarBackgroundColor">@color/material_orange_600</item>
|
||||
<item name="messageListSwipeArchiveIcon">?attr/iconActionArchive</item>
|
||||
<item name="messageListSwipeArchiveBackgroundColor">@color/material_green_600</item>
|
||||
<item name="messageListSwipeDeleteIcon">?attr/iconActionDelete</item>
|
||||
|
@ -243,13 +241,11 @@
|
|||
<item name="messageListSwipeSelectIcon">@drawable/ic_import_status</item>
|
||||
<item name="messageListSwipeSelectBackgroundColor">@color/material_blue_700</item>
|
||||
<item name="messageListSwipeMarkAsReadIcon">?attr/iconActionMarkAsRead</item>
|
||||
<item name="messageListSwipeMarkAsReadBackgroundColor">@color/material_blue_700</item>
|
||||
<item name="messageListSwipeMarkAsUnreadIcon">?attr/iconActionMarkAsUnread</item>
|
||||
<item name="messageListSwipeMarkAsUnreadBackgroundColor">@color/material_blue_700</item>
|
||||
<item name="messageListSwipeToggleReadBackgroundColor">@color/material_blue_700</item>
|
||||
<item name="messageListSwipeAddStarIcon">?attr/iconActionFlag</item>
|
||||
<item name="messageListSwipeAddStarBackgroundColor">@color/material_orange_700</item>
|
||||
<item name="messageListSwipeRemoveStarIcon">?attr/iconActionUnflag</item>
|
||||
<item name="messageListSwipeRemoveStarBackgroundColor">@color/material_orange_700</item>
|
||||
<item name="messageListSwipeToggleStarBackgroundColor">@color/material_orange_700</item>
|
||||
<item name="messageListSwipeArchiveIcon">?attr/iconActionArchive</item>
|
||||
<item name="messageListSwipeArchiveBackgroundColor">@color/material_green_700</item>
|
||||
<item name="messageListSwipeDeleteIcon">?attr/iconActionDelete</item>
|
||||
|
|
Loading…
Reference in a new issue