Browse Source

Fixed loading screen issue.

pull/24/head
Roman Sedaikin 5 years ago
parent
commit
728210fdde
  1. 1
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/model/ContentState.kt
  2. 7
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/MainScreen.kt
  3. 2
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/style/Palette.kt
  4. 2
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Clickable.kt
  5. 1
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Scalable.kt
  6. 5
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/ContentState.kt
  7. 25
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullImageScreen.kt
  8. 15
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt
  9. 43
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt
  10. 14
      examples/imageviewer/desktop/src/main/kotlin/imageviewer/Main.kt

1
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/model/ContentState.kt

@ -302,6 +302,7 @@ object ContentState { @@ -302,6 +302,7 @@ object ContentState {
clearCache(context)
miniatures.clear()
isAppUIReady.value = false
initData()
}
} else {
handler.post {

7
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/MainScreen.kt

@ -64,6 +64,7 @@ import example.imageviewer.R @@ -64,6 +64,7 @@ import example.imageviewer.R
@Composable
fun setMainScreen(content: ContentState) {
if (content.isContentReady()) {
Column {
setTopContent(content)
@ -129,9 +130,11 @@ fun setTitleBar(text: String, content: ContentState) { @@ -129,9 +130,11 @@ fun setTitleBar(text: String, content: ContentState) {
) {
Clickable(
onClick = {
if (content.isContentReady())
if (content.isContentReady()) {
content.refresh()
}) {
}
}
) {
Image(
icRefresh(),
modifier = Modifier.preferredSize(35.dp)

2
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/style/Palette.kt

@ -24,7 +24,7 @@ val DarkGray = Color(32, 32, 32) @@ -24,7 +24,7 @@ val DarkGray = Color(32, 32, 32)
val PreviewImageAreaHoverColor = Color(45, 45, 45)
val ToastBackground = Color(23, 23, 23)
val MiniatureColor = Color(50, 50, 50)
val MiniatureHoverColor = Color(60, 60, 60)
val MiniatureHoverColor = Color(55, 55, 55)
val Foreground = Color(210, 210, 210)
val TranslucentBlack = Color(0, 0, 0, 60)
val TranslucentWhite = Color(255, 255, 255, 20)

2
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Clickable.kt

@ -17,8 +17,8 @@ package example.imageviewer.view @@ -17,8 +17,8 @@ package example.imageviewer.view
import androidx.compose.runtime.Composable
import androidx.compose.runtime.emptyContent
import androidx.compose.foundation.Box
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
@Composable

1
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Scalable.kt

@ -21,7 +21,6 @@ import androidx.compose.ui.gesture.RawScaleObserver @@ -21,7 +21,6 @@ import androidx.compose.ui.gesture.RawScaleObserver
import androidx.compose.ui.gesture.doubleTapGestureFilter
import androidx.compose.ui.gesture.rawScaleGestureFilter
import androidx.compose.ui.Modifier
import androidx.compose.foundation.ContentGravity
import androidx.compose.foundation.Interaction
import androidx.compose.foundation.InteractionState
import androidx.compose.material.Surface

5
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/model/ContentState.kt

@ -37,6 +37,7 @@ object ContentState { @@ -37,6 +37,7 @@ object ContentState {
private lateinit var repository: ImageRepository
private lateinit var uriRepository: String
@Composable
fun applyContent(uriRepository: String): ContentState {
if (this::uriRepository.isInitialized && this.uriRepository == uriRepository) {
return this
@ -214,8 +215,9 @@ object ContentState { @@ -214,8 +215,9 @@ object ContentState {
fun setMainImage(picture: Picture) {
if (mainImageWrapper.getId() == picture.id) {
if (!isContentReady())
if (!isContentReady()) {
isAppUIReady.value = true
}
return
}
@ -272,6 +274,7 @@ object ContentState { @@ -272,6 +274,7 @@ object ContentState {
clearCache()
miniatures.clear()
isAppUIReady.value = false
initData()
}
} else {
invokeLater {

25
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullImageScreen.kt

@ -16,34 +16,34 @@ @@ -16,34 +16,34 @@
package example.imageviewer.view
import java.awt.image.BufferedImage
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.ScrollableRow
import androidx.compose.foundation.Image
import androidx.compose.foundation.Text
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageAsset
import androidx.compose.ui.graphics.asImageAsset
import androidx.compose.ui.layout.ContentScale
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.foundation.Box
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Stack
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageAsset
import androidx.compose.ui.graphics.asImageAsset
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import example.imageviewer.core.FilterType
import example.imageviewer.model.AppState
@ -93,7 +93,7 @@ fun setImageFullScreen( @@ -93,7 +93,7 @@ fun setImageFullScreen(
@Composable
private fun setLoadingScreen() {
Stack {
Box {
Surface(color = MiniatureColor, modifier = Modifier.preferredHeight(44.dp)) {}
Box(modifier = Modifier.align(Alignment.Center)) {
Surface(color = DarkGray, elevation = 4.dp, shape = CircleShape) {
@ -179,9 +179,8 @@ fun FilterButton( @@ -179,9 +179,8 @@ fun FilterButton(
modifier: Modifier = Modifier.preferredSize(38.dp)
) {
val filterButtonHover = remember { mutableStateOf(false) }
Surface(
color = Transparent,
shape = CircleShape
Box(
modifier = Modifier.background(color = Transparent).clip(CircleShape)
) {
Clickable(
modifier = Modifier.hover(

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

@ -17,7 +17,6 @@ package example.imageviewer.view @@ -17,7 +17,6 @@ package example.imageviewer.view
import androidx.compose.foundation.clickable
import androidx.compose.foundation.background
import androidx.compose.foundation.Box
import androidx.compose.foundation.Text
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollableColumn
@ -28,6 +27,7 @@ import androidx.compose.ui.graphics.asImageAsset @@ -28,6 +27,7 @@ import androidx.compose.ui.graphics.asImageAsset
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@ -88,7 +88,7 @@ fun setMainScreen(content: ContentState) { @@ -88,7 +88,7 @@ fun setMainScreen(content: ContentState) {
@Composable
private fun setLoadingScreen(content: ContentState) {
Stack {
Box {
Column {
setTopContent(content)
}
@ -148,9 +148,11 @@ fun setTitleBar(text: String, content: ContentState) { @@ -148,9 +148,11 @@ fun setTitleBar(text: String, content: ContentState) {
})
.background(color = if (refreshButtonHover.value) TranslucentBlack else Transparent),
onClick = {
if (content.isContentReady())
if (content.isContentReady()) {
content.refresh()
}) {
}
}
) {
Image(
icRefresh(),
modifier = Modifier.preferredSize(35.dp)
@ -213,9 +215,8 @@ fun setMiniatureUI( @@ -213,9 +215,8 @@ fun setMiniatureUI(
shape = RectangleShape,
elevation = 20.dp
) {
Row(modifier = Modifier.padding(end = 30.dp)
) {
Clickable(
Row(modifier = Modifier.padding(end = 30.dp)) {
Clickable(
onClick = {
content.fullscreen(picture)
}

43
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt

@ -15,9 +15,11 @@ @@ -15,9 +15,11 @@
*/
package example.imageviewer.view
import androidx.compose.foundation.Box
import androidx.compose.foundation.ContentGravity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.Text
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
@ -25,8 +27,8 @@ import androidx.compose.runtime.onActive @@ -25,8 +27,8 @@ import androidx.compose.runtime.onActive
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.clip
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.Popup
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
@ -34,6 +36,7 @@ import kotlinx.coroutines.delay @@ -34,6 +36,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.GlobalScope
import example.imageviewer.style.ToastBackground
import example.imageviewer.style.Foreground
import androidx.compose.material.Surface
enum class ToastDuration(val value: Int) {
Short(1000), Long(3000)
@ -53,25 +56,27 @@ fun Toast( @@ -53,25 +56,27 @@ fun Toast(
if (visibility.value) {
isShown = true
Popup(
Box(
modifier = Modifier.fillMaxSize().padding(bottom = 20.dp),
alignment = Alignment.BottomCenter
) {
Box(
Modifier.preferredSize(300.dp, 70.dp),
backgroundColor = ToastBackground,
shape = RoundedCornerShape(4.dp),
gravity = ContentGravity.Center
Surface(
modifier = Modifier.preferredSize(300.dp, 70.dp),
color = ToastBackground,
shape = RoundedCornerShape(4.dp)
) {
Text(
text = text,
color = Foreground
)
}
onActive {
GlobalScope.launch {
delay(duration.value.toLong())
isShown = false
visibility.value = false
Box(alignment = Alignment.Center) {
Text(
text = text,
color = Foreground
)
}
onActive {
GlobalScope.launch {
delay(duration.value.toLong())
isShown = false
visibility.value = false
}
}
}
}

14
examples/imageviewer/desktop/src/main/kotlin/imageviewer/Main.kt

@ -15,7 +15,8 @@ @@ -15,7 +15,8 @@
*/
package example.imageviewer
import androidx.compose.desktop.AppWindow
import androidx.compose.desktop.Window
import androidx.compose.runtime.remember
import example.imageviewer.utils.getPreferredWindowSize
import example.imageviewer.view.BuildAppUI
import example.imageviewer.model.ContentState
@ -24,15 +25,14 @@ import example.imageviewer.style.icAppRounded @@ -24,15 +25,14 @@ import example.imageviewer.style.icAppRounded
fun main() {
val content = ContentState.applyContent(
"https://spvessel.com/iv/images/fetching.list"
)
AppWindow(
Window(
title = "ImageViewer",
size = getPreferredWindowSize(800, 1000),
icon = icAppRounded()
).show {
) {
val content = ContentState.applyContent(
"https://spvessel.com/iv/images/fetching.list"
)
BuildAppUI(content)
}
}

Loading…
Cancel
Save