Skip to content
Snippets Groups Projects
Commit 728b4d5f authored by Igor Demin's avatar Igor Demin
Browse files

ImageVIewer. Don't show splash screen on click on refresh button

parent bde57fd8
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ object ContentState {
}
this.uriRepository = uriRepository
repository = ImageRepository(uriRepository)
isAppUIReady.value = false
isContentReady.value = false
initData()
......@@ -36,9 +36,14 @@ object ContentState {
private val executor: ExecutorService by lazy { Executors.newFixedThreadPool(2) }
private val isAppUIReady = mutableStateOf(false)
private val isAppReady = mutableStateOf(false)
fun isAppReady(): Boolean {
return isAppReady.value
}
private val isContentReady = mutableStateOf(false)
fun isContentReady(): Boolean {
return isAppUIReady.value
return isContentReady.value
}
// drawable content
......@@ -124,7 +129,7 @@ object ContentState {
// application content initialization
private fun initData() {
if (isAppUIReady.value)
if (isContentReady.value)
return
val directory = File(cacheImagePath)
......@@ -142,7 +147,7 @@ object ContentState {
showPopUpMessage(
ResString.repoInvalid
)
isAppUIReady.value = true
onContentReady()
}
return@execute
}
......@@ -154,7 +159,7 @@ object ContentState {
showPopUpMessage(
ResString.repoEmpty
)
isAppUIReady.value = true
onContentReady()
}
} else {
val picture = loadFullImage(imageList[0])
......@@ -168,7 +173,7 @@ object ContentState {
appliedFilters.add(mainImageWrapper.getFilters())
currentImageIndex.value = mainImageWrapper.getId()
}
isAppUIReady.value = true
onContentReady()
}
}
} else {
......@@ -176,7 +181,7 @@ object ContentState {
showPopUpMessage(
ResString.noInternet
)
isAppUIReady.value = true
onContentReady()
}
}
} catch (e: Exception) {
......@@ -191,7 +196,7 @@ object ContentState {
}
fun fullscreen(picture: Picture) {
isAppUIReady.value = false
isContentReady.value = false
AppState.screenState(ScreenType.FullscreenImage)
setMainImage(picture)
}
......@@ -199,7 +204,7 @@ object ContentState {
fun setMainImage(picture: Picture) {
if (mainImageWrapper.getId() == picture.id) {
if (!isContentReady()) {
isAppUIReady.value = true
onContentReady()
}
return
}
......@@ -211,7 +216,7 @@ object ContentState {
val fullSizePicture = loadFullImage(picture.source)
fullSizePicture.id = picture.id
wrapPictureIntoMainImage(fullSizePicture)
isAppUIReady.value = true
onContentReady()
}
} else {
invokeLater {
......@@ -219,12 +224,17 @@ object ContentState {
"${ResString.noInternet}\n${ResString.loadImageUnavailable}"
)
wrapPictureIntoMainImage(picture)
isAppUIReady.value = true
onContentReady()
}
}
}
}
private fun onContentReady() {
isContentReady.value = true
isAppReady.value = true
}
private fun wrapPictureIntoMainImage(picture: Picture) {
mainImageWrapper.wrapPicture(picture)
mainImageWrapper.saveOrigin()
......@@ -258,7 +268,7 @@ object ContentState {
invokeLater {
clearCache()
miniatures.clear()
isAppUIReady.value = false
isContentReady.value = false
initData()
}
} else {
......
......@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
......@@ -21,6 +22,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Card
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
......@@ -56,10 +58,36 @@ import example.imageviewer.utils.toByteArray
@Composable
fun setMainScreen(content: ContentState) {
check(content.isContentReady())
Column {
setTopContent(content)
setScrollableArea(content)
if (content.isContentReady()) {
Column {
setTopContent(content)
setScrollableArea(content)
}
} else {
setLoadingScreen(content)
}
}
@Composable
private fun setLoadingScreen(content: ContentState) {
Box {
Column {
setTopContent(content)
}
Box(modifier = Modifier.align(Alignment.Center)) {
Surface(color = DarkGray, elevation = 4.dp, shape = CircleShape) {
CircularProgressIndicator(
modifier = Modifier.preferredSize(50.dp).padding(3.dp, 3.dp, 4.dp, 4.dp),
color = DarkGreen
)
}
}
Text(
text = ResString.loading,
modifier = Modifier.align(Alignment.Center).offset(0.dp, 70.dp),
style = MaterialTheme.typography.body1,
color = Foreground
)
}
}
......
......@@ -10,39 +10,39 @@ import example.imageviewer.utils.getPreferredWindowSize
import example.imageviewer.view.BuildAppUI
import example.imageviewer.view.SplashUI
fun main() {
val content = ContentState.applyContent(
"https://raw.githubusercontent.com/JetBrains/compose-jb/master/artwork/imageviewerrepo/fetching.list"
)
fun main() = Application {
val content = remember {
ContentState.applyContent(
"https://raw.githubusercontent.com/JetBrains/compose-jb/master/artwork/imageviewerrepo/fetching.list"
)
}
Application {
val icon = remember(::icAppRounded)
val icon = remember(::icAppRounded)
if (content.isContentReady()) {
ComposableWindow(
title = "Image Viewer",
size = getPreferredWindowSize(800, 1000),
icon = icon
) {
MaterialTheme {
DesktopTheme {
BuildAppUI(content)
}
if (content.isAppReady()) {
ComposableWindow(
title = "Image Viewer",
size = getPreferredWindowSize(800, 1000),
icon = icon
) {
MaterialTheme {
DesktopTheme {
BuildAppUI(content)
}
}
} else {
ComposableWindow(
title = "Image Viewer",
size = getPreferredWindowSize(800, 300),
undecorated = true,
icon = icon,
) {
MaterialTheme {
DesktopTheme {
SplashUI()
}
}
} else {
ComposableWindow(
title = "Image Viewer",
size = getPreferredWindowSize(800, 300),
undecorated = true,
icon = icon,
) {
MaterialTheme {
DesktopTheme {
SplashUI()
}
}
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment