-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from kaleidot725/feat/send_tab_key
feat: add tab key
- Loading branch information
Showing
18 changed files
with
214 additions
and
11 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
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
10 changes: 10 additions & 0 deletions
10
src/jvmMain/kotlin/jp/kaleidot725/adbpad/domain/model/command/KeyCommand.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,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")) | ||
} |
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
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
13 changes: 13 additions & 0 deletions
13
src/jvmMain/kotlin/jp/kaleidot725/adbpad/domain/repository/KeyCommandRepository.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,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, | ||
) | ||
} |
36 changes: 36 additions & 0 deletions
36
src/jvmMain/kotlin/jp/kaleidot725/adbpad/domain/usecase/text/SendTabCommandUseCase.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,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() | ||
}, | ||
) | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/jvmMain/kotlin/jp/kaleidot725/adbpad/repository/impl/KeyCommandRepositoryImpl.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,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() | ||
} | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
src/jvmMain/kotlin/jp/kaleidot725/adbpad/view/component/language/LanguageDropButton.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
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
Oops, something went wrong.