Skip to content

Commit

Permalink
use material MultiChoiceSegmentedButtonRow
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Sep 24, 2024
1 parent 9e317ff commit 0292cd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.view.MenuItem
import androidx.activity.viewModels
import androidx.annotation.PluralsRes
import androidx.appcompat.view.ActionMode
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -34,7 +33,6 @@ import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.view.isVisible
Expand All @@ -50,9 +48,9 @@ import org.totschnig.myexpenses.compose.MenuEntry.Companion.delete
import org.totschnig.myexpenses.compose.MenuEntry.Companion.edit
import org.totschnig.myexpenses.compose.MenuEntry.Companion.select
import org.totschnig.myexpenses.databinding.ActivityComposeBinding
import org.totschnig.myexpenses.dialog.SetupCategoriesConfirmDialogFragment
import org.totschnig.myexpenses.dialog.MessageDialogFragment
import org.totschnig.myexpenses.dialog.SelectCategoryMoveTargetDialogFragment
import org.totschnig.myexpenses.dialog.SetupCategoriesConfirmDialogFragment
import org.totschnig.myexpenses.injector
import org.totschnig.myexpenses.model.ContribFeature
import org.totschnig.myexpenses.model.Sort
Expand Down Expand Up @@ -252,9 +250,7 @@ class ManageCategories : ProtectedFragmentActivity(),
Column(modifier = Modifier.fillMaxSize()) {
if (typeFlags != null) {
TypeConfiguration(
modifier = Modifier
.fillMaxWidth()
.background(color = colorResource(id = R.color.cardBackground)),
modifier = Modifier.align(CenterHorizontally),
typeFlags = typeFlags,
onCheckedChange = { viewModel.typeFilter = it }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ package org.totschnig.myexpenses.compose

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ExpandLess
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -27,18 +25,17 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import app.futured.donut.compose.DonutProgress
import app.futured.donut.compose.data.DonutModel
import app.futured.donut.compose.data.DonutSection
import org.totschnig.myexpenses.R
import org.totschnig.myexpenses.db2.FLAG_EXPENSE
import org.totschnig.myexpenses.db2.FLAG_INCOME
import kotlin.experimental.and
import kotlin.experimental.xor
import kotlin.experimental.inv
import kotlin.experimental.or

@Composable
fun ExpansionHandle(
Expand Down Expand Up @@ -108,8 +105,6 @@ fun DonutInABox(
}
}

// Swap this in when upgrading to 1.6
/*@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TypeConfiguration(
modifier: Modifier,
Expand All @@ -132,30 +127,6 @@ fun TypeConfiguration(
}
}
}
}*/

@Composable
fun TypeConfiguration(
modifier: Modifier,
typeFlags: Byte,
onCheckedChange: (Byte) -> Unit
) {
Row(
modifier = modifier,
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
val options = listOf(R.string.expense to FLAG_EXPENSE, R.string.income to FLAG_INCOME)
options.forEach { type ->
Checkbox(
onCheckedChange = {
onCheckedChange(typeFlags xor type.second)
},
checked = (typeFlags and type.second) != 0.toByte()
)
Text(stringResource(id = type.first))
}
}
}

@Composable
Expand Down

0 comments on commit 0292cd5

Please sign in to comment.