-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df6d4b9
commit 69fe9da
Showing
12 changed files
with
175 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.jvm") | ||
alias(libs.plugins.kotlin.serialization) | ||
} | ||
|
||
dependencies { | ||
// Exposed | ||
implementation(libs.exposed.core) | ||
implementation(libs.exposed.dao) | ||
implementation(libs.kotlin.coroutines) | ||
implementation(libs.kotlin.serialization.json) | ||
implementation(kotlin("test")) | ||
// Local | ||
implementation(projects.modules.buildKonfig) | ||
implementation(projects.modules.apiStatus) | ||
implementation(projects.modules.core) | ||
implementation(projects.modules.sharedBackendModel) | ||
implementation(projects.modules.sharedUiModel) | ||
implementation(projects.modules.apiStatus) | ||
implementation(projects.modules.parser) | ||
} |
7 changes: 7 additions & 0 deletions
7
modules/ui-generator/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.flipperdevices.ifrmvp.parser | ||
|
||
import com.flipperdevices.ifrmvp.model.PagesLayout | ||
|
||
interface UiGenerator { | ||
fun generate(remoteContent: String): PagesLayout | ||
} |
43 changes: 43 additions & 0 deletions
43
modules/ui-generator/src/main/kotlin/com/flipperdevices/ifrmvp/parser/UiGeneratorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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.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 chunks = signals.chunked(MAX_ROWS * MAX_COLUMNS) { it } | ||
return PagesLayout( | ||
pages = chunks.map { signals -> | ||
var x = -1 | ||
PageLayout( | ||
buttons = signals.map { signal -> | ||
x += 1 | ||
IfrButton( | ||
data = TextButtonData( | ||
keyIdentifier = IfrKeyIdentifier.Name(signal.name), | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...pi/src/main/kotlin/com/flipperdevices/ifrmvp/backend/route/key/data/KeyRouteRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.flipperdevices.ifrmvp.backend.route.key.data | ||
|
||
import com.flipperdevices.ifrmvp.backend.db.signal.table.BrandTable | ||
import com.flipperdevices.ifrmvp.backend.db.signal.table.CategoryTable | ||
import com.flipperdevices.ifrmvp.backend.db.signal.table.IfrFileTable | ||
import com.flipperdevices.ifrmvp.backend.model.IfrFileModel | ||
import com.flipperdevices.ifrmvp.parser.util.ParserPathResolver | ||
import org.jetbrains.exposed.sql.Database | ||
import org.jetbrains.exposed.sql.selectAll | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import java.io.File | ||
|
||
interface KeyRouteRepository { | ||
suspend fun getIfrFile(ifrFileId: Long): File | ||
} | ||
|
||
class KeyRouteRepositoryImpl(private val database: Database) : KeyRouteRepository { | ||
override suspend fun getIfrFile(ifrFileId: Long): File { | ||
val ifrFileModel = transaction(database) { | ||
IfrFileTable.selectAll() | ||
.where { IfrFileTable.id eq ifrFileId } | ||
.map { | ||
IfrFileModel( | ||
id = it[IfrFileTable.id].value, | ||
categoryId = it[IfrFileTable.categoryId].value, | ||
brandId = it[IfrFileTable.brandId].value, | ||
fileName = it[IfrFileTable.fileName] | ||
) | ||
} | ||
.firstOrNull() | ||
?: error("Ir file with id $ifrFileId not found!") | ||
} | ||
val categoryFolderName = transaction(database) { | ||
CategoryTable.select(CategoryTable.folderName) | ||
.where { CategoryTable.id eq ifrFileModel.categoryId } | ||
.map { it[CategoryTable.folderName] } | ||
.firstOrNull() | ||
?: error("Category with id ${ifrFileModel.categoryId} not found!") | ||
} | ||
val brandFolderName = transaction(database) { | ||
BrandTable.select(BrandTable.displayName) | ||
.where { BrandTable.id eq ifrFileModel.brandId } | ||
.map { it[BrandTable.displayName] } | ||
.firstOrNull() | ||
?: error("Brand with id ${ifrFileModel.brandId} not found!") | ||
} | ||
println("Category :$categoryFolderName brand: $brandFolderName ifr: ${ifrFileModel.fileName}") | ||
val file = ParserPathResolver.ifrFile( | ||
category = categoryFolderName, | ||
brand = brandFolderName, | ||
ifrFolderName = ifrFileModel.fileName.replaceFirst(".ir", "") // todo | ||
) | ||
return file | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 4 additions & 44 deletions
48
.../main/kotlin/com/flipperdevices/ifrmvp/backend/route/key/presentation/KeyRouteRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters