From 081fd0f872281b8c01ae90b37e5155c40c1a5f31 Mon Sep 17 00:00:00 2001 From: Yiqun Zhang Date: Mon, 19 Feb 2024 20:40:00 +0800 Subject: [PATCH] :lipstick: Implement preview display of text pasted items (#350) --- .../kotlin/com/clipevery/ui/base/ClipIcon.kt | 73 +++++++++++++++++ .../clipevery/ui/clip/ClipPreviewItemView.kt | 2 +- .../com/clipevery/ui/clip/TextPreviewView.kt | 82 +++++++++++++++++-- .../desktopMain/resources/i18n/en.properties | 3 +- .../desktopMain/resources/i18n/es.properties | 3 +- .../desktopMain/resources/i18n/jp.properties | 3 +- .../desktopMain/resources/i18n/zh.properties | 3 +- 7 files changed, 156 insertions(+), 13 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt new file mode 100644 index 000000000..963bbd421 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt @@ -0,0 +1,73 @@ +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.Companion.NonZero +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.graphics.StrokeCap.Companion.Butt +import androidx.compose.ui.graphics.StrokeJoin.Companion.Miter +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.graphics.vector.path +import androidx.compose.ui.unit.dp + +@Composable +fun feed(): ImageVector { + return remember { + ImageVector.Builder( + name = "Feed", defaultWidth = 24.0.dp, defaultHeight = 24.0.dp, + viewportWidth = 960.0f, viewportHeight = 960.0f + ).apply { + path(fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f, + strokeLineCap = Butt, strokeLineJoin = Miter, strokeLineMiter = 4.0f, + pathFillType = NonZero) { + moveTo(200.0f, 840.0f) + quadToRelative(-33.0f, 0.0f, -56.5f, -23.5f) + reflectiveQuadTo(120.0f, 760.0f) + verticalLineToRelative(-560.0f) + quadToRelative(0.0f, -33.0f, 23.5f, -56.5f) + reflectiveQuadTo(200.0f, 120.0f) + horizontalLineToRelative(440.0f) + lineToRelative(200.0f, 200.0f) + verticalLineToRelative(440.0f) + quadToRelative(0.0f, 33.0f, -23.5f, 56.5f) + reflectiveQuadTo(760.0f, 840.0f) + lineTo(200.0f, 840.0f) + close() + moveTo(200.0f, 760.0f) + horizontalLineToRelative(560.0f) + verticalLineToRelative(-400.0f) + lineTo(600.0f, 360.0f) + verticalLineToRelative(-160.0f) + lineTo(200.0f, 200.0f) + verticalLineToRelative(560.0f) + close() + moveTo(280.0f, 680.0f) + horizontalLineToRelative(400.0f) + verticalLineToRelative(-80.0f) + lineTo(280.0f, 600.0f) + verticalLineToRelative(80.0f) + close() + moveTo(280.0f, 360.0f) + horizontalLineToRelative(200.0f) + verticalLineToRelative(-80.0f) + lineTo(280.0f, 280.0f) + verticalLineToRelative(80.0f) + close() + moveTo(280.0f, 520.0f) + horizontalLineToRelative(400.0f) + verticalLineToRelative(-80.0f) + lineTo(280.0f, 440.0f) + verticalLineToRelative(80.0f) + close() + moveTo(200.0f, 200.0f) + verticalLineToRelative(160.0f) + verticalLineToRelative(-160.0f) + verticalLineToRelative(560.0f) + verticalLineToRelative(-560.0f) + close() + } + } + .build() + } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt index d9c10b4aa..57fc4a791 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt @@ -51,7 +51,7 @@ fun ClipPreviewItemView(clipData: ClipData, clipContent: @Composable ClipAppearI Row(modifier = Modifier .fillMaxWidth() - .height(64.dp) + .height(150.dp) .onPointerEvent( eventType = PointerEventType.Enter, onEvent = { diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/TextPreviewView.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/TextPreviewView.kt index 369575f90..95389e54b 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/TextPreviewView.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/TextPreviewView.kt @@ -1,34 +1,100 @@ package com.clipevery.ui.clip +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.wrapContentWidth +import androidx.compose.material.Icon import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.clipevery.LocalKoinApplication import com.clipevery.clip.item.ClipText import com.clipevery.dao.clip.ClipData +import com.clipevery.i18n.GlobalCopywriter +import com.clipevery.ui.base.feed fun getTitle(clipText: ClipText): String { - return clipText.text + val parts = clipText.text.split("\n", limit = 2) + println(parts[0]) + return parts[0] } @Composable fun TextPreviewView(clipData: ClipData) { + val current = LocalKoinApplication.current + val copywriter = current.koin.get() + clipData.getClipItem(ClipText::class)?.let { - Column() { - Text(text = getTitle(it), - maxLines = 1, - overflow = TextOverflow.Ellipsis, + Column( + modifier = Modifier.fillMaxWidth() + .padding(8.dp) + ) { + Row( + modifier = Modifier.fillMaxWidth().padding(bottom = 10.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text( + modifier = Modifier.weight(1f), + text = getTitle(it), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + fontFamily = FontFamily.SansSerif, + style = TextStyle( + fontWeight = FontWeight.Bold, + color = MaterialTheme.colors.onBackground, + fontSize = 17.sp + ) + ) + + Row( + modifier = Modifier.wrapContentWidth(), + horizontalArrangement = Arrangement.End, + verticalAlignment = Alignment.CenterVertically + ) { + Icon( + feed(), + contentDescription = "Text", + modifier = Modifier.padding(3.dp).size(14.dp), + tint = MaterialTheme.colors.onBackground + ) + + Text( + text = copywriter.getText("Text"), + fontFamily = FontFamily.SansSerif, + style = TextStyle( + fontWeight = FontWeight.Light, + color = MaterialTheme.colors.onBackground, + fontSize = 8.sp + ) + ) + } + } + + + Text( + modifier = Modifier.weight(1f), + text = it.text, + fontFamily = FontFamily.SansSerif, style = TextStyle( - fontWeight = FontWeight.Bold, + fontWeight = FontWeight.Normal, color = MaterialTheme.colors.onBackground, - fontSize = 17.sp + fontSize = 14.sp ) ) } - } + } } \ No newline at end of file diff --git a/composeApp/src/desktopMain/resources/i18n/en.properties b/composeApp/src/desktopMain/resources/i18n/en.properties index 941091f5f..d94525725 100644 --- a/composeApp/src/desktopMain/resources/i18n/en.properties +++ b/composeApp/src/desktopMain/resources/i18n/en.properties @@ -38,4 +38,5 @@ Sync_Control=Sync Control Base_Info=Base Info Allow_Send_to_this_device=Allow Send to this device Allow_Receive_from_this_device=Allow Receive from this device -Remove_Device=Remove Device \ No newline at end of file +Remove_Device=Remove Device +Text=Text \ No newline at end of file diff --git a/composeApp/src/desktopMain/resources/i18n/es.properties b/composeApp/src/desktopMain/resources/i18n/es.properties index 617268e09..6162163dc 100644 --- a/composeApp/src/desktopMain/resources/i18n/es.properties +++ b/composeApp/src/desktopMain/resources/i18n/es.properties @@ -38,4 +38,5 @@ Sync_Control=Control de sincronización Base_Info=Información básica Allow_Send_to_this_device=Permitir enviar a este dispositivo Allow_Receive_from_this_device=Permitir recibir de este dispositivo -Remove_Device=Eliminar dispositivo \ No newline at end of file +Remove_Device=Eliminar dispositivo +Text=Texto \ No newline at end of file diff --git a/composeApp/src/desktopMain/resources/i18n/jp.properties b/composeApp/src/desktopMain/resources/i18n/jp.properties index 9d20c373f..f3470f0b3 100644 --- a/composeApp/src/desktopMain/resources/i18n/jp.properties +++ b/composeApp/src/desktopMain/resources/i18n/jp.properties @@ -38,4 +38,5 @@ Sync_Control=同期制御 Base_Info=基本情報 Allow_Send_to_this_device=このデバイスに送信を許可する Allow_Receive_from_this_device=このデバイスからの受信を許可する -Remove_Device=デバイスを削除 \ No newline at end of file +Remove_Device=デバイスを削除 +Text=テキスト \ No newline at end of file diff --git a/composeApp/src/desktopMain/resources/i18n/zh.properties b/composeApp/src/desktopMain/resources/i18n/zh.properties index cf6e1ff9e..d4ab09d9c 100644 --- a/composeApp/src/desktopMain/resources/i18n/zh.properties +++ b/composeApp/src/desktopMain/resources/i18n/zh.properties @@ -38,4 +38,5 @@ Sync_Control=同步控制 Base_Info=基础信息 Allow_Send_to_this_device=允许发送到此设备 Allow_Receive_from_this_device=允许从此设备接收 -Remove_Device=移除设备 \ No newline at end of file +Remove_Device=移除设备 +Text=文本 \ No newline at end of file