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

🐛 Pasteboard preview list only shows supported types #347

Merged
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
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
Loading