Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/delete old feature #102

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinExecution

plugins {
alias(libs.plugins.multiplatform)
alias(libs.plugins.compose)
Expand Down
214 changes: 69 additions & 145 deletions src/jvmMain/kotlin/jp/kaleidot725/adbpad/Main.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
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.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
Expand Down Expand Up @@ -48,7 +41,6 @@ import jp.kaleidot725.adbpad.MainState
import jp.kaleidot725.adbpad.MainStateHolder
import jp.kaleidot725.adbpad.domain.di.domainModule
import jp.kaleidot725.adbpad.domain.model.Dialog
import jp.kaleidot725.adbpad.domain.model.Menu
import jp.kaleidot725.adbpad.domain.model.UserColor
import jp.kaleidot725.adbpad.domain.model.device.Device
import jp.kaleidot725.adbpad.domain.model.language.Language
Expand All @@ -60,15 +52,13 @@ import jp.kaleidot725.adbpad.ui.common.resource.clickableBackground
import jp.kaleidot725.adbpad.ui.component.NavigationRail
import jp.kaleidot725.adbpad.ui.di.stateHolderModule
import jp.kaleidot725.adbpad.ui.screen.CommandScreen
import jp.kaleidot725.adbpad.ui.screen.MenuScreen
import jp.kaleidot725.adbpad.ui.screen.ScreenLayout
import jp.kaleidot725.adbpad.ui.screen.error.AdbErrorScreen
import jp.kaleidot725.adbpad.ui.screen.menu.component.DropDownDeviceMenu
import jp.kaleidot725.adbpad.ui.screen.menu.screenshot.ScreenshotScreen
import jp.kaleidot725.adbpad.ui.screen.menu.text.TextCommandScreen
import jp.kaleidot725.adbpad.ui.screen.screenshot.ScreenshotScreen
import jp.kaleidot725.adbpad.ui.screen.setting.SettingScreen
import jp.kaleidot725.adbpad.ui.screen.setting.SettingStateHolder
import jp.kaleidot725.adbpad.ui.screen.version.VersionScreen
import jp.kaleidot725.adbpad.ui.screen.text.TextCommandScreen
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.intui.standalone.theme.IntUiTheme
import org.jetbrains.jewel.intui.standalone.theme.darkThemeDefinition
Expand Down Expand Up @@ -211,38 +201,78 @@ fun DecoratedWindowScope.App(mainStateHolder: MainStateHolder) {
},
content = {
when (state.category) {
MainCategory.Device -> {
DeviceContent(mainStateHolder, Modifier.fillMaxSize())
MainCategory.Command -> {
val commandStateHolder = mainStateHolder.commandStateHolder
val commandState by commandStateHolder.state.collectAsState()
CommandScreen(
commands = commandState.commands,
filtered = commandState.filtered,
onClickFilter = commandStateHolder::clickTab,
canExecute = commandState.canExecuteCommand,
onExecute = { command ->
commandStateHolder.executeCommand(command)
},
)
}

MainCategory.Version -> {
val versionStateHolder = mainStateHolder.versionStateHolder
val versionState by versionStateHolder.state.collectAsState()

DisposableEffect(mainStateHolder) {
versionStateHolder.setup()
onDispose { versionStateHolder.dispose() }
}
MainCategory.Text -> {
val inputTextStateHolder = mainStateHolder.textCommandStateHolder
val inputTextState by inputTextStateHolder.state.collectAsState()

VersionScreen(versionState, versionStateHolder::retry, Modifier.fillMaxSize())
TextCommandScreen(
// InputText
inputText = inputTextState.userInputText,
onTextChange = { text ->
inputTextStateHolder.updateInputText(text)
},
isSendingInputText = inputTextState.isSendingUserInputText,
onSendInputText = {
inputTextStateHolder.sendInputText()
},
canSendInputText = inputTextState.canSendInputText,
canSendTabKey = inputTextState.canSendTabKey,
onSendTabKey = {
inputTextStateHolder.sendTabCommand()
},
onSaveInputText = {
inputTextStateHolder.saveInputText()
},
canSaveInputText = inputTextState.canSaveInputText,
// Commands
commands = inputTextState.commands,
onSendCommand = { text ->
inputTextStateHolder.sendTextCommand(text)
},
canSendCommand = inputTextState.canSendCommand,
isSendingTab = inputTextState.isSendingTab,
onDeleteCommand = { text ->
inputTextStateHolder.deleteInputText(text)
},
)
}
}
},
notificationArea = {
Box(
Modifier.fillMaxWidth().height(25.dp)
.padding(horizontal = 8.dp, vertical = 4.dp),
) {
Text(
text = event.message,
color =
when (event.level) {
Event.Level.INFO -> MaterialTheme.colors.onSurface
Event.Level.WARN -> Color.Yellow
Event.Level.ERROR -> Color.Red

MainCategory.Screenshot -> {
val screenshotStateHolder = mainStateHolder.screenshotStateHolder
val screenshotState by screenshotStateHolder.state.collectAsState()

ScreenshotScreen(
screenshot = screenshotState.preview,
canCapture = screenshotState.canExecute,
isCapturing = screenshotState.isCapturing,
commands = screenshotState.commands,
onCopyScreenshot = {
screenshotStateHolder.copyScreenShotToClipboard()
},
onDeleteScreenshot = {
screenshotStateHolder.deleteScreenShotToClipboard()
},
onTakeScreenshot = { screenshot ->
screenshotStateHolder.takeScreenShot(
screenshot,
)
},
style = MaterialTheme.typography.caption,
)
)
}
}
},
dialog = {
Expand Down Expand Up @@ -291,112 +321,6 @@ fun DecoratedWindowScope.App(mainStateHolder: MainStateHolder) {
}
}

@Composable
private fun DeviceContent(
mainStateHolder: MainStateHolder,
modifier: Modifier = Modifier,
) {
val menuStateHolder = mainStateHolder.menuStateHolder
val menuState by menuStateHolder.state.collectAsState()

val commandStateHolder = mainStateHolder.commandStateHolder
val commandState by commandStateHolder.state.collectAsState()

val inputTextStateHolder = mainStateHolder.textCommandStateHolder
val inputTextState by inputTextStateHolder.state.collectAsState()

val screenshotStateHolder = mainStateHolder.screenshotStateHolder
val screenshotState by screenshotStateHolder.state.collectAsState()

Row(modifier) {
Box(Modifier.background(MaterialTheme.colors.background)) {
MenuScreen(
menus = menuState.menus,
selectedMenu = menuState.selectedMenu,
onSelectMenu = { menuStateHolder.selectMenu(it) },
modifier =
Modifier
.width(250.dp)
.fillMaxHeight()
.padding(horizontal = 12.dp, vertical = 16.dp),
)
}

Spacer(Modifier.width(1.dp).fillMaxHeight().border(BorderStroke(1.dp, UserColor.getSplitterColor())))

Box(Modifier.background(MaterialTheme.colors.background)) {
when (menuState.selectedMenu) {
Menu.Command -> {
CommandScreen(
commands = commandState.commands,
filtered = commandState.filtered,
onClickFilter = commandStateHolder::clickTab,
canExecute = commandState.canExecuteCommand,
onExecute = { command ->
commandStateHolder.executeCommand(command)
},
)
}

Menu.InputText -> {
TextCommandScreen(
// InputText
inputText = inputTextState.userInputText,
onTextChange = { text ->
inputTextStateHolder.updateInputText(text)
},
isSendingInputText = inputTextState.isSendingUserInputText,
onSendInputText = {
inputTextStateHolder.sendInputText()
},
canSendInputText = inputTextState.canSendInputText,
canSendTabKey = inputTextState.canSendTabKey,
onSendTabKey = {
inputTextStateHolder.sendTabCommand()
},
onSaveInputText = {
inputTextStateHolder.saveInputText()
},
canSaveInputText = inputTextState.canSaveInputText,
// Commands
commands = inputTextState.commands,
onSendCommand = { text ->
inputTextStateHolder.sendTextCommand(text)
},
canSendCommand = inputTextState.canSendCommand,
isSendingTab = inputTextState.isSendingTab,
onDeleteCommand = { text ->
inputTextStateHolder.deleteInputText(text)
},
)
}

Menu.Screenshot -> {
ScreenshotScreen(
screenshot = screenshotState.preview,
canCapture = screenshotState.canExecute,
isCapturing = screenshotState.isCapturing,
commands = screenshotState.commands,
onCopyScreenshot = {
screenshotStateHolder.copyScreenShotToClipboard()
},
onDeleteScreenshot = {
screenshotStateHolder.deleteScreenShotToClipboard()
},
onTakeScreenshot = { screenshot ->
screenshotStateHolder.takeScreenShot(
screenshot,
)
},
)
}

null -> Unit
}
}
}
}

private val LightColors =
Colors(
primary = UserColor.Light.PRIMARY,
Expand Down
5 changes: 3 additions & 2 deletions src/jvmMain/kotlin/jp/kaleidot725/adbpad/MainCategory.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jp.kaleidot725.adbpad

enum class MainCategory {
Device,
Version,
Command,
Text,
Screenshot,
}
2 changes: 1 addition & 1 deletion src/jvmMain/kotlin/jp/kaleidot725/adbpad/MainState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class MainState(
val isDark: Boolean = false,
val size: WindowSize = WindowSize.UNKNOWN,
val dialog: Dialog? = null,
val category: MainCategory = MainCategory.Device,
val category: MainCategory = MainCategory.Command,
val devices: List<Device> = emptyList(),
val selectedDevice: Device? = null,
)
13 changes: 4 additions & 9 deletions src/jvmMain/kotlin/jp/kaleidot725/adbpad/MainStateHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import jp.kaleidot725.adbpad.domain.usecase.window.GetWindowSizeUseCase
import jp.kaleidot725.adbpad.domain.usecase.window.SaveWindowSizeUseCase
import jp.kaleidot725.adbpad.ui.common.ChildStateHolder
import jp.kaleidot725.adbpad.ui.common.ParentStateHolder
import jp.kaleidot725.adbpad.ui.screen.menu.MenuStateHolder
import jp.kaleidot725.adbpad.ui.screen.menu.command.CommandStateHolder
import jp.kaleidot725.adbpad.ui.screen.menu.screenshot.ScreenshotStateHolder
import jp.kaleidot725.adbpad.ui.screen.menu.text.TextCommandStateHolder
import jp.kaleidot725.adbpad.ui.screen.version.VersionStateHolder
import jp.kaleidot725.adbpad.ui.screen.command.CommandStateHolder
import jp.kaleidot725.adbpad.ui.screen.screenshot.ScreenshotStateHolder
import jp.kaleidot725.adbpad.ui.screen.text.TextCommandStateHolder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -39,11 +37,9 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch

class MainStateHolder(
val menuStateHolder: MenuStateHolder,
val commandStateHolder: CommandStateHolder,
val textCommandStateHolder: TextCommandStateHolder,
val screenshotStateHolder: ScreenshotStateHolder,
val versionStateHolder: VersionStateHolder,
private val getEventFlowUseCase: GetEventFlowUseCase,
private val getWindowSizeUseCase: GetWindowSizeUseCase,
private val saveWindowSizeUseCase: SaveWindowSizeUseCase,
Expand All @@ -60,7 +56,7 @@ class MainStateHolder(
private val windowSize: MutableStateFlow<WindowSize> = MutableStateFlow(WindowSize.UNKNOWN)
private val isDark: MutableStateFlow<Boolean> = MutableStateFlow(true)
private val dialog: MutableStateFlow<Dialog?> = MutableStateFlow(null)
private val category: MutableStateFlow<MainCategory> = MutableStateFlow(MainCategory.Device)
private val category: MutableStateFlow<MainCategory> = MutableStateFlow(MainCategory.Command)

private var deviceJob: Job? = null
private val _devices: MutableStateFlow<List<Device>> = MutableStateFlow(emptyList())
Expand All @@ -86,7 +82,6 @@ class MainStateHolder(

private val children: List<ChildStateHolder<*>> =
listOf(
menuStateHolder,
commandStateHolder,
textCommandStateHolder,
screenshotStateHolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import jp.kaleidot725.adbpad.domain.usecase.device.UpdateDevicesUseCase
import jp.kaleidot725.adbpad.domain.usecase.event.GetEventFlowUseCase
import jp.kaleidot725.adbpad.domain.usecase.language.GetLanguageUseCase
import jp.kaleidot725.adbpad.domain.usecase.language.SaveLanguageUseCase
import jp.kaleidot725.adbpad.domain.usecase.menu.GetMenuListUseCase
import jp.kaleidot725.adbpad.domain.usecase.refresh.RefreshUseCase
import jp.kaleidot725.adbpad.domain.usecase.screenshot.CopyScreenshotToClipboardUseCase
import jp.kaleidot725.adbpad.domain.usecase.screenshot.DeleteScreenshotPreviewUseCase
Expand Down Expand Up @@ -63,9 +62,6 @@ val domainModule =
factory {
GetTextCommandUseCase(get())
}
factory {
GetMenuListUseCase()
}
factory {
TakeScreenshotUseCase(get(), get())
}
Expand Down
34 changes: 0 additions & 34 deletions src/jvmMain/kotlin/jp/kaleidot725/adbpad/domain/model/Menu.kt

This file was deleted.

This file was deleted.

Loading
Loading