Skip to content

Commit

Permalink
refactor: rename button model to multi button configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppzippy committed Dec 26, 2024
1 parent d1ef289 commit 5b2b48c
Show file tree
Hide file tree
Showing 79 changed files with 620 additions and 565 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.oppzippy.openscq30.lib.wrapper.ButtonAction
import com.oppzippy.openscq30.lib.wrapper.ButtonState
import com.oppzippy.openscq30.lib.wrapper.CustomButtonActions
import com.oppzippy.openscq30.lib.wrapper.ButtonConfiguration
import com.oppzippy.openscq30.lib.wrapper.MultiButtonConfiguration
import com.oppzippy.openscq30.ui.buttonactions.ButtonActionSelection
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
Expand All @@ -29,17 +29,17 @@ class DeviceSettingsButtonActionsTest {

@Test
fun itWorks() {
var actions = CustomButtonActions(
leftSingleClick = ButtonState(true, ButtonAction.NextSong),
leftDoubleClick = ButtonState(false, ButtonAction.NextSong),
leftLongPress = ButtonState(false, ButtonAction.NextSong),
rightSingleClick = ButtonState(false, ButtonAction.NextSong),
rightDoubleClick = ButtonState(false, ButtonAction.NextSong),
rightLongPress = ButtonState(false, ButtonAction.NextSong),
var actions = MultiButtonConfiguration(
leftSingleClick = ButtonConfiguration(true, ButtonAction.NextSong),
leftDoubleClick = ButtonConfiguration(false, ButtonAction.NextSong),
leftLongPress = ButtonConfiguration(false, ButtonAction.NextSong),
rightSingleClick = ButtonConfiguration(false, ButtonAction.NextSong),
rightDoubleClick = ButtonConfiguration(false, ButtonAction.NextSong),
rightLongPress = ButtonConfiguration(false, ButtonAction.NextSong),
)
composeRule.setContent {
ButtonActionSelection(
buttonActions = actions,
buttonConfiguration = actions,
onChange = { actions = it },
)
}
Expand All @@ -49,13 +49,13 @@ class DeviceSettingsButtonActionsTest {
composeRule.onNodeWithText(composeRule.activity.getString(ButtonAction.PreviousSong.toStringResource()))
.performClick()
Assert.assertEquals(
CustomButtonActions(
leftSingleClick = ButtonState(true, ButtonAction.PreviousSong),
leftDoubleClick = ButtonState(false, ButtonAction.NextSong),
leftLongPress = ButtonState(false, ButtonAction.NextSong),
rightSingleClick = ButtonState(false, ButtonAction.NextSong),
rightDoubleClick = ButtonState(false, ButtonAction.NextSong),
rightLongPress = ButtonState(false, ButtonAction.NextSong),
MultiButtonConfiguration(
leftSingleClick = ButtonConfiguration(true, ButtonAction.PreviousSong),
leftDoubleClick = ButtonConfiguration(false, ButtonAction.NextSong),
leftLongPress = ButtonConfiguration(false, ButtonAction.NextSong),
rightSingleClick = ButtonConfiguration(false, ButtonAction.NextSong),
rightDoubleClick = ButtonConfiguration(false, ButtonAction.NextSong),
rightLongPress = ButtonConfiguration(false, ButtonAction.NextSong),
),
actions,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DeviceSettingsQuickPresetsTest {
numEqualizerChannels = 2,
numEqualizerBands = 8,
hasDynamicRangeCompression = true,
hasCustomButtonModel = true,
hasButtonConfiguration = true,
hasWearDetection = true,
hasTouchTone = true,
hasAutoPowerOff = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fun DeviceState.Companion.empty(): DeviceState = DeviceState(
numEqualizerChannels = 0,
numEqualizerBands = 0,
hasDynamicRangeCompression = false,
hasCustomButtonModel = false,
hasButtonConfiguration = false,
hasWearDetection = false,
hasTouchTone = false,
hasAutoPowerOff = false,
Expand All @@ -28,7 +28,7 @@ fun DeviceState.Companion.empty(): DeviceState = DeviceState(
battery = Battery.Single(SingleBattery(false, 0u)),
ageRange = null,
gender = null,
customButtonModel = null,
buttonConfiguration = null,
hearId = null,
ambientSoundModeCycle = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.annotation.SuppressLint
import com.oppzippy.openscq30.lib.bindings.NativeDeviceStateObserver
import com.oppzippy.openscq30.lib.bindings.NativeSoundcoreDevice
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundModeCycle
import com.oppzippy.openscq30.lib.wrapper.CustomButtonActions
import com.oppzippy.openscq30.lib.wrapper.DeviceState
import com.oppzippy.openscq30.lib.wrapper.EqualizerConfiguration
import com.oppzippy.openscq30.lib.wrapper.HearId
import com.oppzippy.openscq30.lib.wrapper.MultiButtonConfiguration
import com.oppzippy.openscq30.lib.wrapper.SoundModes
import com.oppzippy.openscq30.lib.wrapper.SoundModesTypeTwo
import java.util.UUID
Expand Down Expand Up @@ -70,7 +70,7 @@ class SoundcoreDevice(
nativeDevice.setHearId(hearId)
}

suspend fun setCustomButtonModel(customButtonModel: CustomButtonActions) {
nativeDevice.setCustomButtonModel(customButtonModel)
suspend fun setMultiButtonConfiguration(buttonConfiguration: MultiButtonConfiguration) {
nativeDevice.setMultiButtonConfiguration(buttonConfiguration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.util.Log
import com.oppzippy.openscq30.features.soundcoredevice.api.SoundcoreDeviceConnector
import com.oppzippy.openscq30.features.soundcoredevice.impl.SoundcoreDevice
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundModeCycle
import com.oppzippy.openscq30.lib.wrapper.CustomButtonActions
import com.oppzippy.openscq30.lib.wrapper.EqualizerConfiguration
import com.oppzippy.openscq30.lib.wrapper.MultiButtonConfiguration
import com.oppzippy.openscq30.lib.wrapper.SoundModes
import com.oppzippy.openscq30.lib.wrapper.SoundModesTypeTwo
import java.lang.Exception
Expand Down Expand Up @@ -136,9 +136,9 @@ class DeviceConnectionManager @Inject constructor(
}
}

fun setCustomButtonModel(buttonModel: CustomButtonActions) {
fun setMultiButtonConfiguration(buttonConfiguration: MultiButtonConfiguration) {
scope.launch {
device?.setCustomButtonModel(buttonModel)
device?.setMultiButtonConfiguration(buttonConfiguration)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class DeviceFeatures(
val numEqualizerChannels: Int,
val numEqualizerBands: Int,
val hasDynamicRangeCompression: Boolean,
val hasCustomButtonModel: Boolean,
val hasButtonConfiguration: Boolean,
val hasWearDetection: Boolean,
val hasTouchTone: Boolean,
val hasAutoPowerOff: Boolean,
Expand All @@ -27,7 +27,7 @@ data class DeviceFeatures(
numEqualizerChannels = this@DeviceFeatures.numEqualizerChannels
numEqualizerBands = this@DeviceFeatures.numEqualizerBands
hasDynamicRangeCompression = this@DeviceFeatures.hasDynamicRangeCompression
hasCustomButtonModel = this@DeviceFeatures.hasCustomButtonModel
hasButtonConfiguration = this@DeviceFeatures.hasButtonConfiguration
hasWearDetection = this@DeviceFeatures.hasWearDetection
hasTouchTone = this@DeviceFeatures.hasTouchTone
hasAutoPowerOff = this@DeviceFeatures.hasAutoPowerOff
Expand All @@ -43,7 +43,7 @@ fun ProtobufDeviceFeatures.toKotlin(): DeviceFeatures = DeviceFeatures(
numEqualizerChannels = numEqualizerChannels,
numEqualizerBands = numEqualizerBands,
hasDynamicRangeCompression = hasDynamicRangeCompression,
hasCustomButtonModel = hasCustomButtonModel,
hasButtonConfiguration = hasButtonConfiguration,
hasWearDetection = hasWearDetection,
hasTouchTone = hasTouchTone,
hasAutoPowerOff = hasAutoPowerOff,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.oppzippy.openscq30.lib.wrapper

import com.oppzippy.openscq30.lib.protobuf.ambientSoundModeCycleOrNull
import com.oppzippy.openscq30.lib.protobuf.customButtonActionsOrNull
import com.oppzippy.openscq30.lib.protobuf.buttonConfigurationOrNull
import com.oppzippy.openscq30.lib.protobuf.deviceState
import com.oppzippy.openscq30.lib.protobuf.firmwareVersionOrNull
import com.oppzippy.openscq30.lib.protobuf.hearIdOrNull
Expand All @@ -17,7 +17,7 @@ data class DeviceState(
val ageRange: UByte?,
val gender: UByte?,
val hearId: HearId?,
val customButtonModel: CustomButtonActions?,
val buttonConfiguration: MultiButtonConfiguration?,
val firmwareVersion: FirmwareVersion?,
val serialNumber: String?,
val ambientSoundModeCycle: AmbientSoundModeCycle?,
Expand Down Expand Up @@ -45,7 +45,7 @@ data class DeviceState(
this@DeviceState.ageRange?.let { ageRange = it.toInt() }
this@DeviceState.gender?.let { gender = it.toInt() }
this@DeviceState.hearId?.let { hearId = it.toProtobuf() }
this@DeviceState.customButtonModel?.let { customButtonActions = it.toProtobuf() }
this@DeviceState.buttonConfiguration?.let { buttonConfiguration = it.toProtobuf() }
this@DeviceState.firmwareVersion?.let { firmwareVersion = it.toProtobuf() }
this@DeviceState.serialNumber?.let { serialNumber = it }
this@DeviceState.ambientSoundModeCycle?.let { ambientSoundModeCycle = it.toProtobuf() }
Expand All @@ -61,7 +61,7 @@ fun com.oppzippy.openscq30.lib.protobuf.DeviceState.toKotlin(): DeviceState = De
ageRange = if (hasAgeRange()) ageRange.toUByte() else null,
gender = if (hasGender()) gender.toUByte() else null,
hearId = hearIdOrNull?.toKotlin(),
customButtonModel = customButtonActionsOrNull?.toKotlin(),
buttonConfiguration = buttonConfigurationOrNull?.toKotlin(),
firmwareVersion = firmwareVersionOrNull?.toKotlin(),
serialNumber = if (hasSerialNumber()) serialNumber else null,
ambientSoundModeCycle = ambientSoundModeCycleOrNull?.toKotlin(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
package com.oppzippy.openscq30.lib.wrapper

import com.oppzippy.openscq30.R
import com.oppzippy.openscq30.lib.protobuf.buttonState
import com.oppzippy.openscq30.lib.protobuf.customButtonActions
import com.oppzippy.openscq30.lib.protobuf.buttonConfiguration
import com.oppzippy.openscq30.lib.protobuf.multiButtonConfiguration

data class CustomButtonActions(
val leftSingleClick: ButtonState,
val leftDoubleClick: ButtonState,
val leftLongPress: ButtonState,
val rightSingleClick: ButtonState,
val rightDoubleClick: ButtonState,
val rightLongPress: ButtonState,
data class MultiButtonConfiguration(
val leftSingleClick: ButtonConfiguration,
val leftDoubleClick: ButtonConfiguration,
val leftLongPress: ButtonConfiguration,
val rightSingleClick: ButtonConfiguration,
val rightDoubleClick: ButtonConfiguration,
val rightLongPress: ButtonConfiguration,
) {
fun toProtobuf(): com.oppzippy.openscq30.lib.protobuf.CustomButtonActions = customButtonActions {
leftSingleClick = this@CustomButtonActions.leftSingleClick.toProtobuf()
leftDoubleClick = this@CustomButtonActions.leftDoubleClick.toProtobuf()
leftLongPress = this@CustomButtonActions.leftLongPress.toProtobuf()
rightSingleClick = this@CustomButtonActions.rightSingleClick.toProtobuf()
rightDoubleClick = this@CustomButtonActions.rightDoubleClick.toProtobuf()
rightLongPress = this@CustomButtonActions.rightLongPress.toProtobuf()
fun toProtobuf(): com.oppzippy.openscq30.lib.protobuf.MultiButtonConfiguration = multiButtonConfiguration {
leftSingleClick = this@MultiButtonConfiguration.leftSingleClick.toProtobuf()
leftDoubleClick = this@MultiButtonConfiguration.leftDoubleClick.toProtobuf()
leftLongPress = this@MultiButtonConfiguration.leftLongPress.toProtobuf()
rightSingleClick = this@MultiButtonConfiguration.rightSingleClick.toProtobuf()
rightDoubleClick = this@MultiButtonConfiguration.rightDoubleClick.toProtobuf()
rightLongPress = this@MultiButtonConfiguration.rightLongPress.toProtobuf()
}
}

fun com.oppzippy.openscq30.lib.protobuf.CustomButtonActions.toKotlin(): CustomButtonActions = CustomButtonActions(
leftSingleClick = leftSingleClick.toKotlin(),
leftDoubleClick = leftDoubleClick.toKotlin(),
leftLongPress = leftLongPress.toKotlin(),
rightSingleClick = rightSingleClick.toKotlin(),
rightDoubleClick = rightDoubleClick.toKotlin(),
rightLongPress = rightLongPress.toKotlin(),
)
fun com.oppzippy.openscq30.lib.protobuf.MultiButtonConfiguration.toKotlin(): MultiButtonConfiguration =
MultiButtonConfiguration(
leftSingleClick = leftSingleClick.toKotlin(),
leftDoubleClick = leftDoubleClick.toKotlin(),
leftLongPress = leftLongPress.toKotlin(),
rightSingleClick = rightSingleClick.toKotlin(),
rightDoubleClick = rightDoubleClick.toKotlin(),
rightLongPress = rightLongPress.toKotlin(),
)

data class ButtonState(val isEnabled: Boolean, val action: ButtonAction) {
fun toProtobuf(): com.oppzippy.openscq30.lib.protobuf.ButtonState = buttonState {
isEnabled = this@ButtonState.isEnabled
action = this@ButtonState.action.toProtobuf()
data class ButtonConfiguration(val isEnabled: Boolean, val action: ButtonAction) {
fun toProtobuf(): com.oppzippy.openscq30.lib.protobuf.ButtonConfiguration = buttonConfiguration {
isEnabled = this@ButtonConfiguration.isEnabled
action = this@ButtonConfiguration.action.toProtobuf()
}

fun actionOrNull(): ButtonAction? = if (isEnabled) {
Expand All @@ -44,7 +45,8 @@ data class ButtonState(val isEnabled: Boolean, val action: ButtonAction) {
}
}

fun com.oppzippy.openscq30.lib.protobuf.ButtonState.toKotlin(): ButtonState = ButtonState(isEnabled, action.toKotlin())
fun com.oppzippy.openscq30.lib.protobuf.ButtonConfiguration.toKotlin(): ButtonConfiguration =
ButtonConfiguration(isEnabled, action.toKotlin())

enum class ButtonAction {
VolumeUp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import android.os.IBinder
import com.oppzippy.openscq30.features.soundcoredevice.service.ConnectionStatus
import com.oppzippy.openscq30.features.soundcoredevice.service.DeviceService
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundModeCycle
import com.oppzippy.openscq30.lib.wrapper.CustomButtonActions
import com.oppzippy.openscq30.lib.wrapper.EqualizerConfiguration
import com.oppzippy.openscq30.lib.wrapper.MultiButtonConfiguration
import com.oppzippy.openscq30.lib.wrapper.SoundModes
import com.oppzippy.openscq30.lib.wrapper.SoundModesTypeTwo
import com.oppzippy.openscq30.ui.devicesettings.models.UiDeviceState
Expand Down Expand Up @@ -87,7 +87,7 @@ class DeviceServiceConnection(private val unbind: () -> Unit) : ServiceConnectio
service?.get()?.connectionManager?.setEqualizerConfiguration(equalizerConfiguration)
}

fun setCustomButtonModel(buttonModel: CustomButtonActions) {
service?.get()?.connectionManager?.setCustomButtonModel(buttonModel)
fun setMultiButtonConfiguration(buttonConfiguration: MultiButtonConfiguration) {
service?.get()?.connectionManager?.setMultiButtonConfiguration(buttonConfiguration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import com.oppzippy.openscq30.features.soundcoredevice.service.DeviceService
import com.oppzippy.openscq30.lib.wrapper.AdaptiveNoiseCanceling
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundMode
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundModeCycle
import com.oppzippy.openscq30.lib.wrapper.CustomButtonActions
import com.oppzippy.openscq30.lib.wrapper.EqualizerConfiguration
import com.oppzippy.openscq30.lib.wrapper.ManualNoiseCanceling
import com.oppzippy.openscq30.lib.wrapper.MultiButtonConfiguration
import com.oppzippy.openscq30.lib.wrapper.NoiseCancelingMode
import com.oppzippy.openscq30.lib.wrapper.NoiseCancelingModeTypeTwo
import com.oppzippy.openscq30.lib.wrapper.SoundModes
Expand Down Expand Up @@ -142,7 +142,7 @@ class DeviceSettingsViewModel @Inject constructor(
deviceServiceConnection.setAmbientSoundModeCycle(cycle)
}

fun setCustomButtonModel(buttonModel: CustomButtonActions) {
deviceServiceConnection.setCustomButtonModel(buttonModel)
fun setMultiButtonConfiguration(buttonConfigu: MultiButtonConfiguration) {
deviceServiceConnection.setMultiButtonConfiguration(buttonConfigu)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ fun OpenSCQ30Root(viewModel: DeviceSettingsViewModel = hiltViewModel()) {
viewModel.setEqualizerConfiguration(it)
}
},
onCustomButtonModelChange = {
onButtonConfigurationChange = {
withErrorToast(context) {
viewModel.setCustomButtonModel(it)
viewModel.setMultiButtonConfiguration(it)
}
},
)
Expand Down
Loading

0 comments on commit 5b2b48c

Please sign in to comment.