Skip to content

Commit

Permalink
Merge pull request #33 from KevinSchildhorn/ImagePreview
Browse files Browse the repository at this point in the history
Image preview
  • Loading branch information
KevinSchildhorn authored Dec 8, 2023
2 parents c79fda9 + 646eb8a commit 75082ca
Show file tree
Hide file tree
Showing 41 changed files with 438 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,45 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.kevinschildhorn.fotopresenter.data.DirectoryContents
import com.kevinschildhorn.fotopresenter.data.FolderDirectoryContent
import com.kevinschildhorn.fotopresenter.data.network.MockNetworkDirectory
import com.kevinschildhorn.fotopresenter.ui.compose.directory.BaseDirectory
import com.kevinschildhorn.fotopresenter.data.FolderDirectory
import com.kevinschildhorn.fotopresenter.data.State
import com.kevinschildhorn.fotopresenter.data.network.MockNetworkDirectoryDetails
import com.kevinschildhorn.fotopresenter.ui.compose.directory.DirectoryGridCell
import com.kevinschildhorn.fotopresenter.ui.compose.directory.DirectoryGrid
import com.kevinschildhorn.fotopresenter.ui.compose.directory.FolderDirectoryItem
import com.kevinschildhorn.fotopresenter.ui.compose.directory.FolderDirectoryGridCell
import com.kevinschildhorn.fotopresenter.ui.state.DirectoryGridState
import com.kevinschildhorn.fotopresenter.ui.state.FolderDirectoryGridCellState
import com.kevinschildhorn.fotopresenter.ui.state.ImageDirectoryGridCellState

@Preview
@Composable
fun BaseDirectoryPreview() {
Column {
BaseDirectory() {}
DirectoryGridCell() {}
}
}

@Preview
@Composable
fun FolderDirectoryEmptyPreview() {
Column {
FolderDirectoryItem("Folder")
FolderDirectoryGridCell(FolderDirectoryGridCellState("Hello",0))
}
}

@Preview
@Composable
fun DirectoryGridPreview() {
DirectoryGrid(
DirectoryContents(
folders = listOf(
FolderDirectoryContent(MockNetworkDirectory("Test 1", id = 1)),
FolderDirectoryContent(MockNetworkDirectory("Test 2", id = 2)),
FolderDirectoryContent(MockNetworkDirectory("Test 3", id = 3)),
FolderDirectoryContent(MockNetworkDirectory("Test 4", id = 4)),
FolderDirectoryContent(MockNetworkDirectory("Test 6", id = 5)),
FolderDirectoryContent(MockNetworkDirectory("Test 5", id = 6)),
directoryContent = DirectoryGridState(
folderStates = listOf(
FolderDirectoryGridCellState("Hello",0),
),
imageStates = mutableListOf(
ImageDirectoryGridCellState(State.IDLE,"Hello", 1)
)
),
) {
}
onFolderPressed = {},
onImageDirectoryPressed = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.kevinschildhorn.fotopresenter.ui.compose.common.ErrorView
import com.kevinschildhorn.fotopresenter.ui.compose.common.TitleView
import com.kevinschildhorn.fotopresenter.ui.compose.login.FotoPasswordTextField
import com.kevinschildhorn.fotopresenter.ui.compose.login.FotoTextField
import com.kevinschildhorn.fotopresenter.ui.compose.login.LoginPasswordTextField
import com.kevinschildhorn.fotopresenter.ui.compose.login.LoginTextField
import com.kevinschildhorn.fotopresenter.ui.compose.login.LoginScreenForm
import com.kevinschildhorn.fotopresenter.ui.state.LoginScreenState
import com.kevinschildhorn.fotopresenter.ui.state.State
import com.kevinschildhorn.fotopresenter.ui.state.UiState

@Preview
Expand All @@ -28,10 +27,10 @@ fun ErrorViewPreview() {
@Composable
fun FotoTextFieldPreview() {
Column {
FotoTextField("", {}, "Hint")
FotoTextField("Value", {}, "Hint")
FotoPasswordTextField("", {}, "Password")
FotoPasswordTextField("Value", {}, "Password")
LoginTextField("", {}, "Hint")
LoginTextField("Value", {}, "Hint")
LoginPasswordTextField("", {}, "Password")
LoginPasswordTextField("Value", {}, "Password")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.kevinschildhorn.fotopresenter.ui
package com.kevinschildhorn.fotopresenter.ui.shared

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import com.hierynomus.smbj.share.File

actual fun getBitmapFromFile(file: File): ImageBitmap? {
actual fun getBitmapFromFile(file: File, size: Int): ImageBitmap? {
val options = BitmapFactory.Options()
options.inSampleSize = 3
options.inSampleSize = 2
BitmapFactory.decodeStream(file.inputStream, null, options)?.let {
return Bitmap.createScaledBitmap(it, 200, 200, false).asImageBitmap()
val dimensions = getScaledDimensions(it.width, it.height, size)
return Bitmap.createScaledBitmap(it, dimensions.first, dimensions.second, false)
.asImageBitmap()
}

return null
Expand Down
1 change: 0 additions & 1 deletion shared/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fun App(
LoginScreen(loginViewModel) {
currentScreen.value = Screen.DIRECTORY
}

Screen.DIRECTORY -> DirectoryScreen(directoryViewModel)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.kevinschildhorn.fotopresenter.data

import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectoryDetails
import com.kevinschildhorn.fotopresenter.ui.shared.SharedImage

interface Directory {
val details: NetworkDirectoryDetails

val name: String
get() = details.name

val id: Int
get() = details.id
}

data class FolderDirectory(
override val details: NetworkDirectoryDetails,
) : Directory

data class ImageDirectory(
override val details: NetworkDirectoryDetails,
val image: SharedImage? = null,
) : Directory

data class DirectoryContents(
val folders: List<FolderDirectory> = emptyList(),
val images: List<ImageDirectory> = emptyList(),
) {
val allDirectories: List<Directory>
get() = folders + images
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kevinschildhorn.fotopresenter.ui.state
package com.kevinschildhorn.fotopresenter.data

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kevinschildhorn.fotopresenter.data.datasources

import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectory
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectoryDetails
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandler
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandlerError
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandlerException
Expand All @@ -18,14 +18,14 @@ class DirectoryDataSource(private val networkHandler: NetworkHandler) {
throw NetworkHandlerException(NetworkHandlerError.DIRECTORY_NOT_FOUND)
}

suspend fun getFolderDirectories(path: String): List<NetworkDirectory> {
suspend fun getFolderDirectories(path: String): List<NetworkDirectoryDetails> {
if (!networkHandler.isConnected) throw NetworkHandlerException(NetworkHandlerError.NOT_CONNECTED)
return networkHandler.getDirectoryContents(path).filter {
it.fileName != "."
}.filter { it.isDirectory }
}

suspend fun getImageDirectories(path: String): List<NetworkDirectory> {
suspend fun getImageDirectories(path: String): List<NetworkDirectoryDetails> {
if (!networkHandler.isConnected) throw NetworkHandlerException(NetworkHandlerError.NOT_CONNECTED)
return networkHandler.getDirectoryContents(path).filter {
it.fileName != "."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.kevinschildhorn.fotopresenter.data.datasources

import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectory
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectoryDetails
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandler
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandlerError
import com.kevinschildhorn.fotopresenter.data.network.NetworkHandlerException
import com.kevinschildhorn.fotopresenter.ui.SharedImage
import com.kevinschildhorn.fotopresenter.ui.shared.SharedImage
import kotlin.coroutines.cancellation.CancellationException

/**
Fetches Photos from a NAS
**/
class ImageRemoteDataSource(private val networkHandler: NetworkHandler) {
@Throws(NetworkHandlerException::class, CancellationException::class)
suspend fun getImage(directory: NetworkDirectory): SharedImage? {
suspend fun getImage(directory: NetworkDirectoryDetails): SharedImage? {
if (!networkHandler.isConnected) throw NetworkHandlerException(NetworkHandlerError.NOT_CONNECTED)
return networkHandler.openImage(directory.fullPath)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kevinschildhorn.fotopresenter.data.network

interface NetworkDirectory {
interface NetworkDirectoryDetails {
val fullPath: String
val id: Int

Expand All @@ -23,7 +23,7 @@ interface NetworkDirectory {
fileExtension == "bmp"
}

class MockNetworkDirectory(
class MockNetworkDirectoryDetails(
override val fullPath: String,
override val id: Int,
) : NetworkDirectory
) : NetworkDirectoryDetails
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kevinschildhorn.fotopresenter.data.network

import com.kevinschildhorn.fotopresenter.data.LoginCredentials
import com.kevinschildhorn.fotopresenter.ui.SharedImage
import com.kevinschildhorn.fotopresenter.ui.shared.SharedImage

interface NetworkHandler {
val isConnected: Boolean
Expand All @@ -10,7 +10,7 @@ interface NetworkHandler {

suspend fun disconnect()

suspend fun getDirectoryContents(path: String): List<NetworkDirectory>
suspend fun getDirectoryContents(path: String): List<NetworkDirectoryDetails>

suspend fun openDirectory(path: String): String?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.kevinschildhorn.fotopresenter.data.repositories

import com.kevinschildhorn.fotopresenter.data.DirectoryContents
import com.kevinschildhorn.fotopresenter.data.FolderDirectoryContent
import com.kevinschildhorn.fotopresenter.data.ImageDirectoryContent
import com.kevinschildhorn.fotopresenter.data.FolderDirectory
import com.kevinschildhorn.fotopresenter.data.ImageDirectory
import com.kevinschildhorn.fotopresenter.data.datasources.DirectoryDataSource
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectory
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectoryDetails

class DirectoryRepository(
private val dataSource: DirectoryDataSource,
) {
suspend fun getDirectoryContents(path: String): DirectoryContents {
val folderDirectories: List<NetworkDirectory> = dataSource.getFolderDirectories(path)
val imageDirectories: List<NetworkDirectory> = dataSource.getImageDirectories(path)
val folderDirectories: List<NetworkDirectoryDetails> = dataSource.getFolderDirectories(path)
val imageDirectories: List<NetworkDirectoryDetails> = dataSource.getImageDirectories(path)

return DirectoryContents(
folders = folderDirectories.map { FolderDirectoryContent(it) },
images = imageDirectories.map { ImageDirectoryContent(it) },
folders = folderDirectories.map { FolderDirectory(it) },
images = imageDirectories.map { ImageDirectory(it) },
)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.kevinschildhorn.fotopresenter.data.repositories

import com.kevinschildhorn.fotopresenter.data.datasources.ImageRemoteDataSource
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectory
import com.kevinschildhorn.fotopresenter.ui.SharedImage
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectoryDetails
import com.kevinschildhorn.fotopresenter.ui.shared.SharedImage

class ImageRepository(
private val remoteDataSource: ImageRemoteDataSource,
) {
suspend fun getImage(directory: NetworkDirectory): SharedImage? = remoteDataSource.getImage(directory)
suspend fun getImage(directory: NetworkDirectoryDetails): SharedImage? = remoteDataSource.getImage(directory)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.kevinschildhorn.fotopresenter.domain

import co.touchlab.kermit.Logger
import com.kevinschildhorn.fotopresenter.data.DirectoryContents
import com.kevinschildhorn.fotopresenter.data.ImageDirectoryContent
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectory
import com.kevinschildhorn.fotopresenter.data.ImageDirectory
import com.kevinschildhorn.fotopresenter.data.network.NetworkDirectoryDetails
import com.kevinschildhorn.fotopresenter.data.repositories.DirectoryRepository
import com.kevinschildhorn.fotopresenter.data.repositories.ImageRepository
import com.kevinschildhorn.fotopresenter.ui.SharedImage
import com.kevinschildhorn.fotopresenter.ui.shared.SharedImage

/**
Retrieving Directories from Location
Expand All @@ -24,10 +24,10 @@ class RetrieveDirectoryContentsUseCase(
}
}

private suspend fun DirectoryContents.updateImages(block: suspend (NetworkDirectory) -> SharedImage?): DirectoryContents =
private suspend fun DirectoryContents.updateImages(block: suspend (NetworkDirectoryDetails) -> SharedImage?): DirectoryContents =
this.copy(
images =
images.map {
ImageDirectoryContent(it.directory, image = block(it.directory))
ImageDirectory(it.details, image = block(it.details))
},
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

enum class Padding(val rawValue: Int) {
IMAGE(50),
EXTRA_LARGE(64),
LARGE(32),
STANDARD(20),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.kevinschildhorn.fotopresenter.data.State
import com.kevinschildhorn.fotopresenter.ui.atoms.Padding
import com.kevinschildhorn.fotopresenter.ui.compose.directory.DirectoryGrid
import com.kevinschildhorn.fotopresenter.ui.viewmodel.DirectoryViewModel
Expand All @@ -25,11 +27,21 @@ fun DirectoryScreen(viewModel: DirectoryViewModel) {
),
)
DirectoryGrid(
uiState.directoryContents,
uiState.directoryGridState,
modifier =
Modifier
.padding(top = Padding.EXTRA_LARGE.dp),
) {
viewModel.changeDirectory(it)
onFolderPressed = {
uiState.selectedImage = State.IDLE
viewModel.changeDirectory(it)
},
onImageDirectoryPressed = {
uiState.selectedImage = it
},
)
if (uiState.selectedImage != State.IDLE) {
ImagePreviewOverlay(uiState.selectedImage) {
uiState.selectedImage = State.IDLE
}
}
}
Loading

0 comments on commit 75082ca

Please sign in to comment.