From 57618848e1c8ac125b21d9925e26cc47d8939bc6 Mon Sep 17 00:00:00 2001 From: Yiqun Zhang Date: Fri, 10 Jan 2025 21:30:28 +0800 Subject: [PATCH] :hammer: Restructure UI implementation for better multiplatform reusability --- .../com/crosspaste/ui/AboutContentView.kt | 4 +- .../kotlin/com/crosspaste/ui/AboutScreen.kt | 6 - .../com/crosspaste/ui/CrossPasteLogoView.kt | 7 -- .../com/crosspaste/ui/CrossPasteScreen.kt | 6 - .../kotlin/com/crosspaste/ui/HomeScreen.kt | 6 - .../com/crosspaste/ui/ScreenProvider.kt | 35 ++++++ .../crosspaste/ui/base/BaseViewProvider.kt | 27 +++++ .../ui/devices/DeviceConnectView.kt | 11 -- .../ui/devices/DeviceDetailContentView.kt | 3 +- .../ui/devices/DeviceDetailScreen.kt | 6 - .../ui/devices/DeviceViewProvider.kt | 22 ++++ .../ui/devices/DevicesContentView.kt} | 11 +- .../crosspaste/ui/devices/DevicesScreen.kt | 6 - .../com/crosspaste/ui/devices/DevicesView.kt | 3 +- .../crosspaste/ui/devices/NearbyDeviceView.kt | 4 +- .../com/crosspaste/ui/devices/QRScreen.kt | 6 - .../crosspaste/ui/devices/SyncDeviceView.kt | 11 -- .../crosspaste/ui/paste/PasteboardScreen.kt | 8 -- .../ui/paste/PasteboardViewProvider.kt | 10 ++ .../ui/paste/edit/PasteTextEditScreen.kt | 6 - .../ui/paste/preview/PasteShimmer.kt | 7 -- .../ui/settings/BlackListDeviceView.kt | 6 +- ...ingsView.kt => MainSettingsContentView.kt} | 2 +- .../crosspaste/ui/settings/NetSettingsView.kt | 6 - .../ui/settings/PasteboardSettingsView.kt | 6 - ...ingsContentView.kt => SettingsCoreView.kt} | 13 ++- .../crosspaste/ui/settings/SettingsScreen.kt | 6 - .../ui/settings/SettingsViewProvider.kt | 18 +++ .../ui/settings/StoreSettingsView.kt | 6 - .../com/crosspaste/DesktopCrossPasteModule.kt | 15 +++ .../com/crosspaste/ui/AboutScreen.desktop.kt | 9 -- .../com/crosspaste/ui/CrossPasteLogoView.kt | 23 ---- .../ui/CrossPasteMainWindowContent.kt | 5 +- .../crosspaste/ui/CrossPasteScreen.desktop.kt | 44 -------- .../crosspaste/ui/DesktopScreenProvider.kt | 105 ++++++++++++++++++ ...een.desktop.kt => HomeWindowDecoration.kt} | 10 +- .../kotlin/com/crosspaste/ui/TabsView.kt | 12 +- .../ui/base/DesktopBaseViewProvider.kt | 51 +++++++++ .../{ExpandView.kt => ExpandContentView.kt} | 2 +- .../ui/devices/DesktopDeviceViewProvider.kt | 26 +++++ ...desktop.kt => DeviceConnectContentView.kt} | 2 +- .../ui/devices/DeviceDetailScreen.desktop.kt | 10 -- .../crosspaste/ui/devices/QRScreen.desktop.kt | 8 -- ...ew.desktop.kt => SyncDeviceContentView.kt} | 2 +- .../ui/paste/DesktopPasteboardViewProvider.kt | 12 ++ ...en.desktop.kt => PasteboardContentView.kt} | 2 +- .../paste/edit/PasteTextEditScreen.desktop.kt | 10 -- ....desktop.kt => PasteShimmerContentView.kt} | 2 +- .../ui/paste/preview/PrePreviewView.kt | 4 +- .../settings/DesktopSettingsViewProvider.kt | 47 ++++++++ .../ui/settings/NetSettingsView.desktop.kt | 15 --- .../PasteboardSettingsView.desktop.kt | 15 --- ...reen.desktop.kt => SettingsContentView.kt} | 4 +- ....desktop.kt => ShortcutKeysContentView.kt} | 7 -- .../ui/settings/StoreSettingsView.desktop.kt | 15 --- 55 files changed, 418 insertions(+), 307 deletions(-) delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutScreen.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteScreen.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/HomeScreen.kt create mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/ScreenProvider.kt create mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/base/BaseViewProvider.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceConnectView.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.kt create mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceViewProvider.kt rename composeApp/src/{desktopMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.desktop.kt => commonMain/kotlin/com/crosspaste/ui/devices/DevicesContentView.kt} (89%) delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/QRScreen.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/SyncDeviceView.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardScreen.kt create mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardViewProvider.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmer.kt rename composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/{MainSettingsView.kt => MainSettingsContentView.kt} (99%) delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.kt rename composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/{SettingsContentView.kt => SettingsCoreView.kt} (56%) delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsScreen.kt create mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsViewProvider.kt delete mode 100644 composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.kt delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/AboutScreen.desktop.kt delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteScreen.desktop.kt create mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/DesktopScreenProvider.kt rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/{HomeScreen.desktop.kt => HomeWindowDecoration.kt} (98%) create mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/DesktopBaseViewProvider.kt rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/{ExpandView.kt => ExpandContentView.kt} (99%) create mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DesktopDeviceViewProvider.kt rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/{DeviceConnectView.desktop.kt => DeviceConnectContentView.kt} (99%) delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.desktop.kt delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/QRScreen.desktop.kt rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/{SyncDeviceView.desktop.kt => SyncDeviceContentView.kt} (98%) create mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/DesktopPasteboardViewProvider.kt rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/{PasteboardScreen.desktop.kt => PasteboardContentView.kt} (99%) delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.desktop.kt rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/{PasteShimmer.desktop.kt => PasteShimmerContentView.kt} (98%) create mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/DesktopSettingsViewProvider.kt delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.desktop.kt delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.desktop.kt rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/{SettingsScreen.desktop.kt => SettingsContentView.kt} (98%) rename composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/{ShortcutKeysScreen.desktop.kt => ShortcutKeysContentView.kt} (98%) delete mode 100644 composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.desktop.kt diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutContentView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutContentView.kt index 11a70685..ba5329ee 100644 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutContentView.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutContentView.kt @@ -29,6 +29,7 @@ import androidx.compose.ui.unit.sp import com.crosspaste.app.AppInfo import com.crosspaste.app.AppUrls import com.crosspaste.i18n.GlobalCopywriter +import com.crosspaste.ui.base.BaseViewProvider import com.crosspaste.ui.base.UISupport import com.crosspaste.ui.base.chevronRight import com.crosspaste.ui.base.robotoFontFamily @@ -38,6 +39,7 @@ import org.koin.compose.koinInject fun AboutContentView() { val appInfo = koinInject() val appUrls = koinInject() + val baseViewProvider = koinInject() val uiSupport = koinInject() Box( @@ -57,7 +59,7 @@ fun AboutContentView() { modifier = Modifier.align(Alignment.Center), horizontalAlignment = Alignment.CenterHorizontally, ) { - CrossPasteLogoView( + baseViewProvider.CrossPasteLogoView( modifier = Modifier.clip(RoundedCornerShape(6.dp)) .background(MaterialTheme.colorScheme.primary) diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutScreen.kt deleted file mode 100644 index d88e2746..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/AboutScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui - -import androidx.compose.runtime.Composable - -@Composable -expect fun AboutScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt deleted file mode 100644 index 43f14bae..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.crosspaste.ui - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier - -@Composable -expect fun CrossPasteLogoView(modifier: Modifier = Modifier) diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteScreen.kt deleted file mode 100644 index f4c0b862..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/CrossPasteScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui - -import androidx.compose.runtime.Composable - -@Composable -expect fun CrossPasteScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/HomeScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/HomeScreen.kt deleted file mode 100644 index 36dfb7ba..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/HomeScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui - -import androidx.compose.runtime.Composable - -@Composable -expect fun HomeScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/ScreenProvider.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/ScreenProvider.kt new file mode 100644 index 00000000..5f63e14b --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/ScreenProvider.kt @@ -0,0 +1,35 @@ +package com.crosspaste.ui + +import androidx.compose.runtime.Composable + +interface ScreenProvider { + + @Composable + fun AboutScreen() + + @Composable + fun CrossPasteScreen() + + @Composable + fun DeviceDetailScreen() + + @Composable + fun DevicesScreen() + + @Composable + fun HomeScreen() + + // openTopBar is used on mobile to expand the top bar + // Desktop does not need to do anything + @Composable + fun PasteboardScreen(openTopBar: () -> Unit = {}) + + @Composable + fun PasteTextEditScreen() + + @Composable + fun QRScreen() + + @Composable + fun SettingsScreen() +} diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/base/BaseViewProvider.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/base/BaseViewProvider.kt new file mode 100644 index 00000000..9bd700c8 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/base/BaseViewProvider.kt @@ -0,0 +1,27 @@ +package com.crosspaste.ui.base + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp + +interface BaseViewProvider { + + @Composable + fun ExpandView( + title: String, + icon: @Composable () -> Painter? = { null }, + defaultExpand: Boolean = false, + horizontalPadding: Dp = 16.dp, + titleBackgroundColor: Color = MaterialTheme.colorScheme.secondary, + onTitleBackgroundColor: Color = MaterialTheme.colorScheme.onSecondary, + backgroundColor: Color = MaterialTheme.colorScheme.surfaceContainerLowest.copy(alpha = 0.72f), + content: @Composable () -> Unit, + ) + + @Composable + fun CrossPasteLogoView(modifier: Modifier = Modifier) +} diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceConnectView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceConnectView.kt deleted file mode 100644 index d100f796..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceConnectView.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.crosspaste.ui.devices - -import androidx.compose.runtime.Composable -import com.crosspaste.realm.sync.SyncRuntimeInfo - -@Composable -expect fun DeviceConnectView( - syncRuntimeInfo: SyncRuntimeInfo, - deviceInteractionEnabled: Boolean, - onEdit: (SyncRuntimeInfo) -> Unit, -) diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailContentView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailContentView.kt index f180a673..2f12719b 100644 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailContentView.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailContentView.kt @@ -48,6 +48,7 @@ fun DeviceDetailContentView() { val appInfo = koinInject() val appWindowManager = koinInject() val copywriter = koinInject() + val deviceViewProvider = koinInject() val syncManager = koinInject() val screen by appWindowManager.screenContext.collectAsState() @@ -65,7 +66,7 @@ fun DeviceDetailContentView() { } Column { - DeviceConnectView(syncRuntimeInfo, false) { } + deviceViewProvider.DeviceConnectView(syncRuntimeInfo, false) { } Column( modifier = diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.kt deleted file mode 100644 index 8f7772f1..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.devices - -import androidx.compose.runtime.Composable - -@Composable -expect fun DeviceDetailScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceViewProvider.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceViewProvider.kt new file mode 100644 index 00000000..846b4885 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DeviceViewProvider.kt @@ -0,0 +1,22 @@ +package com.crosspaste.ui.devices + +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color +import com.crosspaste.dto.sync.SyncInfo +import com.crosspaste.realm.sync.SyncRuntimeInfo + +interface DeviceViewProvider { + + @Composable + fun DeviceConnectView( + syncRuntimeInfo: SyncRuntimeInfo, + deviceInteractionEnabled: Boolean, + onEdit: (SyncRuntimeInfo) -> Unit, + ) + + @Composable + fun SyncDeviceView( + syncInfo: SyncInfo, + action: @Composable (Color) -> Unit, + ) +} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.desktop.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesContentView.kt similarity index 89% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.desktop.kt rename to composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesContentView.kt index e1db6245..2de03914 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.desktop.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesContentView.kt @@ -16,11 +16,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.unit.dp import com.crosspaste.sync.SyncManager -import com.crosspaste.ui.base.ExpandView +import com.crosspaste.ui.base.BaseViewProvider import org.koin.compose.koinInject @Composable -actual fun DevicesScreen() { +fun DevicesContentView() { + val baseViewProvider = koinInject() val syncManager = koinInject() LaunchedEffect(Unit) { @@ -38,7 +39,7 @@ actual fun DevicesScreen() { val syncRuntimeInfos by syncManager.realTimeSyncRuntimeInfos.collectAsState() if (syncRuntimeInfos.isNotEmpty()) { - ExpandView( + baseViewProvider.ExpandView( title = "my_devices", horizontalPadding = 0.dp, defaultExpand = true, @@ -49,7 +50,7 @@ actual fun DevicesScreen() { Spacer(modifier = Modifier.height(10.dp)) } - ExpandView( + baseViewProvider.ExpandView( title = "add_device_manually", horizontalPadding = 0.dp, defaultExpand = false, @@ -58,7 +59,7 @@ actual fun DevicesScreen() { AddDeviceManuallyView() } Spacer(modifier = Modifier.height(10.dp)) - ExpandView( + baseViewProvider.ExpandView( title = "nearby_devices", horizontalPadding = 0.dp, defaultExpand = true, diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.kt deleted file mode 100644 index 8e07c00c..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.devices - -import androidx.compose.runtime.Composable - -@Composable -expect fun DevicesScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesView.kt index e6c5cb6b..cfd131b1 100644 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesView.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/DevicesView.kt @@ -174,9 +174,10 @@ fun DevicesListView( syncRuntimeInfos: List, onEdit: (SyncRuntimeInfo) -> Unit, ) { + val deviceViewProvider = koinInject() Column(modifier = Modifier.fillMaxWidth()) { for ((index, syncRuntimeInfo) in syncRuntimeInfos.withIndex()) { - DeviceConnectView(syncRuntimeInfo, true, onEdit) + deviceViewProvider.DeviceConnectView(syncRuntimeInfo, true, onEdit) if (index != syncRuntimeInfos.size - 1) { HorizontalDivider() } diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/NearbyDeviceView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/NearbyDeviceView.kt index 2707afa3..04abb2e5 100644 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/NearbyDeviceView.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/NearbyDeviceView.kt @@ -35,11 +35,13 @@ import org.koin.compose.koinInject fun NearbyDeviceView(syncInfo: SyncInfo) { val copywriter = koinInject() val deviceManager = koinInject() + val deviceViewProvider = koinInject() val syncRuntimeInfoRealm = koinInject() val configManager = koinInject() val jsonUtils = getJsonUtils() val scope = rememberCoroutineScope() - SyncDeviceView(syncInfo = syncInfo) { background -> + + deviceViewProvider.SyncDeviceView(syncInfo = syncInfo) { background -> Button( modifier = Modifier.height(28.dp), onClick = { diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/QRScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/QRScreen.kt deleted file mode 100644 index ad503f81..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/QRScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.devices - -import androidx.compose.runtime.Composable - -@Composable -expect fun QRScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/SyncDeviceView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/SyncDeviceView.kt deleted file mode 100644 index ffafbcef..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/devices/SyncDeviceView.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.crosspaste.ui.devices - -import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.Color -import com.crosspaste.dto.sync.SyncInfo - -@Composable -expect fun SyncDeviceView( - syncInfo: SyncInfo, - action: @Composable (Color) -> Unit, -) diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardScreen.kt deleted file mode 100644 index cc895fb7..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardScreen.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.crosspaste.ui.paste - -import androidx.compose.runtime.Composable - -// openTopBar is used on mobile to expand the top bar -// Desktop does not need to do anything -@Composable -expect fun PasteboardScreen(openTopBar: () -> Unit = {}) diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardViewProvider.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardViewProvider.kt new file mode 100644 index 00000000..4062822e --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/PasteboardViewProvider.kt @@ -0,0 +1,10 @@ +package com.crosspaste.ui.paste + +import androidx.compose.runtime.Composable +import com.crosspaste.paste.PasteSingleProcess + +interface PasteboardViewProvider { + + @Composable + fun PasteShimmer(singleProcess: PasteSingleProcess?) +} diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.kt deleted file mode 100644 index 2c6c5c20..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.paste.edit - -import androidx.compose.runtime.Composable - -@Composable -expect fun PasteTextEditScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmer.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmer.kt deleted file mode 100644 index d454d568..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmer.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.crosspaste.ui.paste.preview - -import androidx.compose.runtime.Composable -import com.crosspaste.paste.PasteSingleProcess - -@Composable -expect fun PasteShimmer(singleProcess: PasteSingleProcess?) diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/BlackListDeviceView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/BlackListDeviceView.kt index b6fdf04c..c789e2d4 100644 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/BlackListDeviceView.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/BlackListDeviceView.kt @@ -13,14 +13,16 @@ import androidx.compose.ui.unit.dp import com.crosspaste.dto.sync.SyncInfo import com.crosspaste.ui.base.PasteIconButton import com.crosspaste.ui.base.remove -import com.crosspaste.ui.devices.SyncDeviceView +import com.crosspaste.ui.devices.DeviceViewProvider +import org.koin.compose.koinInject @Composable fun BlackListDeviceView( syncInfo: SyncInfo, clickable: () -> Unit, ) { - SyncDeviceView(syncInfo = syncInfo) { + val deviceViewProvider = koinInject() + deviceViewProvider.SyncDeviceView(syncInfo = syncInfo) { PasteIconButton( size = 20.dp, onClick = clickable, diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/MainSettingsView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/MainSettingsContentView.kt similarity index 99% rename from composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/MainSettingsView.kt rename to composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/MainSettingsContentView.kt index 0fb70dd8..584b4f27 100644 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/MainSettingsView.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/MainSettingsContentView.kt @@ -29,7 +29,7 @@ import com.crosspaste.ui.base.shield import org.koin.compose.koinInject @Composable -fun MainSettingsView() { +fun MainSettingsContentView() { val appInfo = koinInject() val appWindowManager = koinInject() val configManager = koinInject() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.kt deleted file mode 100644 index 8d4cc2c4..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.settings - -import androidx.compose.runtime.Composable - -@Composable -expect fun NetSettingsView() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.kt deleted file mode 100644 index 1b1204b0..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.settings - -import androidx.compose.runtime.Composable - -@Composable -expect fun PasteboardSettingsView() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsContentView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsCoreView.kt similarity index 56% rename from composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsContentView.kt rename to composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsCoreView.kt index db34eb6e..2a415d2f 100644 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsContentView.kt +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsCoreView.kt @@ -5,20 +5,23 @@ import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import org.koin.compose.koinInject @Composable -fun SettingsContentView() { - MainSettingsView() +fun SettingsCoreView() { + val settingsViewProvider = koinInject() + + settingsViewProvider.MainSettingsView() Spacer(modifier = Modifier.height(25.dp)) - NetSettingsView() + settingsViewProvider.NetSettingsView() Spacer(modifier = Modifier.height(25.dp)) - StoreSettingsView() + settingsViewProvider.StoreSettingsView() Spacer(modifier = Modifier.height(25.dp)) - PasteboardSettingsView() + settingsViewProvider.PasteboardSettingsView() } diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsScreen.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsScreen.kt deleted file mode 100644 index 1e7b8062..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsScreen.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.settings - -import androidx.compose.runtime.Composable - -@Composable -expect fun SettingsScreen() diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsViewProvider.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsViewProvider.kt new file mode 100644 index 00000000..d040d434 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/SettingsViewProvider.kt @@ -0,0 +1,18 @@ +package com.crosspaste.ui.settings + +import androidx.compose.runtime.Composable + +interface SettingsViewProvider { + + @Composable + fun MainSettingsView() + + @Composable + fun NetSettingsView() + + @Composable + fun PasteboardSettingsView() + + @Composable + fun StoreSettingsView() +} diff --git a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.kt b/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.kt deleted file mode 100644 index e0aebfeb..00000000 --- a/composeApp/src/commonMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.crosspaste.ui.settings - -import androidx.compose.runtime.Composable - -@Composable -expect fun StoreSettingsView() diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/DesktopCrossPasteModule.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/DesktopCrossPasteModule.kt index ed622a6d..6f2ae725 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/DesktopCrossPasteModule.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/DesktopCrossPasteModule.kt @@ -152,7 +152,11 @@ import com.crosspaste.task.PullIconTaskExecutor import com.crosspaste.task.Rtf2ImageTaskExecutor import com.crosspaste.task.SyncPasteTaskExecutor import com.crosspaste.task.TaskExecutor +import com.crosspaste.ui.DesktopScreenProvider import com.crosspaste.ui.DesktopThemeDetector +import com.crosspaste.ui.ScreenProvider +import com.crosspaste.ui.base.BaseViewProvider +import com.crosspaste.ui.base.DesktopBaseViewProvider import com.crosspaste.ui.base.DesktopIconStyle import com.crosspaste.ui.base.DesktopNotificationManager import com.crosspaste.ui.base.DesktopToastManager @@ -160,9 +164,15 @@ import com.crosspaste.ui.base.DesktopUISupport import com.crosspaste.ui.base.DialogService import com.crosspaste.ui.base.IconStyle import com.crosspaste.ui.base.UISupport +import com.crosspaste.ui.devices.DesktopDeviceViewProvider +import com.crosspaste.ui.devices.DeviceViewProvider import com.crosspaste.ui.model.PasteDataViewModel import com.crosspaste.ui.model.PasteSearchViewModel import com.crosspaste.ui.model.PasteSelectionViewModel +import com.crosspaste.ui.paste.DesktopPasteboardViewProvider +import com.crosspaste.ui.paste.PasteboardViewProvider +import com.crosspaste.ui.settings.DesktopSettingsViewProvider +import com.crosspaste.ui.settings.SettingsViewProvider import com.crosspaste.ui.theme.ThemeDetector import com.crosspaste.utils.DesktopDeviceUtils import com.crosspaste.utils.DesktopLocaleUtils @@ -388,10 +398,12 @@ class DesktopCrossPasteModule( single { DesktopAppSize } single { DesktopAppTokenService(get()) } single { get() } + single { DesktopBaseViewProvider() } single { DesktopAppSize } single { getDesktopAppWindowManager(get(), lazy { get() }, get(), get()) } single { DesktopMouseListener } single { DesktopShortcutKeysListener(get()) } + single { DesktopDeviceViewProvider() } single { DialogService } single { GlobalCopywriterImpl(get()) } single { DesktopGlobalListener(get(), get(), get(), get(), get()) } @@ -399,7 +411,10 @@ class DesktopCrossPasteModule( single { get() } single { get() } single { DesktopNotificationManager(get(), get(), get()) } + single { DesktopPasteboardViewProvider() } single { PlatformContext.INSTANCE } + single { DesktopScreenProvider(get()) } + single { DesktopSettingsViewProvider(get()) } single { DesktopShortcutKeys(get()) } single { DesktopShortKeysAction(get(), get(), get(), get(), get(), get()) } single { get() } diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/AboutScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/AboutScreen.desktop.kt deleted file mode 100644 index cc93da4c..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/AboutScreen.desktop.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.crosspaste.ui - -import androidx.compose.runtime.Composable - -@Composable -actual fun AboutScreen() { - WindowDecoration("about") - AboutContentView() -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt deleted file mode 100644 index 17db1d53..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteLogoView.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.crosspaste.ui - -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material.Icon -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import com.crosspaste.composeapp.generated.resources.Res -import com.crosspaste.composeapp.generated.resources.crosspaste_svg -import org.jetbrains.compose.resources.painterResource - -@Composable -actual fun CrossPasteLogoView(modifier: Modifier) { - Box(modifier = modifier) { - Icon( - modifier = Modifier.fillMaxSize(), - painter = painterResource(Res.drawable.crosspaste_svg), - tint = MaterialTheme.colorScheme.onPrimary, - contentDescription = "CrossPaste Logo", - ) - } -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteMainWindowContent.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteMainWindowContent.kt index 774d2404..fe73701a 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteMainWindowContent.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteMainWindowContent.kt @@ -47,8 +47,9 @@ fun CrossPasteMainWindowContent() { val appSize = koinInject() as DesktopAppSize val appWindowManager = koinInject() val appTokenApi = koinInject() - val toastManager = koinInject() val dialogService = koinInject() + val screenProvider = koinInject() + val toastManager = koinInject() val toast by toastManager.toast.collectAsState() Theme { @@ -97,7 +98,7 @@ fun CrossPasteMainWindowContent() { .focusRequester(appWindowManager.mainFocusRequester), horizontalAlignment = Alignment.CenterHorizontally, ) { - CrossPasteScreen() + screenProvider.CrossPasteScreen() } toast?.let { diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteScreen.desktop.kt deleted file mode 100644 index aee57005..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/CrossPasteScreen.desktop.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.crosspaste.ui - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import com.crosspaste.app.AppWindowManager -import com.crosspaste.ui.devices.DeviceDetailScreen -import com.crosspaste.ui.paste.edit.PasteTextEditScreen -import com.crosspaste.ui.settings.SettingsScreen -import com.crosspaste.ui.settings.ShortcutKeysScreen -import org.koin.compose.koinInject - -@Composable -actual fun CrossPasteScreen() { - val appWindowManager = koinInject() - - val screen by appWindowManager.screenContext.collectAsState() - - when (screen.screenType) { - ScreenType.PASTE_PREVIEW, - ScreenType.DEVICES, - ScreenType.QR_CODE, - ScreenType.DEBUG, - -> { - HomeScreen() - } - ScreenType.SETTINGS -> { - SettingsScreen() - } - ScreenType.SHORTCUT_KEYS -> { - ShortcutKeysScreen() - } - ScreenType.ABOUT -> { - AboutScreen() - } - ScreenType.DEVICE_DETAIL -> { - DeviceDetailScreen() - } - ScreenType.PASTE_TEXT_EDIT -> { - PasteTextEditScreen() - } - else -> {} - } -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/DesktopScreenProvider.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/DesktopScreenProvider.kt new file mode 100644 index 00000000..0bc2b60e --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/DesktopScreenProvider.kt @@ -0,0 +1,105 @@ +package com.crosspaste.ui + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import com.crosspaste.app.AppWindowManager +import com.crosspaste.ui.devices.DeviceDetailContentView +import com.crosspaste.ui.devices.DevicesContentView +import com.crosspaste.ui.devices.QRContentView +import com.crosspaste.ui.paste.PasteboardContentView +import com.crosspaste.ui.paste.edit.PasteTextEditContentView +import com.crosspaste.ui.settings.SettingsContentView +import com.crosspaste.ui.settings.ShortcutKeysContentView + +class DesktopScreenProvider( + private val appWindowManager: AppWindowManager, +) : ScreenProvider { + + @Composable + override fun AboutScreen() { + WindowDecoration("about") + AboutContentView() + } + + @Composable + override fun CrossPasteScreen() { + val screen by appWindowManager.screenContext.collectAsState() + + when (screen.screenType) { + ScreenType.PASTE_PREVIEW, + ScreenType.DEVICES, + ScreenType.QR_CODE, + ScreenType.DEBUG, + -> { + HomeScreen() + } + + ScreenType.SETTINGS -> { + SettingsScreen() + } + + ScreenType.SHORTCUT_KEYS -> { + ShortcutKeysScreen() + } + + ScreenType.ABOUT -> { + AboutScreen() + } + + ScreenType.DEVICE_DETAIL -> { + DeviceDetailScreen() + } + + ScreenType.PASTE_TEXT_EDIT -> { + PasteTextEditScreen() + } + + else -> {} + } + } + + @Composable + override fun DeviceDetailScreen() { + WindowDecoration("device_detail") + DeviceDetailContentView() + } + + @Composable + override fun DevicesScreen() { + DevicesContentView() + } + + @Composable + override fun HomeScreen() { + HomeWindowDecoration() + TabsView() + } + + @Composable + override fun PasteboardScreen(openTopBar: () -> Unit) { + PasteboardContentView(openTopBar) + } + + @Composable + override fun PasteTextEditScreen() { + WindowDecoration("text_edit") + PasteTextEditContentView() + } + + @Composable + override fun QRScreen() { + QRContentView() + } + + @Composable + fun ShortcutKeysScreen() { + WindowDecoration("shortcut_keys") + ShortcutKeysContentView() + } + + @Composable + override fun SettingsScreen() { + SettingsContentView() + } +} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/HomeScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/HomeWindowDecoration.kt similarity index 98% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/HomeScreen.desktop.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/HomeWindowDecoration.kt index 891ad46d..83c46430 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/HomeScreen.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/HomeWindowDecoration.kt @@ -51,6 +51,7 @@ import com.crosspaste.app.DesktopAppLaunchState import com.crosspaste.app.DesktopAppWindowManager import com.crosspaste.config.ConfigManager import com.crosspaste.i18n.GlobalCopywriter +import com.crosspaste.ui.base.BaseViewProvider import com.crosspaste.ui.base.PasteTooltipIconView import com.crosspaste.ui.base.UISupport import com.crosspaste.ui.base.menuItemReminderTextStyle @@ -61,12 +62,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.koin.compose.koinInject -@Composable -actual fun HomeScreen() { - HomeWindowDecoration() - TabsView() -} - @Preview @Composable fun HomeWindowDecoration() { @@ -74,6 +69,7 @@ fun HomeWindowDecoration() { val appLaunchState = koinInject() val appWindowManager = koinInject() val appUpdateService = koinInject() + val baseViewProvider = koinInject() val configManager = koinInject() val uiSupport = koinInject() @@ -102,7 +98,7 @@ fun HomeWindowDecoration() { horizontalArrangement = Arrangement.Start, verticalAlignment = Alignment.CenterVertically, ) { - CrossPasteLogoView( + baseViewProvider.CrossPasteLogoView( modifier = Modifier.padding(start = 13.dp, top = 13.dp, end = 10.dp, bottom = 13.dp) .align(Alignment.CenterVertically) diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/TabsView.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/TabsView.kt index fa5754f7..9ef77660 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/TabsView.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/TabsView.kt @@ -50,9 +50,6 @@ import com.crosspaste.notification.NotificationManager import com.crosspaste.realm.paste.PasteRealm import com.crosspaste.ui.base.PasteTooltipIconView import com.crosspaste.ui.base.trash -import com.crosspaste.ui.devices.DevicesScreen -import com.crosspaste.ui.devices.QRScreen -import com.crosspaste.ui.paste.PasteboardScreen import com.crosspaste.utils.getAppEnvUtils import org.koin.compose.koinInject @@ -68,6 +65,7 @@ val tabTextStyle = fun TabsView() { val appWindowManager = koinInject() val copywriter = koinInject() + val screenProvider = koinInject() val textMeasurer = rememberTextMeasurer() @@ -180,11 +178,11 @@ fun TabsView() { } when (screen.screenType) { - ScreenType.PASTE_PREVIEW -> PasteboardScreen() - ScreenType.DEVICES -> DevicesScreen() - ScreenType.QR_CODE -> QRScreen() + ScreenType.PASTE_PREVIEW -> screenProvider.PasteboardScreen() + ScreenType.DEVICES -> screenProvider.DevicesScreen() + ScreenType.QR_CODE -> screenProvider.QRScreen() ScreenType.DEBUG -> DebugScreen() - else -> PasteboardScreen() + else -> screenProvider.PasteboardScreen() } } } diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/DesktopBaseViewProvider.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/DesktopBaseViewProvider.kt new file mode 100644 index 00000000..ca2ec7c1 --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/DesktopBaseViewProvider.kt @@ -0,0 +1,51 @@ +package com.crosspaste.ui.base + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.unit.Dp +import com.crosspaste.composeapp.generated.resources.Res +import com.crosspaste.composeapp.generated.resources.crosspaste_svg +import org.jetbrains.compose.resources.painterResource + +class DesktopBaseViewProvider : BaseViewProvider { + @Composable + override fun ExpandView( + title: String, + icon: @Composable (() -> Painter?), + defaultExpand: Boolean, + horizontalPadding: Dp, + titleBackgroundColor: Color, + onTitleBackgroundColor: Color, + backgroundColor: Color, + content: @Composable (() -> Unit), + ) { + ExpandContentView( + title = title, + icon = icon, + defaultExpand = defaultExpand, + horizontalPadding = horizontalPadding, + titleBackgroundColor = titleBackgroundColor, + onTitleBackgroundColor = onTitleBackgroundColor, + backgroundColor = backgroundColor, + content = content, + ) + } + + @Composable + override fun CrossPasteLogoView(modifier: Modifier) { + Box(modifier = modifier) { + Icon( + modifier = Modifier.fillMaxSize(), + painter = painterResource(Res.drawable.crosspaste_svg), + tint = MaterialTheme.colorScheme.onPrimary, + contentDescription = "CrossPaste Logo", + ) + } + } +} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/ExpandView.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/ExpandContentView.kt similarity index 99% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/ExpandView.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/ExpandContentView.kt index 2bd076e0..3b4ce751 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/ExpandView.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/base/ExpandContentView.kt @@ -56,7 +56,7 @@ import org.koin.compose.koinInject @OptIn(ExperimentalFoundationApi::class, ExperimentalComposeUiApi::class) @Composable -fun ExpandView( +fun ExpandContentView( title: String, icon: @Composable () -> Painter? = { null }, defaultExpand: Boolean = false, diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DesktopDeviceViewProvider.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DesktopDeviceViewProvider.kt new file mode 100644 index 00000000..f121f445 --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DesktopDeviceViewProvider.kt @@ -0,0 +1,26 @@ +package com.crosspaste.ui.devices + +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color +import com.crosspaste.dto.sync.SyncInfo +import com.crosspaste.realm.sync.SyncRuntimeInfo + +class DesktopDeviceViewProvider : DeviceViewProvider { + + @Composable + override fun DeviceConnectView( + syncRuntimeInfo: SyncRuntimeInfo, + deviceInteractionEnabled: Boolean, + onEdit: (SyncRuntimeInfo) -> Unit, + ) { + DeviceConnectContentView(syncRuntimeInfo, deviceInteractionEnabled, onEdit) + } + + @Composable + override fun SyncDeviceView( + syncInfo: SyncInfo, + action: @Composable ((Color) -> Unit), + ) { + SyncDeviceContentView(syncInfo, action) + } +} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceConnectView.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceConnectContentView.kt similarity index 99% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceConnectView.desktop.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceConnectContentView.kt index fd9280b6..ee2675b5 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceConnectView.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceConnectContentView.kt @@ -65,7 +65,7 @@ import org.koin.compose.koinInject @OptIn(ExperimentalComposeUiApi::class) @Composable -actual fun DeviceConnectView( +fun DeviceConnectContentView( syncRuntimeInfo: SyncRuntimeInfo, deviceInteractionEnabled: Boolean, onEdit: (SyncRuntimeInfo) -> Unit, diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.desktop.kt deleted file mode 100644 index 21b85b70..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/DeviceDetailScreen.desktop.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.crosspaste.ui.devices - -import androidx.compose.runtime.Composable -import com.crosspaste.ui.WindowDecoration - -@Composable -actual fun DeviceDetailScreen() { - WindowDecoration("device_detail") - DeviceDetailContentView() -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/QRScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/QRScreen.desktop.kt deleted file mode 100644 index c4cccf9a..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/QRScreen.desktop.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.crosspaste.ui.devices - -import androidx.compose.runtime.Composable - -@Composable -actual fun QRScreen() { - QRContentView() -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/SyncDeviceView.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/SyncDeviceContentView.kt similarity index 98% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/SyncDeviceView.desktop.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/SyncDeviceContentView.kt index f6158980..5ba5f2b2 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/SyncDeviceView.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/devices/SyncDeviceContentView.kt @@ -25,7 +25,7 @@ import com.crosspaste.realm.sync.createSyncRuntimeInfo @OptIn(ExperimentalComposeUiApi::class) @Composable -actual fun SyncDeviceView( +fun SyncDeviceContentView( syncInfo: SyncInfo, action: @Composable (Color) -> Unit, ) { diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/DesktopPasteboardViewProvider.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/DesktopPasteboardViewProvider.kt new file mode 100644 index 00000000..a8bb23ab --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/DesktopPasteboardViewProvider.kt @@ -0,0 +1,12 @@ +package com.crosspaste.ui.paste + +import androidx.compose.runtime.Composable +import com.crosspaste.paste.PasteSingleProcess +import com.crosspaste.ui.paste.preview.PasteShimmerContentView + +class DesktopPasteboardViewProvider : PasteboardViewProvider { + @Composable + override fun PasteShimmer(singleProcess: PasteSingleProcess?) { + PasteShimmerContentView(singleProcess) + } +} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/PasteboardScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/PasteboardContentView.kt similarity index 99% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/PasteboardScreen.desktop.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/PasteboardContentView.kt index 3592360c..dd16f7b8 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/PasteboardScreen.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/PasteboardContentView.kt @@ -51,7 +51,7 @@ import org.koin.compose.koinInject import org.mongodb.kbson.ObjectId @Composable -actual fun PasteboardScreen(openTopBar: () -> Unit) { +fun PasteboardContentView(openTopBar: () -> Unit) { val pasteDataViewModel = koinInject() val appWindowManager = koinInject() diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.desktop.kt deleted file mode 100644 index e6fff125..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/edit/PasteTextEditScreen.desktop.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.crosspaste.ui.paste.edit - -import androidx.compose.runtime.Composable -import com.crosspaste.ui.WindowDecoration - -@Composable -actual fun PasteTextEditScreen() { - WindowDecoration("text_edit") - PasteTextEditContentView() -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmer.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmerContentView.kt similarity index 98% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmer.desktop.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmerContentView.kt index 9dc9867e..0469e215 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmer.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PasteShimmerContentView.kt @@ -26,7 +26,7 @@ import com.crosspaste.paste.PasteSingleProcess import com.valentinilk.shimmer.shimmer @Composable -actual fun PasteShimmer(singleProcess: PasteSingleProcess?) { +fun PasteShimmerContentView(singleProcess: PasteSingleProcess?) { Row( modifier = Modifier diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PrePreviewView.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PrePreviewView.kt index bf58f7a2..ac592ec0 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PrePreviewView.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/paste/preview/PrePreviewView.kt @@ -16,11 +16,13 @@ import com.crosspaste.paste.PasteSingleProcess import com.crosspaste.paste.PasteSyncProcessManager import com.crosspaste.realm.paste.PasteData import com.crosspaste.ui.base.PasteProgressbar +import com.crosspaste.ui.paste.PasteboardViewProvider import org.koin.compose.koinInject import org.mongodb.kbson.ObjectId @Composable fun PrePreviewView(pasteData: PasteData) { + val pasteboardViewProvider = koinInject() val pasteSyncProcessManager = koinInject>() val singleProcess: PasteSingleProcess? by remember(pasteData.id) { mutableStateOf(pasteSyncProcessManager.getProcess(pasteData.id)) } @@ -45,7 +47,7 @@ fun PrePreviewView(pasteData: PasteData) { .background(Color.Transparent) .clip(RoundedCornerShape(5.dp)), ) { - PasteShimmer(singleProcess) + pasteboardViewProvider.PasteShimmer(singleProcess) } }, pasteRightInfo = { toShow -> diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/DesktopSettingsViewProvider.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/DesktopSettingsViewProvider.kt new file mode 100644 index 00000000..1b376dcc --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/DesktopSettingsViewProvider.kt @@ -0,0 +1,47 @@ +package com.crosspaste.ui.settings + +import androidx.compose.runtime.Composable +import com.crosspaste.ui.base.BaseViewProvider +import com.crosspaste.ui.base.clipboard +import com.crosspaste.ui.base.database +import com.crosspaste.ui.base.network + +class DesktopSettingsViewProvider( + private val baseViewProvider: BaseViewProvider, +) : SettingsViewProvider { + + @Composable + override fun MainSettingsView() { + MainSettingsContentView() + } + + @Composable + override fun NetSettingsView() { + baseViewProvider.ExpandView( + title = "network", + icon = { network() }, + ) { + NetSettingsContentView() + } + } + + @Composable + override fun PasteboardSettingsView() { + baseViewProvider.ExpandView( + title = "pasteboard", + icon = { clipboard() }, + ) { + PasteboardSettingsContentView() + } + } + + @Composable + override fun StoreSettingsView() { + baseViewProvider.ExpandView( + title = "store", + icon = { database() }, + ) { + StoreSettingsContentView() + } + } +} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.desktop.kt deleted file mode 100644 index a016d920..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/NetSettingsView.desktop.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.crosspaste.ui.settings - -import androidx.compose.runtime.Composable -import com.crosspaste.ui.base.ExpandView -import com.crosspaste.ui.base.network - -@Composable -actual fun NetSettingsView() { - ExpandView( - title = "network", - icon = { network() }, - ) { - NetSettingsContentView() - } -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.desktop.kt deleted file mode 100644 index 48173ec0..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/PasteboardSettingsView.desktop.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.crosspaste.ui.settings - -import androidx.compose.runtime.Composable -import com.crosspaste.ui.base.ExpandView -import com.crosspaste.ui.base.clipboard - -@Composable -actual fun PasteboardSettingsView() { - ExpandView( - title = "pasteboard", - icon = { clipboard() }, - ) { - PasteboardSettingsContentView() - } -} diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/SettingsScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/SettingsContentView.kt similarity index 98% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/SettingsScreen.desktop.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/SettingsContentView.kt index 819c49a2..c52ed963 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/SettingsScreen.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/SettingsContentView.kt @@ -36,7 +36,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch @Composable -actual fun SettingsScreen() { +fun SettingsContentView() { val scrollState = rememberScrollState() var isScrolling by remember { mutableStateOf(false) } @@ -66,7 +66,7 @@ actual fun SettingsScreen() { .fillMaxSize() .padding(vertical = 25.dp), ) { - SettingsContentView() + SettingsCoreView() } VerticalScrollbar( diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/ShortcutKeysScreen.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/ShortcutKeysContentView.kt similarity index 98% rename from composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/ShortcutKeysScreen.desktop.kt rename to composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/ShortcutKeysContentView.kt index 0c62908b..ec78e189 100644 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/ShortcutKeysScreen.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/ShortcutKeysContentView.kt @@ -51,7 +51,6 @@ import com.crosspaste.listen.DesktopShortcutKeys.Companion.SWITCH_MONITOR_PASTEB import com.crosspaste.listener.KeyboardKey import com.crosspaste.listener.ShortcutKeys import com.crosspaste.listener.ShortcutKeysListener -import com.crosspaste.ui.WindowDecoration import com.crosspaste.ui.base.DialogButtonsView import com.crosspaste.ui.base.DialogService import com.crosspaste.ui.base.KeyboardView @@ -59,12 +58,6 @@ import com.crosspaste.ui.base.PasteDialog import com.crosspaste.ui.base.edit import org.koin.compose.koinInject -@Composable -fun ShortcutKeysScreen() { - WindowDecoration("shortcut_keys") - ShortcutKeysContentView() -} - @Composable fun ShortcutKeysContentView() { val scrollState = rememberScrollState() diff --git a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.desktop.kt b/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.desktop.kt deleted file mode 100644 index 229a7ba4..00000000 --- a/composeApp/src/desktopMain/kotlin/com/crosspaste/ui/settings/StoreSettingsView.desktop.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.crosspaste.ui.settings - -import androidx.compose.runtime.Composable -import com.crosspaste.ui.base.ExpandView -import com.crosspaste.ui.base.database - -@Composable -actual fun StoreSettingsView() { - ExpandView( - title = "store", - icon = { database() }, - ) { - StoreSettingsContentView() - } -}