Browse Source

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

pull/328/head 0.3.0-build145
Igor Demin 3 years ago
parent
commit
728b4d5f76
  1. 36
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/DesktopContentState.kt
  2. 36
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt
  3. 48
      examples/imageviewer/desktop/src/jvmMain/kotlin/example/imageviewer/Main.kt
  4. 48
      examples/imageviewer/desktop/src/jvmMain/kotlin/imageviewer/Main.kt

36
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/DesktopContentState.kt

@ -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 {

36
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt

@ -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
)
}
}

48
examples/imageviewer/desktop/src/jvmMain/kotlin/example/imageviewer/Main.kt

@ -0,0 +1,48 @@
package example.imageviewer
import androidx.compose.desktop.DesktopTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.remember
import example.imageviewer.model.ContentState
import example.imageviewer.style.icAppRounded
import example.imageviewer.utils.Application
import example.imageviewer.utils.getPreferredWindowSize
import example.imageviewer.view.BuildAppUI
import example.imageviewer.view.SplashUI
fun main() = Application {
val content = remember {
ContentState.applyContent(
"https://raw.githubusercontent.com/JetBrains/compose-jb/master/artwork/imageviewerrepo/fetching.list"
)
}
val icon = remember(::icAppRounded)
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()
}
}
}
}
}

48
examples/imageviewer/desktop/src/jvmMain/kotlin/imageviewer/Main.kt

@ -1,48 +0,0 @@
package example.imageviewer
import androidx.compose.desktop.DesktopTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.remember
import example.imageviewer.model.ContentState
import example.imageviewer.style.icAppRounded
import example.imageviewer.utils.Application
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"
)
Application {
val icon = remember(::icAppRounded)
if (content.isContentReady()) {
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()
}
}
}
}
}
}
Loading…
Cancel
Save