Skip to content

Commit

Permalink
Collections not in alphabetical order #97
Browse files Browse the repository at this point in the history
Updating icon for "Remove from collection"
Upping versionCode to 34
  • Loading branch information
Dima-Android committed Dec 24, 2023
1 parent af04d58 commit 81cf1a1
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private fun EditingBottomPanel(
)
if(viewState.isCollectionACollection) {
IconWithPadding(
drawableRes = Drawables.unsubscribe_24,
drawableRes = Drawables.remove_from_collection,
isEnabled = isRestoreAndDeleteEnabled,
tintColor = if (isRestoreAndDeleteEnabled) CustomTheme.colors.zoteroDefaultBlue else CustomTheme.colors.disabledContent,
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ internal class CollectionPickerViewModel @Inject constructor(
libraryId = libraryId,
includeItemCounts = false
)
collectionTree.sortNodes()
startObservingResults()
updateCollectionTree(collectionTree)
} catch (error: Throwable) {
Expand Down Expand Up @@ -121,6 +122,7 @@ internal class CollectionPickerViewModel @Inject constructor(
libraryId = viewState.library.identifier,
includeItemCounts = false
)
tree.sortNodes()
updateCollectionTree(tree)
val removed = mutableSetOf<String>()
for (key in viewState.selected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ internal class CollectionsViewModel @Inject constructor(
libraryId = libraryId,
includeItemCounts = includeItemCounts
)

collectionTree.sortNodes()

collectionTree.insert(
collection = Collection.initWithCustomType(
type = CollectionIdentifier.CustomType.all,
Expand Down Expand Up @@ -332,6 +335,7 @@ internal class CollectionsViewModel @Inject constructor(
libraryId = viewState.libraryId,
includeItemCounts = includeItemCounts
)
tree.sortNodes()
val collectionTree = viewState.collectionTree
collectionTree.replace(matching = { it.isCollection }, tree = tree)
updateCollectionTree(collectionTree, collectionTree.createSnapshot())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class CollectionTree(
data class Node(
val identifier: CollectionIdentifier,
val parent: CollectionIdentifier?,
val children: List<Node>,
var children: List<Node>,
)

enum class CollapseState {
Expand Down Expand Up @@ -149,4 +149,21 @@ data class CollectionTree(
return null
}

fun sortNodes() {
nodes.sortBy { this.collections[it.identifier]!!.name.lowercase() }
nodes.forEach { node ->
recursivelySortChildren(node)
}
}

private fun recursivelySortChildren(node: Node) {
val childsSorted =
node.children
.sortedBy { this.collections[it.identifier]!!.name.lowercase() }
node.children = childsSorted
node.children.forEach {
recursivelySortChildren(it)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,11 @@ class CollectionTreeBuilder {
parent = parent,
children = children
)
// val insertionIndex =
// insertionIndex(node = node, nodes, collections = allCollections)
// nodes.add(index = insertionIndex, node)
nodes.add(node)
}
return nodes
}

private fun insertionIndex(node: CollectionTree.Node, array: MutableList<CollectionTree.Node>, collections: Map<CollectionIdentifier, Collection>): Int {
return array.sortedWith {lhs, rhs ->
val lCollection = collections[lhs.identifier] ?: return@sortedWith 1
val rCollection = collections[rhs.identifier] ?: return@sortedWith 1
lCollection.name.compareTo(rCollection.name)
}.indexOf(node)
}

private fun collection(
rCollection: RCollection,
libraryId: LibraryIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sealed class LongPressOptionItem(

data class RemoveFromCollection(val item: RItem): LongPressOptionItem(
titleId = Strings.items_action_remove_from_collection,
resIcon = Drawables.unsubscribe_24
resIcon = Drawables.remove_from_collection
)

data class CreateParentItem(val item: RItem): LongPressOptionItem(
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/remove_from_collection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12.25,13.75H17.75V12.25H12.25V13.75ZM4.308,19.5C3.803,19.5 3.375,19.325 3.025,18.975C2.675,18.625 2.5,18.197 2.5,17.692V6.308C2.5,5.803 2.675,5.375 3.025,5.025C3.375,4.675 3.803,4.5 4.308,4.5H9.798L11.798,6.5H19.692C20.197,6.5 20.625,6.675 20.975,7.025C21.325,7.375 21.5,7.803 21.5,8.308V17.692C21.5,18.197 21.325,18.625 20.975,18.975C20.625,19.325 20.197,19.5 19.692,19.5H4.308ZM4.308,18H19.692C19.782,18 19.856,17.971 19.913,17.913C19.971,17.856 20,17.782 20,17.692V8.308C20,8.218 19.971,8.144 19.913,8.087C19.856,8.029 19.782,8 19.692,8H11.185L9.185,6H4.308C4.218,6 4.144,6.029 4.087,6.087C4.029,6.144 4,6.218 4,6.308V17.692C4,17.782 4.029,17.856 4.087,17.913C4.144,17.971 4.218,18 4.308,18Z"
android:fillColor="#000000"/>
</vector>
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/unsubscribe_24.xml

This file was deleted.

2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object BuildConfig {
const val compileSdkVersion = 34
const val targetSdk = 33

val versionCode = 33 // Must be updated on every build
val versionCode = 34 // Must be updated on every build
val version = Version(
major = 1,
minor = 0,
Expand Down

0 comments on commit 81cf1a1

Please sign in to comment.