Browse Source

Merge pull request #374 from jimgoog/imageviewerbuild150

Upgrade imageviewer to build150
pull/379/head
Igor Demin 4 years ago committed by GitHub
parent
commit
40b17c608a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      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

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

@ -22,4 +22,11 @@ android {
dependencies {
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 androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.platform.setContent
import androidx.activity.compose.setContent
import example.imageviewer.view.BuildAppUI
import example.imageviewer.model.ContentState
import example.imageviewer.model.ImageRepository

2
examples/imageviewer/build.gradle.kts

@ -11,7 +11,7 @@ buildscript {
dependencies {
// __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")
// __KOTLIN_COMPOSE_VERSION__
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
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.painterResource
import example.imageviewer.common.R
@Composable
fun icEmpty() = imageResource(R.raw.empty)
fun icEmpty() = painterResource(R.raw.empty)
@Composable
fun icBack() = imageResource(R.raw.back)
fun icBack() = painterResource(R.raw.back)
@Composable
fun icRefresh() = imageResource(R.raw.refresh)
fun icRefresh() = painterResource(R.raw.refresh)
@Composable
fun icDots() = imageResource(R.raw.dots)
fun icDots() = painterResource(R.raw.dots)
@Composable
fun icFilterGrayscaleOn() = imageResource(R.raw.grayscale_on)
fun icFilterGrayscaleOn() = painterResource(R.raw.grayscale_on)
@Composable
fun icFilterGrayscaleOff() = imageResource(R.raw.grayscale_off)
fun icFilterGrayscaleOff() = painterResource(R.raw.grayscale_off)
@Composable
fun icFilterPixelOn() = imageResource(R.raw.pixel_on)
fun icFilterPixelOn() = painterResource(R.raw.pixel_on)
@Composable
fun icFilterPixelOff() = imageResource(R.raw.pixel_off)
fun icFilterPixelOff() = painterResource(R.raw.pixel_off)
@Composable
fun icFilterBlurOn() = imageResource(R.raw.blur_on)
fun icFilterBlurOn() = painterResource(R.raw.blur_on)
@Composable
fun icFilterBlurOff() = imageResource(R.raw.blur_off)
fun icFilterBlurOff() = painterResource(R.raw.blur_off)
@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.Rect
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollableRow
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.Column
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.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.unit.dp
import example.imageviewer.core.FilterType
@ -85,7 +87,7 @@ fun setToolBar(
text: String,
content: ContentState
) {
val scrollState = rememberScrollState()
Surface(color = MiniatureColor, modifier = Modifier.preferredHeight(44.dp)) {
Row(modifier = Modifier.padding(end = 30.dp)) {
Surface(
@ -122,11 +124,9 @@ fun setToolBar(
.align(Alignment.CenterVertically),
shape = CircleShape
) {
ScrollableRow {
Row {
for (type in FilterType.values()) {
FilterButton(content, type)
}
Row(Modifier.horizontalScroll(scrollState)) {
for (type in FilterType.values()) {
FilterButton(content, type)
}
}
}
@ -158,7 +158,7 @@ fun FilterButton(
}
@Composable
fun getFilterImage(type: FilterType, content: ContentState): ImageBitmap {
fun getFilterImage(type: FilterType, content: ContentState): Painter {
return when (type) {
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
import android.content.res.Configuration
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -28,6 +29,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import example.imageviewer.common.R
@ -145,7 +147,7 @@ fun setPreviewImageUI(content: ContentState) {
if (content.isMainImageEmpty()) {
icEmpty()
} else {
content.getSelectedImage().asImageBitmap()
BitmapPainter(content.getSelectedImage().asImageBitmap())
},
contentDescription = null,
modifier = Modifier
@ -223,18 +225,16 @@ fun setMiniatureUI(
@Composable
fun setScrollableArea(content: ContentState) {
ScrollableColumn {
var index = 1
Column {
for (picture in content.getMiniatures()) {
setMiniatureUI(
picture = picture,
content = content
)
Spacer(modifier = Modifier.height(5.dp))
index++
}
var index = 1
val scrollState = rememberScrollState()
Column(Modifier.verticalScroll(scrollState)) {
for (picture in content.getMiniatures()) {
setMiniatureUI(
picture = picture,
content = content
)
Spacer(modifier = Modifier.height(5.dp))
index++
}
}
}

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

@ -1,7 +1,6 @@
package example.imageviewer.view
import androidx.compose.runtime.Composable
import androidx.compose.runtime.emptyContent
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Modifier
@ -10,7 +9,7 @@ import androidx.compose.ui.Modifier
fun Clickable(
modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
children: @Composable () -> Unit = emptyContent()
children: @Composable () -> Unit = { }
) {
Box(
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.MonotonicFrameClock
import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.emptyContent
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -46,7 +45,7 @@ class ApplicationScope(
private val scope = CoroutineScope(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 var windowsVersion by mutableStateOf(Any())
@ -89,7 +88,7 @@ class ApplicationScope(
resizable: Boolean = true,
events: WindowEvents = WindowEvents(),
onDismissRequest: (() -> Unit)? = null,
content: @Composable () -> Unit = emptyContent()
content: @Composable () -> Unit = {}
) {
var isOpened by remember { mutableStateOf(true) }
if (isOpened) {

Loading…
Cancel
Save