-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Implement collection of image paste items (#372)
- Loading branch information
1 parent
0f2239b
commit 2ca3872
Showing
27 changed files
with
473 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
composeApp/src/commonMain/kotlin/com/clipevery/clip/item/ClipImage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.clipevery.clip.item | ||
|
||
import java.awt.Image | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import java.nio.file.Path | ||
|
||
interface ClipImage { | ||
|
||
fun getImage(): Image | ||
fun getImage(): ImageBitmap | ||
|
||
fun getImagePath(): Path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ImagePreviewView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.clipevery.ui.clip | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.wrapContentWidth | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.clipevery.LocalKoinApplication | ||
import com.clipevery.clip.item.ClipImage | ||
import com.clipevery.dao.clip.ClipData | ||
import com.clipevery.i18n.GlobalCopywriter | ||
import com.clipevery.ui.base.image | ||
import com.clipevery.utils.FileUtils | ||
|
||
@Composable | ||
fun ImagePreviewView(clipData: ClipData) { | ||
clipData.getClipItem(ClipImage::class)?.let { | ||
|
||
val current = LocalKoinApplication.current | ||
val copywriter = current.koin.get<GlobalCopywriter>() | ||
val fileUtils = current.koin.get<FileUtils>() | ||
|
||
val imageBitmap: ImageBitmap = remember(it) { | ||
it.getImage() | ||
} | ||
|
||
val imageSize = remember(it) { | ||
fileUtils.formatBytes(fileUtils.getFileSize(it.getImagePath())) | ||
} | ||
|
||
Row(modifier = Modifier.fillMaxSize() | ||
.padding(10.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween | ||
) { | ||
|
||
Row { | ||
Image( | ||
modifier = Modifier.size(100.dp) | ||
.clip(RoundedCornerShape(5.dp)), | ||
bitmap = imageBitmap, | ||
contentDescription = "Image", | ||
contentScale = ContentScale.Crop | ||
) | ||
|
||
Column( | ||
modifier = Modifier.fillMaxHeight() | ||
.wrapContentWidth() | ||
.padding(horizontal = 8.dp), | ||
verticalArrangement = Arrangement.Bottom | ||
) { | ||
Text( | ||
text = "${copywriter.getText("File_Name")}: ${fileUtils.getFileNameFromRelativePath(it.getImagePath())}", | ||
color = MaterialTheme.colors.onBackground, | ||
style = TextStyle( | ||
fontWeight = FontWeight.Light, | ||
color = MaterialTheme.colors.onBackground, | ||
fontSize = 10.sp | ||
) | ||
) | ||
|
||
Text( | ||
text = "${copywriter.getText("Dimensions")}: ${imageBitmap.width} x ${imageBitmap.height}", | ||
color = MaterialTheme.colors.onBackground, | ||
style = TextStyle( | ||
fontWeight = FontWeight.Light, | ||
color = MaterialTheme.colors.onBackground, | ||
fontSize = 10.sp | ||
) | ||
) | ||
|
||
Text( | ||
text = "${copywriter.getText("Size")}: $imageSize", | ||
color = MaterialTheme.colors.onBackground, | ||
style = TextStyle( | ||
fontWeight = FontWeight.Light, | ||
color = MaterialTheme.colors.onBackground, | ||
fontSize = 10.sp | ||
) | ||
) | ||
} | ||
} | ||
|
||
Row( | ||
modifier = Modifier.wrapContentWidth() | ||
.padding(end = 8.dp), | ||
horizontalArrangement = Arrangement.End, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Icon( | ||
image(), | ||
contentDescription = "Image", | ||
modifier = Modifier.padding(3.dp).size(14.dp), | ||
tint = MaterialTheme.colors.onBackground | ||
) | ||
|
||
Text( | ||
text = copywriter.getText("Image"), | ||
fontFamily = FontFamily.SansSerif, | ||
style = TextStyle( | ||
fontWeight = FontWeight.Light, | ||
color = MaterialTheme.colors.onBackground, | ||
fontSize = 10.sp | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
composeApp/src/commonMain/kotlin/com/clipevery/utils/FileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.clipevery.utils | ||
|
||
import java.nio.file.Path | ||
|
||
interface FileUtils { | ||
|
||
fun formatBytes(bytesSize: Long): String | ||
|
||
fun createRandomFileName(ext: String): String | ||
|
||
fun getExtFromFileName(fileName: String): String? | ||
|
||
fun createClipRelativePath(clipId: Int, fileName: String): String | ||
|
||
fun getFileNameFromRelativePath(relativePath: Path): String | ||
|
||
fun createClipPath(fileRelativePath: String, isFile: Boolean, isImage: Boolean = false): Path | ||
|
||
fun getFileSize(path: Path): Long | ||
|
||
fun getFileMd5(path: Path): String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.