Skip to content

Commit

Permalink
refine extendRange
Browse files Browse the repository at this point in the history
  • Loading branch information
GuhDoy committed Aug 6, 2024
1 parent ab15d34 commit 82c96a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
2 changes: 1 addition & 1 deletion library/src/main/java/me/gm/selection/SelectionState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ class KeySelectionState<V>(
)
} else {
KeySelectionState(
initialSelection = selectedKeys.zip(selectedItems),
autoDeselectMode = autoDeselectMode,
initialSelection = selectedKeys.zip(selectedItems),
mutable = mutable
)
}
Expand Down
28 changes: 13 additions & 15 deletions library/src/main/java/me/gm/selection/grid/Gestures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,21 @@ private class RangeSupport<V>(
val newRange = range()

val removed = oldRange - newRange
if (removed.isNotEmpty()) {
removed.forEach { index ->
val itemInfo = lookupItemInfoForIndex(index) ?: return@forEach
if (!initialSelection.contains(selectionState.key(itemInfo))) {
selectionState.deselect(selectionState.key(itemInfo))
}
}
} else {
val added = newRange - oldRange
added.forEach { index ->
val itemInfo =
if (index == extendToItem.index) extendToItem
else lookupItemInfoForIndex(index) ?: return@forEach
val item = detailsLookup.getItem(itemInfo) ?: return@forEach
selectionState.select(selectionState.key(itemInfo), item)
removed.forEach { index ->
val itemInfo = lookupItemInfoForIndex(index) ?: return@forEach
if (!initialSelection.contains(selectionState.key(itemInfo))) {
selectionState.deselect(selectionState.key(itemInfo))
}
}

val added = newRange - oldRange
added.forEach { index ->
val itemInfo =
if (index == extendToItem.index) extendToItem
else lookupItemInfoForIndex(index) ?: return@forEach
val item = detailsLookup.getItem(itemInfo) ?: return@forEach
selectionState.select(selectionState.key(itemInfo), item)
}
}
}

Expand Down
28 changes: 13 additions & 15 deletions library/src/main/java/me/gm/selection/list/Gestures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,21 @@ private class RangeSupport<V>(
val newRange = range()

val removed = oldRange - newRange
if (removed.isNotEmpty()) {
removed.forEach { index ->
val itemInfo = lookupItemInfoForIndex(index) ?: return@forEach
if (!initialSelection.contains(selectionState.key(itemInfo))) {
selectionState.deselect(selectionState.key(itemInfo))
}
}
} else {
val added = newRange - oldRange
added.forEach { index ->
val itemInfo =
if (index == extendToItem.index) extendToItem
else lookupItemInfoForIndex(index) ?: return@forEach
val item = detailsLookup.getItem(itemInfo) ?: return@forEach
selectionState.select(selectionState.key(itemInfo), item)
removed.forEach { index ->
val itemInfo = lookupItemInfoForIndex(index) ?: return@forEach
if (!initialSelection.contains(selectionState.key(itemInfo))) {
selectionState.deselect(selectionState.key(itemInfo))
}
}

val added = newRange - oldRange
added.forEach { index ->
val itemInfo =
if (index == extendToItem.index) extendToItem
else lookupItemInfoForIndex(index) ?: return@forEach
val item = detailsLookup.getItem(itemInfo) ?: return@forEach
selectionState.select(selectionState.key(itemInfo), item)
}
}
}

Expand Down

0 comments on commit 82c96a7

Please sign in to comment.