mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 16:55:26 +02:00
Added a way to open unit groups screen from units list screen
This commit is contained in:
parent
e3c1c5376f
commit
9094d9b527
@ -123,6 +123,7 @@ fun UnittoApp(
|
|||||||
currentUnit = mainViewModel.unitFrom,
|
currentUnit = mainViewModel.unitFrom,
|
||||||
navigateUp = { navController.navigateUp() },
|
navigateUp = { navController.navigateUp() },
|
||||||
selectAction = { mainViewModel.changeUnitFrom(it) },
|
selectAction = { mainViewModel.changeUnitFrom(it) },
|
||||||
|
navigateToSettingsActtion = { navController.navigate(UNIT_GROUPS_SCREEN) },
|
||||||
viewModel = secondViewModel
|
viewModel = secondViewModel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,7 @@ private fun BasicUnitListScreen(
|
|||||||
*
|
*
|
||||||
* @param currentUnit Currently selected [AbstractUnit].
|
* @param currentUnit Currently selected [AbstractUnit].
|
||||||
* @param navigateUp Action to navigate up. Called when user click back button.
|
* @param navigateUp Action to navigate up. Called when user click back button.
|
||||||
|
* @param navigateToSettingsActtion Action to perform when clicking settings chip at the end.
|
||||||
* @param selectAction Action to perform when user clicks on [UnitListItem].
|
* @param selectAction Action to perform when user clicks on [UnitListItem].
|
||||||
* @param viewModel [SecondViewModel].
|
* @param viewModel [SecondViewModel].
|
||||||
*/
|
*/
|
||||||
@ -142,6 +143,7 @@ private fun BasicUnitListScreen(
|
|||||||
fun LeftSideScreen(
|
fun LeftSideScreen(
|
||||||
currentUnit: AbstractUnit,
|
currentUnit: AbstractUnit,
|
||||||
navigateUp: () -> Unit,
|
navigateUp: () -> Unit,
|
||||||
|
navigateToSettingsActtion: () -> Unit,
|
||||||
selectAction: (AbstractUnit) -> Unit,
|
selectAction: (AbstractUnit) -> Unit,
|
||||||
viewModel: SecondViewModel
|
viewModel: SecondViewModel
|
||||||
) = BasicUnitListScreen(
|
) = BasicUnitListScreen(
|
||||||
@ -157,6 +159,7 @@ fun LeftSideScreen(
|
|||||||
viewModel.toggleSelectedChip(it)
|
viewModel.toggleSelectedChip(it)
|
||||||
viewModel.loadUnitsToShow(true)
|
viewModel.loadUnitsToShow(true)
|
||||||
},
|
},
|
||||||
|
navigateToSettingsActtion = navigateToSettingsActtion,
|
||||||
lazyListState = lazyListState
|
lazyListState = lazyListState
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -25,6 +25,7 @@ import androidx.compose.foundation.clickable
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
@ -33,6 +34,7 @@ import androidx.compose.foundation.lazy.items
|
|||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Check
|
import androidx.compose.material.icons.filled.Check
|
||||||
|
import androidx.compose.material.icons.filled.Settings
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@ -53,6 +55,7 @@ import com.sadellie.unitto.data.units.UnitGroup
|
|||||||
* @param items All [UnitGroup]s
|
* @param items All [UnitGroup]s
|
||||||
* @param chosenUnitGroup Currently selected [UnitGroup]
|
* @param chosenUnitGroup Currently selected [UnitGroup]
|
||||||
* @param selectAction Action to perform when a chip is clicked
|
* @param selectAction Action to perform when a chip is clicked
|
||||||
|
* @param navigateToSettingsActtion Action to perform when clicking settings chip at the end
|
||||||
* @param lazyListState Used for animated scroll when entering unit selection screen
|
* @param lazyListState Used for animated scroll when entering unit selection screen
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
@ -60,9 +63,9 @@ fun ChipsRow(
|
|||||||
items: List<UnitGroup> = ALL_UNIT_GROUPS,
|
items: List<UnitGroup> = ALL_UNIT_GROUPS,
|
||||||
chosenUnitGroup: UnitGroup?,
|
chosenUnitGroup: UnitGroup?,
|
||||||
selectAction: (UnitGroup) -> Unit,
|
selectAction: (UnitGroup) -> Unit,
|
||||||
|
navigateToSettingsActtion: () -> Unit,
|
||||||
lazyListState: LazyListState
|
lazyListState: LazyListState
|
||||||
) {
|
) {
|
||||||
val chipShape = RoundedCornerShape(8.dp)
|
|
||||||
LazyRow(
|
LazyRow(
|
||||||
modifier = Modifier.background(MaterialTheme.colorScheme.background),
|
modifier = Modifier.background(MaterialTheme.colorScheme.background),
|
||||||
state = lazyListState,
|
state = lazyListState,
|
||||||
@ -71,25 +74,9 @@ fun ChipsRow(
|
|||||||
) {
|
) {
|
||||||
items(items, key = { it.name }) { item ->
|
items(items, key = { it.name }) { item ->
|
||||||
val isSelected: Boolean = item == chosenUnitGroup
|
val isSelected: Boolean = item == chosenUnitGroup
|
||||||
Row(
|
UnittoFilterChip(
|
||||||
modifier = Modifier
|
isSelected = isSelected,
|
||||||
.height(32.dp)
|
selectAction = { selectAction(item) }
|
||||||
.clip(chipShape)
|
|
||||||
.background(
|
|
||||||
if (isSelected) MaterialTheme.colorScheme.secondaryContainer else Color.Transparent
|
|
||||||
)
|
|
||||||
// Remove border when selected
|
|
||||||
.border(
|
|
||||||
1.dp,
|
|
||||||
if (isSelected) Color.Transparent else MaterialTheme.colorScheme.outline,
|
|
||||||
chipShape
|
|
||||||
)
|
|
||||||
.clickable { selectAction(item) }
|
|
||||||
.padding(
|
|
||||||
start = 8.dp,
|
|
||||||
end = 16.dp
|
|
||||||
),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
) {
|
||||||
AnimatedVisibility(visible = isSelected) {
|
AnimatedVisibility(visible = isSelected) {
|
||||||
Icon(
|
Icon(
|
||||||
@ -106,5 +93,61 @@ fun ChipsRow(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Usually this chip is placed at the start, but since we scroll to currently selected
|
||||||
|
* chip, user may never find it. There is higher chance that user will notice this chip when
|
||||||
|
* scrolling right (to the last one).
|
||||||
|
*/
|
||||||
|
item("settings") {
|
||||||
|
UnittoFilterChip(
|
||||||
|
isSelected = false,
|
||||||
|
selectAction = navigateToSettingsActtion,
|
||||||
|
paddingValues = PaddingValues(horizontal = 8.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.height(18.dp),
|
||||||
|
imageVector = Icons.Default.Settings,
|
||||||
|
contentDescription = stringResource(id = R.string.open_settings_description)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic chip implementation
|
||||||
|
*
|
||||||
|
* @param isSelected Chip state.
|
||||||
|
* @param selectAction Action to perform when clicking chip.
|
||||||
|
* @param paddingValues Padding values applied to Row.
|
||||||
|
* @param content Content of the list. Icon and/or label.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun UnittoFilterChip(
|
||||||
|
isSelected: Boolean,
|
||||||
|
selectAction: () -> Unit,
|
||||||
|
paddingValues: PaddingValues = PaddingValues(start = 8.dp, end = 16.dp),
|
||||||
|
content: @Composable RowScope.() -> Unit
|
||||||
|
) {
|
||||||
|
val chipShape = RoundedCornerShape(8.dp)
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.height(32.dp)
|
||||||
|
.clip(chipShape)
|
||||||
|
.background(
|
||||||
|
if (isSelected) MaterialTheme.colorScheme.secondaryContainer else Color.Transparent
|
||||||
|
)
|
||||||
|
// Remove border when selected
|
||||||
|
.border(
|
||||||
|
1.dp,
|
||||||
|
if (isSelected) Color.Transparent else MaterialTheme.colorScheme.outline,
|
||||||
|
chipShape
|
||||||
|
)
|
||||||
|
.clickable { selectAction() }
|
||||||
|
.padding(paddingValues),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
content()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user