Skip to content

Commit

Permalink
🐛 Pasteboard preview list only shows supported types
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang committed Feb 19, 2024
1 parent 0e93316 commit cc1c85d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.clipevery.ui.clip

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material.MaterialTheme
Expand All @@ -15,34 +17,90 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.unit.dp
import com.clipevery.dao.clip.ClipAppearItem
import com.clipevery.dao.clip.ClipContent
import com.clipevery.dao.clip.ClipData
import com.clipevery.dao.clip.ClipType
import kotlin.reflect.KClass
import kotlin.reflect.cast

fun <T: Any> ClipData.getClipItem(kclass: KClass<T>): T? {
return ClipContent.getClipItem(this.clipAppearContent)?.let {
if (kclass.isInstance(it)) {
kclass.cast(it)
} else {
null
}
}
}

fun ClipData.getClipItem(): ClipAppearItem? {
return ClipContent.getClipItem(this.clipAppearContent)
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun ClipPreviewItemView(clipData: ClipData) {

var hover by remember { mutableStateOf(false) }
val backgroundColor = if (hover) MaterialTheme.colors.secondaryVariant else MaterialTheme.colors.background

Row(modifier = Modifier
.fillMaxWidth()
.height(64.dp)
.onPointerEvent(
eventType = PointerEventType.Enter,
onEvent = {
hover = true
}
)
.onPointerEvent(
eventType = PointerEventType.Exit,
onEvent = {
hover = false
fun ClipPreviewItemView(clipData: ClipData, clipContent: @Composable ClipAppearItem.() -> Unit) {

clipData.getClipItem()?.let {

if (it.getClipType() == ClipType.TEXT) {

var hover by remember { mutableStateOf(false) }
val backgroundColor = if (hover) MaterialTheme.colors.secondaryVariant else MaterialTheme.colors.background

Row(modifier = Modifier
.fillMaxWidth()
.height(64.dp)
.onPointerEvent(
eventType = PointerEventType.Enter,
onEvent = {
hover = true
}
)
.onPointerEvent(
eventType = PointerEventType.Exit,
onEvent = {
hover = false
}
)
.background(backgroundColor)) {

Column(
modifier = Modifier.fillMaxWidth()
.height(150.dp)
) {
Row(
modifier = Modifier.fillMaxWidth()
.height(120.dp)
) {
it.clipContent()
Column(modifier = Modifier.fillMaxHeight()) {
Row() {

}
}
}
Row(
modifier = Modifier.fillMaxWidth()
.background(color = MaterialTheme.colors.surface)
.height(30.dp)
) {

}
}
}
)
.background(backgroundColor)) {
}
}
}

ClipPreviewView(clipData) {
ClipPreview(clipData)
@Composable
fun ClipSpecificPreviewItemView(clipData: ClipData) {
if (clipData.preCreate) {
// todo preCreate
} else {
when(clipData.clipType) {
ClipType.TEXT -> TextPreviewView(clipData)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ fun ClipPreviewsView() {
modifier = Modifier.wrapContentHeight()
) {
items(rememberClipDataList) { clipData ->
ClipPreviewItemView(clipData)
ClipPreviewItemView(clipData) {
ClipSpecificPreviewItemView(clipData)
}
}
}

Expand Down

0 comments on commit cc1c85d

Please sign in to comment.