|
|
@ -1,9 +1,7 @@ |
|
|
|
package example.imageviewer.view |
|
|
|
package example.imageviewer.view |
|
|
|
|
|
|
|
|
|
|
|
import androidx.compose.foundation.BorderStroke |
|
|
|
|
|
|
|
import androidx.compose.foundation.Image |
|
|
|
import androidx.compose.foundation.Image |
|
|
|
import androidx.compose.foundation.background |
|
|
|
import androidx.compose.foundation.background |
|
|
|
import androidx.compose.foundation.border |
|
|
|
|
|
|
|
import androidx.compose.foundation.clickable |
|
|
|
import androidx.compose.foundation.clickable |
|
|
|
import androidx.compose.foundation.layout.Arrangement |
|
|
|
import androidx.compose.foundation.layout.Arrangement |
|
|
|
import androidx.compose.foundation.layout.Box |
|
|
|
import androidx.compose.foundation.layout.Box |
|
|
@ -15,15 +13,13 @@ import androidx.compose.foundation.layout.fillMaxSize |
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth |
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth |
|
|
|
import androidx.compose.foundation.layout.height |
|
|
|
import androidx.compose.foundation.layout.height |
|
|
|
import androidx.compose.foundation.layout.padding |
|
|
|
import androidx.compose.foundation.layout.padding |
|
|
|
import androidx.compose.foundation.layout.size |
|
|
|
import androidx.compose.foundation.layout.width |
|
|
|
import androidx.compose.foundation.lazy.grid.GridCells |
|
|
|
import androidx.compose.foundation.lazy.grid.GridCells |
|
|
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid |
|
|
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid |
|
|
|
import androidx.compose.foundation.lazy.grid.itemsIndexed |
|
|
|
import androidx.compose.foundation.lazy.grid.itemsIndexed |
|
|
|
import androidx.compose.foundation.shape.CircleShape |
|
|
|
import androidx.compose.foundation.shape.CircleShape |
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api |
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api |
|
|
|
import androidx.compose.material3.MaterialTheme |
|
|
|
import androidx.compose.material3.MaterialTheme |
|
|
|
import androidx.compose.material3.Surface |
|
|
|
|
|
|
|
import androidx.compose.material3.Text |
|
|
|
|
|
|
|
import androidx.compose.material3.TopAppBar |
|
|
|
import androidx.compose.material3.TopAppBar |
|
|
|
import androidx.compose.material3.TopAppBarDefaults |
|
|
|
import androidx.compose.material3.TopAppBarDefaults |
|
|
|
import androidx.compose.runtime.Composable |
|
|
|
import androidx.compose.runtime.Composable |
|
|
@ -32,14 +28,10 @@ import androidx.compose.runtime.collectAsState |
|
|
|
import androidx.compose.runtime.getValue |
|
|
|
import androidx.compose.runtime.getValue |
|
|
|
import androidx.compose.ui.Alignment |
|
|
|
import androidx.compose.ui.Alignment |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
import androidx.compose.ui.graphics.Color |
|
|
|
import androidx.compose.ui.draw.clip |
|
|
|
import androidx.compose.ui.graphics.ImageBitmap |
|
|
|
import androidx.compose.ui.graphics.ImageBitmap |
|
|
|
import androidx.compose.ui.layout.ContentScale |
|
|
|
import androidx.compose.ui.layout.ContentScale |
|
|
|
import androidx.compose.ui.text.font.FontStyle |
|
|
|
|
|
|
|
import androidx.compose.ui.text.font.FontWeight |
|
|
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign |
|
|
|
|
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import androidx.compose.ui.unit.sp |
|
|
|
|
|
|
|
import example.imageviewer.Dependencies |
|
|
|
import example.imageviewer.Dependencies |
|
|
|
import example.imageviewer.ExternalImageViewerEvent |
|
|
|
import example.imageviewer.ExternalImageViewerEvent |
|
|
|
import example.imageviewer.model.GalleryEntryWithMetadata |
|
|
|
import example.imageviewer.model.GalleryEntryWithMetadata |
|
|
@ -48,24 +40,9 @@ import example.imageviewer.model.GalleryPage |
|
|
|
import example.imageviewer.model.PhotoGallery |
|
|
|
import example.imageviewer.model.PhotoGallery |
|
|
|
import example.imageviewer.model.bigUrl |
|
|
|
import example.imageviewer.model.bigUrl |
|
|
|
import example.imageviewer.style.ImageviewerColors |
|
|
|
import example.imageviewer.style.ImageviewerColors |
|
|
|
import example.imageviewer.style.ImageviewerColors.kotlinHorizontalGradientBrush |
|
|
|
|
|
|
|
import org.jetbrains.compose.resources.ExperimentalResourceApi |
|
|
|
import org.jetbrains.compose.resources.ExperimentalResourceApi |
|
|
|
import org.jetbrains.compose.resources.painterResource |
|
|
|
import org.jetbrains.compose.resources.painterResource |
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
|
|
|
|
internal fun GalleryHeader() { |
|
|
|
|
|
|
|
Row( |
|
|
|
|
|
|
|
horizontalArrangement = Arrangement.Center, |
|
|
|
|
|
|
|
modifier = Modifier.padding(10.dp).fillMaxWidth() |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Text( |
|
|
|
|
|
|
|
"My Gallery", |
|
|
|
|
|
|
|
fontSize = 25.sp, |
|
|
|
|
|
|
|
color = MaterialTheme.colorScheme.onBackground, |
|
|
|
|
|
|
|
fontStyle = FontStyle.Italic |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class GalleryStyle { |
|
|
|
enum class GalleryStyle { |
|
|
|
SQUARES, |
|
|
|
SQUARES, |
|
|
@ -91,11 +68,7 @@ internal fun GalleryScreen( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Column(modifier = Modifier.background(MaterialTheme.colorScheme.background)) { |
|
|
|
Column(modifier = Modifier.background(MaterialTheme.colorScheme.background)) { |
|
|
|
TitleBar( |
|
|
|
Box { |
|
|
|
onRefresh = { photoGallery.updatePictures() }, |
|
|
|
|
|
|
|
onToggle = { galleryPage.toggleGalleryStyle() }, |
|
|
|
|
|
|
|
dependencies |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
if (needShowPreview()) { |
|
|
|
if (needShowPreview()) { |
|
|
|
PreviewImage( |
|
|
|
PreviewImage( |
|
|
|
getImage = { dependencies.imageRepository.loadContent(it.bigUrl) }, |
|
|
|
getImage = { dependencies.imageRepository.loadContent(it.bigUrl) }, |
|
|
@ -103,12 +76,18 @@ internal fun GalleryScreen( |
|
|
|
galleryPage.pictureId?.let(onClickPreviewPicture) |
|
|
|
galleryPage.pictureId?.let(onClickPreviewPicture) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TitleBar( |
|
|
|
|
|
|
|
onRefresh = { photoGallery.updatePictures() }, |
|
|
|
|
|
|
|
onToggle = { galleryPage.toggleGalleryStyle() }, |
|
|
|
|
|
|
|
dependencies |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) { |
|
|
|
when (galleryPage.galleryStyle) { |
|
|
|
when (galleryPage.galleryStyle) { |
|
|
|
GalleryStyle.SQUARES -> SquaresGalleryView( |
|
|
|
GalleryStyle.SQUARES -> SquaresGalleryView( |
|
|
|
pictures, |
|
|
|
pictures, |
|
|
|
galleryPage.pictureId, |
|
|
|
galleryPage.pictureId, |
|
|
|
onSelect = { galleryPage.selectPicture(it) }, |
|
|
|
onSelect = { galleryPage.selectPicture(it) }, |
|
|
|
onMakeNewMemory |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
GalleryStyle.LIST -> ListGalleryView( |
|
|
|
GalleryStyle.LIST -> ListGalleryView( |
|
|
@ -118,6 +97,8 @@ internal fun GalleryScreen( |
|
|
|
onFullScreen = { onClickPreviewPicture(it) } |
|
|
|
onFullScreen = { onClickPreviewPicture(it) } |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
MakeNewMemoryMiniature(onMakeNewMemory) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (pictures.isEmpty()) { |
|
|
|
if (pictures.isEmpty()) { |
|
|
|
LoadingScreen(dependencies.localization.loading) |
|
|
|
LoadingScreen(dependencies.localization.loading) |
|
|
@ -129,12 +110,14 @@ private fun SquaresGalleryView( |
|
|
|
images: List<GalleryEntryWithMetadata>, |
|
|
|
images: List<GalleryEntryWithMetadata>, |
|
|
|
selectedImage: GalleryId?, |
|
|
|
selectedImage: GalleryId?, |
|
|
|
onSelect: (GalleryId) -> Unit, |
|
|
|
onSelect: (GalleryId) -> Unit, |
|
|
|
onMakeNewMemory: () -> Unit, |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
LazyVerticalGrid(columns = GridCells.Adaptive(minSize = 128.dp)) { |
|
|
|
Column { |
|
|
|
item { |
|
|
|
Spacer(Modifier.height(1.dp)) |
|
|
|
MakeNewMemoryMiniature(onMakeNewMemory) |
|
|
|
LazyVerticalGrid( |
|
|
|
} |
|
|
|
columns = GridCells.Adaptive(minSize = 130.dp), |
|
|
|
|
|
|
|
verticalArrangement = Arrangement.spacedBy(1.dp), |
|
|
|
|
|
|
|
horizontalArrangement = Arrangement.spacedBy(1.dp) |
|
|
|
|
|
|
|
) { |
|
|
|
itemsIndexed(images) { idx, image -> |
|
|
|
itemsIndexed(images) { idx, image -> |
|
|
|
val isSelected = image.id == selectedImage |
|
|
|
val isSelected = image.id == selectedImage |
|
|
|
val (picture, bitmap) = image |
|
|
|
val (picture, bitmap) = image |
|
|
@ -146,37 +129,76 @@ private fun SquaresGalleryView( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalResourceApi::class) |
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
private fun MakeNewMemoryMiniature(onClick: () -> Unit) { |
|
|
|
private fun MakeNewMemoryMiniature(onClick: () -> Unit) { |
|
|
|
|
|
|
|
Column { |
|
|
|
Box( |
|
|
|
Box( |
|
|
|
Modifier.aspectRatio(1.0f) |
|
|
|
Modifier |
|
|
|
|
|
|
|
.clip(CircleShape) |
|
|
|
|
|
|
|
.width(52.dp) |
|
|
|
|
|
|
|
.background(ImageviewerColors.uiLightBlack) |
|
|
|
|
|
|
|
.aspectRatio(1.0f) |
|
|
|
.clickable { |
|
|
|
.clickable { |
|
|
|
onClick() |
|
|
|
onClick() |
|
|
|
}, contentAlignment = Alignment.Center |
|
|
|
}, |
|
|
|
|
|
|
|
contentAlignment = Alignment.Center |
|
|
|
) { |
|
|
|
) { |
|
|
|
Text( |
|
|
|
Image( |
|
|
|
"+", |
|
|
|
painter = painterResource("plus.png"), |
|
|
|
modifier = Modifier.fillMaxWidth(), |
|
|
|
contentDescription = null, |
|
|
|
color = MaterialTheme.colorScheme.onBackground, |
|
|
|
modifier = Modifier |
|
|
|
textAlign = TextAlign.Center, |
|
|
|
.width(18.dp) |
|
|
|
fontSize = 50.sp |
|
|
|
.height(18.dp), |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Spacer(Modifier.height(32.dp)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalResourceApi::class) |
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
internal fun SquareMiniature(image: ImageBitmap, isHighlighted: Boolean, onClick: () -> Unit) { |
|
|
|
internal fun SquareMiniature(image: ImageBitmap, isHighlighted: Boolean, onClick: () -> Unit) { |
|
|
|
|
|
|
|
Box( |
|
|
|
|
|
|
|
Modifier.aspectRatio(1.0f).clickable { onClick() }, |
|
|
|
|
|
|
|
contentAlignment = Alignment.BottomEnd |
|
|
|
|
|
|
|
) { |
|
|
|
Image( |
|
|
|
Image( |
|
|
|
bitmap = image, |
|
|
|
bitmap = image, |
|
|
|
contentDescription = null, |
|
|
|
contentDescription = null, |
|
|
|
modifier = Modifier.aspectRatio(1.0f).clickable { onClick() }.then( |
|
|
|
modifier = Modifier.fillMaxSize().clickable { onClick() }.then( |
|
|
|
if (isHighlighted) { |
|
|
|
if (isHighlighted) { |
|
|
|
Modifier.border(BorderStroke(5.dp, Color.White)) |
|
|
|
Modifier//.border(BorderStroke(5.dp, Color.White)) |
|
|
|
} else Modifier |
|
|
|
} else Modifier |
|
|
|
), |
|
|
|
), |
|
|
|
contentScale = ContentScale.Crop |
|
|
|
contentScale = ContentScale.Crop |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
if (isHighlighted) { |
|
|
|
|
|
|
|
Box(Modifier.fillMaxSize().background(ImageviewerColors.uiLightBlack)) |
|
|
|
|
|
|
|
Box( |
|
|
|
|
|
|
|
Modifier |
|
|
|
|
|
|
|
.padding(end = 4.dp, bottom = 4.dp) |
|
|
|
|
|
|
|
.clip(CircleShape) |
|
|
|
|
|
|
|
.width(32.dp) |
|
|
|
|
|
|
|
.background(ImageviewerColors.uiLightBlack) |
|
|
|
|
|
|
|
.aspectRatio(1.0f) |
|
|
|
|
|
|
|
.clickable { |
|
|
|
|
|
|
|
onClick() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
contentAlignment = Alignment.Center |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Image( |
|
|
|
|
|
|
|
painter = painterResource("eye.png"), |
|
|
|
|
|
|
|
contentDescription = null, |
|
|
|
|
|
|
|
modifier = Modifier |
|
|
|
|
|
|
|
.width(17.dp) |
|
|
|
|
|
|
|
.height(17.dp), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
@Composable |
|
|
@ -186,8 +208,6 @@ private fun ListGalleryView( |
|
|
|
onSelect: (GalleryId) -> Unit, |
|
|
|
onSelect: (GalleryId) -> Unit, |
|
|
|
onFullScreen: (GalleryId) -> Unit |
|
|
|
onFullScreen: (GalleryId) -> Unit |
|
|
|
) { |
|
|
|
) { |
|
|
|
GalleryHeader() |
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(10.dp)) |
|
|
|
|
|
|
|
ScrollableColumn( |
|
|
|
ScrollableColumn( |
|
|
|
modifier = Modifier.fillMaxSize() |
|
|
|
modifier = Modifier.fillMaxSize() |
|
|
|
) { |
|
|
|
) { |
|
|
@ -215,44 +235,14 @@ private fun ListGalleryView( |
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
private fun TitleBar(onRefresh: () -> Unit, onToggle: () -> Unit, dependencies: Dependencies) { |
|
|
|
private fun TitleBar(onRefresh: () -> Unit, onToggle: () -> Unit, dependencies: Dependencies) { |
|
|
|
TopAppBar( |
|
|
|
TopAppBar( |
|
|
|
modifier = Modifier.background(brush = kotlinHorizontalGradientBrush), |
|
|
|
modifier = Modifier.padding(start = 12.dp, end = 12.dp), |
|
|
|
colors = TopAppBarDefaults.smallTopAppBarColors( |
|
|
|
colors = TopAppBarDefaults.smallTopAppBarColors( |
|
|
|
containerColor = ImageviewerColors.Transparent, |
|
|
|
containerColor = ImageviewerColors.Transparent, |
|
|
|
titleContentColor = MaterialTheme.colorScheme.onBackground |
|
|
|
titleContentColor = MaterialTheme.colorScheme.onBackground |
|
|
|
), |
|
|
|
), |
|
|
|
title = { |
|
|
|
title = { |
|
|
|
Row(Modifier.height(50.dp)) { |
|
|
|
Row(Modifier.height(50.dp).fillMaxWidth(), horizontalArrangement = Arrangement.End) { |
|
|
|
Text( |
|
|
|
CircularButton(painterResource("list_view.png")) { onToggle() } |
|
|
|
dependencies.localization.appName, |
|
|
|
|
|
|
|
modifier = Modifier.weight(1f).align(Alignment.CenterVertically), |
|
|
|
|
|
|
|
fontWeight = FontWeight.Bold |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
Surface( |
|
|
|
|
|
|
|
color = ImageviewerColors.Transparent, |
|
|
|
|
|
|
|
modifier = Modifier.padding(end = 20.dp).align(Alignment.CenterVertically), |
|
|
|
|
|
|
|
shape = CircleShape |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Image( |
|
|
|
|
|
|
|
painter = painterResource("list_view.png"), |
|
|
|
|
|
|
|
contentDescription = null, |
|
|
|
|
|
|
|
modifier = Modifier.size(35.dp).clickable { |
|
|
|
|
|
|
|
onToggle() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Surface( |
|
|
|
|
|
|
|
color = ImageviewerColors.Transparent, |
|
|
|
|
|
|
|
modifier = Modifier.padding(end = 20.dp).align(Alignment.CenterVertically), |
|
|
|
|
|
|
|
shape = CircleShape |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Image( |
|
|
|
|
|
|
|
painter = painterResource("refresh.png"), |
|
|
|
|
|
|
|
contentDescription = null, |
|
|
|
|
|
|
|
modifier = Modifier.size(35.dp).clickable { |
|
|
|
|
|
|
|
onRefresh() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|