mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 20:17:02 +05:30
Wire in ability to toggle sorting order
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
9bf5ee90ef
commit
1408bee041
4 changed files with 60 additions and 0 deletions
|
@ -54,6 +54,12 @@ fun LobstersApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
LobstersTopAppBar(
|
||||||
|
currentDestination,
|
||||||
|
viewModel::toggleSortOrder,
|
||||||
|
)
|
||||||
|
},
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
LobstersBottomNav(
|
LobstersBottomNav(
|
||||||
currentDestination,
|
currentDestination,
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package dev.msfjarvis.lobsters.ui.main
|
||||||
|
|
||||||
|
import androidx.compose.animation.ExperimentalAnimationApi
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.material.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import dev.msfjarvis.lobsters.R
|
||||||
|
import dev.msfjarvis.lobsters.ui.navigation.Destination
|
||||||
|
import dev.msfjarvis.lobsters.util.IconResource
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@OptIn(ExperimentalAnimationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun LobstersTopAppBar(
|
||||||
|
currentDestination: Destination,
|
||||||
|
toggleSortingOrder: suspend () -> Unit,
|
||||||
|
) {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
TopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.app_name),
|
||||||
|
modifier = Modifier.padding(vertical = 8.dp),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
if (currentDestination == Destination.Saved) {
|
||||||
|
IconResource(
|
||||||
|
resourceId = R.drawable.ic_sort_24px,
|
||||||
|
contentDescription = stringResource(id = R.string.change_sorting_order),
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(horizontal = 8.dp, vertical = 8.dp)
|
||||||
|
.clickable { scope.launch { toggleSortingOrder() } },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
9
app/src/main/res/drawable/ic_sort_24px.xml
Normal file
9
app/src/main/res/drawable/ic_sort_24px.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M4,18h4c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L4,16c-0.55,0 -1,0.45 -1,1s0.45,1 1,1zM3,7c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L4,6c-0.55,0 -1,0.45 -1,1zM4,13h10c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L4,11c-0.55,0 -1,0.45 -1,1s0.45,1 1,1z"/>
|
||||||
|
</vector>
|
|
@ -10,4 +10,5 @@
|
||||||
<string name="remove_from_saved_posts">Remove from saved posts</string>
|
<string name="remove_from_saved_posts">Remove from saved posts</string>
|
||||||
<string name="refresh_posts_content_description">Refresh posts</string>
|
<string name="refresh_posts_content_description">Refresh posts</string>
|
||||||
<string name="open_comments">Open comments</string>
|
<string name="open_comments">Open comments</string>
|
||||||
|
<string name="change_sorting_order">Change sort order</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue