Skip to content

Commit d7e99b7

Browse files
committed
some fixes for release
1 parent 80d5a11 commit d7e99b7

File tree

6 files changed

+37
-30
lines changed

6 files changed

+37
-30
lines changed

core/domain/src/main/kotlin/ru/tech/imageresizershrinker/core/domain/utils/KotlinUtils.kt

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ inline fun <reified T, reified R> T.cast(): R = this as R
3939

4040
inline fun <reified T, reified R> T.safeCast(): R? = this as? R
4141

42+
inline fun <reified R> Any?.ifCasts(action: (R) -> Unit) = (this as? R)?.let(action)
43+
4244

4345
inline operator fun CharSequence.times(
4446
count: Int

core/ui/src/main/kotlin/ru/tech/imageresizershrinker/core/ui/widget/image/AspectRatioSelector.kt

+11-10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import com.smarttoolfactory.cropper.model.CropAspectRatio
6969
import com.smarttoolfactory.cropper.util.createRectShape
7070
import com.smarttoolfactory.cropper.widget.AspectRatioSelectionCard
7171
import ru.tech.imageresizershrinker.core.domain.model.DomainAspectRatio
72+
import ru.tech.imageresizershrinker.core.domain.utils.ifCasts
7273
import ru.tech.imageresizershrinker.core.domain.utils.trimTrailingZero
7374
import ru.tech.imageresizershrinker.core.resources.R
7475
import ru.tech.imageresizershrinker.core.ui.theme.outlineVariant
@@ -272,15 +273,15 @@ fun AspectRatioSelector(
272273
value = tempWidth,
273274
onValueChange = { value ->
274275
tempWidth = value
275-
val width = abs(value.toFloatOrNull() ?: 0f)
276-
val custom = selectedAspectRatio as? DomainAspectRatio.Custom
277-
custom?.let {
276+
val width = abs(value.toFloatOrNull() ?: 0f).coerceAtLeast(1f)
277+
278+
selectedAspectRatio.ifCasts<DomainAspectRatio.Custom> { aspect ->
278279
onAspectRatioChange(
279-
custom.copy(
280+
aspect.copy(
280281
widthProportion = width
281282
),
282283
AspectRatio(
283-
(width / selectedAspectRatio.heightProportion).takeIf { !it.isNaN() }
284+
(width / aspect.heightProportion).takeIf { !it.isNaN() }
284285
?: 1f
285286
)
286287
)
@@ -306,15 +307,15 @@ fun AspectRatioSelector(
306307
value = tempHeight,
307308
onValueChange = { value ->
308309
tempHeight = value
309-
val height = abs(value.toFloatOrNull() ?: 0f)
310-
val custom = selectedAspectRatio as? DomainAspectRatio.Custom
311-
custom?.let {
310+
val height = abs(value.toFloatOrNull() ?: 1f).coerceAtLeast(1f)
311+
312+
selectedAspectRatio.ifCasts<DomainAspectRatio.Custom> { aspect ->
312313
onAspectRatioChange(
313-
custom.copy(
314+
aspect.copy(
314315
heightProportion = height
315316
),
316317
AspectRatio(
317-
(selectedAspectRatio.widthProportion / height).takeIf { !it.isNaN() }
318+
(aspect.widthProportion / height).takeIf { !it.isNaN() }
318319
?: 1f
319320
)
320321
)

core/ui/src/main/kotlin/ru/tech/imageresizershrinker/core/ui/widget/modifier/ContainerShapeDefaults.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ internal class AnimatedShapeState(
123123
val density: Density,
124124
val spec: FiniteAnimationSpec<Float>,
125125
) {
126-
private val size = Size(120f, 120f)
126+
private val size = Size(
127+
width = with(density) { 48.dp.toPx() },
128+
height = with(density) { 48.dp.toPx() }
129+
)
127130

128131
private var topStart: Animatable<Float, AnimationVector1D> =
129132
Animatable(shape.topStart.toPx(size, density))

feature/main/src/main/java/ru/tech/imageresizershrinker/feature/main/presentation/components/MainTopAppBar.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ import androidx.compose.material3.LocalTextStyle
5252
import androidx.compose.material3.MaterialTheme
5353
import androidx.compose.material3.Text
5454
import androidx.compose.material3.TopAppBarScrollBehavior
55-
import androidx.compose.runtime.*
5655
import androidx.compose.runtime.Composable
56+
import androidx.compose.runtime.derivedStateOf
5757
import androidx.compose.runtime.getValue
5858
import androidx.compose.runtime.mutableIntStateOf
5959
import androidx.compose.runtime.mutableStateOf
@@ -116,7 +116,7 @@ internal fun MainTopAppBar(
116116
title = {
117117
LocalLayoutDirection.ProvidesValue(LayoutDirection.Ltr) {
118118
val badgeText = remember {
119-
"${Screen.FEATURES_COUNT} $AppVersionPreReleaseFlavored"
119+
"${Screen.FEATURES_COUNT} $AppVersionPreReleaseFlavored".trim()
120120
}
121121

122122
Row(

feature/media-picker/src/main/java/ru/tech/imageresizershrinker/feature/media_picker/presentation/components/MediaImagePager.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ internal fun MediaImagePager(
141141
) {
142142
val density = LocalDensity.current
143143
val screenHeight =
144-
LocalScreenSize.current.height + WindowInsets.Companion.systemBars.asPaddingValues()
144+
LocalScreenSize.current.height + WindowInsets.systemBars.asPaddingValues()
145145
.let { it.calculateTopPadding() + it.calculateBottomPadding() }
146146
val anchors = with(density) {
147147
DraggableAnchors {
@@ -221,14 +221,13 @@ internal fun MediaImagePager(
221221
pageSpacing = if (pagerState.pageCount > 1) 16.dp
222222
else 0.dp
223223
) { page ->
224-
val media = media.getOrNull(page)
225224
Box(
226225
modifier = Modifier.fillMaxSize()
227226
) {
228227
val zoomState = rememberZoomState(10f)
229228
Picture(
230229
showTransparencyChecker = false,
231-
model = media?.uri,
230+
model = media.getOrNull(page)?.uri,
232231
modifier = Modifier
233232
.fillMaxSize()
234233
.clipToBounds()
@@ -402,9 +401,9 @@ internal fun MediaImagePager(
402401
.background(MaterialTheme.colorScheme.scrim.copy(0.5f))
403402
.navigationBarsPadding()
404403
.padding(
405-
WindowInsets.Companion.displayCutout
404+
WindowInsets.displayCutout
406405
.only(
407-
WindowInsetsSides.Companion.Horizontal
406+
WindowInsetsSides.Horizontal
408407
)
409408
.asPaddingValues()
410409
)
@@ -428,9 +427,9 @@ internal fun MediaImagePager(
428427
}
429428

430429
if (visible) {
431-
PredictiveBackHandler { progress ->
430+
PredictiveBackHandler { backProgress ->
432431
try {
433-
progress.collect { event ->
432+
backProgress.collect { event ->
434433
if (event.progress <= 0.05f) {
435434
predictiveBackProgress = 0f
436435
}

feature/media-picker/src/main/java/ru/tech/imageresizershrinker/feature/media_picker/presentation/components/MediaPickerGridWithOverlays.kt

+12-10
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,17 @@ internal fun ColumnScope.MediaPickerGridWithOverlays(
230230
}
231231
}
232232
}
233-
val visible = mediaState.isLoading || filteredMediaState.isLoading
233+
234+
val isHaveNoData = mediaState.media.isEmpty() && !mediaState.isLoading
235+
val showLoading = (mediaState.isLoading || filteredMediaState.isLoading) && !isHaveNoData
234236

235237
val backgroundColor by animateColorAsState(
236238
MaterialTheme.colorScheme.scrim.copy(
237-
if (visible && filteredMediaState.media.isNotEmpty()) 0.5f else 0f
239+
if (showLoading && filteredMediaState.media.isNotEmpty()) 0.5f else 0f
238240
)
239241
)
240242
BoxAnimatedVisibility(
241-
visible = visible,
243+
visible = showLoading,
242244
modifier = Modifier
243245
.fillMaxSize()
244246
.imePadding()
@@ -250,13 +252,13 @@ internal fun ColumnScope.MediaPickerGridWithOverlays(
250252
modifier = Modifier
251253
.fillMaxSize()
252254
.padding(
253-
start = WindowInsets.Companion.displayCutout
255+
start = WindowInsets.displayCutout
254256
.asPaddingValues()
255257
.calculateStartPadding(layoutDirection),
256-
end = WindowInsets.Companion.displayCutout
258+
end = WindowInsets.displayCutout
257259
.asPaddingValues()
258260
.calculateEndPadding(layoutDirection),
259-
bottom = WindowInsets.Companion.navigationBars
261+
bottom = WindowInsets.navigationBars
260262
.asPaddingValues()
261263
.calculateBottomPadding()
262264
),
@@ -304,7 +306,7 @@ internal fun ColumnScope.MediaPickerGridWithOverlays(
304306
}
305307

306308
BoxAnimatedVisibility(
307-
visible = mediaState.media.isEmpty() && !mediaState.isLoading,
309+
visible = isHaveNoData,
308310
enter = scaleIn() + fadeIn(),
309311
exit = scaleOut() + fadeOut(),
310312
modifier = Modifier
@@ -345,7 +347,7 @@ internal fun ColumnScope.MediaPickerGridWithOverlays(
345347
}
346348

347349
BoxAnimatedVisibility(
348-
visible = !mediaState.isLoading,
350+
visible = !mediaState.isLoading && !isHaveNoData,
349351
modifier = Modifier.fillMaxSize(),
350352
enter = fadeIn(),
351353
exit = fadeOut()
@@ -368,8 +370,8 @@ internal fun ColumnScope.MediaPickerGridWithOverlays(
368370
RoundedTextField(
369371
maxLines = 1,
370372
hint = { Text(stringResource(id = R.string.search_here)) },
371-
keyboardOptions = KeyboardOptions.Companion.Default.copy(
372-
imeAction = ImeAction.Companion.Search,
373+
keyboardOptions = KeyboardOptions.Default.copy(
374+
imeAction = ImeAction.Search,
373375
autoCorrectEnabled = null
374376
),
375377
value = searchKeyword,

0 commit comments

Comments
 (0)