Skip to content

Commit

Permalink
feat: support FiiO KA13
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy-Geenexus committed Oct 26, 2024
1 parent bba58df commit b81b684
Show file tree
Hide file tree
Showing 35 changed files with 1,303 additions and 83 deletions.
3 changes: 3 additions & 0 deletions app/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
<ID>CyclomaticComplexMethod:ControlScreen.kt$@Composable fun ControlScreen( windowSizeClass: WindowSizeClass, viewModel: ControlViewModel, onNavigateUp: () -&gt; Unit )</ID>
<ID>EmptyFunctionBlock:ItemAudio.kt$&lt;no name provided&gt;${ }</ID>
<ID>EmptyFunctionBlock:ItemDisplay.kt$&lt;no name provided&gt;${ }</ID>
<ID>ForbiddenComment:FiioKa13UsbRepository.kt$FiioKa13UsbRepository$// FIXME: Reading current state is not working properly (firmware issue?)</ID>
<ID>ForbiddenComment:FiioKa13UsbRepository.kt$FiioKa13UsbRepository$// TODO: Is it actually working?</ID>
<ID>LargeClass:FiioKa5UsbRepository.kt$FiioKa5UsbRepository : UsbRepository</ID>
<ID>LongMethod:ControlScreen.kt$@Composable fun ControlScreen( modifier: Modifier = Modifier, windowSizeClass: WindowSizeClass = WindowSizeClass.calculateFromSize(DpSize.Zero), scrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(), profileListState: LazyStaggeredGridState = rememberLazyStaggeredGridState(), snackBarHostState: SnackbarHostState = remember { SnackbarHostState() }, profiles: LazyPagingItems&lt;Profile&gt; = UnsupportedUsbDongle.profileFlow().collectAsLazyPagingItems(), usbDongle: UsbDongle = UnsupportedUsbDongle, isLoading: Boolean = false, onRefresh: () -&gt; Unit = {}, onReset: () -&gt; Unit = {}, onProfileShortcutAdd: (Profile) -&gt; Unit = {}, onProfileShortcutRemove: (Profile) -&gt; Unit = {}, onProfileDelete: (Profile) -&gt; Unit = { _ -&gt; }, onProfileApply: (Profile) -&gt; Unit = { _ -&gt; }, onProfileExport: (String) -&gt; Unit = { _ -&gt; }, onChannelBalanceSelected: (Int) -&gt; Unit = { _ -&gt; }, onDacModeSelected: (Byte) -&gt; Unit = { _ -&gt; }, onDisplayBrightnessSelected: (Int) -&gt; Unit = { _ -&gt; }, onDisplayTimeoutSelected: (Int) -&gt; Unit = { _ -&gt; }, onDisplayInvertChange: (Boolean) -&gt; Unit = { _ -&gt; }, onFilterSelected: (Byte) -&gt; Unit = { _ -&gt; }, onGainSelected: (Byte) -&gt; Unit = { _ -&gt; }, onHardwareMuteEnabledSelected: (Boolean) -&gt; Unit = { _ -&gt; }, onHidModeSelected: (Byte) -&gt; Unit = { _ -&gt; }, onIndicatorStateSelected: (Byte) -&gt; Unit = { _ -&gt; }, onSpdifOutEnabledSelected: (Boolean) -&gt; Unit = { _ -&gt; }, onVolumeLevelSelected: (Int) -&gt; Unit = { _ -&gt; }, onVolumeModeSelected: (Byte) -&gt; Unit = { _ -&gt; } )</ID>
<ID>LongMethod:ControlScreen.kt$@Composable fun ControlScreen( windowSizeClass: WindowSizeClass, viewModel: ControlViewModel, onNavigateUp: () -&gt; Unit )</ID>
<ID>LongMethod:FiioKa13UsbRepository.kt$FiioKa13UsbRepository$suspend fun setVolumeLevel(fiioKa13: FiioKa13, volumeLevel: VolumeLevel): Result&lt;FiioKa13&gt;</ID>
<ID>LongMethod:FiioKa5Items.kt$@Composable fun FiioKa5Items( modifier: Modifier = Modifier, fiioKa5: FiioKa5 = FiioKa5(), onChannelBalanceSelected: (Int) -&gt; Unit = {}, onVolumeLevelSelected: (Int) -&gt; Unit = {}, onVolumeModeSelected: (Byte) -&gt; Unit = {}, onDisplayBrightnessSelected: (Int) -&gt; Unit = {}, onDisplayTimeoutSelected: (Int) -&gt; Unit = {}, onDisplayInvertSelected: (Boolean) -&gt; Unit = {}, onGainSelected: (Byte) -&gt; Unit = {}, onFilterSelected: (Byte) -&gt; Unit = {}, onSpdifOutSelected: (Boolean) -&gt; Unit = {}, onHardwareMuteSelected: (Boolean) -&gt; Unit = {}, onDacModeSelected: (Byte) -&gt; Unit = {}, onHidModeSelected: (Byte) -&gt; Unit = {} )</ID>
<ID>LongMethod:FiioKa5UsbRepository.kt$FiioKa5UsbRepository$suspend fun getCurrentState(usbDongle: FiioKa5): Result&lt;FiioKa5&gt;</ID>
<ID>LongMethod:FiioKa5UsbRepository.kt$FiioKa5UsbRepository$suspend fun setAll( fiioKa5: FiioKa5, channelBalance: ChannelBalance, dacMode: DacMode, displayBrightness: DisplayBrightness, displayInvert: DisplayInvert, displayTimeout: DisplayTimeout, filter: Filter, gain: Gain, hardwareMute: HardwareMute, hidMode: HidMode, spdifOut: SpdifOut, volumeLevel: VolumeLevel, volumeMode: VolumeMode ): Result&lt;FiioKa5&gt;</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.lifecycle.ViewModel
import androidx.paging.Pager
import androidx.paging.PagingConfig
import dagger.hilt.android.lifecycle.HiltViewModel
import io.github.tommygeenexus.usbdonglecontrol.core.db.Profile
import io.github.tommygeenexus.usbdonglecontrol.control.data.ProfileRepository
import io.github.tommygeenexus.usbdonglecontrol.control.domain.GetCurrentStateUseCase
import io.github.tommygeenexus.usbdonglecontrol.control.domain.GetVolumeLevelUseCase
Expand All @@ -44,6 +43,7 @@ import io.github.tommygeenexus.usbdonglecontrol.control.domain.SetSpdifOutEnable
import io.github.tommygeenexus.usbdonglecontrol.control.domain.SetVolumeLevelUseCase
import io.github.tommygeenexus.usbdonglecontrol.control.domain.SetVolumeModeUseCase
import io.github.tommygeenexus.usbdonglecontrol.core.data.UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.core.db.Profile
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UnsupportedUsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.volume.HardwareVolumeControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ package io.github.tommygeenexus.usbdonglecontrol.control.domain

import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UnsupportedUsbDongleException
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.FiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.FiioKa5
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.MoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka13.data.FiioKa13UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka5.data.FiioKa5UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.moondrop.dawn.data.MoondropDawnUsbRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetCurrentStateUseCase @Inject constructor(
private val fiioKa13UsbRepository: FiioKa13UsbRepository,
private val fiioKa5UsbRepository: FiioKa5UsbRepository,
private val moondropDawnUsbRepository: MoondropDawnUsbRepository
) {

suspend operator fun invoke(usbDongle: UsbDongle): Result<UsbDongle> = when (usbDongle) {
is FiioKa13 -> {
fiioKa13UsbRepository.getCurrentState(usbDongle)
}
is FiioKa5 -> {
fiioKa5UsbRepository.getCurrentState(usbDongle)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ package io.github.tommygeenexus.usbdonglecontrol.control.domain

import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UnsupportedUsbDongleException
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.FiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.FiioKa5
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.MoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka13.data.FiioKa13UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka5.data.FiioKa5UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.moondrop.dawn.data.MoondropDawnUsbRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetVolumeLevelUseCase @Inject constructor(
private val fiioKa13UsbRepository: FiioKa13UsbRepository,
private val fiioKa5UsbRepository: FiioKa5UsbRepository,
private val moondropDawnUsbRepository: MoondropDawnUsbRepository
) {

suspend operator fun invoke(usbDongle: UsbDongle): Result<UsbDongle> = when (usbDongle) {
is FiioKa13 -> {
fiioKa13UsbRepository.getCurrentState(usbDongle)
}
is FiioKa5 -> {
fiioKa5UsbRepository.getVolumeLevelAndMode(usbDongle)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,42 @@ package io.github.tommygeenexus.usbdonglecontrol.control.domain

import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UnsupportedUsbDongleException
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.FiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.feature.Filter as FilterFiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.FiioKa5
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.Filter
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.Filter as FilterFiioKa5
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.MoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka13.data.FiioKa13UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka5.data.FiioKa5UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.moondrop.dawn.data.MoondropDawnUsbRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SetDacFilterUseCase @Inject constructor(
private val fiioKa13UsbRepository: FiioKa13UsbRepository,
private val fiioKa5UsbRepository: FiioKa5UsbRepository,
private val moondropDawnUsbRepository: MoondropDawnUsbRepository
) {

suspend operator fun invoke(usbDongle: UsbDongle, id: Byte): Result<UsbDongle> =
when (usbDongle) {
is FiioKa13 -> {
fiioKa13UsbRepository.setFilter(
fiioKa13 = usbDongle,
filter = FilterFiioKa13.findByIdOrDefault(id)
)
}
is FiioKa5 -> {
fiioKa5UsbRepository.setFilter(
fiioKa5 = usbDongle,
filter = Filter.findByIdOrDefault(id)
filter = FilterFiioKa5.findByIdOrDefault(id)
)
}
is MoondropDawn -> {
moondropDawnUsbRepository.setFilter(
moondropDawn = usbDongle,
filter = Filter.findByIdOrDefault(id)
filter = FilterFiioKa5.findByIdOrDefault(id)
)
}
else -> Result.failure(UnsupportedUsbDongleException())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,33 @@ package io.github.tommygeenexus.usbdonglecontrol.control.domain

import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UnsupportedUsbDongleException
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.FiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.feature.IndicatorState as IndicatorStateFiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.MoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.feature.IndicatorState
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.feature.IndicatorState as IndicatorStateMoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka13.data.FiioKa13UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.moondrop.dawn.data.MoondropDawnUsbRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SetIndicatorStateUseCase @Inject constructor(
private val fiioKa13UsbRepository: FiioKa13UsbRepository,
private val moondropDawnUsbRepository: MoondropDawnUsbRepository
) {

suspend operator fun invoke(usbDongle: UsbDongle, id: Byte): Result<UsbDongle> =
when (usbDongle) {
is FiioKa13 -> {
fiioKa13UsbRepository.setIndicatorState(
fiioKa13 = usbDongle,
indicatorState = IndicatorStateFiioKa13.findByIdOrDefault(id)
)
}
is MoondropDawn -> {
moondropDawnUsbRepository.setIndicatorState(
moondropDawn = usbDongle,
indicatorState = IndicatorState.findByIdOrDefault(id)
indicatorState = IndicatorStateMoondropDawn.findByIdOrDefault(id)
)
}
else -> Result.failure(UnsupportedUsbDongleException())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ package io.github.tommygeenexus.usbdonglecontrol.control.domain
import io.github.tommygeenexus.usbdonglecontrol.core.db.Profile
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UnsupportedUsbDongleException
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.FiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.feature.Filter as FilterFiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.feature.IndicatorState as IndicatorStateFiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.feature.VolumeLevel as VolumeLevelFiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.feature.createFromDisplayValue
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.FiioKa5
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.ChannelBalance
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.DacMode
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.DisplayBrightness
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.DisplayInvert
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.DisplayTimeout
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.Filter
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.Filter as FilterFiioKa5
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.Gain
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.HardwareMute
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.HidMode
Expand All @@ -38,22 +43,35 @@ import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.Vol
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.VolumeMode
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.createFromDisplayValue
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.MoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.feature.IndicatorState
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.feature.VolumeLevel
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.feature.IndicatorState as IndicatorStateMoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.feature.VolumeLevel as VolumeLevelMoondropDawn
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.moondrop.dawn.feature.createFromDisplayValue
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka13.data.FiioKa13UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka5.data.FiioKa5UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.moondrop.dawn.data.MoondropDawnUsbRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SetProfileUseCase @Inject constructor(
private val fiioKa13UsbRepository: FiioKa13UsbRepository,
private val fiioKa5UsbRepository: FiioKa5UsbRepository,
private val moondropDawnUsbRepository: MoondropDawnUsbRepository
) {

suspend operator fun invoke(usbDongle: UsbDongle, profile: Profile): Result<UsbDongle> =
when (usbDongle) {
is FiioKa13 -> {
fiioKa13UsbRepository.setAll(
fiioKa13 = usbDongle,
filter = FilterFiioKa13.findByIdOrDefault(profile.filterId),
indicatorState = IndicatorStateFiioKa13.findByIdOrDefault(
profile.indicatorStateId
),
spdifOut = SpdifOut(isEnabled = profile.isSpdifOutEnabled),
volumeLevel = VolumeLevelFiioKa13.createFromDisplayValue(profile.volumeLevel)
)
}
is FiioKa5 -> {
fiioKa5UsbRepository.setAll(
fiioKa5 = usbDongle,
Expand All @@ -68,7 +86,7 @@ class SetProfileUseCase @Inject constructor(
displayTimeout = DisplayTimeout.createFromDisplayValue(
profile.displayTimeout
),
filter = Filter.findByIdOrDefault(id = profile.filterId),
filter = FilterFiioKa5.findByIdOrDefault(id = profile.filterId),
gain = Gain.findByIdOrDefault(id = profile.gainId),
hardwareMute = HardwareMute(isEnabled = profile.isHardwareMuteEnabled),
hidMode = HidMode.findByIdOrDefault(id = profile.hidModeId),
Expand All @@ -85,12 +103,12 @@ class SetProfileUseCase @Inject constructor(
is MoondropDawn -> {
moondropDawnUsbRepository.setAll(
moondropDawn = usbDongle,
filter = Filter.findByIdOrDefault(id = profile.filterId),
filter = FilterFiioKa5.findByIdOrDefault(id = profile.filterId),
gain = Gain.findByIdOrDefault(id = profile.gainId),
indicatorState = IndicatorState.findByIdOrDefault(
indicatorState = IndicatorStateMoondropDawn.findByIdOrDefault(
id = profile.indicatorStateId
),
volumeLevel = VolumeLevel.createFromDisplayValue(
volumeLevel = VolumeLevelMoondropDawn.createFromDisplayValue(
displayValue = profile.volumeLevel
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,30 @@ package io.github.tommygeenexus.usbdonglecontrol.control.domain

import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UnsupportedUsbDongleException
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.UsbDongle
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka13.FiioKa13
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.FiioKa5
import io.github.tommygeenexus.usbdonglecontrol.core.dongle.fiio.ka5.feature.SpdifOut
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka13.data.FiioKa13UsbRepository
import io.github.tommygeenexus.usbdonglecontrol.dongle.fiio.ka5.data.FiioKa5UsbRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SetSpdifOutEnabledUseCase @Inject constructor(
private val fiioKa13UsbRepository: FiioKa13UsbRepository,
private val fiioKa5UsbRepository: FiioKa5UsbRepository
) {

suspend operator fun invoke(
usbDongle: UsbDongle,
isSpdifOutEnabled: Boolean
): Result<UsbDongle> = when (usbDongle) {
is FiioKa13 -> {
fiioKa13UsbRepository.setSpdifOut(
fiioKa13 = usbDongle,
spdifOut = SpdifOut(isEnabled = isSpdifOutEnabled)
)
}
is FiioKa5 -> {
fiioKa5UsbRepository.setSpdifOut(
fiioKa5 = usbDongle,
Expand Down
Loading

0 comments on commit b81b684

Please sign in to comment.