diff --git a/IRDB b/IRDB index 7d745e6..623461c 160000 --- a/IRDB +++ b/IRDB @@ -1 +1 @@ -Subproject commit 7d745e63d0df0ed8a242dd9a55393b1abb084177 +Subproject commit 623461c905618688f1ce4c21cd81d6c29b40bb9e diff --git a/gradle.properties b/gradle.properties index 1fe55fd..89b3488 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.parallel=true makeevrserg.project.name=IfrBackend makeevrserg.project.url=https://github.com/makeevrserg/IfrSample makeevrserg.project.group=com.flipperdevices.ifrmvp.backend -makeevrserg.project.version.string=0.2.1 +makeevrserg.project.version.string=0.3.0 makeevrserg.project.description=Api for IfrSample makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com # Java diff --git a/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/encoding/InfraredRemoteEncoder.kt b/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/encoding/InfraredRemoteEncoder.kt index 7336efb..86e57a9 100644 --- a/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/encoding/InfraredRemoteEncoder.kt +++ b/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/encoding/InfraredRemoteEncoder.kt @@ -1,5 +1,6 @@ package com.flipperdevices.infrared.editor.encoding +import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier import com.flipperdevices.infrared.editor.model.InfraredRemote /** @@ -8,7 +9,7 @@ import com.flipperdevices.infrared.editor.model.InfraredRemote * Then we flatten it to have single byte array. */ object InfraredRemoteEncoder { - fun encode(remote: InfraredRemote): ByteArray { + private fun encode(remote: InfraredRemote): ByteArray { val bytesList = when (remote) { is InfraredRemote.Parsed -> listOf( remote.type, @@ -28,4 +29,10 @@ object InfraredRemoteEncoder { .flatMap(ByteArray::asList) .toByteArray() } + val InfraredRemote.identifier: IfrKeyIdentifier.Sha256 + get() { + val byteArray = InfraredRemoteEncoder.encode(this) + val sha256 = JvmEncoder(ByteArrayEncoder.Algorithm.SHA_256).encode(byteArray) + return IfrKeyIdentifier.Sha256(name, sha256) + } } \ No newline at end of file diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt index 37b3d18..9b25a48 100644 --- a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt @@ -1,10 +1,22 @@ package com.flipperdevices.ifrmvp.generator.config +import com.flipperdevices.bridge.dao.api.model.FlipperFileFormat import com.flipperdevices.ifrmvp.backend.model.CategoryType -import com.flipperdevices.ifrmvp.generator.config.category.api.AllCategoryConfigGenerator +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.AirPurifierCategoryConfigGenerator +import com.flipperdevices.ifrmvp.generator.config.category.api.AvReceiverCategoryConfigGenerator +import com.flipperdevices.ifrmvp.generator.config.category.api.BoxCategoryConfigGenerator +import com.flipperdevices.ifrmvp.generator.config.category.api.CameraCategoryConfigGenerator +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.generator.config.category.api.DvdCategoryConfigGenerator +import com.flipperdevices.ifrmvp.generator.config.category.api.FanCategoryConfigGenerator +import com.flipperdevices.ifrmvp.generator.config.category.api.ProjectorCategoryConfigGenerator +import com.flipperdevices.ifrmvp.generator.config.category.api.TvsCategoryConfigGenerator import com.flipperdevices.ifrmvp.generator.config.device.api.DefaultDeviceConfigGenerator import com.flipperdevices.ifrmvp.generator.config.device.api.any.AnyDeviceKeyNamesProvider import com.flipperdevices.ifrmvp.parser.util.ParserPathResolver +import com.flipperdevices.infrared.editor.viewmodel.InfraredKeyParser import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -19,7 +31,16 @@ private fun generateCategoriesConfigFiles() { .categories .onEach { categoryFolder -> val categoryType = CategoryType.entries.first { it.folderName == categoryFolder.name } - val config = AllCategoryConfigGenerator.generate(categoryType) + val config = when (categoryType) { + CategoryType.A_V_RECEIVER -> AvReceiverCategoryConfigGenerator.generate(categoryType) + CategoryType.AIR_PURIFIERS -> AirPurifierCategoryConfigGenerator.generate(categoryType) + CategoryType.BOX -> BoxCategoryConfigGenerator.generate(categoryType) + CategoryType.CAMERA -> CameraCategoryConfigGenerator.generate(categoryType) + CategoryType.DVD -> DvdCategoryConfigGenerator.generate(categoryType) + CategoryType.FAN -> FanCategoryConfigGenerator.generate(categoryType) + CategoryType.PROJECTOR -> ProjectorCategoryConfigGenerator.generate(categoryType) + CategoryType.TVS -> TvsCategoryConfigGenerator.generate(categoryType) + } val configFile = ParserPathResolver.categoryMetaPath(categoryFolder.name).resolve("config.json") if (configFile.exists()) configFile.delete() configFile.createNewFile() @@ -49,7 +70,46 @@ private fun generateDevicesConfigFiles() { } } +fun printAllKeys() { + + val keyNames = DeviceKey.entries.associateWith { AnyDeviceKeyNamesProvider.getKeyNames(it) } + val namesToCategories = mutableMapOf>() + val nameToCount = mutableMapOf() + ParserPathResolver + .categories + .filter { it.name.equals("TVs", true) } + .flatMap { categoryFolder -> + ParserPathResolver.brands(categoryFolder.name) + .flatMap { brandFolder -> + ParserPathResolver.brandIfrFiles( + category = categoryFolder.name, + brand = brandFolder.name + ).flatMap { irFile -> + val signals = irFile + .readText() + .let(FlipperFileFormat.Companion::fromFileContent) + .let(InfraredKeyParser::mapParsedKeyToInfraredRemotes) + .onEach { signal -> + val set = namesToCategories[signal.name.lowercase()] ?: mutableSetOf() + set.add(categoryFolder.name) + namesToCategories[signal.name.lowercase()] = set + nameToCount[signal.name.lowercase()] = (nameToCount[signal.name.lowercase()] ?: 0) + 1 + } + signals + } + } + }.distinctBy { it.name.lowercase() } +// .sortedBy { it.name.lowercase() } + .sortedByDescending { nameToCount[it.name.lowercase()] } + .onEach { key -> + val filteredMap = keyNames.filterValues { it.map { it.lowercase() }.contains(key.name.lowercase()) } + println("${key.name.lowercase()} -> ${nameToCount[key.name.lowercase()]} ${namesToCategories[key.name.lowercase()]} -> ${filteredMap.map { (k, v) -> "$k - ${k.getAllowedCategories()} -${v}" }}") + } + +} + fun main() { generateCategoriesConfigFiles() generateDevicesConfigFiles() +// printAllKeys() } diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AirPurifierCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AirPurifierCategoryConfigGenerator.kt new file mode 100644 index 0000000..cd3da46 --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AirPurifierCategoryConfigGenerator.kt @@ -0,0 +1,60 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object AirPurifierCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i =0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is it oscillated?", + data = TextButtonData(text = "OSC"), + key = DeviceKey.OSCILLATE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is Fan speed increased??", + data = TextButtonData(text = "FS+"), + key = DeviceKey.FAN_SPEED_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is Fan speed decreased?", + data = TextButtonData(text = "FS-"), + key = DeviceKey.FAN_SPEED_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it swing?", + data = TextButtonData(text = "SW"), + key = DeviceKey.SWING, + index = ++i, + ), + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AllCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AllCategoryConfigGenerator.kt deleted file mode 100644 index 3875cbb..0000000 --- a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AllCategoryConfigGenerator.kt +++ /dev/null @@ -1,104 +0,0 @@ -package com.flipperdevices.ifrmvp.generator.config.category.api - -import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration -import com.flipperdevices.ifrmvp.backend.model.CategoryType -import com.flipperdevices.ifrmvp.backend.model.DeviceKey -import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories -import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData -import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData - -object AllCategoryConfigGenerator { - /** - * Generate all categories configurations - * - * Some categories wil have the same orders. We need [DeviceKeyExt.getAllowedCategories] - * to understand for which category we need keys - */ - @Suppress("LongMethod") - fun generate(): CategoryConfiguration { - return CategoryConfiguration( - orders = DeviceKey.entries.mapIndexed { index, key -> - when (key) { - DeviceKey.PWR -> CategoryConfiguration.OrderModel( - data = IconButtonData(iconId = IconButtonData.IconType.POWER), - message = "Does %s turns on?", - key = key, - index = index, - ) - - DeviceKey.VOL_UP -> CategoryConfiguration.OrderModel( - message = "Does volume go up?", - data = TextButtonData(text = "+"), - key = key, - index = index, - ) - - DeviceKey.VOL_DOWN -> CategoryConfiguration.OrderModel( - message = "Does volume go down?", - data = TextButtonData(text = "-"), - key = key, - index = index, - ) - - DeviceKey.CH_UP -> CategoryConfiguration.OrderModel( - message = "Does channel go next?", - data = TextButtonData(text = "+"), - key = key, - index = index, - ) - - DeviceKey.CH_DOWN -> CategoryConfiguration.OrderModel( - message = "Does channel go previous?", - data = TextButtonData(text = "-"), - key = key, - index = index, - ) - - DeviceKey.FOCUS_MORE -> CategoryConfiguration.OrderModel( - message = "Does key focuses more?", - data = TextButtonData(text = "+"), - key = key, - index = index, - ) - - DeviceKey.FOCUS_LESS -> CategoryConfiguration.OrderModel( - message = "Does key focuses less?", - data = TextButtonData(text = "-"), - key = key, - index = index, - ) - - DeviceKey.ZOOM_UP -> CategoryConfiguration.OrderModel( - message = "Does key zoom more?", - data = TextButtonData(text = "+"), - key = key, - index = index, - ) - - DeviceKey.ZOOM_DOWN -> CategoryConfiguration.OrderModel( - message = "Does key zoom less?", - data = TextButtonData(text = "-"), - key = key, - index = index, - ) - - else -> CategoryConfiguration.OrderModel( - message = "Does it do something?", - data = TextButtonData(text = key.name), - key = key, - index = index, - ) - } - } - ) - } - - fun generate(categoryType: CategoryType): CategoryConfiguration { - val configuration = generate() - return CategoryConfiguration( - orders = configuration.orders.filter { - it.key.getAllowedCategories().contains(categoryType) - } - ) - } -} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AvReceiverCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AvReceiverCategoryConfigGenerator.kt new file mode 100644 index 0000000..450e255 --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/AvReceiverCategoryConfigGenerator.kt @@ -0,0 +1,60 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object AvReceiverCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i = 0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does volume go up?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_UP), + key = DeviceKey.VOL_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does volume go down?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_DOWN), + key = DeviceKey.VOL_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is volume muted?", + data = IconButtonData(iconId = IconButtonData.IconType.MUTE), + key = DeviceKey.MUTE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is menu opened?", + data = IconButtonData(iconId = IconButtonData.IconType.MENU), + key = DeviceKey.MENU, + index = ++i, + ) + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/BoxCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/BoxCategoryConfigGenerator.kt new file mode 100644 index 0000000..3b76e8f --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/BoxCategoryConfigGenerator.kt @@ -0,0 +1,72 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object BoxCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i = 0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does volume go up?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_UP), + key = DeviceKey.VOL_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does volume go down?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_DOWN), + key = DeviceKey.VOL_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is volume muted?", + data = IconButtonData(iconId = IconButtonData.IconType.MUTE), + key = DeviceKey.MUTE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is next channel shown?", + data = TextButtonData(text = "CH+"), + key = DeviceKey.CH_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is previous channel shown?", + data = TextButtonData(text = "CH-"), + key = DeviceKey.CH_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is menu opened?", + data = IconButtonData(iconId = IconButtonData.IconType.MENU), + key = DeviceKey.MENU, + index = ++i, + ) + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/CameraCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/CameraCategoryConfigGenerator.kt new file mode 100644 index 0000000..5b6c5fe --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/CameraCategoryConfigGenerator.kt @@ -0,0 +1,60 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object CameraCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i = 0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Did it take a photo?", + data = IconButtonData(iconId = IconButtonData.IconType.CAMERA), + key = DeviceKey.SHUTTER, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it zoom in?", + data = IconButtonData(iconId = IconButtonData.IconType.ZOOM_IN), + key = DeviceKey.ZOOM_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it zoom out?", + data = IconButtonData(iconId = IconButtonData.IconType.ZOOM_OUT), + key = DeviceKey.ZOOM_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is menu opened?", + data = IconButtonData(iconId = IconButtonData.IconType.MENU), + key = DeviceKey.MENU, + index = ++i, + ), + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} 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 a02c21e..8bfef87 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 @@ -7,116 +7,98 @@ object DeviceKeyExt { @Suppress("LongMethod", "CyclomaticComplexMethod") fun DeviceKey.getAllowedCategories(): List { return when (this) { + DeviceKey.OFF, DeviceKey.PWR -> listOf( CategoryType.TVS, CategoryType.AIR_PURIFIERS, CategoryType.BOX, CategoryType.FAN, - CategoryType.PROJECTOR + CategoryType.PROJECTOR, + CategoryType.A_V_RECEIVER, ) + DeviceKey.VOL_DOWN, DeviceKey.VOL_UP -> listOf( CategoryType.TVS, CategoryType.BOX, CategoryType.DVD, - CategoryType.PROJECTOR + CategoryType.PROJECTOR, + CategoryType.A_V_RECEIVER, ) - DeviceKey.VOL_DOWN -> listOf( + DeviceKey.RECORD -> listOf( CategoryType.TVS, - CategoryType.BOX, - CategoryType.DVD, - CategoryType.PROJECTOR ) + DeviceKey.CH_DOWN, DeviceKey.CH_UP -> listOf( CategoryType.TVS, CategoryType.BOX ) - DeviceKey.CH_DOWN -> listOf( - CategoryType.TVS, - CategoryType.BOX - ) - + DeviceKey.FOCUS_LESS, DeviceKey.FOCUS_MORE -> listOf( - CategoryType.PROJECTOR - ) - - DeviceKey.FOCUS_LESS -> listOf( - CategoryType.PROJECTOR + CategoryType.PROJECTOR, + CategoryType.BOX, + CategoryType.DVD ) + DeviceKey.ZOOM_DOWN, DeviceKey.ZOOM_UP -> listOf( - CategoryType.PROJECTOR - ) - - DeviceKey.ZOOM_DOWN -> listOf( - CategoryType.PROJECTOR + CategoryType.PROJECTOR, + CategoryType.TVS, + CategoryType.DVD, + CategoryType.CAMERA, + CategoryType.A_V_RECEIVER, ) DeviceKey.RESET -> listOf( - CategoryType.PROJECTOR - ) - - DeviceKey.DOWN -> listOf( - CategoryType.A_V_RECEIVER, - CategoryType.BOX, + CategoryType.PROJECTOR, CategoryType.CAMERA, + CategoryType.TVS, CategoryType.DVD, - CategoryType.PROJECTOR - ) - - DeviceKey.UP -> listOf( CategoryType.A_V_RECEIVER, - CategoryType.BOX, - CategoryType.CAMERA, - CategoryType.DVD, - CategoryType.PROJECTOR ) - DeviceKey.RIGHT -> listOf( + DeviceKey.OK, + DeviceKey.LEFT, + DeviceKey.RIGHT, + DeviceKey.UP, + DeviceKey.DOWN -> listOf( CategoryType.A_V_RECEIVER, CategoryType.BOX, CategoryType.CAMERA, CategoryType.DVD, - CategoryType.PROJECTOR + CategoryType.PROJECTOR, + CategoryType.AIR_PURIFIERS, + CategoryType.FAN, ) - DeviceKey.LEFT -> listOf( - CategoryType.A_V_RECEIVER, - CategoryType.BOX, - CategoryType.CAMERA, - CategoryType.DVD, - CategoryType.PROJECTOR - ) + DeviceKey.PREVIOUS, DeviceKey.NEXT -> listOf( CategoryType.A_V_RECEIVER, CategoryType.CAMERA, - CategoryType.DVD + CategoryType.DVD, + CategoryType.BOX ) - DeviceKey.PREVIOUS -> listOf( - CategoryType.A_V_RECEIVER, - CategoryType.CAMERA, - CategoryType.DVD + DeviceKey.EJECT -> listOf( + CategoryType.DVD, ) + DeviceKey.REW, + DeviceKey.AUX, DeviceKey.TV -> listOf( - CategoryType.A_V_RECEIVER - ) - - DeviceKey.AUX -> listOf( - CategoryType.A_V_RECEIVER - ) - - DeviceKey.HOME -> listOf( CategoryType.A_V_RECEIVER, CategoryType.BOX, - CategoryType.DVD + CategoryType.CAMERA, ) + DeviceKey.INFO, + DeviceKey.EXIT, + DeviceKey.MENU, + DeviceKey.HOME, DeviceKey.BACK -> listOf( CategoryType.A_V_RECEIVER, CategoryType.BOX, @@ -124,16 +106,12 @@ object DeviceKeyExt { CategoryType.PROJECTOR ) - DeviceKey.MENU -> listOf( + DeviceKey.PAUSE, + DeviceKey.PLAY, + DeviceKey.STOP -> listOf( CategoryType.A_V_RECEIVER, - CategoryType.CAMERA, CategoryType.DVD, - CategoryType.PROJECTOR - ) - - DeviceKey.PLAY -> listOf( - CategoryType.A_V_RECEIVER, - CategoryType.DVD + CategoryType.BOX ) DeviceKey.MUTE -> listOf( @@ -141,63 +119,77 @@ object DeviceKeyExt { CategoryType.AIR_PURIFIERS, CategoryType.DVD, CategoryType.FAN, - CategoryType.PROJECTOR - ) - - DeviceKey.FAN_SPEED -> listOf( - CategoryType.AIR_PURIFIERS - ) - - DeviceKey.NEAR -> listOf( - CategoryType.CAMERA - ) - - DeviceKey.FAR -> listOf( - CategoryType.CAMERA + CategoryType.PROJECTOR, + CategoryType.BOX ) - DeviceKey.PAUSE -> listOf( - CategoryType.DVD - ) - - DeviceKey.WIND_SPEED -> listOf( - CategoryType.FAN - ) DeviceKey.MODE -> listOf( - CategoryType.FAN + CategoryType.FAN, + CategoryType.AIR_PURIFIERS ) - DeviceKey.FAN_SPEED_UP -> listOf( - CategoryType.FAN + DeviceKey.FAN_MEDIUM, + DeviceKey.FAN_HIGH, + DeviceKey.FAN_LOW, + DeviceKey.LIGHT -> listOf( + CategoryType.FAN, ) - DeviceKey.FAN_SPEED_DOWN -> listOf( - CategoryType.FAN + DeviceKey.FAN_SPEED, + DeviceKey.SWING, + DeviceKey.COLD_WIND, + DeviceKey.COOL, + DeviceKey.WIND_TYPE, + DeviceKey.SHAKE_WIND, + DeviceKey.WIND_SPEED, + DeviceKey.FAN_SPEED_DOWN, + DeviceKey.SLEEP, + DeviceKey.FAN_SPEED_UP -> listOf( + CategoryType.FAN, + CategoryType.AIR_PURIFIERS ) - DeviceKey.SHAKE_WIND -> listOf( - CategoryType.FAN + DeviceKey.TIMER_REDUCE, + DeviceKey.OSCILLATE, + DeviceKey.TIMER, + DeviceKey.TIMER_ADD, + DeviceKey.TEMPERATURE_DOWN, + DeviceKey.TEMPERATURE_UP -> listOf( + CategoryType.FAN, + CategoryType.AIR_PURIFIERS ) - DeviceKey.WIND_TYPE -> listOf( + DeviceKey.ENERGY_SAVE -> listOf( CategoryType.FAN ) - DeviceKey.TEMPERATURE_UP -> listOf( - CategoryType.FAN + DeviceKey.FAR, + DeviceKey.NEAR, + DeviceKey.SHUTTER -> listOf( + CategoryType.CAMERA, + CategoryType.PROJECTOR ) - DeviceKey.TEMPERATURE_DOWN -> listOf( - CategoryType.FAN + DeviceKey.HEAT_REDUCE, + DeviceKey.HEAT_ADD -> listOf( + CategoryType.AIR_PURIFIERS, ) - DeviceKey.ENERGY_SAVE -> listOf( - CategoryType.FAN + DeviceKey.BRIGHTNESS_DOWN, + DeviceKey.BRIGHTNESS_UP -> listOf( + CategoryType.PROJECTOR, + CategoryType.TVS, + CategoryType.DVD, + CategoryType.A_V_RECEIVER, ) - DeviceKey.SHUTTER -> listOf( - CategoryType.CAMERA + DeviceKey.SET, + DeviceKey.DELETE, + DeviceKey.VOD, + DeviceKey.LIVE_TV, + DeviceKey.FAVORITE -> listOf( + CategoryType.BOX ) } } diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/DvdCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/DvdCategoryConfigGenerator.kt new file mode 100644 index 0000000..7258cf2 --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/DvdCategoryConfigGenerator.kt @@ -0,0 +1,72 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object DvdCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i = 0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it open next channel?", + data = TextButtonData(text = "CH+"), + key = DeviceKey.CH_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it open previous channel?", + data = TextButtonData(text = "CH-"), + key = DeviceKey.CH_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does volume go up?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_UP), + key = DeviceKey.VOL_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does volume go down?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_DOWN), + key = DeviceKey.VOL_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is it muted?", + data = IconButtonData(iconId = IconButtonData.IconType.MUTE), + key = DeviceKey.MUTE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is it ejected?", + data = IconButtonData(iconId = IconButtonData.IconType.EJECT), + key = DeviceKey.EJECT, + index = ++i, + ), + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/FanCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/FanCategoryConfigGenerator.kt new file mode 100644 index 0000000..dadb72e --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/FanCategoryConfigGenerator.kt @@ -0,0 +1,128 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object FanCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i = 0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it change wind speed?", + data = IconButtonData(iconId = IconButtonData.IconType.WIND_SPEED), + key = DeviceKey.WIND_SPEED, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it enable wind shake?", + data = TextButtonData(text = "SH"), + key = DeviceKey.SHAKE_WIND, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it change mode?", + data = IconButtonData(iconId = IconButtonData.IconType.MODE), + key = DeviceKey.MODE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it change lights?", + data = IconButtonData(iconId = IconButtonData.IconType.LIGHT), + key = DeviceKey.LIGHT, + index = ++i, + ), + + CategoryConfiguration.OrderModel( + message = "Does it increase fan speed?", + data = TextButtonData(text = "SP+"), + key = DeviceKey.FAN_SPEED_UP, + index = ++i, + ), + + CategoryConfiguration.OrderModel( + message = "Does it decrease fan speed?", + data = TextButtonData(text = "SP-"), + key = DeviceKey.FAN_SPEED_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is speed changed?", + data = IconButtonData(iconId = IconButtonData.IconType.WIND_SPEED), + key = DeviceKey.FAN_SPEED, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is it oscillated?", + data = TextButtonData(text = "OSC"), + key = DeviceKey.OSCILLATE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is it muted?", + data = IconButtonData(iconId = IconButtonData.IconType.MUTE), + key = DeviceKey.MUTE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it change mode?", + data = IconButtonData(iconId = IconButtonData.IconType.MODE), + key = DeviceKey.MODE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is timer changed?", + data = IconButtonData(iconId = IconButtonData.IconType.TIMER), + key = DeviceKey.TIMER, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is timer increased?", + data = TextButtonData(text = "T+"), + key = DeviceKey.TIMER_ADD, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Is timer decreased?", + data = TextButtonData(text = "T-"), + key = DeviceKey.TIMER_REDUCE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it swing?", + data = TextButtonData(text = "SWING"), + key = DeviceKey.SWING, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it go to sleep?", + data = TextButtonData(text = "SLEEP"), + key = DeviceKey.SLEEP, + index = ++i, + ) + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/ProjectorCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/ProjectorCategoryConfigGenerator.kt new file mode 100644 index 0000000..926101b --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/ProjectorCategoryConfigGenerator.kt @@ -0,0 +1,78 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object ProjectorCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i = 0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it increase volume?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_UP), + key = DeviceKey.VOL_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it decrease volume?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_DOWN), + key = DeviceKey.VOL_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it mute?", + data = IconButtonData(iconId = IconButtonData.IconType.MUTE), + key = DeviceKey.MUTE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it zoom in?", + data = IconButtonData(iconId = IconButtonData.IconType.ZOOM_IN), + key = DeviceKey.ZOOM_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it zoom out?", + data = IconButtonData(iconId = IconButtonData.IconType.ZOOM_OUT), + key = DeviceKey.ZOOM_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it increase brightness?", + data = IconButtonData(iconId = IconButtonData.IconType.BRIGHT_MORE), + key = DeviceKey.BRIGHTNESS_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it decrease brightness?", + data = IconButtonData(iconId = IconButtonData.IconType.BRIGHT_LESS), + key = DeviceKey.BRIGHTNESS_DOWN, + index = ++i, + ), + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/TvsCategoryConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/TvsCategoryConfigGenerator.kt new file mode 100644 index 0000000..27ee280 --- /dev/null +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/category/api/TvsCategoryConfigGenerator.kt @@ -0,0 +1,102 @@ +package com.flipperdevices.ifrmvp.generator.config.category.api + +import com.flipperdevices.ifrmvp.backend.model.CategoryConfiguration +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.category.api.DeviceKeyExt.getAllowedCategories +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.ShutterButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData + +object TvsCategoryConfigGenerator { + @Suppress("LongMethod") + fun generate(): CategoryConfiguration { + var i = 0 + return CategoryConfiguration( + orders = listOf( + CategoryConfiguration.OrderModel( + data = PowerButtonData(), + message = "Does %s turns on?", + key = DeviceKey.PWR, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it increase volume?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_UP), + key = DeviceKey.VOL_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it decrease volume?", + data = IconButtonData(iconId = IconButtonData.IconType.VOL_DOWN), + key = DeviceKey.VOL_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it mute?", + data = IconButtonData(iconId = IconButtonData.IconType.MUTE), + key = DeviceKey.MUTE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it sho next channel?", + data = TextButtonData(text = "CH+"), + key = DeviceKey.CH_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it show previous channel?", + data = TextButtonData(text = "CH-"), + key = DeviceKey.CH_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it pause?", + data = IconButtonData(iconId = IconButtonData.IconType.PAUSE), + key = DeviceKey.PAUSE, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it zoom in?", + data = IconButtonData(iconId = IconButtonData.IconType.ZOOM_IN), + key = DeviceKey.ZOOM_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it zoom out?", + data = IconButtonData(iconId = IconButtonData.IconType.ZOOM_OUT), + key = DeviceKey.ZOOM_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it increase brightness?", + data = IconButtonData(iconId = IconButtonData.IconType.BRIGHT_MORE), + key = DeviceKey.BRIGHTNESS_UP, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it decrease brightness?", + data = IconButtonData(iconId = IconButtonData.IconType.BRIGHT_LESS), + key = DeviceKey.BRIGHTNESS_DOWN, + index = ++i, + ), + CategoryConfiguration.OrderModel( + message = "Does it record?", + data = IconButtonData(iconId = IconButtonData.IconType.RECORD), + key = DeviceKey.RECORD, + index = ++i, + ), + ) + ) + } + + fun generate(categoryType: CategoryType): CategoryConfiguration { + val configuration = generate() + return CategoryConfiguration( + orders = configuration.orders.filter { + it.key.getAllowedCategories().contains(categoryType) + } + ) + } +} diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/DefaultDeviceConfigGenerator.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/DefaultDeviceConfigGenerator.kt index 2601ee1..76886bb 100644 --- a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/DefaultDeviceConfigGenerator.kt +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/DefaultDeviceConfigGenerator.kt @@ -2,10 +2,7 @@ package com.flipperdevices.ifrmvp.generator.config.device.api import com.flipperdevices.ifrmvp.backend.model.DeviceConfiguration import com.flipperdevices.ifrmvp.generator.config.device.api.DeviceKeyNamesProvider.Companion.getKey -import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier -import com.flipperdevices.infrared.editor.encoding.ByteArrayEncoder -import com.flipperdevices.infrared.editor.encoding.JvmEncoder -import com.flipperdevices.infrared.editor.encoding.InfraredRemoteEncoder +import com.flipperdevices.infrared.editor.encoding.InfraredRemoteEncoder.identifier import java.io.File class DefaultDeviceConfigGenerator(private val keyNamesProvider: DeviceKeyNamesProvider) : DeviceConfigGenerator { @@ -14,10 +11,7 @@ class DefaultDeviceConfigGenerator(private val keyNamesProvider: DeviceKeyNamesP val deviceKeyToInstance = remotes.mapNotNull { val name = it.name val deviceKey = keyNamesProvider.getKey(name) ?: return@mapNotNull null - val byteArray = InfraredRemoteEncoder.encode(it) - val hash = JvmEncoder(ByteArrayEncoder.Algorithm.SHA_256).encode(byteArray) - val identifier = IfrKeyIdentifier.Sha256(name = name, hash = hash) - deviceKey to identifier + deviceKey to it.identifier }.associate { pair -> pair } return DeviceConfiguration(deviceKeyToInstance) } 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 6344782..ec9e0ed 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 @@ -11,55 +11,105 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { DeviceKey.PWR -> listOf( "power", "pwr", + "pwron", "power", "power_r", "on", "on_off", "on/off", + "power_on", + "power on", + "powertoggle" ) DeviceKey.VOL_DOWN -> listOf( "vol-", "vol-_r", - "voldown" + "voldown", + "voldwn", + "vol_dn", + "vold", + "volume_down", + "volume down", + "vol_donw", + "vol_dwn", + "amp vol-", + "cent_volume_down", + "ch_vol-", + "master volume-", + "mastervol-", ) DeviceKey.VOL_UP -> listOf( "vol+", "vol+_r", - "volup" + "volup", + "vol_up", + "volu", + "volume_up", + "volume up", + "amp vol-", + "cent_volume_up", + "ch_vol+", + "master volume+", + "mastervol-", ) DeviceKey.CH_UP -> listOf( "ch+", "ch+_r", - "ch_next" + "ch_next", + "chn_up", + "chann_up", + "chan up", + "up", + "next", + "up/ch+", + "tv_ch+", ) DeviceKey.CH_DOWN -> listOf( "ch-", "ch-_r", - "ch_prev" + "ch_prev", + "chn_down", + "chann_down", + "chan down", + "down", + "prev", + "tv_ch-", ) DeviceKey.FOCUS_MORE -> listOf( - "focus-" + "focus-", + "focus_dwn", + "focusing-" ) DeviceKey.FOCUS_LESS -> listOf( - "focus+" + "focus+", + "focus_up", + "focusing+" ) DeviceKey.ZOOM_UP -> listOf( "zoom+", + "ezoom+", "zoom_up", - "digital zoom+" + "digital zoom+", + "zoom_in", + "ezoom_in", + "zoomin" ) DeviceKey.ZOOM_DOWN -> listOf( "zoom-", + "ezoom-", "zoom_down", - "digital zoom-" + "digital zoom-", + "zoom out", + "zoom_out", + "ezoom_out" ) DeviceKey.RESET -> listOf( @@ -112,14 +162,18 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { "input aux_r" ) + DeviceKey.REW -> listOf( + "rew", + ) + DeviceKey.HOME -> listOf( "home", - "home_r" + "home_r", ) DeviceKey.BACK -> listOf( "back", - "back_r" + "back_r", ) DeviceKey.MENU -> listOf( @@ -134,6 +188,15 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { "play_r" ) + DeviceKey.EJECT -> listOf( + "eject", + ) + + DeviceKey.STOP -> listOf( + "stop", + "stop_r" + ) + DeviceKey.MUTE -> listOf( "mute", "mute_r" @@ -163,6 +226,10 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { "strength" ) + DeviceKey.RECORD -> listOf( + "record", + ) + DeviceKey.MODE -> listOf( "mode", "mode_r" @@ -171,6 +238,7 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { DeviceKey.FAN_SPEED_UP -> listOf( "fanspeed+", "fan+", + "fan +", "fan_up", "speed_up" ) @@ -178,10 +246,27 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { DeviceKey.FAN_SPEED_DOWN -> listOf( "fanspeed-", "fan-", + "fan -", "fan_dn", "speed_down" ) + DeviceKey.SLEEP -> listOf( + "sleep" + ) + + DeviceKey.FAN_MEDIUM -> listOf( + "medium" + ) + + DeviceKey.FAN_HIGH -> listOf( + "high" + ) + + DeviceKey.FAN_LOW -> listOf( + "low" + ) + DeviceKey.SHAKE_WIND -> listOf( "shake_wind" ) @@ -213,7 +298,119 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { DeviceKey.SHUTTER -> listOf( "shutter", - "trigger" + "trigger", + "photo", + "picture" + ) + + DeviceKey.OK -> listOf( + "ok", + "enter", + "center", + "apply", + "sure" + ) + + DeviceKey.TIMER -> listOf( + "timer" + ) + + DeviceKey.COLD_WIND -> listOf( + "cold wind", + ) + + DeviceKey.COOL -> listOf( + "cool", + ) + + DeviceKey.TIMER_ADD -> listOf( + "timer+" + ) + + DeviceKey.OSCILLATE -> listOf( + "oscillate", + "osc", + "oscillation", + "oscilate", + "oscil" + ) + + DeviceKey.TIMER_REDUCE -> listOf( + "timer-" + ) + + DeviceKey.SWING -> listOf( + "swing" + ) + + DeviceKey.OFF -> listOf( + "off", + "power_off", + "power off", + "poweroff", + "pwroff" + ) + + DeviceKey.HEAT_ADD -> listOf( + "heat_hi", + "heat+" + ) + + DeviceKey.HEAT_REDUCE -> listOf( + "heat_lo", + "heat-" + ) + + DeviceKey.EXIT -> listOf( + "exit", + ) + + DeviceKey.INFO -> listOf( + "info", + ) + + DeviceKey.BRIGHTNESS_UP -> listOf( + "+brightness", + "bright_up", + "brightness up", + "brightness_up" + ) + + DeviceKey.BRIGHTNESS_DOWN -> listOf( + "-brightness", + "brightness_down", + "brightness_dn" + + ) + + DeviceKey.SET -> listOf( + "set" + ) + + DeviceKey.DELETE -> listOf( + "del", + "delete" + ) + + DeviceKey.VOD -> listOf( + "vod" + ) + + DeviceKey.LIVE_TV -> listOf( + "live tv", + "live tv_r", + "livetv", + "tv", + "letv" + ) + + DeviceKey.FAVORITE -> listOf( + "favorites", + "favorite" + ) + + DeviceKey.LIGHT -> listOf( + "light" ) } } 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 7881b7b..b2d6385 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 @@ -12,11 +12,10 @@ import com.flipperdevices.ifrmvp.backend.db.signal.table.SignalTable import com.flipperdevices.ifrmvp.backend.db.signal.table.UiPresetTable import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier import com.flipperdevices.ifrmvp.parser.util.ParserPathResolver -import com.flipperdevices.infrared.editor.encoding.ByteArrayEncoder -import com.flipperdevices.infrared.editor.encoding.JvmEncoder +import com.flipperdevices.infrared.editor.encoding.InfraredRemoteEncoder.identifier import com.flipperdevices.infrared.editor.model.InfraredRemote -import com.flipperdevices.infrared.editor.encoding.InfraredRemoteEncoder import com.flipperdevices.infrared.editor.viewmodel.InfraredKeyParser +import java.io.File import kotlinx.coroutines.CoroutineScope import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.JoinType @@ -24,7 +23,6 @@ import org.jetbrains.exposed.sql.andWhere import org.jetbrains.exposed.sql.batchInsert import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.transactions.transaction -import java.io.File internal class FillerController(private val database: Database) : CoroutineScope by IoCoroutineScope() { @@ -111,9 +109,7 @@ internal class FillerController(private val database: Database) : CoroutineScope this[SignalTable.frequency] = rawRemote?.frequency this[SignalTable.dutyCycle] = rawRemote?.dutyCycle this[SignalTable.data] = rawRemote?.data - val byteArray = InfraredRemoteEncoder.encode(remote) - val hash = JvmEncoder(ByteArrayEncoder.Algorithm.SHA_256).encode(byteArray) - this[SignalTable.hash] = hash + this[SignalTable.hash] = remote.identifier.hash } // ManyToMany file to signal references val irFileId = InfraredFileTable @@ -187,7 +183,7 @@ internal class FillerController(private val database: Database) : CoroutineScope .andWhere { InfraredFileToSignalTable.infraredFileId eq irFileId } .apply { when (keyIdentifier) { - IfrKeyIdentifier.Empty -> this + IfrKeyIdentifier.Empty -> error("Identifying is not possible!") is IfrKeyIdentifier.Sha256 -> { andWhere { SignalTable.hash eq keyIdentifier.hash } diff --git a/modules/kenerator/ui/build.gradle.kts b/modules/kenerator/ui/build.gradle.kts index 028c605..981256d 100644 --- a/modules/kenerator/ui/build.gradle.kts +++ b/modules/kenerator/ui/build.gradle.kts @@ -18,4 +18,5 @@ dependencies { implementation(projects.modules.database) implementation(projects.modules.infrared) implementation(projects.modules.kenerator.configuration) + implementation(projects.modules.kenerator.paths) } diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/UiGenerator.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/UiGenerator.kt new file mode 100644 index 0000000..6e72c78 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/UiGenerator.kt @@ -0,0 +1,7 @@ +package com.flipperdevices.ifrmvp.kenerator.ui + +import com.flipperdevices.ifrmvp.model.PagesLayout + +interface UiGenerator { + suspend fun generate(irFileId: Long): PagesLayout +} diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/UiGeneratorImpl.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/UiGeneratorImpl.kt new file mode 100644 index 0000000..23a3c29 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/UiGeneratorImpl.kt @@ -0,0 +1,58 @@ +package com.flipperdevices.ifrmvp.kenerator.ui + +import com.flipperdevices.bridge.dao.api.model.FlipperFileFormat +import com.flipperdevices.ifrmvp.backend.db.signal.dao.TableDao +import com.flipperdevices.ifrmvp.backend.model.CategoryType +import com.flipperdevices.ifrmvp.kenerator.ui.category.DefaultUiGenerator +import com.flipperdevices.ifrmvp.kenerator.ui.category.camera.CameraMap +import com.flipperdevices.ifrmvp.kenerator.ui.category.fan.FanMap +import com.flipperdevices.ifrmvp.kenerator.ui.category.tv.TvMap +import com.flipperdevices.ifrmvp.model.PagesLayout +import com.flipperdevices.ifrmvp.parser.util.ParserPathResolver +import com.flipperdevices.infrared.editor.viewmodel.InfraredKeyParser +import java.io.File + +class UiGeneratorImpl(private val tableDao: TableDao) : UiGenerator { + + private suspend fun getIfrFile(ifrFileId: Long): File { + val ifrFileModel = tableDao.ifrFileById(ifrFileId) + val brandModel = tableDao.getBrandById(ifrFileModel.brandId) + val categoryModel = tableDao.getCategoryById(brandModel.categoryId) + + val categoryFolderName = categoryModel.folderName + val brandFolderName = brandModel.folderName + val file = ParserPathResolver.ifrFile( + category = categoryFolderName, + brand = brandFolderName, + ifrFolderName = ifrFileModel.folderName + ) + return file + } + + + override suspend fun generate(irFileId: Long): PagesLayout { + val infraredFileModel = tableDao.ifrFileById(irFileId) + val brand = tableDao.getBrandById(infraredFileModel.brandId) + val category = tableDao.getCategoryById(brand.categoryId) + val categoryType = CategoryType.entries + .find { it.folderName == category.folderName } + ?: error("Could not find category with name ${category.folderName}") + + val signals = getIfrFile(irFileId) + .readText() + .let(FlipperFileFormat.Companion::fromFileContent) + .let(InfraredKeyParser::mapParsedKeyToInfraredRemotes) + println("infraredFileModel: ${category.folderName}/${brand.folderName}/${infraredFileModel.fileName} ") + + return when (categoryType) { + CategoryType.A_V_RECEIVER -> DefaultUiGenerator(TvMap()).generate(signals) + CategoryType.AIR_PURIFIERS -> DefaultUiGenerator(FanMap()).generate(signals) + CategoryType.BOX -> DefaultUiGenerator(TvMap()).generate(signals) + CategoryType.CAMERA -> DefaultUiGenerator(CameraMap()).generate(signals) + CategoryType.DVD -> DefaultUiGenerator(TvMap()).generate(signals) + CategoryType.FAN -> DefaultUiGenerator(FanMap()).generate(signals) + CategoryType.PROJECTOR -> DefaultUiGenerator(TvMap()).generate(signals) + CategoryType.TVS -> DefaultUiGenerator(TvMap()).generate(signals) + } + } +} diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/ChannelButton.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/ChannelButton.kt new file mode 100644 index 0000000..498347a --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/ChannelButton.kt @@ -0,0 +1,8 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.button + +import com.flipperdevices.infrared.editor.model.InfraredRemote + +class ChannelButton( + val next: InfraredRemote, + val prev: InfraredRemote +) \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/NavigationButton.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/NavigationButton.kt new file mode 100644 index 0000000..959b3ea --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/NavigationButton.kt @@ -0,0 +1,10 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.button + +import com.flipperdevices.infrared.editor.model.InfraredRemote + +data class NavigationButton( + val up: InfraredRemote, + val down: InfraredRemote, + val left: InfraredRemote, + val right: InfraredRemote +) \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/OkNavigationButton.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/OkNavigationButton.kt new file mode 100644 index 0000000..c630194 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/OkNavigationButton.kt @@ -0,0 +1,11 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.button + +import com.flipperdevices.infrared.editor.model.InfraredRemote + +data class OkNavigationButton( + val up: InfraredRemote, + val down: InfraredRemote, + val left: InfraredRemote, + val right: InfraredRemote, + val ok: InfraredRemote +) \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/VolButton.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/VolButton.kt new file mode 100644 index 0000000..1b05057 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/button/VolButton.kt @@ -0,0 +1,8 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.button + +import com.flipperdevices.infrared.editor.model.InfraredRemote + +class VolButton( + val add: InfraredRemote, + val reduce: InfraredRemote +) \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/DefaultUiGenerator.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/DefaultUiGenerator.kt new file mode 100644 index 0000000..118b432 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/DefaultUiGenerator.kt @@ -0,0 +1,57 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.category + +import com.flipperdevices.ifrmvp.kenerator.ui.category.tv.TvMap +import com.flipperdevices.ifrmvp.kenerator.ui.core.BrandMap +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findButtonsData +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findChannelButton +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findNavigationRemote +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findOkNavigationRemote +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findVolumeButton +import com.flipperdevices.ifrmvp.model.PageLayout +import com.flipperdevices.ifrmvp.model.PagesLayout +import com.flipperdevices.ifrmvp.model.buttondata.ChannelButtonData +import com.flipperdevices.ifrmvp.model.buttondata.NavigationButtonData +import com.flipperdevices.ifrmvp.model.buttondata.OkNavigationButtonData +import com.flipperdevices.ifrmvp.model.buttondata.VolumeButtonData +import com.flipperdevices.infrared.editor.encoding.InfraredRemoteEncoder.identifier +import com.flipperdevices.infrared.editor.model.InfraredRemote + +class DefaultUiGenerator(private val map: BrandMap) { + + fun generate(signals: List): PagesLayout { + return PagesLayout( + pages = listOf( + PageLayout( + buttons = buildList { + signals.findButtonsData().run(::addAll) + signals.findVolumeButton() + ?.let { VolumeButtonData(it.add.identifier, it.reduce.identifier) } + ?.run(::add) + signals.findChannelButton() + ?.let { ChannelButtonData(it.next.identifier, it.prev.identifier) } + ?.run(::add) + signals.findOkNavigationRemote() + ?.let { + OkNavigationButtonData( + upKeyIdentifier = it.up.identifier, + leftKeyIdentifier = it.left.identifier, + rightKeyIdentifier = it.right.identifier, + downKeyIdentifier = it.down.identifier, + okKeyIdentifier = it.ok.identifier + ) + }?.run(::add) + signals.findNavigationRemote() + ?.let { + NavigationButtonData( + upKeyIdentifier = it.up.identifier, + leftKeyIdentifier = it.left.identifier, + rightKeyIdentifier = it.right.identifier, + downKeyIdentifier = it.down.identifier, + ) + }?.run(::add) + }.let(map::transform) + ) + ) + ) + } +} \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/camera/CameraMap.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/camera/CameraMap.kt new file mode 100644 index 0000000..4b12bd6 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/camera/CameraMap.kt @@ -0,0 +1,43 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.category.camera + +import com.flipperdevices.ifrmvp.kenerator.ui.core.BrandMap +import com.flipperdevices.ifrmvp.model.IfrButton.Position +import com.flipperdevices.ifrmvp.model.buttondata.ButtonData.ButtonType + +internal class CameraMap : BrandMap by BrandMap.Default( + getMap = { + ButtonType.entries.associateWith { + when (it) { + ButtonType.POWER -> mutableListOf( + Position(x = 2, y = 0) + ) + + ButtonType.UNKNOWN, + ButtonType.TEXT, + ButtonType.ICON, + ButtonType.BASE64_IMAGE -> buildList { + Position(x = 0, y = 0).run(::add) + Position(x = 1, y = 0).run(::add) + Position(x = 3, y = 0).run(::add) + Position(x = 4, y = 0).run(::add) + (0..4).map { x -> Position(x = x, y = 1) }.run(::addAll) + (0..4).map { x -> Position(x = x, y = 10) }.run(::addAll) + }.toMutableList() + + + ButtonType.SHUTTER -> mutableListOf( + Position(x = 1, y = 3, containerHeight = 3, containerWidth = 3) + ) + + ButtonType.OK_NAVIGATION, + ButtonType.NAVIGATION -> mutableListOf( + Position(x = 1, y = 7, containerHeight = 3, containerWidth = 3) + ) + + + ButtonType.VOLUME, + ButtonType.CHANNEL -> mutableListOf() + } + }.toMutableMap() + } +) \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/dvd/DvdUiGenerator.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/dvd/DvdUiGenerator.kt new file mode 100644 index 0000000..6440a4b --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/dvd/DvdUiGenerator.kt @@ -0,0 +1,51 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.category.dvd + +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.kenerator.ui.category.tv.TvMap +import com.flipperdevices.ifrmvp.kenerator.ui.core.BrandMap +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findByKey +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findChannelButton +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findNavigationRemote +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findOkNavigationRemote +import com.flipperdevices.ifrmvp.kenerator.ui.util.RemotesListExt.findVolumeButton +import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier.Name +import com.flipperdevices.ifrmvp.model.PageLayout +import com.flipperdevices.ifrmvp.model.PagesLayout +import com.flipperdevices.ifrmvp.model.buttondata.ChannelButtonData +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData +import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData.IconType +import com.flipperdevices.ifrmvp.model.buttondata.NavigationButtonData +import com.flipperdevices.ifrmvp.model.buttondata.OkNavigationButtonData +import com.flipperdevices.ifrmvp.model.buttondata.PowerButtonData +import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData +import com.flipperdevices.ifrmvp.model.buttondata.VolumeButtonData +import com.flipperdevices.infrared.editor.model.InfraredRemote + +class DvdUiGenerator { + private val map: BrandMap = TvMap() + + fun generate(signals: List): PagesLayout { + return PagesLayout( + pages = listOf( + PageLayout( + buttons = listOfNotNull( + signals.findVolumeButton() + ?.let { VolumeButtonData(Name(it.add.name), Name(it.reduce.name)) }, + signals.findChannelButton() + ?.let { ChannelButtonData(Name(it.next.name), Name(it.prev.name)) }, + signals.findOkNavigationRemote() + ?.let { + OkNavigationButtonData( + upKeyIdentifier = Name(it.up.name), + leftKeyIdentifier = Name(it.left.name), + rightKeyIdentifier = Name(it.right.name), + downKeyIdentifier = Name(it.down.name), + okKeyIdentifier = Name(it.ok.name) + ) + }, + ).let(map::transform) + ) + ) + ) + } +} \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/fan/FanMap.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/fan/FanMap.kt new file mode 100644 index 0000000..4768351 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/fan/FanMap.kt @@ -0,0 +1,34 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.category.fan + +import com.flipperdevices.ifrmvp.kenerator.ui.core.BrandMap +import com.flipperdevices.ifrmvp.model.IfrButton.Position +import com.flipperdevices.ifrmvp.model.buttondata.ButtonData.ButtonType + +internal class FanMap : BrandMap by BrandMap.Default( + getMap = { + val oneTypeButtonLocations = buildList { + Position(x = 0, y = 0).run(::add) + Position(x = 4, y = 0).run(::add) + (0..4).map { x -> Position(x = x, y = 1) }.run(::addAll) + (0..4).map { x -> Position(x = x, y = 4) }.run(::addAll) + (0..4).map { x -> Position(x = x, y = 5) }.run(::addAll) + }.toMutableList() + ButtonType.entries.associateWith { + when (it) { + ButtonType.POWER -> oneTypeButtonLocations + + ButtonType.UNKNOWN, + ButtonType.TEXT, + ButtonType.ICON, + ButtonType.BASE64_IMAGE -> oneTypeButtonLocations + + + ButtonType.SHUTTER, + ButtonType.VOLUME, + ButtonType.CHANNEL, + ButtonType.OK_NAVIGATION, + ButtonType.NAVIGATION -> mutableListOf() + } + }.toMutableMap() + } +) \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/tv/TvMap.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/tv/TvMap.kt new file mode 100644 index 0000000..15096e6 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/category/tv/TvMap.kt @@ -0,0 +1,44 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.category.tv + +import com.flipperdevices.ifrmvp.kenerator.ui.core.BrandMap +import com.flipperdevices.ifrmvp.model.IfrButton.Position +import com.flipperdevices.ifrmvp.model.buttondata.ButtonData.ButtonType + +internal class TvMap : BrandMap by BrandMap.Default( + getMap = { + val navigationPositions = mutableListOf( + Position(x = 1, y = 3, containerHeight = 3, containerWidth = 3) + ) + val defaultPositions = buildList { + Position(x = 2, y = 0).run(::add) + Position(x = 4, y = 0).run(::add) + (0..4).map { x -> Position(x = x, y = 1) }.run(::addAll) + (0..4).map { x -> Position(x = x, y = 10) }.run(::addAll) + }.toMutableList() + ButtonType.entries.associateWith { + when (it) { + ButtonType.POWER -> mutableListOf( + Position(x = 0, y = 0) + ) + + ButtonType.UNKNOWN, + ButtonType.TEXT, + ButtonType.ICON, + ButtonType.BASE64_IMAGE -> defaultPositions + + ButtonType.CHANNEL -> mutableListOf( + Position(x = 0, y = 7, containerHeight = 3, containerWidth = 1) + ) + + ButtonType.OK_NAVIGATION, + ButtonType.NAVIGATION -> navigationPositions + + ButtonType.VOLUME -> mutableListOf( + Position(x = 4, y = 7, containerHeight = 3, containerWidth = 1) + ) + + ButtonType.SHUTTER -> mutableListOf() + } + }.toMutableMap() + } +) \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/core/BrandMap.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/core/BrandMap.kt new file mode 100644 index 0000000..8760c10 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/core/BrandMap.kt @@ -0,0 +1,37 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.core + +import com.flipperdevices.ifrmvp.model.IfrButton +import com.flipperdevices.ifrmvp.model.buttondata.ButtonData + +/** + * By given [BrandMap.Default.buildMap] map of locations by [ButtonData.ButtonType] + * [BrandMap] places available [ButtonData] in specified location + * + * Thus, we will have minimum amount of empty spaces for specific button types + * + * This class should be implemented using delegated and switch every [ButtonData.ButtonType] + */ +interface BrandMap { + fun transform(buttonsData: List): List + + class Default( + private val getMap: () -> MutableMap> + ) : BrandMap { + override fun transform(buttonsData: List): List { + val mutableMap = getMap.invoke() + return buttonsData.mapNotNull { buttonData -> + val position = mutableMap[buttonData.type] + val currentPosition = position?.removeFirstOrNull() + if (currentPosition == null) { + println("Could not find position for ${buttonData::class}") + return@mapNotNull null + } + println("Processing button ${buttonData.type} ${currentPosition}") + IfrButton( + data = buttonData, + position = currentPosition + ) + } + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..2769c82 --- /dev/null +++ b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/kenerator/ui/util/RemotesListExt.kt @@ -0,0 +1,305 @@ +package com.flipperdevices.ifrmvp.kenerator.ui.util + +import com.flipperdevices.ifrmvp.backend.model.DeviceKey +import com.flipperdevices.ifrmvp.generator.config.device.api.any.AnyDeviceKeyNamesProvider +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.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.infrared.editor.encoding.InfraredRemoteEncoder.identifier +import com.flipperdevices.infrared.editor.model.InfraredRemote + +internal object RemotesListExt { + fun List.findByKey(key: DeviceKey): InfraredRemote? { + val keyNames = AnyDeviceKeyNamesProvider.getKeyNames(key) + return firstOrNull { keyNames.map(String::lowercase).contains(it.name.lowercase()) } + } + + fun List.findNavigationRemote(): NavigationButton? { + return NavigationButton( + up = findByKey(DeviceKey.UP) ?: return null, + down = findByKey(DeviceKey.DOWN) ?: return null, + left = findByKey(DeviceKey.LEFT) ?: return null, + right = findByKey(DeviceKey.RIGHT) ?: return null, + ) + } + + fun List.findOkNavigationRemote(): OkNavigationButton? { + return OkNavigationButton( + up = findByKey(DeviceKey.UP) ?: return null, + down = findByKey(DeviceKey.DOWN) ?: return null, + left = findByKey(DeviceKey.LEFT) ?: return null, + right = findByKey(DeviceKey.RIGHT) ?: return null, + ok = findByKey(DeviceKey.OK) ?: return null, + ) + } + + fun List.findChannelButton(): ChannelButton? { + return ChannelButton( + next = findByKey(DeviceKey.CH_UP) ?: return null, + prev = findByKey(DeviceKey.CH_DOWN) ?: return null, + ) + } + + fun List.findVolumeButton(): VolButton? { + return VolButton( + add = findByKey(DeviceKey.VOL_UP) ?: return null, + reduce = findByKey(DeviceKey.VOL_DOWN) ?: return null, + ) + } + + fun List.findButtonsData(): List { + val remotes = this + return DeviceKey.entries.mapNotNull { deviceKey -> + when (deviceKey) { + DeviceKey.PWR -> remotes.findByKey(deviceKey)?.let { remote -> + PowerButtonData(keyIdentifier = remote.identifier) + } + + DeviceKey.SHUTTER -> remotes.findByKey(deviceKey)?.let { remote -> + ShutterButtonData(keyIdentifier = remote.identifier) + } + + + DeviceKey.FOCUS_MORE -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "F+") + } + + DeviceKey.FOCUS_LESS -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "F-") + } + + DeviceKey.ZOOM_UP -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.ZOOM_IN) + } + + DeviceKey.ZOOM_DOWN -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.ZOOM_OUT) + } + + DeviceKey.RESET -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.RESET) + } + + + DeviceKey.NEXT -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.NEXT) + } + + DeviceKey.PREVIOUS -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.PREVIOUS) + } + + DeviceKey.TV -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "TV") + } + + DeviceKey.AUX -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "AUX") + } + + DeviceKey.HOME -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.HOME) + } + + DeviceKey.BACK -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.BACK) + } + + DeviceKey.MENU -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.MENU) + } + + DeviceKey.PLAY -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.PLAY) + } + + DeviceKey.MUTE -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.MUTE) + } + + DeviceKey.EJECT -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.EJECT) + } + + DeviceKey.FAN_SPEED -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "FS") + } + + DeviceKey.NEAR -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "NEAR") + } + + DeviceKey.FAR -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "FAR") + } + + DeviceKey.PAUSE -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.PAUSE) + } + + + DeviceKey.WIND_SPEED -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "W+") + } + + DeviceKey.MODE -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "MODE") + } + + DeviceKey.LIGHT -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.LIGHT) + } + + DeviceKey.FAN_MEDIUM -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "F2") + } + + DeviceKey.FAN_HIGH -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "F3") + } + + DeviceKey.FAN_LOW -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "F1") + } + + DeviceKey.STOP -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.STOP) + } + + DeviceKey.EXIT -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.EXIT) + } + + DeviceKey.INFO -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.INFO) + } + + DeviceKey.TIMER -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "T") + } + + DeviceKey.OSCILLATE -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "OSC") + } + + DeviceKey.TIMER_ADD -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "TM+") + } + + DeviceKey.TIMER_REDUCE -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "TM-") + } + + DeviceKey.FAN_SPEED_UP -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "SP+") + } + + DeviceKey.FAN_SPEED_DOWN -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "SP-") + } + + DeviceKey.SLEEP -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "SLEEP") + } + + DeviceKey.SHAKE_WIND -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "SHK") + } + + DeviceKey.SWING -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "SWING") + } + + DeviceKey.OFF -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "OFF") + } + + DeviceKey.BRIGHTNESS_UP -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.BRIGHT_MORE) + } + + DeviceKey.BRIGHTNESS_DOWN -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.BRIGHT_LESS) + } + + DeviceKey.COLD_WIND -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "COLD_WIND") + } + + DeviceKey.COOL -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "COOL") + } + + DeviceKey.WIND_TYPE -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "WT") + } + + DeviceKey.TEMPERATURE_UP -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "T+") + } + + DeviceKey.TEMPERATURE_DOWN -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "T-") + } + + DeviceKey.HEAT_ADD -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "H+") + } + + DeviceKey.HEAT_REDUCE -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "H-") + } + + DeviceKey.ENERGY_SAVE -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.ENERGY_SAVE) + } + + + DeviceKey.REW -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "REW") + } + + DeviceKey.SET -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "SET") + } + + DeviceKey.DELETE -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.DELETE) + } + + DeviceKey.VOD -> remotes.findByKey(deviceKey)?.let { remote -> + TextButtonData(keyIdentifier = remote.identifier, text = "VOD") + } + + DeviceKey.LIVE_TV -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.LIVE_TV) + } + + DeviceKey.FAVORITE -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.FAVORITE) + } + + DeviceKey.RECORD -> remotes.findByKey(deviceKey)?.let { remote -> + IconButtonData(keyIdentifier = remote.identifier, iconId = IconType.RECORD) + } + + DeviceKey.LEFT, + DeviceKey.RIGHT, + DeviceKey.UP, + DeviceKey.DOWN, + DeviceKey.CH_DOWN, + DeviceKey.CH_UP, + DeviceKey.VOL_DOWN, + DeviceKey.OK, + DeviceKey.VOL_UP -> null + } + } + } +} \ No newline at end of file diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGenerator.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGenerator.kt deleted file mode 100644 index e2bd308..0000000 --- a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGenerator.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.flipperdevices.ifrmvp.parser - -import com.flipperdevices.ifrmvp.model.PagesLayout - -interface UiGenerator { - fun generate(remoteContent: String): PagesLayout -} diff --git a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGeneratorImpl.kt b/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGeneratorImpl.kt deleted file mode 100644 index 7eb699d..0000000 --- a/modules/kenerator/ui/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGeneratorImpl.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.flipperdevices.ifrmvp.parser - -import com.flipperdevices.bridge.dao.api.model.FlipperFileFormat -import com.flipperdevices.ifrmvp.model.IfrButton -import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier -import com.flipperdevices.ifrmvp.model.PageLayout -import com.flipperdevices.ifrmvp.model.PagesLayout -import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData -import com.flipperdevices.ifrmvp.model.buttondata.TextButtonData -import com.flipperdevices.infrared.editor.viewmodel.InfraredKeyParser - -class UiGeneratorImpl : UiGenerator { - override fun generate(remoteContent: String): PagesLayout { - val signals = remoteContent - .let(FlipperFileFormat.Companion::fromFileContent) - .let(InfraredKeyParser::mapParsedKeyToInfraredRemotes) - val windowSize = MAX_ROWS * MAX_COLUMNS - val chunks = when { - signals.size > windowSize -> signals.windowed(windowSize) { it } - else -> listOf(signals) - } - return PagesLayout( - pages = chunks.map { signals -> - var x = -1 - PageLayout( - buttons = signals.map { signal -> - x += 1 - val keyIdentifier = IfrKeyIdentifier.Name(signal.name) - IfrButton( - data = when { - signal.name.contains("pwr", true) || - signal.name.contains("power", true) || - signal.name.contains("on", true) -> { - IconButtonData( - keyIdentifier = keyIdentifier, - iconId = IconButtonData.IconType.POWER - ) - } - - else -> TextButtonData( - keyIdentifier = keyIdentifier, - text = signal.name - ) - }, - position = IfrButton.Position( - y = (x / MAX_COLUMNS) % MAX_ROWS, - x = x % MAX_COLUMNS - ) - ) - } - ) - } - ) - } - - companion object { - private const val MAX_COLUMNS = 5 - private const val MAX_ROWS = 11 - } -} 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 ae4c615..63a2802 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 @@ -6,114 +6,70 @@ package com.flipperdevices.ifrmvp.backend.model * The keys have comments in which devices they are present */ enum class DeviceKey { - // TV, Air_Purifiers, Box, DVD, Fan, Projector PWR, - - // TV, Box, Camera, DVD, Projector + SHUTTER, VOL_UP, - - // TV, Box, Camera, DVD, Projector VOL_DOWN, - - // TV, Box CH_UP, - - // TV, Box CH_DOWN, - - // Projector FOCUS_MORE, - - // Projector FOCUS_LESS, - - // Projector ZOOM_UP, - - // Projector ZOOM_DOWN, - - // Projector RESET, - - // A_V_receiver, Box, Camera, DVD, Projector DOWN, - - // A_V_receiver, Box, Camera, DVD, Projector UP, - - // A_V_receiver, Box, Camera, DVD, Projector RIGHT, - - // A_V_receiver, Box, Camera, DVD, Projector LEFT, - - // A_V_receiver, Camera, DVD NEXT, - - // A_V_receiver, Camera, DVD PREVIOUS, - - // A_V_receiver TV, - - // A_V_receiver AUX, - - // A_V_receiver, Box, DVD HOME, - - // A_V_receiver, Box, Camera, Projector BACK, - - // A_V_receiver, Camera, DVD, Projector MENU, - - // A_V_receiver, DVD PLAY, - - // A_V_receiver, Air_Purifiers, DVD, Fan, Projector MUTE, - - // Air_Purifiers + EJECT, FAN_SPEED, - - // Camera NEAR, - - // Camera FAR, - - // Camera - SHUTTER, - - // DVD PAUSE, - - // Fan + RECORD, WIND_SPEED, - - // Fan MODE, - - // Fan + LIGHT, + FAN_MEDIUM, + FAN_HIGH, + FAN_LOW, + STOP, + EXIT, + INFO, + TIMER, + OSCILLATE, + TIMER_ADD, + TIMER_REDUCE, FAN_SPEED_UP, - - // Fan FAN_SPEED_DOWN, - - // Fan + SLEEP, SHAKE_WIND, - - // Fan + SWING, + OFF, + BRIGHTNESS_UP, + BRIGHTNESS_DOWN, + COLD_WIND, + COOL, WIND_TYPE, - - // Fan TEMPERATURE_UP, - - // Fan TEMPERATURE_DOWN, - - // Fan - ENERGY_SAVE + HEAT_ADD, + HEAT_REDUCE, + ENERGY_SAVE, + OK, + REW, + SET, + DELETE, + VOD, + LIVE_TV, + FAVORITE } diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/backend/model/InfraredsResponse.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/backend/model/InfraredsResponse.kt new file mode 100644 index 0000000..5122b3f --- /dev/null +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/backend/model/InfraredsResponse.kt @@ -0,0 +1,10 @@ +package com.flipperdevices.ifrmvp.backend.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +class InfraredsResponse( + @SerialName("infrared_files") + val infraredFiles: List +) \ No newline at end of file diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/ButtonData.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/ButtonData.kt index faf28b1..5c79b74 100644 --- a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/ButtonData.kt +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/ButtonData.kt @@ -15,7 +15,10 @@ sealed interface ButtonData { ICON, BASE64_IMAGE, CHANNEL, + OK_NAVIGATION, NAVIGATION, VOLUME, + SHUTTER, + POWER } } diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/IconButtonData.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/IconButtonData.kt index 0c8373f..5d3f190 100644 --- a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/IconButtonData.kt +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/IconButtonData.kt @@ -14,7 +14,15 @@ data class IconButtonData( override val type: ButtonData.ButtonType = ButtonData.ButtonType.ICON enum class IconType { - BACK, HOME, INFO, MORE, MUTE, POWER, - COOL, HEAT, FAN + BACK, HOME, INFO, MORE, MUTE, + POWER, COOL, HEAT, FAN, CAMERA, + BRIGHT_MORE, BRIGHT_LESS, + PAUSE, PLAY, STOP, EXIT, + MENU, ZOOM_IN, ZOOM_OUT, + RESET, NEXT, PREVIOUS, + EJECT, RECORD, WIND_SPEED, + MODE, LIGHT, TIMER, OFF, + DELETE, LIVE_TV, FAVORITE, + ENERGY_SAVE, VOL_UP, VOL_DOWN } } diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/NavigationButtonData.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/NavigationButtonData.kt index b5c3855..a0d2541 100644 --- a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/NavigationButtonData.kt +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/NavigationButtonData.kt @@ -14,8 +14,6 @@ data class NavigationButtonData( val downKeyIdentifier: IfrKeyIdentifier, @SerialName("right_key_id") val rightKeyIdentifier: IfrKeyIdentifier, - @SerialName("ok_key_id") - val okKeyIdentifier: IfrKeyIdentifier, ) : ButtonData { override val type: ButtonData.ButtonType = ButtonData.ButtonType.NAVIGATION } diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/OkNavigationButtonData.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/OkNavigationButtonData.kt new file mode 100644 index 0000000..85c8ceb --- /dev/null +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/OkNavigationButtonData.kt @@ -0,0 +1,21 @@ +package com.flipperdevices.ifrmvp.model.buttondata + +import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class OkNavigationButtonData( + @SerialName("up_key_id") + val upKeyIdentifier: IfrKeyIdentifier, + @SerialName("left_key_id") + val leftKeyIdentifier: IfrKeyIdentifier, + @SerialName("down_key_id") + val downKeyIdentifier: IfrKeyIdentifier, + @SerialName("right_key_id") + val rightKeyIdentifier: IfrKeyIdentifier, + @SerialName("ok_key_id") + val okKeyIdentifier: IfrKeyIdentifier, +) : ButtonData { + override val type: ButtonData.ButtonType = ButtonData.ButtonType.OK_NAVIGATION +} diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/PowerButtonData.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/PowerButtonData.kt new file mode 100644 index 0000000..b7bf68d --- /dev/null +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/PowerButtonData.kt @@ -0,0 +1,13 @@ +package com.flipperdevices.ifrmvp.model.buttondata + +import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class PowerButtonData( + @SerialName("key_id") + override val keyIdentifier: IfrKeyIdentifier = IfrKeyIdentifier.Empty, +) : SingleKeyButtonData { + override val type: ButtonData.ButtonType = ButtonData.ButtonType.POWER +} diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/ShutterButtonData.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/ShutterButtonData.kt new file mode 100644 index 0000000..34d9bf9 --- /dev/null +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/buttondata/ShutterButtonData.kt @@ -0,0 +1,13 @@ +package com.flipperdevices.ifrmvp.model.buttondata + +import com.flipperdevices.ifrmvp.model.IfrKeyIdentifier +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ShutterButtonData( + @SerialName("key_id") + override val keyIdentifier: IfrKeyIdentifier = IfrKeyIdentifier.Empty, +) : SingleKeyButtonData { + override val type: ButtonData.ButtonType = ButtonData.ButtonType.SHUTTER +} diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataDecoder.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataDecoder.kt index 2d32446..f2d4d22 100644 --- a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataDecoder.kt +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataDecoder.kt @@ -5,6 +5,9 @@ import com.flipperdevices.ifrmvp.model.buttondata.ButtonData import com.flipperdevices.ifrmvp.model.buttondata.ChannelButtonData import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData import com.flipperdevices.ifrmvp.model.buttondata.NavigationButtonData +import com.flipperdevices.ifrmvp.model.buttondata.OkNavigationButtonData +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.model.buttondata.UnknownButtonData import com.flipperdevices.ifrmvp.model.buttondata.VolumeButtonData @@ -30,8 +33,8 @@ internal class ButtonDataDecoder(private val json: Json) { json.decodeFromJsonElement(jsonObject) } - ButtonData.ButtonType.NAVIGATION -> { - json.decodeFromJsonElement(jsonObject) + ButtonData.ButtonType.OK_NAVIGATION -> { + json.decodeFromJsonElement(jsonObject) } ButtonData.ButtonType.VOLUME -> { @@ -42,6 +45,17 @@ internal class ButtonDataDecoder(private val json: Json) { ButtonData.ButtonType.ICON -> { json.decodeFromJsonElement(jsonObject) } + + ButtonData.ButtonType.SHUTTER -> { + json.decodeFromJsonElement(jsonObject) + } + + ButtonData.ButtonType.NAVIGATION -> { + json.decodeFromJsonElement(jsonObject) + } + ButtonData.ButtonType.POWER -> { + json.decodeFromJsonElement(jsonObject) + } } } } diff --git a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataEncoder.kt b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataEncoder.kt index 48f6fa8..2e276e5 100644 --- a/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataEncoder.kt +++ b/modules/model/src/commonMain/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataEncoder.kt @@ -5,6 +5,9 @@ import com.flipperdevices.ifrmvp.model.buttondata.ButtonData import com.flipperdevices.ifrmvp.model.buttondata.ChannelButtonData import com.flipperdevices.ifrmvp.model.buttondata.IconButtonData import com.flipperdevices.ifrmvp.model.buttondata.NavigationButtonData +import com.flipperdevices.ifrmvp.model.buttondata.OkNavigationButtonData +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.model.buttondata.UnknownButtonData import com.flipperdevices.ifrmvp.model.buttondata.VolumeButtonData @@ -36,8 +39,8 @@ internal class ButtonDataEncoder(private val json: Json) { json.encodeToJsonElement(buttonData) } - ButtonData.ButtonType.NAVIGATION -> { - buttonData as NavigationButtonData + ButtonData.ButtonType.OK_NAVIGATION -> { + buttonData as OkNavigationButtonData json.encodeToJsonElement(buttonData) } @@ -50,6 +53,21 @@ internal class ButtonDataEncoder(private val json: Json) { buttonData as IconButtonData json.encodeToJsonElement(buttonData) } + + ButtonData.ButtonType.SHUTTER -> { + buttonData as ShutterButtonData + json.encodeToJsonElement(buttonData) + } + + ButtonData.ButtonType.NAVIGATION -> { + buttonData as NavigationButtonData + json.encodeToJsonElement(buttonData) + } + + ButtonData.ButtonType.POWER -> { + buttonData as PowerButtonData + json.encodeToJsonElement(buttonData) + } }.jsonObject } } diff --git a/modules/model/src/commonTest/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataSerializerTest.kt b/modules/model/src/commonTest/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataSerializerTest.kt index 1b29dc6..b875b59 100644 --- a/modules/model/src/commonTest/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataSerializerTest.kt +++ b/modules/model/src/commonTest/kotlin/com/flipperdevices/ifrmvp/model/serialization/ButtonDataSerializerTest.kt @@ -25,7 +25,7 @@ class ButtonDataSerializerTest { IfrButton( data = IconButtonData( keyIdentifier = IfrKeyIdentifier.Name("Hello"), - iconId = IconButtonData.IconType.POWER + iconId = IconButtonData.IconType.FAN ), position = IfrButton.Position(0, 0) ).run(::assertSerializable) diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/Application.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/Application.kt index f97ff96..0f6e2f5 100644 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/Application.kt +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/Application.kt @@ -23,7 +23,7 @@ internal fun Application.module(rootModule: RootModule, logger: Logger) { rootModule.signalModule.registry, rootModule.keyModule.registry, rootModule.uiModule.registry, - rootModule.configGenModule.registry + rootModule.infraredsModule.registry ).forEach { routeRegistry -> routeRegistry.register(this) } } logger.info("Started!") diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/di/RootModule.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/di/RootModule.kt index e13b1d9..ad7e41b 100644 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/di/RootModule.kt +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/di/RootModule.kt @@ -5,7 +5,7 @@ import com.flipperdevices.ifrmvp.backend.db.signal.di.SignalApiModule import com.flipperdevices.ifrmvp.backend.envkonfig.EnvKonfig import com.flipperdevices.ifrmvp.backend.route.brands.di.BrandsModule import com.flipperdevices.ifrmvp.backend.route.categories.di.CategoriesModule -import com.flipperdevices.ifrmvp.backend.route.configgen.di.ConfigGenModule +import com.flipperdevices.ifrmvp.backend.route.infrareds.di.InfraredsModule import com.flipperdevices.ifrmvp.backend.route.key.di.KeyModule import com.flipperdevices.ifrmvp.backend.route.signal.di.SignalModule import com.flipperdevices.ifrmvp.backend.route.ui.di.UiModule @@ -21,7 +21,7 @@ interface RootModule { val signalModule: SignalModule val keyModule: KeyModule val uiModule: UiModule - val configGenModule: ConfigGenModule + val infraredsModule: InfraredsModule class Default : RootModule { override val coreModule by lazy { @@ -49,14 +49,10 @@ interface RootModule { override val uiModule: UiModule by lazy { UiModule.Default( signalApiModule = signalApiModule, - keyModule = keyModule ) } - override val configGenModule: ConfigGenModule by lazy { - ConfigGenModule.Default( - keyModule = keyModule, - apiModule = signalApiModule - ) + override val infraredsModule: InfraredsModule by lazy { + InfraredsModule.Default(signalApiModule) } } } diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/configgen/di/ConfigGenModule.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/configgen/di/ConfigGenModule.kt deleted file mode 100644 index 1441d8f..0000000 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/configgen/di/ConfigGenModule.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.flipperdevices.ifrmvp.backend.route.configgen.di - -import com.flipperdevices.ifrmvp.backend.core.route.RouteRegistry -import com.flipperdevices.ifrmvp.backend.db.signal.di.SignalApiModule -import com.flipperdevices.ifrmvp.backend.route.configgen.presentation.ConfigGenRouteRegistry -import com.flipperdevices.ifrmvp.backend.route.key.di.KeyModule - -interface ConfigGenModule { - val registry: RouteRegistry - - class Default( - keyModule: KeyModule, - apiModule: SignalApiModule - ) : ConfigGenModule { - override val registry: RouteRegistry by lazy { - ConfigGenRouteRegistry( - keyRouteRepository = keyModule.keyRouteRepository, - tableDao = apiModule.tableDao - ) - } - } -} diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/configgen/presentation/ConfigGenRouteRegistry.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/configgen/presentation/ConfigGenRouteRegistry.kt deleted file mode 100644 index 6aa0a0a..0000000 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/configgen/presentation/ConfigGenRouteRegistry.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.flipperdevices.ifrmvp.backend.route.configgen.presentation - -import com.flipperdevices.ifrmvp.backend.core.route.RouteRegistry -import com.flipperdevices.ifrmvp.backend.db.signal.dao.TableDao -import com.flipperdevices.ifrmvp.backend.model.CategoryType -import com.flipperdevices.ifrmvp.backend.route.key.data.KeyRouteRepository -import com.flipperdevices.ifrmvp.backend.route.key.presentation.KeySwagger -import com.flipperdevices.ifrmvp.generator.config.category.api.AllCategoryConfigGenerator -import com.flipperdevices.ifrmvp.generator.config.device.api.DefaultDeviceConfigGenerator -import com.flipperdevices.ifrmvp.generator.config.device.api.any.AnyDeviceKeyNamesProvider -import io.github.smiley4.ktorswaggerui.dsl.routing.get -import io.ktor.server.response.respond -import io.ktor.server.routing.Routing - -internal class ConfigGenRouteRegistry( - private val keyRouteRepository: KeyRouteRepository, - private val tableDao: TableDao -) : RouteRegistry { - private fun Routing.deviceConfigRoute() { - get( - path = "configuration/device", - builder = { with(KeySwagger) { createSwaggerDefinition() } }, - body = { - val ifrFileId = context.parameters["ifr_file_id"]?.toLongOrNull() ?: -1 - val file = keyRouteRepository.getIfrFile(ifrFileId) - if (!file.exists()) error("Ifr file doesn't exists! ${file.absolutePath}") - context.respond(DefaultDeviceConfigGenerator(AnyDeviceKeyNamesProvider).generate(file)) - } - ) - } - - private fun Routing.categoryConfigRoute() { - get( - path = "configuration/category", - builder = { with(KeySwagger) { createSwaggerDefinition() } }, - body = { - val categoryId = context.parameters["category_id"]?.toLongOrNull() ?: -1 - val category = tableDao.getCategoryById(categoryId) - val categoryType = CategoryType - .entries - .firstOrNull { entry -> entry.folderName == category.folderName } - ?: error("Category with fodlerName ${category.folderName} not found!") - val configuration = AllCategoryConfigGenerator.generate(categoryType) - context.respond(configuration) - } - ) - } - - override fun register(routing: Routing) { - routing.deviceConfigRoute() - routing.categoryConfigRoute() - } -} diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/data/InfraredsRepository.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/data/InfraredsRepository.kt new file mode 100644 index 0000000..df7663e --- /dev/null +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/data/InfraredsRepository.kt @@ -0,0 +1,29 @@ +package com.flipperdevices.ifrmvp.backend.route.infrareds.data + +import com.flipperdevices.ifrmvp.backend.db.signal.dao.TableDao +import com.flipperdevices.ifrmvp.backend.db.signal.table.InfraredFileTable +import com.flipperdevices.ifrmvp.backend.model.IfrFileModel +import org.jetbrains.exposed.sql.Database +import org.jetbrains.exposed.sql.selectAll +import org.jetbrains.exposed.sql.transactions.transaction + +internal class InfraredsRepository( + private val database: Database, + private val tableDao: TableDao +) { + suspend fun fetchInfrareds(brandId: Long): List { + tableDao.getBrandById(brandId) + return transaction(database) { + InfraredFileTable.selectAll() + .where { InfraredFileTable.brandId eq brandId } + .map { + IfrFileModel( + id = it[InfraredFileTable.id].value, + brandId = it[InfraredFileTable.brandId].value, + fileName = it[InfraredFileTable.fileName], + folderName = it[InfraredFileTable.folderName], + ) + } + } + } +} \ No newline at end of file diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/di/InfraredsModule.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/di/InfraredsModule.kt new file mode 100644 index 0000000..ea0e943 --- /dev/null +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/di/InfraredsModule.kt @@ -0,0 +1,23 @@ +package com.flipperdevices.ifrmvp.backend.route.infrareds.di + +import com.flipperdevices.ifrmvp.backend.core.route.RouteRegistry +import com.flipperdevices.ifrmvp.backend.db.signal.di.SignalApiModule +import com.flipperdevices.ifrmvp.backend.route.brands.data.BrandsRepositoryImpl +import com.flipperdevices.ifrmvp.backend.route.brands.presentation.BrandsRouteRegistry +import com.flipperdevices.ifrmvp.backend.route.infrareds.data.InfraredsRepository +import com.flipperdevices.ifrmvp.backend.route.infrareds.presentation.InfraredsRouteRegistry + +interface InfraredsModule { + val registry: RouteRegistry + + class Default(signalApiModule: SignalApiModule) : InfraredsModule { + override val registry: RouteRegistry by lazy { + InfraredsRouteRegistry( + infraredsRepository = InfraredsRepository( + database = signalApiModule.database, + tableDao = signalApiModule.tableDao + ) + ) + } + } +} diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/presentation/InfraredsRouteRegistry.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/presentation/InfraredsRouteRegistry.kt new file mode 100644 index 0000000..3be8e1c --- /dev/null +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/presentation/InfraredsRouteRegistry.kt @@ -0,0 +1,37 @@ +package com.flipperdevices.ifrmvp.backend.route.infrareds.presentation + +import com.flipperdevices.ifrmvp.backend.core.route.RouteRegistry +import com.flipperdevices.ifrmvp.backend.model.BrandsResponse +import com.flipperdevices.ifrmvp.backend.model.InfraredsResponse +import com.flipperdevices.ifrmvp.backend.route.brands.data.BrandsRepository +import com.flipperdevices.ifrmvp.backend.route.infrareds.data.InfraredsRepository +import io.github.smiley4.ktorswaggerui.dsl.routing.get +import io.ktor.server.response.respond +import io.ktor.server.routing.Routing + +internal class InfraredsRouteRegistry( + private val infraredsRepository: InfraredsRepository +) : RouteRegistry { + + private fun Routing.statusRoute() { + get( + path = "infrareds", + builder = { with(InfraredsSwagger) { createSwaggerDefinition() } }, + body = { + val brandId = context.request + .queryParameters["brand_id"] + ?.toLongOrNull() + ?: -1 + val brandsResponse = InfraredsResponse( + infraredFiles = infraredsRepository.fetchInfrareds(brandId) + .sortedBy { infraredModel -> infraredModel.fileName.lowercase() } + ) + context.respond(brandsResponse) + } + ) + } + + override fun register(routing: Routing) { + routing.statusRoute() + } +} diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/presentation/InfraredsSwagger.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/presentation/InfraredsSwagger.kt new file mode 100644 index 0000000..d6aa156 --- /dev/null +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/infrareds/presentation/InfraredsSwagger.kt @@ -0,0 +1,33 @@ +package com.flipperdevices.ifrmvp.backend.route.infrareds.presentation + +import com.flipperdevices.ifrmvp.backend.model.BrandsResponse +import com.flipperdevices.ifrmvp.backend.model.ErrorResponseModel +import io.github.smiley4.ktorswaggerui.dsl.routes.OpenApiRoute +import io.ktor.http.HttpStatusCode + +internal object InfraredsSwagger { + fun OpenApiRoute.createSwaggerDefinition() { + description = "Get list of brand's infrared files" + request { + queryParameter("brand_id") { + description = "Unique id of the brand" + required = true + } + } + response { + HttpStatusCode.OK to { + description = "Brand's infrared files fetched successfully" + body { + description = "List of brand's infrared files" + } + } + + default { + description = "Could not process request" + body { + description = "Unhandled exception" + } + } + } + } +} diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt index 08e9ed4..ec92b79 100644 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/signal/presentation/SignalRouteRegistry.kt @@ -178,6 +178,7 @@ internal class SignalRouteRegistry( categoryType = categoryType, index = index ) + println("Getting order: $order index: $index") // todo When orders is empty we can't define the next key. Need to think how to bypass it or may be just log if (order == null) { val infraredFileId = transaction(database) { @@ -224,6 +225,7 @@ internal class SignalRouteRegistry( body = { @Suppress("UnusedPrivateProperty") val signalRequestModel = context.receive() + println("signalRequestModel: ${signalRequestModel}") val brand = tableDao.getBrandById(signalRequestModel.brandId) val category = tableDao.getCategoryById(brand.categoryId) diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/di/UiModule.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/di/UiModule.kt index 8114999..4b6c690 100644 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/di/UiModule.kt +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/di/UiModule.kt @@ -5,23 +5,17 @@ import com.flipperdevices.ifrmvp.backend.db.signal.di.SignalApiModule import com.flipperdevices.ifrmvp.backend.route.key.di.KeyModule import com.flipperdevices.ifrmvp.backend.route.ui.data.UiFileRepositoryImpl import com.flipperdevices.ifrmvp.backend.route.ui.presentation.UiRouteRegistry -import com.flipperdevices.ifrmvp.parser.UiGeneratorImpl +import com.flipperdevices.ifrmvp.kenerator.ui.UiGeneratorImpl interface UiModule { val registry: RouteRegistry class Default( signalApiModule: SignalApiModule, - keyModule: KeyModule ) : UiModule { override val registry: RouteRegistry by lazy { UiRouteRegistry( - keyRouteRepository = keyModule.keyRouteRepository, - uiGenerator = UiGeneratorImpl(), - uiFileRepository = UiFileRepositoryImpl( - tableDao = signalApiModule.tableDao, - database = signalApiModule.database - ) + uiGenerator = UiGeneratorImpl(signalApiModule.tableDao), ) } } diff --git a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/presentation/UiRouteRegistry.kt b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/presentation/UiRouteRegistry.kt index cdee172..b5c2865 100644 --- a/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/presentation/UiRouteRegistry.kt +++ b/web-api/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/ui/presentation/UiRouteRegistry.kt @@ -1,9 +1,10 @@ package com.flipperdevices.ifrmvp.backend.route.ui.presentation import com.flipperdevices.ifrmvp.backend.core.route.RouteRegistry +import com.flipperdevices.ifrmvp.backend.db.signal.dao.TableDao import com.flipperdevices.ifrmvp.backend.route.key.data.KeyRouteRepository import com.flipperdevices.ifrmvp.backend.route.ui.data.UiFileRepository -import com.flipperdevices.ifrmvp.parser.UiGenerator +import com.flipperdevices.ifrmvp.kenerator.ui.UiGenerator import io.github.smiley4.ktorswaggerui.dsl.routing.get import io.ktor.http.ContentType import io.ktor.server.response.respond @@ -11,9 +12,7 @@ import io.ktor.server.response.respondText import io.ktor.server.routing.Routing internal class UiRouteRegistry( - private val keyRouteRepository: KeyRouteRepository, private val uiGenerator: UiGenerator, - private val uiFileRepository: UiFileRepository ) : RouteRegistry { private fun Routing.statusRoute() { @@ -22,17 +21,8 @@ internal class UiRouteRegistry( builder = { with(UiSwagger) { createSwaggerDefinition() } }, body = { val ifrFileId = context.parameters["ifr_file_id"]?.toLongOrNull() ?: -1 - val uiPresetModel = uiFileRepository.getUiFileModelOrNull(ifrFileId) - if (uiPresetModel == null) { - val ifrFile = keyRouteRepository.getIfrFile(ifrFileId) - context.respond(uiGenerator.generate(ifrFile.readText())) - } else { - val content = uiFileRepository.getUiFileContent(uiPresetModel) - context.respondText( - contentType = ContentType.Application.Json, - text = content - ) - } + + context.respond(uiGenerator.generate(irFileId = ifrFileId)) } ) }