From e66e5d45bb4d72eb9a689aee196b7e45a1135040 Mon Sep 17 00:00:00 2001
From: Wing <44992537+wingio@users.noreply.github.com>
Date: Wed, 29 Nov 2023 11:23:56 -0500
Subject: [PATCH] Replace messages tab with profile
---
.../dimett/ui/screens/main/MainScreen.kt | 68 ++++++++++---------
.../ProfileScreen.kt} | 26 ++++---
.../java/xyz/wingio/dimett/utils/NavUtils.kt | 6 +-
app/src/main/res/values/strings.xml | 2 +
4 files changed, 57 insertions(+), 45 deletions(-)
rename app/src/main/java/xyz/wingio/dimett/ui/screens/{messages/MessagesScreen.kt => profile/ProfileScreen.kt} (81%)
diff --git a/app/src/main/java/xyz/wingio/dimett/ui/screens/main/MainScreen.kt b/app/src/main/java/xyz/wingio/dimett/ui/screens/main/MainScreen.kt
index dba2817..c8db98b 100644
--- a/app/src/main/java/xyz/wingio/dimett/ui/screens/main/MainScreen.kt
+++ b/app/src/main/java/xyz/wingio/dimett/ui/screens/main/MainScreen.kt
@@ -1,15 +1,13 @@
package xyz.wingio.dimett.ui.screens.main
import androidx.activity.compose.BackHandler
-import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
-import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
@@ -42,6 +40,7 @@ class MainScreen : Screen {
@Composable
@OptIn(ExperimentalMaterial3Api::class, ExperimentalPagerApi::class)
private fun Screen() {
+ val viewModel: MainViewModel = getScreenModel()
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val pagerState = rememberPagerState()
val coroutineScope = rememberCoroutineScope()
@@ -58,15 +57,15 @@ class MainScreen : Screen {
LocalPager provides pagerState
) {
Scaffold(
- bottomBar = { TabBar(pagerState) },
- topBar = { TopBar(RootTab.values()[pagerState.currentPage].tab, scrollBehavior) }
+ bottomBar = { TabBar(pagerState, viewModel) },
+ topBar = { TopBar(RootTab.entries[pagerState.currentPage].tab, scrollBehavior) }
) { pv ->
HorizontalPager(
- count = RootTab.values().size,
+ count = RootTab.entries.size,
state = pagerState,
modifier = Modifier.fillMaxSize()
) {
- val tab = RootTab.values()[it]
+ val tab = RootTab.entries[it]
Box(
Modifier
@@ -85,28 +84,19 @@ class MainScreen : Screen {
@OptIn(ExperimentalMaterial3Api::class)
private fun TopBar(
tab: Tab,
- scrollBehavior: TopAppBarScrollBehavior,
- viewModel: MainViewModel = getScreenModel()
+ scrollBehavior: TopAppBarScrollBehavior
) {
LargeTopAppBar(
title = { Text(tab.options.title) },
navigationIcon = {
- Row {
- Spacer(Modifier.width(8.dp))
- AsyncImage(
- model = viewModel.account?.avatar,
- contentDescription = stringResource(
- R.string.cd_avatar,
- viewModel.account?.username ?: ""
- ),
- modifier = Modifier
- .size(33.dp)
- .clip(CircleShape)
- .clickable { }
+ IconButton(
+ onClick = { /* TODO: Open some menu */ }
+ ) {
+ Icon(
+ imageVector = Icons.Filled.Menu,
+ contentDescription = stringResource(R.string.action_open_menu)
)
- Spacer(Modifier.width(12.dp))
}
-
},
scrollBehavior = scrollBehavior
)
@@ -115,26 +105,40 @@ class MainScreen : Screen {
@OptIn(ExperimentalPagerApi::class)
@Composable
private fun TabBar(
- pagerState: PagerState
+ pagerState: PagerState,
+ viewModel: MainViewModel
) {
- val tab = RootTab.values()[pagerState.currentPage].tab
+ val tab = RootTab.entries[pagerState.currentPage].tab
val coroutineScope = rememberCoroutineScope()
NavigationBar {
- RootTab.values().forEach {
+ RootTab.entries.forEach {
NavigationBarItem(
selected = tab == it.tab,
onClick = {
- val page = RootTab.values().indexOf(it)
+ val page = RootTab.entries.indexOf(it)
coroutineScope.launch {
pagerState.animateScrollToPage(page)
}
},
icon = {
- Icon(
- painter = it.tab.options.icon!!,
- contentDescription = it.tab.options.title
- )
+ if(it == RootTab.PROFILE && viewModel.account != null) {
+ AsyncImage(
+ model = viewModel.account!!.avatar,
+ contentDescription = stringResource(
+ R.string.cd_avatar,
+ viewModel.account!!.username
+ ),
+ modifier = Modifier
+ .size(24.dp)
+ .clip(CircleShape)
+ )
+ } else {
+ Icon(
+ painter = it.tab.options.icon!!,
+ contentDescription = it.tab.options.title
+ )
+ }
},
label = { Text(text = it.tab.options.title) }
)
diff --git a/app/src/main/java/xyz/wingio/dimett/ui/screens/messages/MessagesScreen.kt b/app/src/main/java/xyz/wingio/dimett/ui/screens/profile/ProfileScreen.kt
similarity index 81%
rename from app/src/main/java/xyz/wingio/dimett/ui/screens/messages/MessagesScreen.kt
rename to app/src/main/java/xyz/wingio/dimett/ui/screens/profile/ProfileScreen.kt
index 6edbc02..d680a59 100644
--- a/app/src/main/java/xyz/wingio/dimett/ui/screens/messages/MessagesScreen.kt
+++ b/app/src/main/java/xyz/wingio/dimett/ui/screens/profile/ProfileScreen.kt
@@ -1,4 +1,4 @@
-package xyz.wingio.dimett.ui.screens.messages
+package xyz.wingio.dimett.ui.screens.profile
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
@@ -7,8 +7,8 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Mail
-import androidx.compose.material.icons.outlined.Mail
+import androidx.compose.material.icons.filled.Person
+import androidx.compose.material.icons.outlined.Person
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
@@ -17,6 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
+import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabOptions
import xyz.wingio.dimett.R
@@ -24,13 +25,7 @@ import xyz.wingio.dimett.ui.components.Text
import xyz.wingio.dimett.utils.TabOptions
import xyz.wingio.dimett.utils.getString
-class MessagesTab : Tab {
- override val options: TabOptions
- @Composable get() = TabOptions(
- R.string.title_messages,
- icon = Icons.Outlined.Mail,
- iconSelected = Icons.Filled.Mail
- )
+open class ProfileScreen: Screen {
@Composable
override fun Content() {
@@ -54,4 +49,15 @@ class MessagesTab : Tab {
}
}
+}
+
+class ProfileTab : ProfileScreen(), Tab {
+
+ override val options: TabOptions
+ @Composable get() = TabOptions(
+ R.string.title_profile,
+ icon = Icons.Outlined.Person,
+ iconSelected = Icons.Filled.Person
+ )
+
}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/wingio/dimett/utils/NavUtils.kt b/app/src/main/java/xyz/wingio/dimett/utils/NavUtils.kt
index 2d1116d..6074d51 100644
--- a/app/src/main/java/xyz/wingio/dimett/utils/NavUtils.kt
+++ b/app/src/main/java/xyz/wingio/dimett/utils/NavUtils.kt
@@ -15,14 +15,14 @@ import com.google.accompanist.pager.ExperimentalPagerApi
import xyz.wingio.dimett.ui.screens.explore.ExploreTab
import xyz.wingio.dimett.ui.screens.feed.FeedTab
import xyz.wingio.dimett.ui.screens.main.LocalPager
-import xyz.wingio.dimett.ui.screens.messages.MessagesTab
+import xyz.wingio.dimett.ui.screens.profile.ProfileTab
import xyz.wingio.dimett.ui.screens.notifications.NotificationsTab
enum class RootTab(val tab: Tab) {
FEED(FeedTab()),
EXPLORE(ExploreTab()),
NOTIFICATIONS(NotificationsTab()),
- MESSAGES(MessagesTab()),
+ PROFILE(ProfileTab()),
}
tailrec fun Navigator.navigate(screen: Screen) {
@@ -42,7 +42,7 @@ fun Tab.TabOptions(
iconSelected: ImageVector
): TabOptions {
val pager = LocalPager.currentOrThrow
- val selected = RootTab.values()[pager.currentPage].tab == this
+ val selected = RootTab.entries[pager.currentPage].tab == this
return TabOptions(
0u,
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8143a20..700a703 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -5,6 +5,7 @@
Vote
Retry
Share
+ Open menu
Instance
@@ -15,6 +16,7 @@
Explore
Inbox
Messages
+ Profile
%1$s\'s avatar
Boosted