Skip to content

Commit

Permalink
fix #358 and #359
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jul 30, 2023
1 parent 8f99cb9 commit b1d9777
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 111 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId = "ru.tech.imageresizershrinker"
minSdk = 21
targetSdk = 34
versionCode = 76
versionName = "2.2.1"
versionCode = 77
versionName = "2.2.2"
resourceConfigurations += setOf(
"en",
"ar",
Expand Down Expand Up @@ -104,7 +104,7 @@ dependencies {
implementation("androidx.activity:activity-compose:1.8.0-alpha06")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.exifinterface:exifinterface:1.3.6")
implementation("androidx.appcompat:appcompat:1.7.0-alpha02")
implementation("androidx.appcompat:appcompat:1.7.0-alpha03")
implementation("androidx.documentfile:documentfile:1.0.1")
implementation("androidx.datastore:datastore-preferences:1.1.0-alpha04")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1")
Expand All @@ -117,10 +117,10 @@ dependencies {
implementation("nl.dionsegijn:konfetti-compose:2.0.3")

//Compose
implementation("androidx.compose.material3:material3:1.2.0-alpha03")
implementation("androidx.compose.material3:material3-window-size-class:1.2.0-alpha03")
implementation("androidx.compose.material:material-icons-extended:1.6.0-alpha01")
implementation("androidx.compose.material:material:1.6.0-alpha01")
implementation("androidx.compose.material3:material3:1.2.0-alpha04")
implementation("androidx.compose.material3:material3-window-size-class:1.2.0-alpha04")
implementation("androidx.compose.material:material-icons-extended:1.6.0-alpha02")
implementation("androidx.compose.material:material:1.6.0-alpha02")

//Di
implementation("com.google.dagger:hilt-android:2.47")
Expand Down Expand Up @@ -149,6 +149,6 @@ dependencies {

implementation("org.burnoutcrew.composereorderable:reorderable:0.9.6")

implementation("com.google.accompanist:accompanist-systemuicontroller:0.31.5-beta")
implementation("com.google.accompanist:accompanist-systemuicontroller:0.31.6-rc")

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SettingsRepositoryImpl @Inject constructor(
saveFolderUri = prefs[SAVE_FOLDER],
presets = ((prefs[PRESETS]?.split("*")?.map {
it.toInt()
} ?: emptyList()) + List(7) { 100 - it * 10 }).toSortedSet().reversed().toList(),
} ?: emptyList())).toSortedSet().reversed().toList(),
colorTupleList = prefs[COLOR_TUPLES],
allowChangeColorByImage = prefs[IMAGE_MONET] ?: true,
imagePickerModeInt = prefs[PICKER_MODE] ?: 0,
Expand Down Expand Up @@ -156,8 +156,13 @@ class SettingsRepositoryImpl @Inject constructor(
}

override suspend fun updatePresets(newPresets: String) {
dataStore.edit {
it[PRESETS] = newPresets
dataStore.edit { preferences ->
if (newPresets.split("*").size > 3) preferences[PRESETS] =
newPresets.split("*")
.map { it.toIntOrNull()?.coerceIn(10..500) ?: 0 }
.toSortedSet()
.toList().reversed()
.joinToString("*")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.compose.material.icons.rounded.AddCircle
import androidx.compose.material.icons.rounded.PhotoSizeSelectSmall
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -93,9 +93,7 @@ fun EditPresetsSheet(
OutlinedIconButton(
shape = MaterialTheme.shapes.medium,
onClick = {
if (list.size > 7) {
updatePresets(list - it)
}
updatePresets(list - it)
},
border = BorderStroke(
settingsState.borderWidth.coerceAtLeast(1.dp),
Expand Down Expand Up @@ -183,8 +181,7 @@ fun EditPresetsSheet(
OutlinedButton(
onClick = {
updatePresets(
list + (value.toIntOrNull()
?: 0).coerceIn(10..500)
list + (value.toIntOrNull() ?: 0)
)
expanded = false
},
Expand All @@ -209,8 +206,8 @@ fun EditPresetsSheet(
}
}
}
Divider(Modifier.align(Alignment.TopCenter))
Divider(Modifier.align(Alignment.BottomCenter))
HorizontalDivider(Modifier.align(Alignment.TopCenter))
HorizontalDivider(Modifier.align(Alignment.BottomCenter))
}
},
confirmButton = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
Expand Down Expand Up @@ -66,12 +67,12 @@ import androidx.compose.material3.Badge
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.DrawerDefaults
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.FloatingActionButtonDefaults
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonDefaults
Expand Down Expand Up @@ -374,7 +375,7 @@ fun MainScreen(
}
}
)
Divider()
HorizontalDivider()
LazyColumn(
contentPadding = WindowInsets.navigationBars.asPaddingValues() + WindowInsets.displayCutout.asPaddingValues(),
state = lazyListState
Expand Down Expand Up @@ -584,7 +585,13 @@ fun MainScreen(
) { groupOptionsByTypes ->
if (groupOptionsByTypes) {
NavigationBar(
modifier = Modifier.drawHorizontalStroke(top = true),
modifier = Modifier
.drawHorizontalStroke(top = true)
.height(
80.dp + WindowInsets.systemBars
.asPaddingValues()
.calculateBottomPadding()
),
) {
Screen.typedEntries.forEachIndexed { index, (_, data) ->
val selected = index == currentPage
Expand Down Expand Up @@ -942,8 +949,8 @@ fun MainScreen(
)
Spacer(Modifier.height(16.dp))
}
Divider(Modifier.align(Alignment.TopCenter))
Divider(Modifier.align(Alignment.BottomCenter))
HorizontalDivider(Modifier.align(Alignment.TopCenter))
HorizontalDivider(Modifier.align(Alignment.BottomCenter))
}
}
)
Expand Down Expand Up @@ -1006,8 +1013,8 @@ fun MainScreen(
}
}
}
Divider(Modifier.align(Alignment.TopCenter))
Divider(Modifier.align(Alignment.BottomCenter))
HorizontalDivider(Modifier.align(Alignment.TopCenter))
HorizontalDivider(Modifier.align(Alignment.BottomCenter))
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class MainViewModel @Inject constructor(
fun updatePresets(newPresets: List<Int>) {
viewModelScope.launch {
updatePresetsUseCase(
newPresets.toSortedSet().toList().reversed().joinToString("*")
newPresets.joinToString("*")
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
package ru.tech.imageresizershrinker.presentation.root.widget.buttons

import android.annotation.SuppressLint
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.material.ripple.RippleTheme
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -19,10 +12,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.max
import androidx.compose.ui.zIndex
import ru.tech.imageresizershrinker.presentation.root.theme.mixedColor
import ru.tech.imageresizershrinker.presentation.root.theme.onMixedColor
import ru.tech.imageresizershrinker.presentation.root.widget.text.AutoSizeText
import ru.tech.imageresizershrinker.presentation.root.theme.outlineVariant
import ru.tech.imageresizershrinker.presentation.root.widget.utils.LocalSettingsState

@Composable
Expand Down Expand Up @@ -50,6 +40,7 @@ fun ToggleGroupButton(
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ToggleGroupButton(
@SuppressLint("ModifierParameter") modifier: Modifier = defaultModifier,
Expand All @@ -60,7 +51,6 @@ fun ToggleGroupButton(
indexChanged: (Int) -> Unit
) {
val settingsState = LocalSettingsState.current
val cornerRadius = 1000.dp

val disColor = MaterialTheme.colorScheme.onSurface
.copy(alpha = 0.38f)
Expand All @@ -77,67 +67,25 @@ fun ToggleGroupButton(
horizontalAlignment = Alignment.CenterHorizontally
) {
title()
CompositionLocalProvider(
LocalRippleTheme provides GroupRipple
SingleChoiceSegmentedButtonRow(
space = max(settingsState.borderWidth, 1.dp),
modifier = Modifier.padding(bottom = 6.dp)
) {
Row(modifier = Modifier.fillMaxWidth()) {
items.forEachIndexed { index, item ->
OutlinedButton(
enabled = enabled,
onClick = { indexChanged(index) },
contentPadding = PaddingValues(horizontal = 8.dp),
modifier = Modifier
.widthIn(min = 48.dp)
.weight(1f)
.then(
when (index) {
0 ->
Modifier
.offset(0.dp, 0.dp)
.zIndex(if (selectedIndex == 0) 1f else 0f)

else ->
Modifier
.offset((-1 * index).dp, 0.dp)
.zIndex(if (selectedIndex == index) 1f else 0f)
}
),
shape = when (index) {
0 -> RoundedCornerShape(
topStart = cornerRadius,
topEnd = 0.dp,
bottomStart = cornerRadius,
bottomEnd = 0.dp
)

items.size - 1 -> RoundedCornerShape(
topStart = 0.dp,
topEnd = cornerRadius,
bottomStart = 0.dp,
bottomEnd = cornerRadius
)

else -> RoundedCornerShape(0.dp)
},
border = BorderStroke(
max(settingsState.borderWidth, 1.dp),
MaterialTheme.colorScheme.outlineVariant
),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (!enabled) disColor
else if (selectedIndex == index) MaterialTheme.colorScheme.mixedColor
else Color.Transparent
)
) {
AutoSizeText(
text = item,
color = if (!enabled) disColor
else if (selectedIndex == index) MaterialTheme.colorScheme.onMixedColor
else MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(horizontal = 8.dp),
maxLines = 1
items.forEachIndexed { index, item ->
SegmentedButton(
enabled = enabled,
onClick = { indexChanged(index) },
border = SegmentedButtonBorder(max(settingsState.borderWidth, 1.dp)),
selected = index == selectedIndex,
colors = SegmentedButtonDefaults.colors(
activeBorderColor = MaterialTheme.colorScheme.outlineVariant(),
inactiveContainerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
6.dp
)
}
),
shape = SegmentedButtonDefaults.shape(index, items.size)
) {
Text(text = item)
}
}
}
Expand All @@ -147,16 +95,4 @@ fun ToggleGroupButton(

private var defaultModifier = Modifier
.fillMaxWidth()
.padding(8.dp)


object GroupRipple : RippleTheme {
private const val alpha = 0.1f

@Composable
override fun defaultColor(): Color = if (isSystemInDarkTheme()) Color.White
else Color.Black

@Composable
override fun rippleAlpha(): RippleAlpha = RippleAlpha(alpha, alpha, alpha, alpha)
}
.padding(8.dp)

0 comments on commit b1d9777

Please sign in to comment.