-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-selection: Selection mode #5623
Open
0nko
wants to merge
23
commits into
feature/ondrej/tab-multi-selection-menu
Choose a base branch
from
feature/ondrej/tab-multi-selection-select-mode
base: feature/ondrej/tab-multi-selection-menu
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0d83223
Add item checkbox resources and image view
0nko 806091c
Modify tab item decorator to handle the selection mode decoration
0nko 36fd8fd
Add selection mode logic
0nko 63c6157
Fix the tab selection adapter update
0nko cbe6c62
Fix the selection decorator radios
0nko 29dfe8a
Trigger selection mode from the menu
0nko b9b0f51
Add a way to cancel selection mode
0nko 4bb9678
Do not cancel selection mode when scrolling
0nko 0012cda
Update toolbar title on selection change
0nko ae29a6a
Update FAB type based on the selection mode
0nko 065204a
Fix the unit test build
0nko babcd4b
Fix a lint error
0nko c067f19
Trigger normal mode when all tabs are cleared
0nko e2e37d8
Remove tab selection when tab is deleted and restore it when it's undone
0nko 01b7885
Reverse unrelated code
0nko f560274
Fix the tab selection after rebase
0nko 5152c9b
Fix the failing unit test
0nko 9395ad3
Add Deselect all menu item
0nko 1402898
Add a feature flag for the tab switcher items
0nko 01d5604
Add deselect menu
0nko c2949c5
Fix the tab selection
0nko 7bbd585
Fix the build
0nko 63cf555
Uncomment the layout mode change
0nko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,52 +23,66 @@ import android.graphics.RectF | |
import android.util.TypedValue | ||
import android.view.View | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.view.children | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.duckduckgo.app.tabs.ui.TabSwitcherViewModel.SelectionViewState.Mode | ||
import com.duckduckgo.common.ui.view.toPx | ||
import com.duckduckgo.mobile.android.R as CommonR | ||
|
||
class TabItemDecorator( | ||
context: Context, | ||
var tabSwitcherItemId: String?, | ||
tabSwitcherItemId: String?, | ||
mode: Mode, | ||
) : RecyclerView.ItemDecoration() { | ||
|
||
private val borderStroke: Paint = Paint().apply { | ||
var highlightedTabId: String? = tabSwitcherItemId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Why do we need to hold this state? Can it not be held outside of this class? I would have imagined we would know the state of this externally to the decorator class |
||
var selectionMode: Mode = mode | ||
|
||
private val activeTabBorderStroke: Paint = Paint().apply { | ||
isAntiAlias = true | ||
style = Paint.Style.STROKE | ||
strokeWidth = BORDER_WIDTH | ||
strokeWidth = ACTIVE_TAB_BORDER_WIDTH | ||
|
||
val typedValue = TypedValue() | ||
context.theme.resolveAttribute(CommonR.attr.daxColorBackgroundInverted, typedValue, true) | ||
color = ContextCompat.getColor(context, typedValue.resourceId) | ||
} | ||
|
||
private val selectionBorderStroke: Paint = Paint().apply { | ||
isAntiAlias = true | ||
style = Paint.Style.STROKE | ||
strokeWidth = SELECTION_BORDER_WIDTH | ||
|
||
val typedValue = TypedValue() | ||
context.theme.resolveAttribute(CommonR.attr.daxColorAccentBlue, typedValue, true) | ||
color = ContextCompat.getColor(context, typedValue.resourceId) | ||
} | ||
|
||
override fun onDrawOver( | ||
canvas: Canvas, | ||
recyclerView: RecyclerView, | ||
state: RecyclerView.State, | ||
) { | ||
val adapter = recyclerView.adapter as TabSwitcherAdapter? ?: return | ||
|
||
for (i in 0 until recyclerView.childCount) { | ||
val child = recyclerView.getChildAt(i) | ||
|
||
recyclerView.children.forEach { child -> | ||
val positionInAdapter = recyclerView.getChildAdapterPosition(child) | ||
adapter.getTabSwitcherItem(positionInAdapter)?.let { tabSwitcherItem -> | ||
if (tabSwitcherItem.id == tabSwitcherItemId) { | ||
drawSelectedTabDecoration(child, canvas) | ||
if (selectionMode is Mode.Selection) { | ||
if (tabSwitcherItem is TabSwitcherItem.Tab && tabSwitcherItem.isSelected) { | ||
drawTabDecoration(child, canvas, selectionBorderStroke) | ||
} | ||
} else if (tabSwitcherItem.id == highlightedTabId) { | ||
drawTabDecoration(child, canvas, activeTabBorderStroke) | ||
} | ||
} | ||
} | ||
|
||
super.onDrawOver(canvas, recyclerView, state) | ||
} | ||
|
||
private fun drawSelectedTabDecoration( | ||
child: View, | ||
c: Canvas, | ||
) { | ||
borderStroke.alpha = (child.alpha * 255).toInt() | ||
c.drawRoundRect(child.getBounds(), BORDER_RADIUS, BORDER_RADIUS, borderStroke) | ||
private fun drawTabDecoration(child: View, c: Canvas, paint: Paint) { | ||
selectionBorderStroke.alpha = (child.alpha * 255).toInt() | ||
c.drawRoundRect(child.getBounds(), BORDER_RADIUS, BORDER_RADIUS, paint) | ||
} | ||
|
||
private fun View.getBounds(): RectF { | ||
|
@@ -83,7 +97,8 @@ class TabItemDecorator( | |
|
||
companion object { | ||
private val BORDER_RADIUS = 12.toPx().toFloat() | ||
private val BORDER_WIDTH = 2.toPx().toFloat() | ||
private val ACTIVE_TAB_BORDER_WIDTH = 2.toPx().toFloat() | ||
private val SELECTION_BORDER_WIDTH = 4.toPx().toFloat() | ||
private val BORDER_PADDING = 3.toPx().toFloat() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡Something doesn't sit right with us passing in some external state when we're using the TabSwitcherItemDiffCallback to compare items and their changes.
Did you explore anything where the Tab knows what selection mode it's in so then it can reflect that in it's UI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, that's a really good point. I'll refactor it so they this isn't necessary.