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

✨ Record the storage size of each pasted item #767

Merged
merged 2 commits into from
Apr 19, 2024
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
Expand Up @@ -6,6 +6,8 @@ import java.nio.file.Path

interface ClipFiles {

var count: Long

fun getAppFileType(): AppFileType

fun getRelativePaths(): List<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface ClipAppearItem {

var md5: String

var size: Long

var extraInfo: String?

fun update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ClipData : RealmObject {
@Index
var md5: String = ""

var size: Long = 0

@Index
@Transient
var createTime: RealmInstant = RealmInstant.now()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.clipevery.dao.clip

import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey

class ClipResource : RealmObject {
@PrimaryKey
var appInstanceId: String = ""
var imageSize: Long = 0
var fileSize: Long = 0
}

data class ClipResourceInfo(
val clipNumber: Long,
val clipCount: Long,
val clipSize: Long,
val textCount: Long,
val textSize: Long,
val urlCount: Long,
val urlSize: Long,
val htmlCount: Long,
val htmlSize: Long,
val imageCount: Long,
val imageSize: Long,
val fileCount: Long,
val fileSize: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface FileInfoTree {
fun isFile(): Boolean

fun getClipFileList(path: Path): List<ClipFile>

fun getCount(): Long
}

@Serializable
Expand All @@ -43,6 +45,10 @@ class DirFileInfoTree(
fileTree.getClipFileList(path.resolve(name))
}.flatten()
}

override fun getCount(): Long {
return tree.values.sumOf { it.getCount() }
}
}

@Serializable
Expand All @@ -59,6 +65,10 @@ class SingleFileInfoTree(
override fun getClipFileList(path: Path): List<ClipFile> {
return listOf(ClipFileImpl(path, md5))
}

override fun getCount(): Long {
return 1L
}
}

class FileInfoTreeBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object ClipDataSerializer : KSerializer<ClipData> {
element<RealmAny?>("clipAppearContent")
element<ClipContent?>("clipContent")
element<Int>("clipType")
element<Long>("size")
element<String>("md5")
element<Boolean>("isFavorite")
element<RealmSet<ClipLabel>>("labels")
Expand All @@ -41,6 +42,7 @@ object ClipDataSerializer : KSerializer<ClipData> {
var clipAppearContent: RealmAny? = null
var clipContent: ClipContent? = null
var clipType = 0
var size = 0L
var md5 = ""
var isFavorite = false
var labels: RealmSet<ClipLabel> = realmSetOf()
Expand All @@ -52,9 +54,10 @@ object ClipDataSerializer : KSerializer<ClipData> {
3 -> clipAppearContent = dec.decodeSerializableElement(descriptor, index, RealmAnyKSerializer)
4 -> clipContent = dec.decodeSerializableElement(descriptor, index, ClipContent.serializer())
5 -> clipType = dec.decodeIntElement(descriptor, index)
6 -> md5 = dec.decodeStringElement(descriptor, index)
7 -> isFavorite = dec.decodeBooleanElement(descriptor, index)
8 -> labels = dec.decodeSerializableElement(descriptor, index, RealmSetKSerializer(ClipLabel.serializer()))
6 -> size = dec.decodeLongElement(descriptor, index)
7 -> md5 = dec.decodeStringElement(descriptor, index)
8 -> isFavorite = dec.decodeBooleanElement(descriptor, index)
9 -> labels = dec.decodeSerializableElement(descriptor, index, RealmSetKSerializer(ClipLabel.serializer()))
else -> break@loop
}
}
Expand All @@ -69,6 +72,7 @@ object ClipDataSerializer : KSerializer<ClipData> {
this.clipType = clipType
this.clipSearchContent = ClipContent.getClipItem(clipAppearContent)?.getSearchContent()
this.md5 = md5
this.size = size
this.createTime = RealmInstant.now()
this.clipState = ClipState.LOADING
this.isRemote = true
Expand Down Expand Up @@ -99,9 +103,10 @@ object ClipDataSerializer : KSerializer<ClipData> {
compositeOutput.encodeSerializableElement(descriptor, 4, ClipContent.serializer(), it)
}
compositeOutput.encodeIntElement(descriptor, 5, value.clipType)
compositeOutput.encodeStringElement(descriptor, 6, value.md5)
compositeOutput.encodeBooleanElement(descriptor, 7, value.isFavorite)
compositeOutput.encodeSerializableElement(descriptor, 8, RealmSetKSerializer(ClipLabel.serializer()), value.labels)
compositeOutput.encodeLongElement(descriptor, 6, value.size)
compositeOutput.encodeStringElement(descriptor, 7, value.md5)
compositeOutput.encodeBooleanElement(descriptor, 8, value.isFavorite)
compositeOutput.encodeSerializableElement(descriptor, 9, RealmSetKSerializer(ClipLabel.serializer()), value.labels)
compositeOutput.endStructure(descriptor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,19 @@ fun SettingsView(currentPageViewContext: MutableState<PageViewContext>) {
}

@Composable
fun settingsText(text: String) {
fun settingsText(
text: String,
modifier: Modifier = Modifier,
) {
Text(
modifier = modifier,
text = text,
color = MaterialTheme.colors.onBackground,
fontSize = 14.sp,
fontFamily = FontFamily.SansSerif,
style = TextStyle(fontWeight = FontWeight.Light),
style =
TextStyle(
fontSize = 14.sp,
fontWeight = FontWeight.Light,
fontFamily = FontFamily.SansSerif,
),
)
}
Loading
Loading