From 018059866db454e7a372b6a701bb57452b022e22 Mon Sep 17 00:00:00 2001 From: Roman Makeev <57789105+makeevrserg@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:55:29 +0300 Subject: [PATCH] add input button (#14) * add input button * up version 0.6.0 --- IRDB | 2 +- gradle.properties | 2 +- .../backend/db/signal/table/SignalTable.kt | 2 - .../config/category/api/DeviceKeyExt.kt | 7 + .../api/any/AnyDeviceKeyNamesProvider.kt | 25 +++ .../parser/presentation/FillerController.kt | 9 +- modules/kenerator/ui/build.gradle.kts | 1 + .../kenerator/ui/util/RemotesListExt.kt | 7 +- .../ifrmvp/backend/model/DeviceKey.kt | 142 +++++++++--------- modules/resources/build.gradle.kts | 8 + .../flipperdevices/ifrmvp/resources/CoreR.kt | 5 + .../ifrmvp/resources/ServerResource.kt | 27 ++++ .../src/main/resources/images/input.png | Bin 0 -> 2139 bytes .../ifrmvp/resources/ServerResourceTest.kt | 10 ++ settings.gradle.kts | 1 + 15 files changed, 169 insertions(+), 79 deletions(-) create mode 100644 modules/resources/build.gradle.kts create mode 100644 modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/CoreR.kt create mode 100644 modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/ServerResource.kt create mode 100644 modules/resources/src/main/resources/images/input.png create mode 100644 modules/resources/src/test/kotlin/com/flipperdevices/ifrmvp/resources/ServerResourceTest.kt diff --git a/IRDB b/IRDB index 9fd968f..7f31653 160000 --- a/IRDB +++ b/IRDB @@ -1 +1 @@ -Subproject commit 9fd968fe529b5415dd17d505d9577864b215d7cb +Subproject commit 7f316534e15946485ea5cdd94d6b05f87e349e27 diff --git a/gradle.properties b/gradle.properties index f5d77bb..4e86d4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.parallel=true makeevrserg.project.name=IRDBBackend makeevrserg.project.url=https://github.com/flipperdevices/IRDB-Backend makeevrserg.project.group=com.flipperdevices.ifrmvp.backend -makeevrserg.project.version.string=0.5.1 +makeevrserg.project.version.string=0.6.0 makeevrserg.project.description=Api for IfrSample makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com # Java diff --git a/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt index 7baf1aa..f4f97df 100644 --- a/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt +++ b/modules/database/src/main/kotlin/com/flipperdevices/ifrmvp/backend/db/signal/table/SignalTable.kt @@ -24,7 +24,6 @@ object SignalTable : LongIdTable("SIGNAL_TABLE") { init { uniqueIndex( - name, brandId, type, frequency, @@ -32,7 +31,6 @@ object SignalTable : LongIdTable("SIGNAL_TABLE") { data ) uniqueIndex( - name, brandId, type, protocol, diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/DeviceKeyExt.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/DeviceKeyExt.kt index 8bfef87..0adf56d 100644 --- a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/DeviceKeyExt.kt +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/DeviceKeyExt.kt @@ -191,6 +191,13 @@ object DeviceKeyExt { DeviceKey.FAVORITE -> listOf( CategoryType.BOX ) + + DeviceKey.INPUT -> listOf( + CategoryType.BOX, + CategoryType.DVD, + CategoryType.TVS, + + ) } } } diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt index 7169e14..b9a7ecf 100644 --- a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt @@ -1,7 +1,10 @@ package com.flipperdevices.ifrmvp.generator.config.device.api.any +import com.flipperdevices.ifrmvp.backend.model.DeviceConfiguration import com.flipperdevices.ifrmvp.backend.model.DeviceKey import com.flipperdevices.ifrmvp.generator.config.device.api.DeviceKeyNamesProvider +import java.io.File +import kotlinx.serialization.json.Json object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { @Suppress("LongMethod", "CyclomaticComplexMethod") @@ -406,6 +409,28 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { DeviceKey.LIGHT -> listOf( "light" ) + + DeviceKey.INPUT -> listOf( + "input", + "input_r", + "input method", + "next_input", + "pipinput_r", + "pipinput", + "input_next", + "input_source" + ) } } } + +// For docs +fun main() { + DeviceKey.entries.forEach { deviceKey -> + println("#### ${deviceKey.name}") + AnyDeviceKeyNamesProvider.getKeyNames(deviceKey).forEach { alias -> + println("- $alias") + } + println() + } +} \ No newline at end of file diff --git a/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt b/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt index 7fdfd65..5e367b2 100644 --- a/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt +++ b/modules/kenerator/sql/src/main/kotlin/com/flipperdevices/ifrmvp/parser/presentation/FillerController.kt @@ -164,10 +164,7 @@ internal class FillerController(private val database: Database) : CoroutineScope this[SignalKeyTable.type] = IfrKeyIdentifier.Empty.TYPE } - is IfrKeyIdentifier.Name -> { - this[SignalKeyTable.remoteKeyName] = keyIdentifier.name - this[SignalKeyTable.type] = IfrKeyIdentifier.Name.TYPE - } + is IfrKeyIdentifier.Name -> error("Identifying by name is not possible!") is IfrKeyIdentifier.Sha256 -> { this[SignalKeyTable.remoteKeyName] = keyIdentifier.name @@ -194,9 +191,7 @@ internal class FillerController(private val database: Database) : CoroutineScope andWhere { SignalTable.hash eq keyIdentifier.hash } } - is IfrKeyIdentifier.Name -> { - andWhere { SignalTable.name eq keyIdentifier.name } - } + is IfrKeyIdentifier.Name -> error("Identifying by name is not possible!") } } .map { it[SignalTable.id] } diff --git a/modules/kenerator/ui/build.gradle.kts b/modules/kenerator/ui/build.gradle.kts index 981256d..a45dd23 100644 --- a/modules/kenerator/ui/build.gradle.kts +++ b/modules/kenerator/ui/build.gradle.kts @@ -19,4 +19,5 @@ dependencies { implementation(projects.modules.infrared) implementation(projects.modules.kenerator.configuration) implementation(projects.modules.kenerator.paths) + implementation(projects.modules.resources) } diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/util/RemotesListExt.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/util/RemotesListExt.kt index a8df8e1..966d5b4 100644 --- a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/util/RemotesListExt.kt +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/util/RemotesListExt.kt @@ -6,12 +6,13 @@ import com.flipperdevices.ifrmvp.kenerator.ui.button.ChannelButton import com.flipperdevices.ifrmvp.kenerator.ui.button.NavigationButton import com.flipperdevices.ifrmvp.kenerator.ui.button.OkNavigationButton import com.flipperdevices.ifrmvp.kenerator.ui.button.VolButton +import com.flipperdevices.ifrmvp.model.buttondata.Base64ImageButtonData import com.flipperdevices.ifrmvp.model.buttondata.ButtonData import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData.IconType import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData -import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData +import com.flipperdevices.ifrmvp.resources.CoreR import com.flipperdevices.infrared.editor.encoding.InfraredRemoteEncoder.identifier import com.flipperdevices.infrared.editor.model.InfraredRemote @@ -286,6 +287,10 @@ internal object RemotesListExt { IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.FAVORITE) } + DeviceKey.INPUT -> remotes.findByKey(deviceKey)?.let { remote -> + Base64ImageButtonData(keyIdentifier = remote.identifier, pngBase64 = CoreR.inputImage.toBase64()) + } + DeviceKey.RECORD -> remotes.findByKey(deviceKey)?.let { remote -> IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.RECORD) } diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/backend/model/DeviceKey.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/backend/model/DeviceKey.kt index 63a2802..403c0b9 100644 --- a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/backend/model/DeviceKey.kt +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/backend/model/DeviceKey.kt @@ -5,71 +5,79 @@ package com.flipperdevices.ifrmvp.backend.model * * The keys have comments in which devices they are present */ -enum class DeviceKey { - PWR, - SHUTTER, - VOL_UP, - VOL_DOWN, - CH_UP, - CH_DOWN, - FOCUS_MORE, - FOCUS_LESS, - ZOOM_UP, - ZOOM_DOWN, - RESET, - DOWN, - UP, - RIGHT, - LEFT, - NEXT, - PREVIOUS, - TV, - AUX, - HOME, - BACK, - MENU, - PLAY, - MUTE, - EJECT, - FAN_SPEED, - NEAR, - FAR, - PAUSE, - RECORD, - WIND_SPEED, - MODE, - LIGHT, - FAN_MEDIUM, - FAN_HIGH, - FAN_LOW, - STOP, - EXIT, - INFO, - TIMER, - OSCILLATE, - TIMER_ADD, - TIMER_REDUCE, - FAN_SPEED_UP, - FAN_SPEED_DOWN, - SLEEP, - SHAKE_WIND, - SWING, - OFF, - BRIGHTNESS_UP, - BRIGHTNESS_DOWN, - COLD_WIND, - COOL, - WIND_TYPE, - TEMPERATURE_UP, - TEMPERATURE_DOWN, - HEAT_ADD, - HEAT_REDUCE, - ENERGY_SAVE, - OK, - REW, - SET, - DELETE, - VOD, - LIVE_TV, - FAVORITE +enum class DeviceKey(val desc: String) { + PWR("Power enable button"), + SHUTTER("Take a photo with camera"), + VOL_UP("Increase volume"), + VOL_DOWN("Decrease volume"), + CH_UP("Next channel"), + CH_DOWN("Previous channel"), + FOCUS_MORE("Add focus"), + FOCUS_LESS("Decrease focus"), + ZOOM_UP("Zoom up"), + ZOOM_DOWN("Zoom down"), + RESET("Reset"), + DOWN("Navigation button(for TV menu, for example) - down"), + UP("Navigation button(for TV menu, for example) - up"), + RIGHT("Navigation button(for TV menu, for example) - right"), + LEFT("Navigation button(for TV menu, for example) - left"), + NEXT("Next button for TV box"), + PREVIOUS("Previous button for TV box"), + TV("TV button fot TVs"), + AUX("Change AUX mode"), + HOME("Home button"), + BACK("Back button"), + MENU("Show/Open menu"), + PLAY("Play/Resume playback"), + MUTE("Mute sound"), + EJECT("Eject disk"), + FAN_SPEED("Change fan speed recursively"), + NEAR("Near camera clipping plane"), + FAR("Far camera clipping plane"), + PAUSE("Pause playback"), + RECORD("Start recording"), + WIND_SPEED("Change wind speed recursively"), + MODE("Change mode (TV Box, DVD)"), + LIGHT("Increase/Decrease light recursively"), + FAN_MEDIUM("Set fan speed to medium"), + FAN_HIGH("Set fan mode to high"), + FAN_LOW("Change fan speed to low"), + STOP("Stop button (mostly for TV Box)"), + EXIT("Exit(from menu, etc)"), + INFO("Show info"), + TIMER("Start timer, show timer menu"), + OSCILLATE("Start oscillating (mostly for fans)"), + TIMER_ADD("Increase timer value"), + TIMER_REDUCE("Decrease timer value"), + FAN_SPEED_UP("Increase fan speed"), + FAN_SPEED_DOWN("Decrease fan speed"), + SLEEP("Start sleep mode"), + SHAKE_WIND("Same as oscillate, start shaking"), + SWING("Same as oscillate, start swing"), + OFF("Turn off the device"), + BRIGHTNESS_UP("Increase brightness"), + BRIGHTNESS_DOWN("Decrease brightness"), + COLD_WIND("Set wind cold"), + COOL("Set/increase cool"), + WIND_TYPE("Change wind type"), + TEMPERATURE_UP("Increase temperature"), + TEMPERATURE_DOWN("Decrease temperature"), + HEAT_ADD("Add heat"), + HEAT_REDUCE("Reduce heat"), + ENERGY_SAVE("Enter energy save mode"), + OK("Ok button(mostly where up/left/right/down buttons located"), + REW("Rewind button(mostly for playback)"), + SET("Set button(mostly for TV box)"), + DELETE("Delete button(mostly for TV Box)"), + VOD("Enable VODs"), + LIVE_TV("Set TV mode"), + FAVORITE("Add to favorite"), + INPUT("Input button to change input source(hdmi, tv, etc)") +} + +// Generate docs text +fun main() { + DeviceKey.entries.forEach { + println("- `${it.name}` -> ${it.desc}") + } } diff --git a/modules/resources/build.gradle.kts b/modules/resources/build.gradle.kts new file mode 100644 index 0000000..4d0ab23 --- /dev/null +++ b/modules/resources/build.gradle.kts @@ -0,0 +1,8 @@ +import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo + +plugins { + id("org.jetbrains.kotlin.jvm") +} +dependencies { + testImplementation(kotlin("test")) +} \ No newline at end of file diff --git a/modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/CoreR.kt b/modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/CoreR.kt new file mode 100644 index 0000000..ef7355a --- /dev/null +++ b/modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/CoreR.kt @@ -0,0 +1,5 @@ +package com.flipperdevices.ifrmvp.resources + +object CoreR { + val inputImage = ServerResource.Image("/images/input.png") +} \ No newline at end of file diff --git a/modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/ServerResource.kt b/modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/ServerResource.kt new file mode 100644 index 0000000..40dd39f --- /dev/null +++ b/modules/resources/src/main/kotlin/com/flipperdevices/ifrmvp/resources/ServerResource.kt @@ -0,0 +1,27 @@ +package com.flipperdevices.ifrmvp.resources + +import java.io.InputStream +import kotlin.io.encoding.Base64 +import kotlin.io.encoding.ExperimentalEncodingApi + +sealed interface ServerResource { + fun openStream(): InputStream + + class Image(val path: String) : ServerResource { + override fun openStream(): InputStream { + val resource = object {}.javaClass.getResource(path) + return resource?.openStream() ?: error("Could not load file $path") + } + + @OptIn(ExperimentalEncodingApi::class) + fun toBase64(): String { + return openStream().use { + PNG_BASE64_HEADER + Base64.encode(it.readAllBytes()) + } + } + + companion object { + private const val PNG_BASE64_HEADER = "data:image/png;base64," + } + } +} \ No newline at end of file diff --git a/modules/resources/src/main/resources/images/input.png b/modules/resources/src/main/resources/images/input.png new file mode 100644 index 0000000000000000000000000000000000000000..2e3c6d5fcf984a78438200c87ced8092ea229444 GIT binary patch literal 2139 zcmcgu`9IYA9{zmCY!rq@vJ6wY!jUDiO`M^@G{!O#lfs0k$R&kjnX&IF+!IPDI)%uR z-6*oAIuj?$BwV6lF2k{faoqpmzU~jt`*~ik=cniOe%`OwJK4d`T3k$C3;-a0hD>tY zW9EN>M()iHvrGK|ppTp(nLCBK^B>u!Vb5W@=U3C-bja7}HS4to>n#6+L?jC_xkKTCElLR|>444&P~kjZ;CFoo zi;R{g=1d(u?4|O{Ct9JMxsqMZzWB$*VaaeHynHE1*d&iHiM=z208derHCk%n8*?iB0g-DOon} zmw%3C}ga8Z~1P5YzZbDOf7X0Osq_-iVTD=vrm0m38!9E1CYwQ7VAbw32BB13SZO>zuzTixpdocvMx#Md;$$rvBr`s7@ER7 zcftDj#X3xkqJ={r1`cD+ENao|bVO>nSZZtZk0PE1vtZ4}tJ1Z}M^_eTdRIEjI%`O# zN`5EqUK(K$K^4INUT@a!AvEJ*^8Jnt%@*?2K#v>Ie$}-i$RXA+*`_V$sfF4taq9Yw zC9&RuH%Tz2cu#+nl+j&`+7nel^PE0!6|UE!xS;ogzqTg;Z-lNCk(O zEn#;Wz8o@*X9q~b!?-Wf*CxM01URgH@2uV6=8=o5cEB%LO8^hqSYTw!z#u05c*^;@ z@zEz~xt-5q*J%rXl*TSj+uLWSYD@D`0jgj>ozr+N^6v8B(SqAYPczFFuAaKx0b>Cj z2CxVn7FC+R6?2QU-V|DP@+KM%JmdWbFfm^z-(m=mT+H~)1Y(RHv@inN7h#*YrI4;O zW_+)px?QwVOT=4M`}{ir3hert5|G(rg_#MQ!>c|pS8nL%nx+%7?TAo2lCo@-2|mf% zM)0_;1U#-cL!=R4tXsXi6CUAP2xKe_!jBy3S_=r?NtdRAq~cLbHyWJA5-t}dR7+$^ zWLCde=g3h69dsD+CkUJ|Sn6wacUPu97RL7X#C;>``_$)HBaUqgrf6llx@qdTb|0L@ zI4bF0uxdh|bD(NpHue6pj+&gC-sCwYly5P$_o%vd+=NX~FF8M|a+xx`DsL>xY{C9q zlpHh$({)Q1nrqI2o;R7h9(lds{Ym-xU{}*`i@X5+i21E|>zoD{dS$&GZ<#|A=TJpn{-N`ZW1Fzj*3h!l{C)zK_ZeVN5P!>5KZS{cvXI(}4sp2(NI9qGFes|87WTC#TW{IxneB@^7ux7K6chqF9NY-KfRMA*`)N;>NSkHOv;p}FWjdA zkLX|Bm9!O~gxA9g@5rI^{y9m$Wp0 zxcCLroUy|8%v~*y>^L`NFKli4pX{(gAHpNQnjA`rly%lH=oHoR+LXb74Zrq07HHS_ rH98PtvXSL-Xi&bqf|C6|7`v#*2DkUY33>T@PXjn(X-9f#!HD@A(X+yu literal 0 HcmV?d00001 diff --git a/modules/resources/src/test/kotlin/com/flipperdevices/ifrmvp/resources/ServerResourceTest.kt b/modules/resources/src/test/kotlin/com/flipperdevices/ifrmvp/resources/ServerResourceTest.kt new file mode 100644 index 0000000..17b3ab5 --- /dev/null +++ b/modules/resources/src/test/kotlin/com/flipperdevices/ifrmvp/resources/ServerResourceTest.kt @@ -0,0 +1,10 @@ +package com.flipperdevices.ifrmvp.resources + +import kotlin.test.Test + +class ServerResourceTest { + @Test + fun testResource() { + println(CoreR.inputImage.toBase64()) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 733bf5b..5a4e810 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,6 +26,7 @@ include(":modules:build-konfig") include(":modules:core") include(":modules:model") include(":modules:infrared") +include(":modules:resources") // generators include(":modules:kenerator:configuration") include(":modules:kenerator:sql")