Skip to content

Commit

Permalink
refactor: replace sound mode types with availableSoundModes
Browse files Browse the repository at this point in the history
It's simpler and more flexible to just supply a list of allowed sound
modes rather than naming all possible configurations.
  • Loading branch information
Oppzippy committed Dec 28, 2024
1 parent 0cf420e commit f8de30f
Show file tree
Hide file tree
Showing 45 changed files with 539 additions and 582 deletions.
1 change: 0 additions & 1 deletion android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import com.oppzippy.openscq30.features.quickpresets.storage.FallbackQuickPreset
import com.oppzippy.openscq30.features.quickpresets.storage.QuickPreset
import com.oppzippy.openscq30.features.quickpresets.storage.QuickPresetRepository
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundMode
import com.oppzippy.openscq30.lib.wrapper.AvailableSoundModes
import com.oppzippy.openscq30.lib.wrapper.DeviceFeatures
import com.oppzippy.openscq30.lib.wrapper.FirmwareVersion
import com.oppzippy.openscq30.lib.wrapper.NoiseCancelingMode
import com.oppzippy.openscq30.lib.wrapper.NoiseCancelingModeType
import com.oppzippy.openscq30.lib.wrapper.PresetEqualizerProfile
import com.oppzippy.openscq30.lib.wrapper.SoundModeProfile
import com.oppzippy.openscq30.lib.wrapper.TransparencyMode
import com.oppzippy.openscq30.lib.wrapper.TransparencyModeType
import com.oppzippy.openscq30.ui.quickpresets.QuickPresetScreen
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
Expand Down Expand Up @@ -57,7 +55,21 @@ class DeviceSettingsQuickPresetsTest {
lateinit var customProfileDao: CustomProfileDao

private var deviceFeatures = DeviceFeatures(
soundMode = SoundModeProfile(NoiseCancelingModeType.Custom, TransparencyModeType.Custom),
availableSoundModes = AvailableSoundModes(
ambientSoundModes = listOf(
AmbientSoundMode.Normal,
AmbientSoundMode.Transparency,
AmbientSoundMode.NoiseCanceling,
),
transparencyModes = listOf(TransparencyMode.FullyTransparent, TransparencyMode.VocalMode),
noiseCancelingModes = listOf(
NoiseCancelingMode.Indoor,
NoiseCancelingMode.Outdoor,
NoiseCancelingMode.Transport,
NoiseCancelingMode.Custom,
),
customNoiseCanceling = true,
),
hasHearId = true,
numEqualizerChannels = 2,
numEqualizerBands = 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.performClick
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundMode
import com.oppzippy.openscq30.lib.wrapper.AmbientSoundModeCycle
import com.oppzippy.openscq30.lib.wrapper.AvailableSoundModes
import com.oppzippy.openscq30.lib.wrapper.NoiseCancelingMode
import com.oppzippy.openscq30.lib.wrapper.SoundModes
import com.oppzippy.openscq30.lib.wrapper.TransparencyMode
import com.oppzippy.openscq30.ui.soundmode.NoiseCancelingType
import com.oppzippy.openscq30.ui.soundmode.SoundModeSettings
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
Expand Down Expand Up @@ -119,8 +119,15 @@ class DeviceSettingsSoundModeTest {
0u,
),
onAmbientSoundModeChange = onAmbientSoundModeChange,
hasTransparencyModes = false,
noiseCancelingType = NoiseCancelingType.None,
availableSoundModes = AvailableSoundModes(
ambientSoundModes = listOf(
AmbientSoundMode.Normal,
AmbientSoundMode.Transparency,
),
transparencyModes = emptyList(),
noiseCancelingModes = emptyList(),
customNoiseCanceling = false,
),
ambientSoundModeCycle = null,
)
}
Expand All @@ -144,8 +151,15 @@ class DeviceSettingsSoundModeTest {
0u,
),
onTransparencyModeChange = onTransparencyModeChange,
hasTransparencyModes = true,
noiseCancelingType = NoiseCancelingType.None,
availableSoundModes = AvailableSoundModes(
ambientSoundModes = listOf(
AmbientSoundMode.Normal,
AmbientSoundMode.Transparency,
),
transparencyModes = listOf(TransparencyMode.FullyTransparent, TransparencyMode.VocalMode),
noiseCancelingModes = emptyList(),
customNoiseCanceling = false,
),
ambientSoundModeCycle = null,
)
}
Expand All @@ -169,8 +183,21 @@ class DeviceSettingsSoundModeTest {
0u,
),
onNoiseCancelingModeChange = onNoiseCancelingModeChange,
hasTransparencyModes = true,
noiseCancelingType = NoiseCancelingType.Custom,
availableSoundModes = AvailableSoundModes(
ambientSoundModes = listOf(
AmbientSoundMode.Normal,
AmbientSoundMode.Transparency,
AmbientSoundMode.NoiseCanceling,
),
transparencyModes = listOf(TransparencyMode.FullyTransparent, TransparencyMode.VocalMode),
noiseCancelingModes = listOf(
NoiseCancelingMode.Indoor,
NoiseCancelingMode.Outdoor,
NoiseCancelingMode.Transport,
NoiseCancelingMode.Custom,
),
customNoiseCanceling = true,
),
ambientSoundModeCycle = null,
)
}
Expand All @@ -194,8 +221,21 @@ class DeviceSettingsSoundModeTest {
0u,
),
onCustomNoiseCancelingChange = onCustomNoiseCancelingChange,
hasTransparencyModes = false,
noiseCancelingType = NoiseCancelingType.Custom,
availableSoundModes = AvailableSoundModes(
ambientSoundModes = listOf(
AmbientSoundMode.Normal,
AmbientSoundMode.Transparency,
AmbientSoundMode.NoiseCanceling,
),
transparencyModes = emptyList(),
noiseCancelingModes = listOf(
NoiseCancelingMode.Indoor,
NoiseCancelingMode.Outdoor,
NoiseCancelingMode.Transport,
NoiseCancelingMode.Custom,
),
customNoiseCanceling = true,
),
ambientSoundModeCycle = null,
)
}
Expand Down Expand Up @@ -224,8 +264,16 @@ class DeviceSettingsSoundModeTest {
TransparencyMode.VocalMode,
0u,
),
hasTransparencyModes = false,
noiseCancelingType = NoiseCancelingType.Normal,
availableSoundModes = AvailableSoundModes(
ambientSoundModes = listOf(
AmbientSoundMode.Normal,
AmbientSoundMode.Transparency,
AmbientSoundMode.NoiseCanceling,
),
transparencyModes = emptyList(),
noiseCancelingModes = emptyList(),
customNoiseCanceling = false,
),
ambientSoundModeCycle = cycle,
onAmbientSoundModeCycleChange = { cycleFlow.value = it },
)
Expand All @@ -251,8 +299,21 @@ class DeviceSettingsSoundModeTest {
TransparencyMode.VocalMode,
0u,
),
hasTransparencyModes = true,
noiseCancelingType = NoiseCancelingType.Custom,
availableSoundModes = AvailableSoundModes(
ambientSoundModes = listOf(
AmbientSoundMode.Normal,
AmbientSoundMode.Transparency,
AmbientSoundMode.NoiseCanceling,
),
transparencyModes = listOf(TransparencyMode.FullyTransparent, TransparencyMode.VocalMode),
noiseCancelingModes = listOf(
NoiseCancelingMode.Indoor,
NoiseCancelingMode.Outdoor,
NoiseCancelingMode.Transport,
NoiseCancelingMode.Custom,
),
customNoiseCanceling = true,
),
ambientSoundModeCycle = null,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.oppzippy.openscq30.lib.wrapper.SingleBattery

fun DeviceState.Companion.empty(): DeviceState = DeviceState(
deviceFeatures = DeviceFeatures(
soundMode = null,
availableSoundModes = null,
hasHearId = false,
numEqualizerChannels = 0,
numEqualizerBands = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.oppzippy.openscq30.lib.extensions.resources

import com.oppzippy.openscq30.R
import com.oppzippy.openscq30.lib.wrapper.TransparencyMode

fun TransparencyMode.toStringResource(): Int = when (this) {
TransparencyMode.VocalMode -> R.string.vocal_mode
TransparencyMode.FullyTransparent -> R.string.fully_transparent
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.oppzippy.openscq30.lib.wrapper

import com.oppzippy.openscq30.lib.protobuf.AvailableSoundModes as ProtobufAvailableSoundModes
import com.oppzippy.openscq30.lib.protobuf.DeviceFeatures as ProtobufDeviceFeatures
import com.oppzippy.openscq30.lib.protobuf.NoiseCancelingModeType as ProtobufNoiseCancelingModeType
import com.oppzippy.openscq30.lib.protobuf.SoundModeProfile as ProtobufSoundModeProfile
import com.oppzippy.openscq30.lib.protobuf.TransparencyModeType as ProtobufTransparencyModeType
import com.oppzippy.openscq30.lib.protobuf.availableSoundModes
import com.oppzippy.openscq30.lib.protobuf.availableSoundModesOrNull
import com.oppzippy.openscq30.lib.protobuf.deviceFeatures
import com.oppzippy.openscq30.lib.protobuf.dynamicRangeCompressionMinFirmwareVersionOrNull
import com.oppzippy.openscq30.lib.protobuf.soundModeOrNull
import com.oppzippy.openscq30.lib.protobuf.soundModeProfile

data class DeviceFeatures(
val soundMode: SoundModeProfile?,
val availableSoundModes: AvailableSoundModes?,
val hasHearId: Boolean,
val numEqualizerChannels: Int,
val numEqualizerBands: Int,
Expand All @@ -22,7 +22,7 @@ data class DeviceFeatures(
val dynamicRangeCompressionMinFirmwareVersion: FirmwareVersion?,
) {
fun toProtobuf(): ProtobufDeviceFeatures = deviceFeatures {
this@DeviceFeatures.soundMode?.let { soundMode = it.toProtobuf() }
this@DeviceFeatures.availableSoundModes?.let { availableSoundModes = it.toProtobuf() }
hasHearId = this@DeviceFeatures.hasHearId
numEqualizerChannels = this@DeviceFeatures.numEqualizerChannels
numEqualizerBands = this@DeviceFeatures.numEqualizerBands
Expand All @@ -38,7 +38,7 @@ data class DeviceFeatures(
}

fun ProtobufDeviceFeatures.toKotlin(): DeviceFeatures = DeviceFeatures(
soundMode = soundModeOrNull?.toKotlin(),
availableSoundModes = availableSoundModesOrNull?.toKotlin(),
hasHearId = hasHearId,
numEqualizerChannels = numEqualizerChannels,
numEqualizerBands = numEqualizerBands,
Expand All @@ -50,19 +50,25 @@ fun ProtobufDeviceFeatures.toKotlin(): DeviceFeatures = DeviceFeatures(
dynamicRangeCompressionMinFirmwareVersion = dynamicRangeCompressionMinFirmwareVersionOrNull?.toKotlin(),
)

data class SoundModeProfile(
val noiseCancelingModeType: NoiseCancelingModeType,
val transparencyModeType: TransparencyModeType,
data class AvailableSoundModes(
val ambientSoundModes: List<AmbientSoundMode>,
val transparencyModes: List<TransparencyMode>,
val noiseCancelingModes: List<NoiseCancelingMode>,
val customNoiseCanceling: Boolean,
) {
fun toProtobuf(): ProtobufSoundModeProfile = soundModeProfile {
noiseCancelingModeType = this@SoundModeProfile.noiseCancelingModeType.toProtobuf()
transparencyModeType = this@SoundModeProfile.transparencyModeType.toProtobuf()
fun toProtobuf(): ProtobufAvailableSoundModes = availableSoundModes {
ambientSoundModes.addAll(this@AvailableSoundModes.ambientSoundModes.map { it.toProtobuf() })
transparencyModes.addAll(this@AvailableSoundModes.transparencyModes.map { it.toProtobuf() })
noiseCancelingModes.addAll(this@AvailableSoundModes.noiseCancelingModes.map { it.toProtobuf() })
customNoiseCanceling = this@AvailableSoundModes.customNoiseCanceling
}
}

fun ProtobufSoundModeProfile.toKotlin(): SoundModeProfile = SoundModeProfile(
noiseCancelingModeType = noiseCancelingModeType.toKotlin(),
transparencyModeType = transparencyModeType.toKotlin(),
fun ProtobufAvailableSoundModes.toKotlin(): AvailableSoundModes = AvailableSoundModes(
ambientSoundModes = ambientSoundModesList.map { it.toKotlin() },
transparencyModes = transparencyModesList.map { it.toKotlin() },
noiseCancelingModes = noiseCancelingModesList.map { it.toKotlin() },
customNoiseCanceling = customNoiseCanceling,
)

enum class NoiseCancelingModeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ 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.NoiseCancelingModeType
import com.oppzippy.openscq30.lib.wrapper.NoiseCancelingModeTypeTwo
import com.oppzippy.openscq30.lib.wrapper.TransparencyMode
import com.oppzippy.openscq30.lib.wrapper.TransparencyModeType
import com.oppzippy.openscq30.ui.buttonactions.ButtonActionSelection
import com.oppzippy.openscq30.ui.deviceinfo.DeviceInfoScreen
import com.oppzippy.openscq30.ui.devicesettings.Screen
Expand All @@ -42,7 +40,6 @@ import com.oppzippy.openscq30.ui.equalizer.EqualizerSettings
import com.oppzippy.openscq30.ui.importexport.ImportExportScreen
import com.oppzippy.openscq30.ui.importexport.ImportExportViewModel
import com.oppzippy.openscq30.ui.quickpresets.QuickPresetScreen
import com.oppzippy.openscq30.ui.soundmode.NoiseCancelingType
import com.oppzippy.openscq30.ui.soundmode.SoundModeSettings
import com.oppzippy.openscq30.ui.soundmodestypetwo.SoundModeTypeTwoSettings

Expand All @@ -69,7 +66,7 @@ fun DeviceSettings(
) {
val navController = rememberNavController()
val listedScreens = ArrayList<ScreenInfo>()
if (uiState.deviceState.deviceFeatures.soundMode != null) {
if (uiState.deviceState.deviceFeatures.availableSoundModes != null) {
listedScreens.add(Screen.SoundModes.screenInfo)
}
if (uiState.deviceState.soundModesTypeTwo != null) {
Expand Down Expand Up @@ -154,17 +151,12 @@ fun DeviceSettings(
}
uiState.deviceState.soundModes?.let { soundModes ->
composable<Screen.SoundModes> {
val soundModeProfile =
uiState.deviceState.deviceFeatures.soundMode ?: return@composable
val availableSoundModes =
uiState.deviceState.deviceFeatures.availableSoundModes ?: return@composable
SoundModeSettings(
soundModes = soundModes,
ambientSoundModeCycle = uiState.deviceState.ambientSoundModeCycle,
hasTransparencyModes = soundModeProfile.transparencyModeType == TransparencyModeType.Custom,
noiseCancelingType = when (soundModeProfile.noiseCancelingModeType) {
NoiseCancelingModeType.None -> NoiseCancelingType.None
NoiseCancelingModeType.Basic -> NoiseCancelingType.Normal
NoiseCancelingModeType.Custom -> NoiseCancelingType.Custom
},
availableSoundModes = availableSoundModes,
onAmbientSoundModeChange = onAmbientSoundModeChange,
onTransparencyModeChange = onTransparencyModeChange,
onNoiseCancelingModeChange = onNoiseCancelingModeChange,
Expand Down
Loading

0 comments on commit f8de30f

Please sign in to comment.