mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 07:34:13 +01:00
After a long press selects a song, the finger can slide over more songs to select them, as in a photo gallery. Sliding back releases the songs it had passed but nothing selected before, and the list scrolls while the finger rests near its top or bottom edge. A row keeps its own long press and hands the pointer to a DragSelectController, which follows it on the global pointer route: the won long press already keeps the list from scrolling, and the route outlives a row that is rebuilt or scrolled away. Rows register with DragSelectItem so the controller can find the one nearest the finger, which also works in a grid. A held row that is kept alive off screen has no place on it and is skipped. Library Songs keeps the hold and drag onto a playlist: the first hold, and a hold on a selected song, drag as before. Once selecting, a hold on any other song selects it (still with the range from the song selected last) and slides; a slide replaces that range with the songs it passes. LibraryPlaylistDragSource takes an enabled flag for that, and the card gets the long press whenever the drag source does not. Singles, the folder view, album, playlist, mix and Library playlist pages slide from the first hold through SelectionModeMixin.holdToSelect. In selection mode a long press there now selects the row; the folder view and Library playlist rows toggled it before. Desktop is unchanged.
56 lines
1.8 KiB
Dart
56 lines
1.8 KiB
Dart
/// Adds every visible item between [anchor] and [target] to [selected].
|
|
///
|
|
/// Dart's default [Set] preserves insertion order, so walking backwards also
|
|
/// preserves the direction chosen by the user when results are later copied,
|
|
/// shared, or batch processed.
|
|
T addOrderedSelectionRange<T>({
|
|
required Set<T> selected,
|
|
required List<T> visibleItems,
|
|
required T target,
|
|
T? anchor,
|
|
}) {
|
|
final anchorIndex = anchor == null ? -1 : visibleItems.indexOf(anchor);
|
|
final targetIndex = visibleItems.indexOf(target);
|
|
if (anchorIndex < 0 || targetIndex < 0) {
|
|
selected.add(target);
|
|
return target;
|
|
}
|
|
|
|
final step = targetIndex >= anchorIndex ? 1 : -1;
|
|
for (var index = anchorIndex; ; index += step) {
|
|
selected.add(visibleItems[index]);
|
|
if (index == targetIndex) break;
|
|
}
|
|
return target;
|
|
}
|
|
|
|
/// Sets [selected] to [base] plus every visible item between [anchor] and
|
|
/// [target]: the selection of a finger sliding from one row to another, where
|
|
/// sliding back releases the rows it had passed but none of [base].
|
|
void applySlideSelection<T>({
|
|
required Set<T> selected,
|
|
required Set<T> base,
|
|
required List<T> visibleItems,
|
|
required T anchor,
|
|
required T target,
|
|
}) {
|
|
final anchorIndex = visibleItems.indexOf(anchor);
|
|
final targetIndex = visibleItems.indexOf(target);
|
|
if (anchorIndex < 0 || targetIndex < 0) return;
|
|
selected
|
|
..clear()
|
|
..addAll(base);
|
|
final step = targetIndex >= anchorIndex ? 1 : -1;
|
|
for (var index = anchorIndex; ; index += step) {
|
|
selected.add(visibleItems[index]);
|
|
if (index == targetIndex) break;
|
|
}
|
|
}
|
|
|
|
/// Toggles one item and returns the next range-selection anchor.
|
|
T? toggleOrderedSelection<T>({required Set<T> selected, required T target}) {
|
|
if (selected.add(target)) return target;
|
|
selected.remove(target);
|
|
return selected.isEmpty ? null : selected.last;
|
|
}
|