Unpin items when dragging them to tags
This commit is contained in:
parent
d95dd4c829
commit
69042e4d2f
@ -183,6 +183,7 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM) {
|
|||||||
val gridState = rememberLazyGridState()
|
val gridState = rememberLazyGridState()
|
||||||
val tagsListState = rememberLazyListState()
|
val tagsListState = rememberLazyListState()
|
||||||
val tagsTitleSize = 48.dp.toPixels()
|
val tagsTitleSize = 48.dp.toPixels()
|
||||||
|
val tagsSpacing = 12.dp.toPixels()
|
||||||
val state = rememberLazyDragAndDropGridState(
|
val state = rememberLazyDragAndDropGridState(
|
||||||
gridState = gridState,
|
gridState = gridState,
|
||||||
onDragStart = {
|
onDragStart = {
|
||||||
@ -211,7 +212,7 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM) {
|
|||||||
) {
|
) {
|
||||||
val scroll = tagsListState.layoutInfo.viewportStartOffset
|
val scroll = tagsListState.layoutInfo.viewportStartOffset
|
||||||
val tag = tagsListState.layoutInfo.visibleItemsInfo.find {
|
val tag = tagsListState.layoutInfo.visibleItemsInfo.find {
|
||||||
position.x + scroll > it.offset && position.x + scroll < it.offset + it.size
|
draggedCenter.x + scroll > it.offset && draggedCenter.x + scroll < it.offset + it.size - tagsSpacing
|
||||||
}
|
}
|
||||||
hoveredTag = tag?.index?.let { pinnedTags[it].tag }
|
hoveredTag = tag?.index?.let { pinnedTags[it].tag }
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -55,8 +55,8 @@ class EditFavoritesSheetVM : ViewModel(), KoinComponent {
|
|||||||
val pinnedTags = MutableLiveData<List<Tag>>(emptyList())
|
val pinnedTags = MutableLiveData<List<Tag>>(emptyList())
|
||||||
val availableTags = MutableLiveData<List<Tag>>(emptyList())
|
val availableTags = MutableLiveData<List<Tag>>(emptyList())
|
||||||
|
|
||||||
suspend fun reload() {
|
suspend fun reload(showLoadingIndicator: Boolean = true) {
|
||||||
loading.value = true
|
loading.value = showLoadingIndicator
|
||||||
manuallySorted = mutableListOf()
|
manuallySorted = mutableListOf()
|
||||||
manuallySorted = repository.getFavorites(
|
manuallySorted = repository.getFavorites(
|
||||||
manuallySorted = true,
|
manuallySorted = true,
|
||||||
@ -236,8 +236,10 @@ class EditFavoritesSheetVM : ViewModel(), KoinComponent {
|
|||||||
gridItems.find { it is FavoritesSheetGridItem.Favorite && it.item.key == key } as FavoritesSheetGridItem.Favorite?
|
gridItems.find { it is FavoritesSheetGridItem.Favorite && it.item.key == key } as FavoritesSheetGridItem.Favorite?
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
repository.removeFromFavorites(item.item)
|
repository.removeFromFavorites(item.item)
|
||||||
gridItems.remove(item)
|
automaticallySorted.removeAll { it.key == item.item.key }
|
||||||
this.gridItems.value = gridItems
|
|| manuallySorted.removeAll { it.key == item.item.key }
|
||||||
|
|| frequentlyUsed.removeAll { it.key == item.item.key }
|
||||||
|
buildItemList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +304,19 @@ class EditFavoritesSheetVM : ViewModel(), KoinComponent {
|
|||||||
val item =
|
val item =
|
||||||
gridItems.find { it is FavoritesSheetGridItem.Favorite && it.item.key == key } as FavoritesSheetGridItem.Favorite?
|
gridItems.find { it is FavoritesSheetGridItem.Favorite && it.item.key == key } as FavoritesSheetGridItem.Favorite?
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
|
automaticallySorted.removeAll { it.key == item.item.key }
|
||||||
|
|| manuallySorted.removeAll { it.key == item.item.key }
|
||||||
|
|| frequentlyUsed.removeAll { it.key == item.item.key }
|
||||||
|
buildItemList()
|
||||||
customAttributesRepository.addTag(item.item, tag)
|
customAttributesRepository.addTag(item.item, tag)
|
||||||
|
repository.unpinItem(item.item)
|
||||||
|
viewModelScope.launch {
|
||||||
|
frequentlyUsed = repository.getFavorites(
|
||||||
|
frequentlyUsed = true,
|
||||||
|
excludeTypes = listOf("tag"),
|
||||||
|
).first().toMutableList()
|
||||||
|
buildItemList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user