Skip to content

Commit

Permalink
Merge pull request #68 from kaleidot725/feat/send_tab_key
Browse files Browse the repository at this point in the history
feat: add tab key
  • Loading branch information
kaleidot725 authored Jun 1, 2024
2 parents f5e39b5 + d87556a commit 6f38323
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/jvmMain/kotlin/jp/kaleidot725/adbpad/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,21 @@ private fun DeviceContent(
inputTextStateHolder.sendInputText()
},
canSendInputText = inputTextState.canSendInputText,
canSendTabKey = inputTextState.canSendTabKey,
onSendTabKey = {
inputTextStateHolder.sendTabCommand()
},
onSaveInputText = {
inputTextStateHolder.saveInputText()
},
canSaveInputText = inputTextState.canSaveInputText,
// Commands
commands = inputTextState.commands,
onSendCommand = { text ->
inputTextStateHolder.sendCommand(text)
inputTextStateHolder.sendTextCommand(text)
},
canSendCommand = inputTextState.canSendCommand,
isSendingTab = inputTextState.isSendingTab,
onDeleteCommand = { text ->
inputTextStateHolder.deleteInputText(text)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import jp.kaleidot725.adbpad.domain.usecase.text.AddTextCommandUseCase
import jp.kaleidot725.adbpad.domain.usecase.text.DeleteTextCommandUseCase
import jp.kaleidot725.adbpad.domain.usecase.text.ExecuteTextCommandUseCase
import jp.kaleidot725.adbpad.domain.usecase.text.GetTextCommandUseCase
import jp.kaleidot725.adbpad.domain.usecase.text.SendTabCommandUseCase
import jp.kaleidot725.adbpad.domain.usecase.text.SendUserInputTextCommandUseCase
import jp.kaleidot725.adbpad.domain.usecase.theme.GetDarkModeFlowUseCase
import jp.kaleidot725.adbpad.domain.usecase.window.GetWindowSizeUseCase
Expand Down Expand Up @@ -112,4 +113,7 @@ val domainModule =
factory {
CopyScreenshotToClipboardUseCase(get(), get())
}
factory {
SendTabCommandUseCase(get(), get())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package jp.kaleidot725.adbpad.domain.model.command

import com.malinskiy.adam.request.shell.v1.ShellCommandRequest

data class KeyCommand(
val keycode: Int,
val isRunning: Boolean = false,
) {
val requests: List<ShellCommandRequest> = listOf(ShellCommandRequest("input keyevent $keycode"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ object Language : StringResources {
get() = getCurrentResources().notFoundScreenshot
override val execute: String
get() = getCurrentResources().execute
override val tab: String
get() = getCurrentResources().tab
override val save: String
get() = getCurrentResources().save
override val delete: String
Expand Down Expand Up @@ -120,6 +122,14 @@ object Language : StringResources {
get() = getCurrentResources().textCommandEndEventFormat
override val textCommandErrorEventFormat: String
get() = getCurrentResources().textCommandErrorEventFormat

override val keyCommandStartEventFormat: String
get() = getCurrentResources().keyCommandStartEventFormat
override val keyCommandEndEventFormat: String
get() = getCurrentResources().keyCommandEndEventFormat
override val keyCommandErrorEventFormat: String
get() = getCurrentResources().keyCommandErrorEventFormat

override val screenshotCommandStartEventFormat: String
get() = getCurrentResources().screenshotCommandStartEventFormat
override val screenshotCommandEndEventFormat: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object EnglishResources : StringResources {
override val execute = "Run"
override val save = "Save"
override val delete = "Delete"
override val tab = "Tab"
override val send = "Send"
override val cancel = "Cancel"
override val targetDevice = "Devices"
Expand Down Expand Up @@ -65,6 +66,10 @@ object EnglishResources : StringResources {
override val textCommandEndEventFormat = "End sending text「%s」"
override val textCommandErrorEventFormat = "Error sending text「%s」"

override val keyCommandStartEventFormat = "Start sending key「%s」"
override val keyCommandEndEventFormat = "End sending key「%s」"
override val keyCommandErrorEventFormat = "Error sending key「%s」"

override val screenshotCommandStartEventFormat = "Start taking screenshot"
override val screenshotCommandEndEventFormat = "End taking screenshot"
override val screenshotCommandErrorEventFormat = "Error taking screenshot"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object JapaneseResources : StringResources {
override val execute = "実行"
override val save = "保存"
override val delete = "削除"
override val tab = "Tab"
override val send = "送信"
override val cancel = "キャンセル"
override val targetDevice = "端末"
Expand Down Expand Up @@ -65,6 +66,10 @@ object JapaneseResources : StringResources {
override val textCommandEndEventFormat = "「%s」のテキスト送信が完了しました"
override val textCommandErrorEventFormat = "「%s」のテキスト送信に失敗しました"

override val keyCommandStartEventFormat = "「%s」のキー送信を開始しました"
override val keyCommandEndEventFormat = "「%s」のキー送信が完了しました"
override val keyCommandErrorEventFormat = "「%s」のキー送信に失敗しました"

override val screenshotCommandStartEventFormat = "スクリーンショットの撮影を開始しました"
override val screenshotCommandEndEventFormat = "スクリーンショットの撮影が完了しました"
override val screenshotCommandErrorEventFormat = "スクリーンショットの撮影に失敗しました"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface StringResources {
val execute: String
val save: String
val delete: String
val tab: String
val send: String
val cancel: String
val targetDevice: String
Expand Down Expand Up @@ -64,6 +65,10 @@ interface StringResources {
val textCommandEndEventFormat: String
val textCommandErrorEventFormat: String

val keyCommandStartEventFormat: String
val keyCommandEndEventFormat: String
val keyCommandErrorEventFormat: String

val screenshotCommandStartEventFormat: String
val screenshotCommandEndEventFormat: String
val screenshotCommandErrorEventFormat: String
Expand Down
24 changes: 24 additions & 0 deletions src/jvmMain/kotlin/jp/kaleidot725/adbpad/domain/model/log/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ interface Event {
get() = Level.ERROR
}

data class StartSendKeyCommand(val code: Int) : Event {
override val message: String
get() = String.format(Language.keyCommandStartEventFormat, code.toString())

override val level: Level
get() = Level.INFO
}

data class EndSendKeyCommand(val code: Int) : Event {
override val message: String
get() = String.format(Language.keyCommandEndEventFormat, code.toString())

override val level: Level
get() = Level.INFO
}

data class ErrorSendKeyCommand(val code: Int) : Event {
override val message: String
get() = String.format(Language.keyCommandErrorEventFormat, code.toString())

override val level: Level
get() = Level.ERROR
}

object StartSendScreenshotCommand : Event {
override val message: String
get() = Language.screenshotCommandStartEventFormat
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package jp.kaleidot725.adbpad.domain.repository

import jp.kaleidot725.adbpad.domain.model.device.Device

interface KeyCommandRepository {
suspend fun sendKeyCommand(
device: Device,
keycode: Int,
onStart: suspend () -> Unit,
onComplete: suspend () -> Unit,
onFailed: suspend () -> Unit,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package jp.kaleidot725.adbpad.domain.usecase.text

import jp.kaleidot725.adbpad.domain.model.device.Device
import jp.kaleidot725.adbpad.domain.model.log.Event
import jp.kaleidot725.adbpad.domain.repository.EventRepository
import jp.kaleidot725.adbpad.domain.repository.KeyCommandRepository

class SendTabCommandUseCase(
private val eventRepository: EventRepository,
private val keyCommandRepository: KeyCommandRepository,
) {
suspend operator fun invoke(
device: Device,
onStart: suspend () -> Unit,
onFailed: suspend () -> Unit,
onComplete: suspend () -> Unit,
) {
val tabKeyCode = 61
keyCommandRepository.sendKeyCommand(
device = device,
keycode = tabKeyCode,
onStart = {
eventRepository.sendEvent(Event.StartSendKeyCommand(tabKeyCode))
onStart()
},
onFailed = {
eventRepository.sendEvent(Event.ErrorSendKeyCommand(tabKeyCode))
onFailed()
},
onComplete = {
eventRepository.sendEvent(Event.EndSendKeyCommand(tabKeyCode))
onComplete()
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package jp.kaleidot725.adbpad.repository.di

import jp.kaleidot725.adbpad.domain.repository.DeviceRepository
import jp.kaleidot725.adbpad.domain.repository.EventRepository
import jp.kaleidot725.adbpad.domain.repository.KeyCommandRepository
import jp.kaleidot725.adbpad.domain.repository.NormalCommandRepository
import jp.kaleidot725.adbpad.domain.repository.ScreenshotCommandRepository
import jp.kaleidot725.adbpad.domain.repository.SettingRepository
import jp.kaleidot725.adbpad.domain.repository.TextCommandRepository
import jp.kaleidot725.adbpad.repository.impl.DeviceRepositoryImpl
import jp.kaleidot725.adbpad.repository.impl.EventRepositoryImpl
import jp.kaleidot725.adbpad.repository.impl.KeyCommandRepositoryImpl
import jp.kaleidot725.adbpad.repository.impl.NormalCommandRepositoryImpl
import jp.kaleidot725.adbpad.repository.impl.ScreenshotCommandRepositoryImpl
import jp.kaleidot725.adbpad.repository.impl.SettingRepositoryImpl
Expand Down Expand Up @@ -38,4 +40,7 @@ val repositoryModule =
factory<VersionRepository> {
VersionRepository()
}
factory<KeyCommandRepository> {
KeyCommandRepositoryImpl()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package jp.kaleidot725.adbpad.repository.impl

import com.malinskiy.adam.AndroidDebugBridgeClientFactory
import jp.kaleidot725.adbpad.domain.model.command.KeyCommand
import jp.kaleidot725.adbpad.domain.model.device.Device
import jp.kaleidot725.adbpad.domain.repository.KeyCommandRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class KeyCommandRepositoryImpl : KeyCommandRepository {
private val adbClient = AndroidDebugBridgeClientFactory().build()

override suspend fun sendKeyCommand(
device: Device,
keycode: Int,
onStart: suspend () -> Unit,
onComplete: suspend () -> Unit,
onFailed: suspend () -> Unit,
) {
withContext(Dispatchers.IO) {
val command = KeyCommand(keycode)
command.requests.forEach { request ->
val result = adbClient.execute(request, device.serial)
if (result.exitCode != 0) {
onFailed()
return@withContext
}
}

onComplete()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package jp.kaleidot725.adbpad.view.component.language

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ fun InputTextActionMenu(
onTextChange: (String) -> Unit,
onSend: () -> Unit,
isSending: Boolean,
canSendTab: Boolean,
onSendTab: () -> Unit,
isSendingTag: Boolean,
canSend: Boolean,
onSave: () -> Unit,
canSave: Boolean,
Expand Down Expand Up @@ -51,6 +54,22 @@ fun InputTextActionMenu(
)
}

Button(
enabled = canSendTab,
onClick = { onSendTab() },
modifier = Modifier.fillMaxHeight().width(85.dp),
) {
when (isSendingTag) {
true -> RunningIndicator()
else -> {
Text(
text = Language.tab,
textAlign = TextAlign.Center,
)
}
}
}

Button(
enabled = canSend,
onClick = { onSend() },
Expand All @@ -77,9 +96,12 @@ private fun InputTextActionMenu_Preview() {
onSend = {},
isSending = false,
canSend = true,
canSendTab = false,
onSendTab = {},
onSave = {},
canSave = true,
onTextChange = {},
isSendingTag = false,
modifier = Modifier.height(50.dp),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ val stateHolderModule =
executeTextCommandUseCase = get(),
getSelectedDeviceFlowUseCase = get(),
sendUserInputTextCommandUseCase = get(),
sendTabCommandUseCase = get(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ fun TextCommandScreen(
canSendInputText: Boolean,
onSaveInputText: () -> Unit,
canSaveInputText: Boolean,
canSendTabKey: Boolean,
onSendTabKey: () -> Unit,
isSendingTab: Boolean,
// Commands
commands: List<TextCommand>,
onSendCommand: (TextCommand) -> Unit,
Expand All @@ -45,6 +48,9 @@ fun TextCommandScreen(
isSending = isSendingInputText,
onSend = onSendInputText,
canSend = canSendInputText,
onSendTab = onSendTabKey,
isSendingTag = isSendingTab,
canSendTab = canSendTabKey,
onSave = onSaveInputText,
canSave = canSaveInputText,
modifier = Modifier.height(50.dp).fillMaxWidth().align(Alignment.BottomEnd),
Expand All @@ -64,8 +70,11 @@ private fun InputTextScreen_Preview() {
canSaveInputText = true,
commands = listOf(TextCommand("TEST1"), TextCommand("TEST2")),
onSendCommand = {},
isSendingTab = false,
canSendCommand = true,
canSendInputText = true,
onDeleteCommand = {},
canSendTabKey = false,
onSendTabKey = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ data class TextCommandState(
val userInputText: String = "",
val isSendingUserInputText: Boolean = false,
val selectedDevice: Device? = null,
val isSendingTab: Boolean = false,
) {
val canSendCommand: Boolean get() = selectedDevice != null
val canSendInputText: Boolean get() = selectedDevice != null && userInputText.isNotEmpty()
val canSaveInputText: Boolean get() = userInputText.isNotEmpty()
val canSendTabKey: Boolean get() = selectedDevice != null
}
Loading

0 comments on commit 6f38323

Please sign in to comment.