Add topAppBar to some tabs

This commit is contained in:
Shinokuni 2023-08-07 19:31:01 +02:00
parent f08d3eac71
commit cf0f94bff2
3 changed files with 115 additions and 76 deletions

View File

@ -3,9 +3,13 @@ package com.readrops.app.compose.account
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
@ -27,6 +31,7 @@ object AccountTab : Tab {
title = "Account"
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
override fun Content() {
val navigator = LocalNavigator.currentOrThrow
@ -37,27 +42,33 @@ object AccountTab : Tab {
navigator.replaceAll(AccountSelectionScreen())
}
Column {
Text(text = "Account")
Spacer(modifier = Modifier.size(16.dp))
Row {
Button(onClick = { viewModel.deleteAccount() }) {
Text(
text = "Delete"
)
Scaffold(
topBar = {
TopAppBar(title = { Text(text = "Account") })
}
) { paddingValues ->
Column(
modifier = Modifier.padding(paddingValues)
) {
Row {
Button(onClick = { viewModel.deleteAccount() }) {
Text(
text = "Delete"
)
}
Spacer(modifier = Modifier.size(16.dp))
Spacer(modifier = Modifier.size(16.dp))
Button(onClick = { navigator.push(AccountSelectionScreen()) }) {
Text(
text = "New"
)
Button(onClick = { navigator.push(AccountSelectionScreen()) }) {
Text(
text = "New"
)
}
}
}
}
}
}

View File

@ -7,8 +7,12 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
@ -31,6 +35,7 @@ object FeedTab : Tab {
title = "Feeds"
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
override fun Content() {
val viewModel = getViewModel<FeedViewModel>()
@ -40,55 +45,62 @@ object FeedTab : Tab {
if (showDialog) {
AddFeedDialog(
onDismiss = { showDialog = false },
onValidate = {
showDialog = false
viewModel.insertFeed(it)
}
onDismiss = { showDialog = false },
onValidate = {
showDialog = false
viewModel.insertFeed(it)
}
)
}
Box(
modifier = Modifier.fillMaxSize()
) {
when (state) {
is FeedsState.LoadedState -> {
val feeds = (state as FeedsState.LoadedState).feeds
Scaffold(
topBar = {
TopAppBar(title = { Text(text = "Feeds") })
}
) { paddingValues ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
) {
when (state) {
is FeedsState.LoadedState -> {
val feeds = (state as FeedsState.LoadedState).feeds
if (feeds.isNotEmpty()) {
LazyColumn {
items(
items = feeds
) { feed ->
FeedItem(
feed = feed,
)
if (feeds.isNotEmpty()) {
LazyColumn {
items(
items = feeds
) { feed ->
FeedItem(
feed = feed,
)
}
}
}
}
is FeedsState.ErrorState -> {
}
else -> {
}
}
is FeedsState.ErrorState -> {
FloatingActionButton(
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp),
onClick = { showDialog = true }
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = null
)
}
else -> {
}
}
FloatingActionButton(
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp),
onClick = { showDialog = true }
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = null
)
}
}
}
}

View File

@ -3,21 +3,23 @@ package com.readrops.app.compose.timelime
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.navigator.currentOrThrow
import cafe.adriel.voyager.navigator.tab.LocalTabNavigator
import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabOptions
import com.google.accompanist.swiperefresh.SwipeRefresh
@ -37,6 +39,7 @@ object TimelineTab : Tab {
)
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
override fun Content() {
val viewModel = getViewModel<TimelineViewModel>()
@ -47,37 +50,50 @@ object TimelineTab : Tab {
val navigator = LocalNavigator.currentOrThrow
SwipeRefresh(
state = swipeToRefreshState,
onRefresh = {
viewModel.refreshTimeline()
},
) {
when (state) {
is TimelineState.LoadedState -> {
val items = (state as TimelineState.LoadedState).items
Scaffold(
topBar = {
TopAppBar(
title = { Text(text = "Timeline") }
)
}
) { paddingValues ->
SwipeRefresh(
state = swipeToRefreshState,
onRefresh = {
viewModel.refreshTimeline()
},
modifier = Modifier.padding(paddingValues)
) {
when (state) {
is TimelineState.LoadedState -> {
val items = (state as TimelineState.LoadedState).items
if (items.isNotEmpty()) {
LazyColumn {
items(
items = items
) {
TimelineItem(
onClick = { navigator.push(ItemScreen()) }
)
if (items.isNotEmpty()) {
LazyColumn {
items(
items = items
) {
TimelineItem(
onClick = { navigator.push(ItemScreen()) }
)
}
}
} else {
NoItemPlaceholder()
}
} else {
}
else -> {
NoItemPlaceholder()
}
}
else -> {
NoItemPlaceholder()
}
}
}
}
}
@Composable
fun NoItemPlaceholder() {
val scrollState = rememberScrollState()