Skip to content

Commit

Permalink
feat(android): move backup/restore and search to a dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
msfjarvis committed Nov 3, 2023
1 parent f636b56 commit 348b3a7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 55 deletions.
112 changes: 61 additions & 51 deletions android/src/main/kotlin/dev/msfjarvis/claw/android/ui/LobstersApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package dev.msfjarvis.claw.android.ui

import android.content.Intent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
Expand All @@ -17,13 +18,15 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.ImportExport
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.NewReleases
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Whatshot
import androidx.compose.material.icons.outlined.FavoriteBorder
import androidx.compose.material.icons.outlined.NewReleases
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.Whatshot
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
Expand All @@ -35,8 +38,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -55,14 +60,14 @@ import androidx.paging.compose.collectAsLazyPagingItems
import com.deliveryhero.whetstone.compose.injectedViewModel
import dev.msfjarvis.claw.android.MainActivity
import dev.msfjarvis.claw.android.R
import dev.msfjarvis.claw.android.SearchActivity
import dev.msfjarvis.claw.android.ui.datatransfer.DataTransferScreen
import dev.msfjarvis.claw.android.ui.decorations.ClawAppBar
import dev.msfjarvis.claw.android.ui.decorations.ClawNavigationBar
import dev.msfjarvis.claw.android.ui.decorations.ClawNavigationRail
import dev.msfjarvis.claw.android.ui.decorations.NavigationItem
import dev.msfjarvis.claw.android.ui.lists.DatabasePosts
import dev.msfjarvis.claw.android.ui.lists.NetworkPosts
import dev.msfjarvis.claw.android.ui.lists.SearchList
import dev.msfjarvis.claw.android.ui.navigation.ClawNavigationType
import dev.msfjarvis.claw.android.ui.navigation.Destinations
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
Expand All @@ -88,7 +93,6 @@ fun LobstersApp(
val hottestListState = rememberLazyListState()
val newestListState = rememberLazyListState()
val savedListState = rememberLazyListState()
val searchListState = rememberLazyListState()
val navController = rememberNavController()
val coroutineScope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -138,52 +142,68 @@ fun LobstersApp(
) {
coroutineScope.launch { savedListState.animateScrollToItem(index = 0) }
},
NavigationItem(
label = "Search",
route = Destinations.Search.route,
icon = Icons.Outlined.Search,
selectedIcon = Icons.Filled.Search,
) {
coroutineScope.launch { searchListState.animateScrollToItem(index = 0) }
},
)

Scaffold(
topBar = {
if (currentDestination != Destinations.Search.route) {
ClawAppBar(
navigationIcon = {
if (
navController.previousBackStackEntry != null &&
navItems.none { it.route == currentDestination }
ClawAppBar(
navigationIcon = {
if (
navController.previousBackStackEntry != null &&
navItems.none { it.route == currentDestination }
) {
IconButton(
onClick = { if (!navController.popBackStack()) context.getActivity()?.finish() },
) {
IconButton(
onClick = { if (!navController.popBackStack()) context.getActivity()?.finish() },
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Go back to previous screen",
)
}
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Go back to previous screen",
)
}
},
title = {
if (navItems.any { it.route == currentDestination }) {
Text(text = stringResource(R.string.app_name), fontWeight = FontWeight.Bold)
}
},
title = {
if (navItems.any { it.route == currentDestination }) {
Text(text = stringResource(R.string.app_name), fontWeight = FontWeight.Bold)
}
},
actions = {
var expanded by remember { mutableStateOf(false) }
if (navItems.any { it.route == currentDestination }) {
IconButton(onClick = { expanded = true }) {
Icon(Icons.Default.MoreVert, contentDescription = "Extra options")
}
},
actions = {
if (navItems.any { it.route == currentDestination }) {
IconButton(onClick = { navController.navigate(Destinations.DataTransfer.route) }) {
Icon(
imageVector = Icons.Filled.ImportExport,
contentDescription = "Data transfer options",
)
}
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
DropdownMenuItem(
text = { Text("Backup and restore") },
onClick = {
navController.navigate(Destinations.DataTransfer.route)
expanded = false
},
leadingIcon = {
Icon(
imageVector = Icons.Filled.ImportExport,
contentDescription = "Data transfer options",
)
}
)
DropdownMenuItem(
text = { Text("Search posts") },
onClick = {
context.startActivity(Intent(context, SearchActivity::class.java))
expanded = false
},
leadingIcon = {
Icon(
imageVector = Icons.Filled.Search,
contentDescription = "Search posts",
)
}
)
}
},
)
}
}
},
)
},
bottomBar = {
AnimatedVisibility(visible = navigationType == ClawNavigationType.BOTTOM_NAVIGATION) {
Expand Down Expand Up @@ -242,16 +262,6 @@ fun LobstersApp(
postActions = postActions,
)
}
composable(Destinations.Search.route) {
setWebUri("https://lobste.rs/search")
SearchList(
items = viewModel.searchResults,
isPostSaved = viewModel::isPostSaved,
postActions = postActions,
searchQuery = viewModel.searchQuery,
setSearchQuery = { query -> viewModel.searchQuery = query },
)
}
composable(
route = Destinations.Comments.route,
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ sealed class Destinations {
override val route = "saved"
}

object Search : Destinations() {
override val route = "search"
}

object Comments : Destinations() {
const val placeholder = "{postId}"
override val route = "comments/$placeholder"
Expand Down

0 comments on commit 348b3a7

Please sign in to comment.