-
-
Notifications
You must be signed in to change notification settings - Fork 238
#1223 feature: sorting key maps #1337
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
2a023c3
add simple key map fields comparators
maksimowiczm ff05ca8
add sorting use cases
maksimowiczm 4b04437
use sorting inside `ListKeyMapsUseCaseImpl`
maksimowiczm 11e736f
add ui
maksimowiczm 5e9daa7
rename `KeyMapField` to `SortField`
maksimowiczm 011f7ab
Implement `KeyMapConstraintsComparator`
maksimowiczm 81dd15f
Implement `KeyMapTriggerComparator`
maksimowiczm 635e7c2
fix constraints sorting
maksimowiczm 58ce5e0
add sorting actions by value
maksimowiczm 0640365
add sorting by options
maksimowiczm 559ac8b
fix menu
maksimowiczm e7b759f
add `None` sort order
maksimowiczm 9ba565c
implement sort menu with chips
maksimowiczm dea3889
refactor use cases associated with `SortField` priority
maksimowiczm 0a191fe
add chip drag
maksimowiczm ad9a41d
Merge remote-tracking branch 'prod/develop' into feature/sorting
maksimowiczm 1127a13
add compose ui
maksimowiczm f38ad92
go back to string preference because somehow set stopped working
maksimowiczm 61e567a
simplify use cases
maksimowiczm cce4ef0
that wasn't supposed to be here
maksimowiczm bb2b354
fix sort cancel
maksimowiczm 133bb3d
move comparators to sorting package
maksimowiczm 2a317d8
another ui version goes brrr
maksimowiczm a8f8123
use material3 modal bottom sheet
maksimowiczm 71143e8
improve sort help
maksimowiczm 9b6cd73
clean up
maksimowiczm 549edcf
squash use cases
maksimowiczm 87f8298
fix bottom sheet lag
maksimowiczm 0a28629
fix: hide the drag handle on Advanced triggers bottom sheet to be con…
sds100 5ddba58
#1337 refactor, fix style, and remove unnecessary code
sds100 f665299
#1337 rename doFinal method
sds100 effc42e
#1337 remove sorting/ui package
sds100 ed433fb
#1337 use interface for SortKeyMapsUseCase
sds100 f05070d
#1337 update comments
sds100 19e47d4
Merge branch 'develop' into feature/sorting
sds100 37f466b
Merge branch 'develop' into feature/sorting
sds100 7d8fb55
use localized strings for constraints comparison
maksimowiczm 9070e83
Merge branch 'develop' into feature/sorting
sds100 5eb072b
#1223 remove unnecessary functions for creating comparators
sds100 7833710
#1223 show reset sort button when changing the order as well
sds100 7f2bfe4
#1223 sort constraints by their type and sub fields if there are any
sds100 0898aa9
#1223 sort actions by their type and sub fields if there are any
sds100 747da9d
Merge branch 'develop' into feature/sorting
sds100 c955c5c
upload apk artifact from pull request github actions
sds100 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapField.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.github.sds100.keymapper.mappings.keymaps | ||
|
|
||
| import io.github.sds100.keymapper.constraints.KeyMapConstraintsComparator | ||
| import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTriggerComparator | ||
|
|
||
| enum class KeyMapField { | ||
maksimowiczm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| TRIGGER, | ||
| ACTIONS, | ||
| CONSTRAINTS, | ||
| OPTIONS, | ||
| ; | ||
|
|
||
| fun getComparator(reverse: Boolean) = when (this) { | ||
| TRIGGER -> KeyMapTriggerComparator(reverse) | ||
| ACTIONS -> KeyMapActionsComparator(reverse) | ||
| CONSTRAINTS -> KeyMapConstraintsComparator(reverse) | ||
| OPTIONS -> KeyMapOptionsComparator(reverse) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
app/src/main/java/io/github/sds100/keymapper/sorting/ObserveKeyMapFieldSortOrderUseCase.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package io.github.sds100.keymapper.sorting | ||
|
|
||
| import io.github.sds100.keymapper.data.Keys | ||
| import io.github.sds100.keymapper.data.repositories.PreferenceRepository | ||
| import io.github.sds100.keymapper.mappings.keymaps.KeyMapField | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.map | ||
|
|
||
| /** | ||
| * Observes the sorting order of a key map field, indicating the order in which the specified field | ||
| * should be sorted. | ||
| */ | ||
| class ObserveKeyMapFieldSortOrderUseCase( | ||
maksimowiczm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private val preferenceRepository: PreferenceRepository, | ||
| ) { | ||
| /** | ||
| * Observe the sorting order of the key map field. | ||
| * | ||
| * @param field The key map field to observe. | ||
| * @return A flow of the sorting order. | ||
| */ | ||
| operator fun invoke(field: KeyMapField): Flow<SortOrder> { | ||
| val key = when (field) { | ||
| KeyMapField.TRIGGER -> Keys.sortTriggerAscending | ||
| KeyMapField.ACTIONS -> Keys.sortActionsAscending | ||
| KeyMapField.CONSTRAINTS -> Keys.sortConstraintsAscending | ||
| KeyMapField.OPTIONS -> Keys.sortOptionsAscending | ||
| } | ||
|
|
||
| return preferenceRepository.get(key).map { | ||
| when (it) { | ||
| // Default value is ascending | ||
| null, true -> SortOrder.ASCENDING | ||
| false -> SortOrder.DESCENDING | ||
| } | ||
| } | ||
| } | ||
| } | ||
46 changes: 46 additions & 0 deletions
46
app/src/main/java/io/github/sds100/keymapper/sorting/ObserveKeyMapSortOrderUseCase.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package io.github.sds100.keymapper.sorting | ||
|
|
||
| import io.github.sds100.keymapper.data.Keys | ||
| import io.github.sds100.keymapper.data.repositories.PreferenceRepository | ||
| import io.github.sds100.keymapper.mappings.keymaps.KeyMapField | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.map | ||
|
|
||
| /** | ||
| * Observes the order in which key map fields should be sorted, prioritizing specific fields. | ||
| * For example, if the order is [TRIGGER, ACTIONS, CONSTRAINTS, OPTIONS], | ||
| * it means the key maps should be sorted first by trigger, then by actions, followed by constraints, | ||
| * and finally by options. | ||
| */ | ||
| class ObserveKeyMapSortOrderUseCase( | ||
| private val preferenceRepository: PreferenceRepository, | ||
| ) { | ||
| private val default by lazy { | ||
| listOf( | ||
| KeyMapField.TRIGGER, | ||
| KeyMapField.ACTIONS, | ||
| KeyMapField.CONSTRAINTS, | ||
| KeyMapField.OPTIONS, | ||
| ) | ||
| } | ||
|
|
||
| operator fun invoke(): Flow<List<KeyMapField>> { | ||
| return preferenceRepository | ||
| .get(Keys.sortOrder) | ||
| .map { | ||
| val result = runCatching { | ||
| it | ||
| ?.split(",") | ||
| ?.map { KeyMapField.valueOf(it) } | ||
| ?: default | ||
| }.getOrDefault(default).distinct() | ||
|
|
||
| // If the result is not the expected size it means that the preference is corrupted | ||
| if (result.size != 4) { | ||
| return@map default | ||
| } | ||
|
|
||
| result | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.