Skip to content

Commit

Permalink
🔨 Refactor ui code to package by interface (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Jan 30, 2024
1 parent 9ec4e40 commit cdef40d
Show file tree
Hide file tree
Showing 20 changed files with 403 additions and 514 deletions.
12 changes: 6 additions & 6 deletions composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.toComposeImageBitmap
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
import com.clipevery.ui.AboutUI
import com.clipevery.ui.AboutView
import com.clipevery.ui.ClipeveryTheme
import com.clipevery.ui.HomeUI
import com.clipevery.ui.HomeView
import com.clipevery.ui.PageViewContext
import com.clipevery.ui.PageViewType
import com.clipevery.ui.SettingsUI
import com.clipevery.ui.devices.DeviceDetailView
import com.clipevery.ui.settings.SettingsView
import org.koin.core.KoinApplication

@Composable
Expand Down Expand Up @@ -97,13 +97,13 @@ fun ClipeveryContent() {
val currentPageViewContext = remember { mutableStateOf(PageViewContext(PageViewType.HOME)) }
when (currentPageViewContext.value.pageViewType) {
PageViewType.HOME -> {
HomeUI(currentPageViewContext)
HomeView(currentPageViewContext)
}
PageViewType.SETTINGS -> {
SettingsUI(currentPageViewContext)
SettingsView(currentPageViewContext)
}
PageViewType.ABOUT -> {
AboutUI(currentPageViewContext)
AboutView(currentPageViewContext)
}
PageViewType.DEVICE_DETAIL -> {
DeviceDetailView(currentPageViewContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.util.UUID
@Serializable
data class AppConfig(
val appInstanceId: String = UUID.randomUUID().toString(),
val bindingState: Boolean = false,
val language: String = Locale.getDefault().language,
val isFollowSystemTheme: Boolean = true,
val isDarkTheme: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier

@Composable
fun AboutUI(currentPageViewContext: MutableState<PageViewContext>) {
fun AboutView(currentPageViewContext: MutableState<PageViewContext>) {
WindowDecoration(currentPageViewContext, "About")
AboutContentUI()
AboutContentView()
}

@Composable
fun AboutContentUI() {
fun AboutContentView() {
Column(modifier = Modifier.fillMaxSize()) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,20 @@ import com.clipevery.LocalKoinApplication
import com.clipevery.i18n.GlobalCopywriter
import com.clipevery.loadImageBitmap
import com.clipevery.ui.base.ClipIconButton
import com.clipevery.ui.devices.TokenView
import java.awt.Desktop
import java.net.URI

@Composable
fun HomeUI(currentPageViewContext: MutableState<PageViewContext>) {
fun HomeView(currentPageViewContext: MutableState<PageViewContext>) {
HomeWindowDecoration(currentPageViewContext)
TokenUI()
TabsUI(currentPageViewContext)
TokenView()
TabsView(currentPageViewContext)
}

@Composable
fun HomeWindowDecoration(currentPage: MutableState<PageViewContext>) {
TitleUI(currentPage)
TitleView(currentPage)
}

val customFontFamily = FontFamily(
Expand All @@ -81,7 +82,7 @@ val clipeveryIcon = loadImageBitmap("clipevery_icon.png")

@Preview
@Composable
fun TitleUI(currentPage: MutableState<PageViewContext>) {
fun TitleView(currentPage: MutableState<PageViewContext>) {
val current = LocalKoinApplication.current
val applicationExit = LocalExitApplication.current
val copywriter = current.koin.get<GlobalCopywriter>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,23 @@ import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.clipevery.LocalKoinApplication
import com.clipevery.config.ConfigManager
import com.clipevery.i18n.GlobalCopywriter
import com.clipevery.ui.clip.ClipPreviewView
import com.clipevery.ui.devices.DevicesView
import com.clipevery.ui.devices.bindingQRCode

@Composable
fun TabsUI(currentPageViewContext: MutableState<PageViewContext>) {
fun TabsView(currentPageViewContext: MutableState<PageViewContext>) {
val current = LocalKoinApplication.current
val copywriter = current.koin.get<GlobalCopywriter>()
val configManager = current.koin.get<ConfigManager>()
val config = remember { mutableStateOf(configManager.config) }
var selectedTabIndex by remember { mutableStateOf(0) }

val showBindingQRCode = remember(config.value.bindingState) {
!config.value.bindingState
}

val tabTitles = listOf("Clipboard", "Devices", "Scan")
Row(modifier = Modifier.padding(8.dp)
.wrapContentWidth()) {

tabTitles.forEachIndexed { index, title ->
TabUI(index == selectedTabIndex, copywriter.getText(title)) {
TabView(index == selectedTabIndex, copywriter.getText(title)) {
selectedTabIndex = index
}
}
Expand All @@ -71,15 +66,9 @@ fun TabsUI(currentPageViewContext: MutableState<PageViewContext>) {

Column(modifier = Modifier.fillMaxSize()) {
when (selectedTabIndex) {
0 -> ClipPreview()
0 -> ClipPreviewView()
1 -> DevicesView(currentPageViewContext)
2 -> {
if (showBindingQRCode) {
bindingQRCode()
} else {
mainUI()
}
}
2 -> bindingQRCode()
}
}
}
Expand All @@ -93,7 +82,7 @@ val bottomBorderShape = GenericShape { size, _ ->
}

@Composable
fun TabUI(isSelect: Boolean, title: String, clickable: () -> Unit) {
fun TabView(isSelect: Boolean, title: String, clickable: () -> Unit) {
val textStyle: TextStyle
val textUnit: TextUnit
var modifier: Modifier = Modifier.padding(2.dp)
Expand Down Expand Up @@ -127,7 +116,7 @@ fun TabUI(isSelect: Boolean, title: String, clickable: () -> Unit) {

@Composable
@Preview
fun PreviewTabsUI() {
fun PreviewTabsView() {
var selectedTabIndex by remember { mutableStateOf(0) }
var searchText by remember { mutableStateOf("") }
val tabTitles = listOf("Tab 1", "Tab 2", "Tab 3")
Expand Down Expand Up @@ -174,8 +163,3 @@ fun PreviewTabsUI() {
fun TabContent(text: String) {
Text(text = text)
}

@Composable
fun mainUI() {
Text("mainUI")
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.clipevery.LocalKoinApplication
import com.clipevery.i18n.GlobalCopywriter
import com.clipevery.ui.icon.left
import com.clipevery.ui.base.left

@Composable
fun WindowDecoration(currentPageViewContext: MutableState<PageViewContext>, title: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.clipevery.ui.icon
package com.clipevery.ui.base

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.clipevery.ui
package com.clipevery.ui.base

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand Down
116 changes: 116 additions & 0 deletions composeApp/src/commonMain/kotlin/com/clipevery/ui/base/SettingsIcon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.clipevery.ui.base

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

@Composable
fun arrowLeft(): ImageVector {
return remember {
ImageVector.Builder(
name = "arrowLeft", defaultWidth = 24.0.dp,
defaultHeight = 24.0.dp, viewportWidth = 24.0f, viewportHeight = 24.0f
).apply {
path(
fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f,
strokeLineCap = StrokeCap.Butt, strokeLineJoin = StrokeJoin.Miter, strokeLineMiter = 4.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(15.41f, 7.41f)
lineTo(14.0f, 6.0f)
lineToRelative(-6.0f, 6.0f)
lineToRelative(6.0f, 6.0f)
lineToRelative(1.41f, -1.41f)
lineTo(10.83f, 12.0f)
lineToRelative(4.58f, -4.59f)
close()
}
}
.build()
}
}

@Composable
fun arrowRight(): ImageVector {
return remember {
ImageVector.Builder(
name = "arrowRight", defaultWidth = 24.0.dp,
defaultHeight = 24.0.dp, viewportWidth = 24.0f, viewportHeight = 24.0f
).apply {
path(
fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f,
strokeLineCap = StrokeCap.Butt, strokeLineJoin = StrokeJoin.Miter, strokeLineMiter = 4.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(8.59f, 16.59f)
lineTo(10.0f, 18.0f)
lineToRelative(6.0f, -6.0f)
lineToRelative(-6.0f, -6.0f)
lineToRelative(-1.41f, 1.41f)
lineTo(13.17f, 12.0f)
lineToRelative(-4.58f, 4.59f)
close()
}
}
.build()
}
}

@Composable
fun arrowUp(): ImageVector {
return remember {
ImageVector.Builder(
name = "ExpandLessBlack24dp", defaultWidth = 24.0.dp,
defaultHeight = 24.0.dp, viewportWidth = 24.0f, viewportHeight = 24.0f
).apply {
path(
fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f,
strokeLineCap = StrokeCap.Butt, strokeLineJoin = StrokeJoin.Miter, strokeLineMiter = 4.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(12.0f, 8.0f)
lineToRelative(-6.0f, 6.0f)
lineToRelative(1.41f, 1.41f)
lineTo(12.0f, 10.83f)
lineToRelative(4.59f, 4.58f)
lineTo(18.0f, 14.0f)
lineToRelative(-6.0f, -6.0f)
close()
}
}
.build()
}
}

@Composable
fun arrowDown(): ImageVector {
return remember {
ImageVector.Builder(
name = "ExpandMoreBlack24dp", defaultWidth = 24.0.dp,
defaultHeight = 24.0.dp, viewportWidth = 24.0f, viewportHeight = 24.0f
).apply {
path(
fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f,
strokeLineCap = StrokeCap.Butt, strokeLineJoin = StrokeJoin.Miter, strokeLineMiter = 4.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(16.59f, 8.59f)
lineTo(12.0f, 13.17f)
lineTo(7.41f, 8.59f)
lineTo(6.0f, 10.0f)
lineToRelative(6.0f, 6.0f)
lineToRelative(6.0f, -6.0f)
lineToRelative(-1.41f, -1.41f)
close()
}
}
.build()
}
}
Loading

0 comments on commit cdef40d

Please sign in to comment.