Browse Source

Upgrade imageviewer to build150

pull/374/head
Jim Sproch 4 years ago
parent
commit
a74417fcef
  1. 7
      examples/imageviewer/android/build.gradle.kts
  2. 2
      examples/imageviewer/android/src/main/java/imageviewer/MainActivity.kt
  3. 2
      examples/imageviewer/build.gradle.kts
  4. 24
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/style/Decoration.kt
  5. 16
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/FullImageScreen.kt
  6. 28
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/MainScreen.kt
  7. 3
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Clickable.kt
  8. 5
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/utils/Application.kt

7
examples/imageviewer/android/build.gradle.kts

@ -22,4 +22,11 @@ android {
dependencies { dependencies {
implementation(project(":common")) implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.0-alpha02") {
exclude(group = "androidx.compose.animation")
exclude(group = "androidx.compose.foundation")
exclude(group = "androidx.compose.material")
exclude(group = "androidx.compose.runtime")
exclude(group = "androidx.compose.ui")
}
} }

2
examples/imageviewer/android/src/main/java/imageviewer/MainActivity.kt

@ -2,7 +2,7 @@ package example.imageviewer
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.platform.setContent import androidx.activity.compose.setContent
import example.imageviewer.view.BuildAppUI import example.imageviewer.view.BuildAppUI
import example.imageviewer.model.ContentState import example.imageviewer.model.ContentState
import example.imageviewer.model.ImageRepository import example.imageviewer.model.ImageRepository

2
examples/imageviewer/build.gradle.kts

@ -11,7 +11,7 @@ buildscript {
dependencies { dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build149") classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build150")
classpath("com.android.tools.build:gradle:4.0.1") classpath("com.android.tools.build:gradle:4.0.1")
// __KOTLIN_COMPOSE_VERSION__ // __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.4.30")) classpath(kotlin("gradle-plugin", version = "1.4.30"))

24
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/style/Decoration.kt

@ -1,38 +1,38 @@
package example.imageviewer.style package example.imageviewer.style
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.res.imageResource import androidx.compose.ui.res.painterResource
import example.imageviewer.common.R import example.imageviewer.common.R
@Composable @Composable
fun icEmpty() = imageResource(R.raw.empty) fun icEmpty() = painterResource(R.raw.empty)
@Composable @Composable
fun icBack() = imageResource(R.raw.back) fun icBack() = painterResource(R.raw.back)
@Composable @Composable
fun icRefresh() = imageResource(R.raw.refresh) fun icRefresh() = painterResource(R.raw.refresh)
@Composable @Composable
fun icDots() = imageResource(R.raw.dots) fun icDots() = painterResource(R.raw.dots)
@Composable @Composable
fun icFilterGrayscaleOn() = imageResource(R.raw.grayscale_on) fun icFilterGrayscaleOn() = painterResource(R.raw.grayscale_on)
@Composable @Composable
fun icFilterGrayscaleOff() = imageResource(R.raw.grayscale_off) fun icFilterGrayscaleOff() = painterResource(R.raw.grayscale_off)
@Composable @Composable
fun icFilterPixelOn() = imageResource(R.raw.pixel_on) fun icFilterPixelOn() = painterResource(R.raw.pixel_on)
@Composable @Composable
fun icFilterPixelOff() = imageResource(R.raw.pixel_off) fun icFilterPixelOff() = painterResource(R.raw.pixel_off)
@Composable @Composable
fun icFilterBlurOn() = imageResource(R.raw.blur_on) fun icFilterBlurOn() = painterResource(R.raw.blur_on)
@Composable @Composable
fun icFilterBlurOff() = imageResource(R.raw.blur_off) fun icFilterBlurOff() = painterResource(R.raw.blur_off)
@Composable @Composable
fun icFilterUnknown() = imageResource(R.raw.filter_unknown) fun icFilterUnknown() = painterResource(R.raw.filter_unknown)

16
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/FullImageScreen.kt

@ -3,8 +3,9 @@ package example.imageviewer.view
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Rect import android.graphics.Rect
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollableRow
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -25,6 +26,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import example.imageviewer.core.FilterType import example.imageviewer.core.FilterType
@ -85,7 +87,7 @@ fun setToolBar(
text: String, text: String,
content: ContentState content: ContentState
) { ) {
val scrollState = rememberScrollState()
Surface(color = MiniatureColor, modifier = Modifier.preferredHeight(44.dp)) { Surface(color = MiniatureColor, modifier = Modifier.preferredHeight(44.dp)) {
Row(modifier = Modifier.padding(end = 30.dp)) { Row(modifier = Modifier.padding(end = 30.dp)) {
Surface( Surface(
@ -122,11 +124,9 @@ fun setToolBar(
.align(Alignment.CenterVertically), .align(Alignment.CenterVertically),
shape = CircleShape shape = CircleShape
) { ) {
ScrollableRow { Row(Modifier.horizontalScroll(scrollState)) {
Row { for (type in FilterType.values()) {
for (type in FilterType.values()) { FilterButton(content, type)
FilterButton(content, type)
}
} }
} }
} }
@ -158,7 +158,7 @@ fun FilterButton(
} }
@Composable @Composable
fun getFilterImage(type: FilterType, content: ContentState): ImageBitmap { fun getFilterImage(type: FilterType, content: ContentState): Painter {
return when (type) { return when (type) {
FilterType.GrayScale -> if (content.isFilterEnabled(type)) icFilterGrayscaleOn() else icFilterGrayscaleOff() FilterType.GrayScale -> if (content.isFilterEnabled(type)) icFilterGrayscaleOn() else icFilterGrayscaleOff()

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

@ -1,8 +1,9 @@
package example.imageviewer.view package example.imageviewer.view
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@ -28,6 +29,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import example.imageviewer.common.R import example.imageviewer.common.R
@ -145,7 +147,7 @@ fun setPreviewImageUI(content: ContentState) {
if (content.isMainImageEmpty()) { if (content.isMainImageEmpty()) {
icEmpty() icEmpty()
} else { } else {
content.getSelectedImage().asImageBitmap() BitmapPainter(content.getSelectedImage().asImageBitmap())
}, },
contentDescription = null, contentDescription = null,
modifier = Modifier modifier = Modifier
@ -223,18 +225,16 @@ fun setMiniatureUI(
@Composable @Composable
fun setScrollableArea(content: ContentState) { fun setScrollableArea(content: ContentState) {
var index = 1
ScrollableColumn { val scrollState = rememberScrollState()
var index = 1 Column(Modifier.verticalScroll(scrollState)) {
Column { for (picture in content.getMiniatures()) {
for (picture in content.getMiniatures()) { setMiniatureUI(
setMiniatureUI( picture = picture,
picture = picture, content = content
content = content )
) Spacer(modifier = Modifier.height(5.dp))
Spacer(modifier = Modifier.height(5.dp)) index++
index++
}
} }
} }
} }

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

@ -1,7 +1,6 @@
package example.imageviewer.view package example.imageviewer.view
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.emptyContent
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -10,7 +9,7 @@ import androidx.compose.ui.Modifier
fun Clickable( fun Clickable(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
children: @Composable () -> Unit = emptyContent() children: @Composable () -> Unit = { }
) { ) {
Box( Box(
modifier = modifier.clickable { modifier = modifier.clickable {

5
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/utils/Application.kt

@ -11,7 +11,6 @@ import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MonotonicFrameClock import androidx.compose.runtime.MonotonicFrameClock
import androidx.compose.runtime.Recomposer import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.emptyContent
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@ -46,7 +45,7 @@ class ApplicationScope(
private val scope = CoroutineScope(context) private val scope = CoroutineScope(context)
private val recomposer = Recomposer(context) private val recomposer = Recomposer(context)
private val composition = Composition(Unit, EmptyApplier(), recomposer) private val composition = Composition(EmptyApplier(), recomposer)
private val windows = mutableSetOf<AppWindow>() private val windows = mutableSetOf<AppWindow>()
private var windowsVersion by mutableStateOf(Any()) private var windowsVersion by mutableStateOf(Any())
@ -89,7 +88,7 @@ class ApplicationScope(
resizable: Boolean = true, resizable: Boolean = true,
events: WindowEvents = WindowEvents(), events: WindowEvents = WindowEvents(),
onDismissRequest: (() -> Unit)? = null, onDismissRequest: (() -> Unit)? = null,
content: @Composable () -> Unit = emptyContent() content: @Composable () -> Unit = {}
) { ) {
var isOpened by remember { mutableStateOf(true) } var isOpened by remember { mutableStateOf(true) }
if (isOpened) { if (isOpened) {

Loading…
Cancel
Save