Skip to content

Commit

Permalink
fixed crash
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Aug 26, 2023
1 parent ed25915 commit 391bdbd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ fun ChangeLanguagePreference() {
},
onClick = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.startActivity(
Intent(
Settings.ACTION_APP_LOCALE_SETTINGS,
Uri.parse("package:${context.packageName}")
kotlin.runCatching {
context.startActivity(
Intent(
Settings.ACTION_APP_LOCALE_SETTINGS,
Uri.parse("package:${context.packageName}")
)
)
)
}.getOrNull().let {
if (it == null) showDialog.value = true
}
} else {
showDialog.value = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import kotlin.random.Random

@ExperimentalMaterial3Api
@Composable
fun ColorPickerDialog(
fun ColorTuplePicker(
visible: MutableState<Boolean>,
colorTuple: ColorTuple,
borderWidth: Dp = LocalSettingsState.current.borderWidth,
Expand Down Expand Up @@ -146,7 +146,7 @@ fun ColorPickerDialog(

LaunchedEffect(visible.value) {
if (!visible.value) {
delay(2500)
delay(1000)
primary = colorTuple.primary.toArgb()
secondary = colorTuple.secondary?.toArgb()
?: colorTuple.primary.calculateSecondaryColor()
Expand Down Expand Up @@ -326,7 +326,7 @@ fun ColorPickerDialog(
ExperimentalMaterial3Api::class
)
@Composable
fun AvailableColorTuplesDialog(
fun AvailableColorTuplesSheet(
visible: MutableState<Boolean>,
colorTupleList: List<ColorTuple>,
currentColorTuple: ColorTuple,
Expand Down Expand Up @@ -600,7 +600,7 @@ fun AvailableColorTuplesDialog(
}
},
)
ColorPickerDialog(
ColorTuplePicker(
visible = showEditColorPicker,
colorTuple = currentColorTuple,
onColorChange = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import androidx.compose.foundation.lazy.staggeredgrid.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AlternateEmail
import androidx.compose.material.icons.rounded.Close
Expand Down Expand Up @@ -110,7 +109,6 @@ import androidx.compose.ui.draw.shadow
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -153,11 +151,7 @@ import ru.tech.imageresizershrinker.presentation.root.utils.navigation.LocalNavC
import ru.tech.imageresizershrinker.presentation.root.utils.navigation.Screen
import ru.tech.imageresizershrinker.presentation.root.widget.other.AnimationBox
import ru.tech.imageresizershrinker.presentation.root.widget.other.LocalToastHost
import ru.tech.imageresizershrinker.presentation.root.widget.other.RevealDirection
import ru.tech.imageresizershrinker.presentation.root.widget.other.RevealValue
import ru.tech.imageresizershrinker.presentation.root.widget.other.TopAppBarEmoji
import ru.tech.imageresizershrinker.presentation.root.widget.other.rememberRevealState
import ru.tech.imageresizershrinker.presentation.root.widget.other.revealSwipeable
import ru.tech.imageresizershrinker.presentation.root.widget.preferences.PreferenceItem
import ru.tech.imageresizershrinker.presentation.root.widget.preferences.PreferenceItemOverload
import ru.tech.imageresizershrinker.presentation.root.widget.sheets.SimpleSheet
Expand All @@ -167,12 +161,10 @@ import ru.tech.imageresizershrinker.presentation.root.widget.text.TitleItem
import ru.tech.imageresizershrinker.presentation.root.widget.utils.LocalEditPresetsState
import ru.tech.imageresizershrinker.presentation.root.widget.utils.LocalSettingsState
import ru.tech.imageresizershrinker.presentation.root.widget.utils.LocalWindowSizeClass
import kotlin.math.roundToInt

@OptIn(
ExperimentalMaterial3Api::class,
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class
ExperimentalFoundationApi::class
)
@Composable
fun MainScreen(
Expand Down Expand Up @@ -253,22 +245,27 @@ fun MainScreen(
}

val configuration = LocalConfiguration.current
val state = rememberRevealState()

val widthState by remember(state.offset) {
var expanded by remember { mutableStateOf(false) }
val widthState by remember(expanded) {
derivedStateOf {
min(
configuration.screenWidthDp.dp * 0.85f,
if (!isSheetSlideable) {
if (isSheetSlideable) {
min(
configuration.screenWidthDp.dp * 0.85f,
DrawerDefaults.MaximumDrawerWidth
)
} else {
if (expanded) configuration.screenWidthDp.dp * 0.5f
else min(
configuration.screenWidthDp.dp * 0.3f,
270.dp
} else DrawerDefaults.MaximumDrawerWidth
) - (if (!isSheetSlideable) state.offset.value.roundToInt().dp else 0.dp)
)
}
}
}

ModalDrawerSheet(
modifier = Modifier
.width(widthState)
.width(animateDpAsState(targetValue = widthState).value)
.then(
if (isSheetSlideable) {
Modifier
Expand All @@ -281,15 +278,7 @@ fun MainScreen(
),
DrawerDefaults.shape
)
} else Modifier.revealSwipeable(
maxRevealPx = with(LocalDensity.current) { 80.dp.toPx() },
directions = setOf(
RevealDirection.EndToStart,
),
maxAmountOfOverflow = 1.dp,
state = state,
enabled = false
)
} else Modifier
),
windowInsets = WindowInsets(0)
) {
Expand Down Expand Up @@ -361,20 +350,14 @@ fun MainScreen(
if (!isSheetSlideable) {
IconButton(
onClick = {
scope.launch {
if (state.currentValue == RevealValue.Default) {
state.animateTo(RevealValue.FullyRevealedStart)
} else {
state.animateTo(RevealValue.Default)
}
}
expanded = !expanded
}
) {
Icon(
Icons.Rounded.MenuOpen,
null,
modifier = Modifier.rotate(
animateFloatAsState(if (state.currentValue == RevealValue.Default) 0f else 180f).value
animateFloatAsState(if (!expanded) 0f else 180f).value
)
)
}
Expand Down Expand Up @@ -782,7 +765,7 @@ fun MainScreen(
}

val showColorPicker = rememberSaveable { mutableStateOf(false) }
AvailableColorTuplesDialog(
AvailableColorTuplesSheet(
visible = showPickColorDialog,
colorTupleList = settingsState.colorTupleList,
currentColorTuple = getAppColorTuple(
Expand All @@ -794,7 +777,7 @@ fun MainScreen(
showColorPicker.value = true
},
colorPicker = { onUpdateColorTuples ->
ColorPickerDialog(
ColorTuplePicker(
visible = showColorPicker,
colorTuple = settingsState.appColorTuple,
onColorChange = {
Expand Down

0 comments on commit 391bdbd

Please sign in to comment.