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

💄 The preview interface supports displaying skeleton preloading #389

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
1 change: 1 addition & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {

desktopMain.dependencies {
implementation(compose.desktop.currentOs)
implementation(libs.compose.shimmer)
implementation(libs.guava)
implementation(libs.jmdns)
implementation(libs.jna)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface ClipDao {
fun getClipData(appInstanceId: String? = null,
limit: Int): RealmResults<ClipData>

fun getClipData(objectId: ObjectId): ClipData?

fun releaseClipData(id: ObjectId, clipPlugins: List<ClipPlugin>)

fun updateClipItem(update: (MutableRealm) -> Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ fun ClipPreviewItemView(clipData: ClipData, isLast: Boolean, clipContent: @Compo
)
}
}
} ?: run {
PrePreviewView(clipData)
if (!isLast) {
Divider(
color = MaterialTheme.colors.onBackground,
thickness = 2.dp
)
}
}
}

Expand All @@ -148,7 +156,7 @@ fun getDateText(createTime: RealmInstant, copywriter: Copywriter): String {
@Composable
fun ClipSpecificPreviewItemView(clipData: ClipData) {
if (clipData.preCreate) {
// todo preCreate
PrePreviewView(clipData)
} else {
when(clipData.clipType) {
ClipType.TEXT -> TextPreviewView(clipData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.unit.dp
import com.clipevery.LocalKoinApplication
import com.clipevery.dao.clip.ClipDao
import com.clipevery.dao.clip.ClipData
import com.clipevery.dao.clip.ClipType
import io.realm.kotlin.notifications.ResultsChange
import io.realm.kotlin.notifications.UpdatedResults
import io.realm.kotlin.query.RealmResults
Expand Down Expand Up @@ -60,7 +61,7 @@ fun ClipPreviewsView() {
} }

LaunchedEffect(Unit) {
val clipDatasFlow = clipDao.getClipData(limit = 20).asFlow()
val clipDatasFlow = clipDataList.asFlow()
clipDatasFlow.collect { changes: ResultsChange<ClipData> ->
when (changes) {
is UpdatedResults -> {
Expand All @@ -79,6 +80,17 @@ fun ClipPreviewsView() {
val newClipDataList = clipDao.getClipData(limit = 20)
rememberClipDataList.addAll(newClipDataList.sortedWith(clipDataComparator))
}

changes.changes
changes.changeRanges

rememberClipDataList.forEachIndexed { index, currentElement ->
if (currentElement.clipType == ClipType.INVALID) {
clipDao.getClipData(currentElement.id)?.let {
rememberClipDataList[index] = it
}
}
}
}
else -> {
// types other than UpdatedResults are not changes -- ignore them
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.clipevery.ui.clip

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.clipevery.dao.clip.ClipData
import com.valentinilk.shimmer.shimmer

@Composable
fun PrePreviewView(clipData: ClipData) {
Row(
modifier = Modifier
.width(400.dp)
.height(150.dp)
.background(MaterialTheme.colors.background)
.shimmer(),
verticalAlignment = Alignment.CenterVertically
) {
Box(
modifier = Modifier
.size(131.dp)
.padding(10.dp)
.background(Color.Gray)
)

Column(modifier = Modifier.height(150.dp).width(230.dp).padding(10.dp),
verticalArrangement = Arrangement.Center
) {
Box(
modifier = Modifier
.height(37.dp)
.width(230.dp)
.padding(bottom = 5.dp)
.background(Color.Gray)
)
Box(
modifier = Modifier
.height(37.dp)
.width(180.dp)
.padding(vertical = 5.dp)
.background(Color.Gray)
)
Box(
modifier = Modifier
.height(37.dp)
.width(230.dp)
.padding(top = 5.dp)
.background(Color.Gray)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class ClipRealm(private val realm: Realm) : ClipDao {
return query.sort("createTime", Sort.DESCENDING).limit(limit).find()
}

override fun getClipData(objectId: ObjectId): ClipData? {
return realm.query(ClipData::class).query("id == $0", objectId).first().find()
}

override fun releaseClipData(id: ObjectId, clipPlugins: List<ClipPlugin>) {
var md5: String? = null
realm.writeBlocking {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
compose = "1.6.1"
compose-plugin = "1.6.0-rc03"
compose-compiler = "1.5.8"
compose-shimmer = "1.2.0"
compose-webview-multiplatform = "1.8.8"
guava = "33.0.0-jre"
jmdns = "3.5.9"
Expand All @@ -28,6 +29,7 @@ compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref =
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
compose-material = { module = "androidx.compose.material:material", version.ref = "compose" }
compose-shimmer = { module = "com.valentinilk.shimmer:compose-shimmer", version.ref = "compose-shimmer" }
compose-webview-multiplatform = { module = "io.github.kevinnzou:compose-webview-multiplatform", version.ref = "compose-webview-multiplatform" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
jmdns = { module = "org.jmdns:jmdns", version.ref = "jmdns" }
Expand Down
Loading