Skip to content

Commit

Permalink
[fix|build] Fix "Add Screen" tag bugs; update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Nov 14, 2024
1 parent 36ff7c1 commit bf85ab3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 47 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
minSdk = 24
targetSdk = 35
versionCode = 67
versionName = "2.3-beta02"
versionName = "2.3-rc01"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -161,12 +161,12 @@ dependencies {
implementation("com.google.dagger:hilt-android:2.52")
ksp("com.google.dagger:hilt-android-compiler:2.52")
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
implementation("androidx.navigation:navigation-compose:2.8.3")
implementation("androidx.navigation:navigation-compose:2.8.4")
implementation("androidx.security:security-crypto:1.1.0-alpha06")
implementation("com.google.accompanist:accompanist-drawablepainter:0.36.0")
implementation("io.coil-kt:coil-compose:2.7.0")
implementation("io.coil-kt:coil-gif:2.7.0")
implementation("io.coil-kt:coil-svg:2.7.0")
implementation("io.coil-kt.coil3:coil-compose:3.0.2")
implementation("io.coil-kt.coil3:coil-gif:3.0.2")
implementation("io.coil-kt.coil3:coil-svg:3.0.2")
implementation("androidx.profileinstaller:profileinstaller:1.4.1")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.room:room-runtime:2.6.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class AddRepository @Inject constructor(
TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)
.process(image)
.addOnSuccessListener {
cont.resume(
getTexts(it, textRecognizeThreshold), onCancellation = null
)
cont.resume(getTexts(it, textRecognizeThreshold), onCancellation = null)
}
.addOnFailureListener { cont.resumeWithException(it) }
})
Expand All @@ -109,9 +107,7 @@ class AddRepository @Inject constructor(
TextRecognition.getClient(ChineseTextRecognizerOptions.Builder().build())
.process(image)
.addOnSuccessListener {
cont.resume(
getTexts(it, textRecognizeThreshold), onCancellation = null
)
cont.resume(getTexts(it, textRecognizeThreshold), onCancellation = null)
}
.addOnFailureListener { cont.resumeWithException(it) }
})
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/java/com/skyd/rays/ui/component/RaysImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import androidx.compose.ui.graphics.DefaultAlpha
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.ImageLoader
import coil.compose.AsyncImage
import coil.decode.GifDecoder
import coil.decode.ImageDecoderDecoder
import coil.decode.SvgDecoder
import coil.request.ImageRequest
import coil3.ImageLoader
import coil3.compose.AsyncImage
import coil3.gif.AnimatedImageDecoder
import coil3.gif.GifDecoder
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.transformations
import coil3.svg.SvgDecoder
import com.skyd.rays.config.STICKER_DIR
import com.skyd.rays.ext.dataStore
import com.skyd.rays.ext.getOrDefault
Expand Down Expand Up @@ -93,7 +95,7 @@ private fun rememberRaysImageLoader(): ImageLoader {
ImageLoader.Builder(context)
.components {
if (SDK_INT >= 28) {
add(ImageDecoderDecoder.Factory())
add(AnimatedImageDecoder.Factory())
} else {
add(GifDecoder.Factory())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.skyd.rays.R
import com.skyd.rays.config.ANIVU_URL
import com.skyd.rays.config.GITHUB_REPO
Expand All @@ -76,6 +75,7 @@ import com.skyd.rays.ext.isCompact
import com.skyd.rays.ext.plus
import com.skyd.rays.model.bean.OtherWorksBean
import com.skyd.rays.ui.component.RaysIconButton
import com.skyd.rays.ui.component.RaysImage
import com.skyd.rays.ui.component.RaysTopBar
import com.skyd.rays.ui.component.RaysTopBarStyle
import com.skyd.rays.ui.component.dialog.RaysDialog
Expand Down Expand Up @@ -467,12 +467,13 @@ private fun OtherWorksItem(
.padding(15.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
AsyncImage(
RaysImage(
modifier = Modifier
.size(30.dp)
.aspectRatio(1f),
model = data.icon,
contentDescription = data.name
contentDescription = data.name,
blur = false,
)
Spacer(modifier = Modifier.width(16.dp))
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ internal sealed interface AddPartialStateChange {
) : AddPartialStateChange {
override fun reduce(oldState: AddState): AddState {
val getStickersWithTagsState = getStickersWithTagsState(oldState)
val stickerWithTags =
(getStickersWithTagsState as? GetStickersWithTagsState.Success)?.stickerWithTags
return oldState.copy(
waitingList = oldState.waitingList.toMutableList().apply { set(index, sticker) },
getStickersWithTagsState = getStickersWithTagsState,
suggestTags = suggestTags ?: oldState.suggestTags,
addedTags = if (currentStickerChanged) emptyList() else oldState.addedTags,
addedTags = if (currentStickerChanged) {
stickerWithTags?.tags?.map { it.tag }.orEmpty()
} else oldState.addedTags,
titleText = if (currentStickerChanged) {
(getStickersWithTagsState as? GetStickersWithTagsState.Success)?.stickerWithTags?.sticker?.title.orEmpty()
stickerWithTags?.sticker?.title.orEmpty()
} else oldState.titleText,
)
}
Expand All @@ -77,13 +81,17 @@ internal sealed interface AddPartialStateChange {
) : AddPartialStateChange {
override fun reduce(oldState: AddState): AddState {
val getStickersWithTagsState = getStickersWithTagsState(oldState)
val stickerWithTags =
(getStickersWithTagsState as? GetStickersWithTagsState.Success)?.stickerWithTags
return oldState.copy(
waitingList = oldState.waitingList.toMutableList().apply { remove(willSticker) },
getStickersWithTagsState = getStickersWithTagsState,
suggestTags = suggestTags ?: oldState.suggestTags,
addedTags = if (currentStickerChanged) emptyList() else oldState.addedTags,
addedTags = if (currentStickerChanged) {
stickerWithTags?.tags?.map { it.tag }.orEmpty()
} else oldState.addedTags,
titleText = if (currentStickerChanged) {
(getStickersWithTagsState as? GetStickersWithTagsState.Success)?.stickerWithTags?.sticker?.title.orEmpty()
stickerWithTags?.sticker?.title.orEmpty()
} else oldState.titleText,
)
}
Expand All @@ -109,13 +117,17 @@ internal sealed interface AddPartialStateChange {
) : AddPartialStateChange {
override fun reduce(oldState: AddState): AddState {
val getStickersWithTagsState = getStickersWithTagsState(oldState)
val stickerWithTags =
(getStickersWithTagsState as? GetStickersWithTagsState.Success)?.stickerWithTags
return oldState.copy(
waitingList = oldState.waitingList + stickers,
getStickersWithTagsState = getStickersWithTagsState,
suggestTags = suggestTags ?: oldState.suggestTags,
addedTags = if (currentStickerChanged) emptyList() else oldState.addedTags,
addedTags = if (currentStickerChanged) {
stickerWithTags?.tags?.map { it.tag }.orEmpty()
} else oldState.addedTags,
titleText = if (currentStickerChanged) {
(getStickersWithTagsState as? GetStickersWithTagsState.Success)?.stickerWithTags?.sticker?.title.orEmpty()
stickerWithTags?.sticker?.title.orEmpty()
} else oldState.titleText,
)
}
Expand All @@ -125,7 +137,6 @@ internal sealed interface AddPartialStateChange {
data class Add(val text: String) : AllToAllTag {
override fun reduce(oldState: AddState): AddState = oldState.copy(
addToAllTags = (oldState.addToAllTags + text).distinct(),
addedTags = (oldState.addedTags + text).distinct(),
loadingDialog = false,
)
}
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/com/skyd/rays/ui/screen/add/AddScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ fun AddScreen(
val uiState by viewModel.viewState.collectAsStateWithLifecycle()
val dispatch = viewModel.getDispatcher(startWith = AddIntent.Init(initStickers))

LaunchedEffect(uiState.currentSticker) {
saveButtonEnable = true
}

fun processNext() {
if (uiState.waitingList.size <= 1 && isEdit) {
navController.popBackStackWithLifecycle()
Expand Down Expand Up @@ -231,7 +235,8 @@ fun AddScreen(
)
val stickerWithTags = StickerWithTags(
sticker = stickerBean,
tags = uiState.addedTags.distinct().map { TagBean(tag = it) }
tags = (uiState.addedTags + uiState.addToAllTags).distinct()
.map { TagBean(tag = it) }
)
dispatch(
AddIntent.AddNewStickerWithTags(
Expand Down Expand Up @@ -336,11 +341,7 @@ fun AddScreen(
)
}

is AddEvent.AddStickersResultEvent.Success -> {
saveButtonEnable = true
processNext()
}

is AddEvent.AddStickersResultEvent.Success -> processNext()
is AddEvent.InitFailed -> openErrorDialog = event.msg
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import android.renderscript.RenderScript
import android.renderscript.ScriptIntrinsicBlur
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.createBitmap
import coil.size.Size
import coil.transform.Transformation
import coil3.size.Size
import coil3.transform.Transformation

/**
* A [Transformation] that applies a Gaussian blur to an image.
Expand All @@ -26,7 +26,7 @@ class BlurTransformation @JvmOverloads constructor(
private val context: Context,
private val radius: Float = DEFAULT_RADIUS,
private val sampling: Float = DEFAULT_SAMPLING
) : Transformation {
) : Transformation() {

init {
require(radius in 0.0..25.0) { "radius must be in [0, 25]." }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.skyd.rays.util.coil.apng

import coil.ImageLoader
import coil.decode.DecodeResult
import coil.decode.Decoder
import coil.decode.ImageSource
import coil.fetch.SourceResult
import coil.request.Options
import coil3.ImageLoader
import coil3.asImage
import coil3.decode.DecodeResult
import coil3.decode.Decoder
import coil3.decode.ImageSource
import coil3.fetch.SourceFetchResult
import coil3.request.Options
import com.github.penfeizhou.animation.apng.APNGDrawable
import com.github.penfeizhou.animation.loader.StreamLoader
import com.skyd.rays.util.image.format.FormatStandard.PngFormat.PNG_FORMAT_DATA
Expand All @@ -24,7 +25,7 @@ class AnimatedPngDecoder(private val source: ImageSource) : Decoder {
drawable.start()
drawable.setLoopLimit(-1)
return DecodeResult(
drawable = drawable,
image = drawable.asImage(),
isSampled = false
)
}
Expand All @@ -36,7 +37,7 @@ class AnimatedPngDecoder(private val source: ImageSource) : Decoder {
* https://twitter.com/angealbertini/status/1372082666632327169
*/
override fun create(
result: SourceResult,
result: SourceFetchResult,
options: Options,
imageLoader: ImageLoader
): Decoder? {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.7.1" apply false
id("com.android.library") version "8.7.1" apply false
id("com.android.application") version "8.7.2" apply false
id("com.android.library") version "8.7.2" apply false
id("org.jetbrains.kotlin.android") version "2.0.21" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.0.21"
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.21"
Expand Down

0 comments on commit bf85ab3

Please sign in to comment.