Skip to content
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

#1223 feature: sorting key maps #1337

Open
wants to merge 44 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2a023c3
add simple key map fields comparators
maksimowiczm Nov 9, 2024
ff05ca8
add sorting use cases
maksimowiczm Nov 9, 2024
4b04437
use sorting inside `ListKeyMapsUseCaseImpl`
maksimowiczm Nov 9, 2024
11e736f
add ui
maksimowiczm Nov 9, 2024
5e9daa7
rename `KeyMapField` to `SortField`
maksimowiczm Nov 17, 2024
011f7ab
Implement `KeyMapConstraintsComparator`
maksimowiczm Nov 17, 2024
81dd15f
Implement `KeyMapTriggerComparator`
maksimowiczm Nov 17, 2024
635e7c2
fix constraints sorting
maksimowiczm Nov 25, 2024
58ce5e0
add sorting actions by value
maksimowiczm Nov 25, 2024
0640365
add sorting by options
maksimowiczm Nov 25, 2024
559ac8b
fix menu
maksimowiczm Nov 26, 2024
e7b759f
add `None` sort order
maksimowiczm Nov 26, 2024
9ba565c
implement sort menu with chips
maksimowiczm Nov 26, 2024
dea3889
refactor use cases associated with `SortField` priority
maksimowiczm Dec 19, 2024
0a191fe
add chip drag
maksimowiczm Dec 19, 2024
ad9a41d
Merge remote-tracking branch 'prod/develop' into feature/sorting
maksimowiczm Dec 19, 2024
1127a13
add compose ui
maksimowiczm Dec 23, 2024
f38ad92
go back to string preference because somehow set stopped working
maksimowiczm Dec 23, 2024
61e567a
simplify use cases
maksimowiczm Dec 23, 2024
cce4ef0
that wasn't supposed to be here
maksimowiczm Dec 23, 2024
bb2b354
fix sort cancel
maksimowiczm Dec 26, 2024
133bb3d
move comparators to sorting package
maksimowiczm Dec 26, 2024
2a317d8
another ui version goes brrr
maksimowiczm Dec 26, 2024
a8f8123
use material3 modal bottom sheet
maksimowiczm Dec 26, 2024
71143e8
improve sort help
maksimowiczm Dec 27, 2024
9b6cd73
clean up
maksimowiczm Dec 28, 2024
549edcf
squash use cases
maksimowiczm Dec 28, 2024
87f8298
fix bottom sheet lag
maksimowiczm Dec 28, 2024
0a28629
fix: hide the drag handle on Advanced triggers bottom sheet to be con…
sds100 Dec 29, 2024
5ddba58
#1337 refactor, fix style, and remove unnecessary code
sds100 Dec 29, 2024
f665299
#1337 rename doFinal method
sds100 Dec 29, 2024
effc42e
#1337 remove sorting/ui package
sds100 Dec 29, 2024
ed433fb
#1337 use interface for SortKeyMapsUseCase
sds100 Dec 29, 2024
f05070d
#1337 update comments
sds100 Dec 29, 2024
19e47d4
Merge branch 'develop' into feature/sorting
sds100 Dec 29, 2024
37f466b
Merge branch 'develop' into feature/sorting
sds100 Dec 29, 2024
7d8fb55
use localized strings for constraints comparison
maksimowiczm Jan 5, 2025
9070e83
Merge branch 'develop' into feature/sorting
sds100 Jan 22, 2025
5eb072b
#1223 remove unnecessary functions for creating comparators
sds100 Jan 22, 2025
7833710
#1223 show reset sort button when changing the order as well
sds100 Feb 2, 2025
7f2bfe4
#1223 sort constraints by their type and sub fields if there are any
sds100 Feb 2, 2025
0898aa9
#1223 sort actions by their type and sub fields if there are any
sds100 Feb 2, 2025
747da9d
Merge branch 'develop' into feature/sorting
sds100 Feb 2, 2025
c955c5c
upload apk artifact from pull request github actions
sds100 Feb 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/src/main/java/io/github/sds100/keymapper/UseCases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import io.github.sds100.keymapper.mappings.keymaps.detection.DetectKeyMapsUseCas
import io.github.sds100.keymapper.onboarding.OnboardingUseCaseImpl
import io.github.sds100.keymapper.reroutekeyevents.RerouteKeyEventsUseCaseImpl
import io.github.sds100.keymapper.shizuku.ShizukuInputEventInjector
import io.github.sds100.keymapper.sorting.ObserveKeyMapFieldSortOrderUseCase
import io.github.sds100.keymapper.sorting.ObserveKeyMapSortOrderUseCase
import io.github.sds100.keymapper.sorting.ObserveKeyMapsSorterUseCase
import io.github.sds100.keymapper.sorting.SetKeyMapFieldSortOrderUseCase
import io.github.sds100.keymapper.system.Shell
import io.github.sds100.keymapper.system.accessibility.ControlAccessibilityServiceUseCase
import io.github.sds100.keymapper.system.accessibility.ControlAccessibilityServiceUseCaseImpl
Expand Down Expand Up @@ -231,4 +235,21 @@ object UseCases {
keyEventRelayService,
ServiceLocator.inputMethodAdapter(ctx),
)

fun observeKeyMapFieldSortOrderUseCase(ctx: Context) = ObserveKeyMapFieldSortOrderUseCase(
ServiceLocator.settingsRepository(ctx),
)

fun observeKeyMapsSorter(ctx: Context) = ObserveKeyMapsSorterUseCase(
observeKeyMapFieldSortOrderUseCase(ctx),
observeKeyMapSortOrderUseCase(ctx),
)

fun observeKeyMapSortOrderUseCase(ctx: Context) = ObserveKeyMapSortOrderUseCase(
ServiceLocator.settingsRepository(ctx),
)

fun setKeyMapFieldSortOrderUseCase(ctx: Context) = SetKeyMapFieldSortOrderUseCase(
ServiceLocator.settingsRepository(ctx),
)
}
151 changes: 150 additions & 1 deletion app/src/main/java/io/github/sds100/keymapper/actions/ActionData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import io.github.sds100.keymapper.system.volume.VolumeStream
import kotlinx.serialization.Serializable

@Serializable
sealed class ActionData {
sealed class ActionData : Comparable<ActionData> {
abstract val id: ActionId

override fun compareTo(other: ActionData) = id.compareTo(other.id)

@Serializable
data class App(
val packageName: String,
) : ActionData() {
override val id: ActionId = ActionId.APP

override fun compareTo(other: ActionData) = when (other) {
is App -> packageName.compareTo(other.packageName)
else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -28,6 +35,11 @@ sealed class ActionData {
val uri: String,
) : ActionData() {
override val id: ActionId = ActionId.APP_SHORTCUT

override fun compareTo(other: ActionData) = when (other) {
is AppShortcut -> shortcutTitle.compareTo(other.shortcutTitle)
else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -45,6 +57,11 @@ sealed class ActionData {
val descriptor: String,
val name: String,
)

override fun compareTo(other: ActionData) = when (other) {
is InputKeyEvent -> keyCode.compareTo(other.keyCode)
else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -53,6 +70,11 @@ sealed class ActionData {
val soundDescription: String,
) : ActionData() {
override val id = ActionId.SOUND

override fun compareTo(other: ActionData) = when (other) {
is Sound -> soundUid.compareTo(other.soundUid)
else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -61,6 +83,17 @@ sealed class ActionData {
abstract val volumeStream: VolumeStream
abstract val showVolumeUi: Boolean

override fun compareTo(other: ActionData) = when (other) {
is Stream -> compareValuesBy(
this,
other,
{ it.id },
{ it.volumeStream },
)

else -> super.compareTo(other)
}

@Serializable
data class Increase(
override val showVolumeUi: Boolean,
Expand Down Expand Up @@ -108,6 +141,11 @@ sealed class ActionData {
val ringerMode: RingerMode,
) : Volume() {
override val id: ActionId = ActionId.CHANGE_RINGER_MODE

override fun compareTo(other: ActionData) = when (other) {
is SetRingerMode -> ringerMode.compareTo(other.ringerMode)
else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -130,6 +168,17 @@ sealed class ActionData {
sealed class Flashlight : ActionData() {
abstract val lens: CameraLens

override fun compareTo(other: ActionData) = when (other) {
is Flashlight -> compareValuesBy(
this,
other,
{ it.id },
{ it.lens },
)

else -> super.compareTo(other)
}

@Serializable
data class Toggle(override val lens: CameraLens) : Flashlight() {
override val id = ActionId.TOGGLE_FLASHLIGHT
Expand All @@ -152,6 +201,11 @@ sealed class ActionData {
val savedImeName: String,
) : ActionData() {
override val id = ActionId.SWITCH_KEYBOARD

override fun compareTo(other: ActionData) = when (other) {
is SwitchKeyboard -> savedImeName.compareTo(other.savedImeName)
else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -160,11 +214,21 @@ sealed class ActionData {
@Serializable
data class Toggle(val dndMode: DndMode) : DoNotDisturb() {
override val id: ActionId = ActionId.TOGGLE_DND_MODE

override fun compareTo(other: ActionData) = when (other) {
is Toggle -> dndMode.compareTo(other.dndMode)
else -> super.compareTo(other)
}
}

@Serializable
data class Enable(val dndMode: DndMode) : DoNotDisturb() {
override val id: ActionId = ActionId.ENABLE_DND_MODE

override fun compareTo(other: ActionData) = when (other) {
is Enable -> dndMode.compareTo(other.dndMode)
else -> super.compareTo(other)
}
}

@Serializable
Expand Down Expand Up @@ -210,13 +274,34 @@ sealed class ActionData {
val orientations: List<Orientation>,
) : Rotation() {
override val id = ActionId.CYCLE_ROTATIONS

override fun compareTo(other: ActionData) = when (other) {
// Compare orientations one by one until a difference is found otherwise compare the size
is CycleRotations -> orientations.zip(other.orientations)
.map { (a, b) -> a.compareTo(b) }
.firstOrNull { it != 0 }
?: orientations.size.compareTo(other.orientations.size)

else -> super.compareTo(other)
}
}
}

@Serializable
sealed class ControlMediaForApp : ActionData() {
abstract val packageName: String

override fun compareTo(other: ActionData) = when (other) {
is ControlMediaForApp -> compareValuesBy(
this,
other,
{ it.id },
{ it.packageName },
)

else -> super.compareTo(other)
}

@Serializable
data class Pause(override val packageName: String) : ControlMediaForApp() {
override val id = ActionId.PAUSE_MEDIA_PACKAGE
Expand Down Expand Up @@ -299,6 +384,11 @@ sealed class ActionData {
val extras: List<IntentExtraModel>,
) : ActionData() {
override val id = ActionId.INTENT

override fun compareTo(other: ActionData) = when (other) {
is Intent -> description.compareTo(other.description)
else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -308,6 +398,18 @@ sealed class ActionData {
val description: String?,
) : ActionData() {
override val id = ActionId.TAP_SCREEN

override fun compareTo(other: ActionData) = when (other) {
is TapScreen -> compareValuesBy(
this,
other,
{ it.description },
{ it.x },
{ it.y },
)

else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -321,6 +423,22 @@ sealed class ActionData {
val description: String?,
) : ActionData() {
override val id = ActionId.SWIPE_SCREEN

override fun compareTo(other: ActionData) = when (other) {
is SwipeScreen -> compareValuesBy(
this,
other,
{ it.description },
{ it.fingerCount },
{ it.xStart },
{ it.yStart },
{ it.xEnd },
{ it.yEnd },
{ it.duration },
)

else -> super.compareTo(other)
}
}

@Serializable
Expand All @@ -334,27 +452,58 @@ sealed class ActionData {
val description: String?,
) : ActionData() {
override val id = ActionId.PINCH_SCREEN

override fun compareTo(other: ActionData) = when (other) {
is PinchScreen -> compareValuesBy(
this,
other,
{ it.description },
{ it.pinchType },
{ it.fingerCount },
{ it.x },
{ it.y },
{ it.distance },
{ it.duration },
)

else -> super.compareTo(other)
}
}

@Serializable
data class PhoneCall(
val number: String,
) : ActionData() {
override val id = ActionId.PHONE_CALL

override fun compareTo(other: ActionData) = when (other) {
is PhoneCall -> number.compareTo(other.number)
else -> super.compareTo(other)
}
}

@Serializable
data class Url(
val url: String,
) : ActionData() {
override val id = ActionId.URL

override fun compareTo(other: ActionData) = when (other) {
is Url -> url.compareTo(other.url)
else -> super.compareTo(other)
}
}

@Serializable
data class Text(
val text: String,
) : ActionData() {
override val id = ActionId.TEXT

override fun compareTo(other: ActionData) = when (other) {
is Text -> text.compareTo(other.text)
else -> super.compareTo(other)
}
}

@Serializable
Expand Down
Loading