diff --git a/app/src/main/java/com/jerboa/MainActivity.kt b/app/src/main/java/com/jerboa/MainActivity.kt index 5db081e27..107db7ee7 100644 --- a/app/src/main/java/com/jerboa/MainActivity.kt +++ b/app/src/main/java/com/jerboa/MainActivity.kt @@ -23,6 +23,7 @@ import com.jerboa.ui.components.community.CommunityActivity import com.jerboa.ui.components.community.CommunityViewModel import com.jerboa.ui.components.community.list.CommunityListActivity import com.jerboa.ui.components.community.list.CommunityListViewModel +import com.jerboa.ui.components.community.sidebar.CommunitySidebarActivity import com.jerboa.ui.components.home.* import com.jerboa.ui.components.inbox.InboxActivity import com.jerboa.ui.components.inbox.InboxViewModel @@ -203,13 +204,21 @@ class MainActivity : ComponentActivity() { ) } composable( - route = "sidebar", + route = "siteSidebar", ) { - SidebarActivity( + SiteSidebarActivity( siteViewModel = siteViewModel, navController = navController, ) } + composable( + route = "communitySidebar", + ) { + CommunitySidebarActivity( + communityViewModel = communityViewModel, + navController = navController, + ) + } composable( route = "commentEdit", ) { diff --git a/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt b/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt index 9ce1f005a..57d5373c7 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt @@ -18,6 +18,7 @@ import androidx.navigation.compose.rememberNavController import com.jerboa.datatypes.PersonSafe import com.jerboa.datatypes.api.GetUnreadCountResponse import com.jerboa.db.Account +import com.jerboa.siFormat import com.jerboa.ui.components.person.PersonProfileLink import com.jerboa.ui.theme.* import com.jerboa.unreadCountTotal @@ -277,3 +278,82 @@ fun InboxIconAndBadge( ) } } + +@Composable +fun Sidebar( + title: String?, + banner: String?, + icon: String?, + content: String?, + published: String, + usersActiveMonth: Int, + postCount: Int, + commentCount: Int, +) { + Column( + modifier = Modifier.padding(MEDIUM_PADDING), + verticalArrangement = Arrangement.spacedBy(MEDIUM_PADDING) + ) { + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.BottomStart + ) { + banner?.also { + PictrsBannerImage( + url = it, modifier = Modifier.height(PROFILE_BANNER_SIZE) + ) + } + Box(modifier = Modifier.padding(MEDIUM_PADDING)) { + icon?.also { + LargerCircularIcon(icon = it) + } + } + } + title?.also { + Text( + text = it, + style = MaterialTheme.typography.subtitle1 + ) + } + TimeAgo( + precedingString = "Created", + includeAgo = true, + published = published + ) + CommentsAndPosts( + usersActiveMonth = usersActiveMonth, + postCount = postCount, + commentCount = commentCount, + ) + content?.also { + MyMarkdownText( + markdown = it, + color = Muted, + ) + } + } +} + +@Composable +fun CommentsAndPosts( + usersActiveMonth: Int, + postCount: Int, + commentCount: Int, +) { + Row { + Text( + text = "${siFormat(usersActiveMonth)} users / month", + color = Muted, + ) + DotSpacer() + Text( + text = "${siFormat(postCount)} posts", + color = Muted, + ) + DotSpacer() + Text( + text = "${siFormat(commentCount)} comments", + color = Muted, + ) + } +} diff --git a/app/src/main/java/com/jerboa/ui/components/community/Community.kt b/app/src/main/java/com/jerboa/ui/components/community/Community.kt index 2d3f0839b..0eab389e6 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/Community.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/Community.kt @@ -4,10 +4,7 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.material.icons.filled.CheckCircle -import androidx.compose.material.icons.filled.MoreVert -import androidx.compose.material.icons.filled.Sort +import androidx.compose.material.icons.filled.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -22,6 +19,7 @@ import com.jerboa.ui.components.common.LargerCircularIcon import com.jerboa.ui.components.common.PictrsBannerImage import com.jerboa.ui.components.common.SortOptionsDialog import com.jerboa.ui.components.common.SortTopOptionsDialog +import com.jerboa.ui.components.home.IconAndTextDrawerItem import com.jerboa.ui.theme.ACTION_BAR_ICON_SIZE import com.jerboa.ui.theme.APP_BAR_ELEVATION import com.jerboa.ui.theme.DRAWER_BANNER_SIZE @@ -108,6 +106,7 @@ fun CommunityHeader( var showSortOptions by remember { mutableStateOf(false) } var showTopOptions by remember { mutableStateOf(false) } + var showMoreOptions by remember { mutableStateOf(false) } if (showSortOptions) { SortOptionsDialog( @@ -135,6 +134,13 @@ fun CommunityHeader( ) } + if (showMoreOptions) { + CommunityMoreDialog( + onDismissRequest = { showMoreOptions = false }, + navController = navController, + ) + } + TopAppBar( title = { CommunityHeaderTitle( @@ -162,6 +168,7 @@ fun CommunityHeader( ) } IconButton(onClick = { + showMoreOptions = !showMoreOptions }) { Icon( Icons.Default.MoreVert, @@ -190,3 +197,26 @@ fun CommunityHeaderTitle( ) } } + +@Composable +fun CommunityMoreDialog( + onDismissRequest: () -> Unit = {}, + navController: NavController, +) { + AlertDialog( + onDismissRequest = onDismissRequest, + text = { + Column { + IconAndTextDrawerItem( + text = "View Sidebar", + icon = Icons.Default.Info, + onClick = { + navController.navigate("communitySidebar") + onDismissRequest() + }, + ) + } + }, + buttons = {}, + ) +} diff --git a/app/src/main/java/com/jerboa/ui/components/community/sidebar/CommunitySidebar.kt b/app/src/main/java/com/jerboa/ui/components/community/sidebar/CommunitySidebar.kt new file mode 100644 index 000000000..915b077cf --- /dev/null +++ b/app/src/main/java/com/jerboa/ui/components/community/sidebar/CommunitySidebar.kt @@ -0,0 +1,21 @@ +package com.jerboa.ui.components.community.sidebar + +import androidx.compose.runtime.Composable +import com.jerboa.datatypes.CommunityView +import com.jerboa.ui.components.common.Sidebar + +@Composable +fun CommunitySidebar(communityView: CommunityView) { + val community = communityView.community + val counts = communityView.counts + Sidebar( + title = community.title, + content = community.description, + banner = community.banner, + icon = community.icon, + published = community.published, + usersActiveMonth = counts.users_active_month, + postCount = counts.posts, + commentCount = counts.comments, + ) +} diff --git a/app/src/main/java/com/jerboa/ui/components/community/sidebar/CommunitySidebarActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/sidebar/CommunitySidebarActivity.kt new file mode 100644 index 000000000..0ced47768 --- /dev/null +++ b/app/src/main/java/com/jerboa/ui/components/community/sidebar/CommunitySidebarActivity.kt @@ -0,0 +1,37 @@ +package com.jerboa.ui.components.community.sidebar + +import android.util.Log +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Scaffold +import androidx.compose.material.Surface +import androidx.compose.runtime.Composable +import androidx.navigation.NavController +import com.jerboa.ui.components.common.SimpleTopAppBar +import com.jerboa.ui.components.community.CommunityViewModel + +@Composable +fun CommunitySidebarActivity( + communityViewModel: CommunityViewModel, + navController: NavController, +) { + + Log.d("jerboa", "got to community sidebar activity") + + val title = "${communityViewModel.communityView?.community?.name} Sidebar" + + Surface(color = MaterialTheme.colors.background) { + Scaffold( + topBar = { + SimpleTopAppBar( + text = title, + navController = navController + ) + }, + content = { + communityViewModel.communityView?.also { + CommunitySidebar(it) + } + } + ) + } +} diff --git a/app/src/main/java/com/jerboa/ui/components/home/Home.kt b/app/src/main/java/com/jerboa/ui/components/home/Home.kt index eccf0a821..40ba55580 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/Home.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/Home.kt @@ -538,7 +538,7 @@ fun HomeMoreDialog( text = "View Sidebar", icon = Icons.Default.Info, onClick = { - navController.navigate("sidebar") + navController.navigate("siteSidebar") onDismissRequest() }, ) diff --git a/app/src/main/java/com/jerboa/ui/components/home/Sidebar.kt b/app/src/main/java/com/jerboa/ui/components/home/Sidebar.kt deleted file mode 100644 index 1857eaa64..000000000 --- a/app/src/main/java/com/jerboa/ui/components/home/Sidebar.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.jerboa.ui.components.home - -import androidx.compose.foundation.layout.* -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview -import com.jerboa.datatypes.SiteView -import com.jerboa.datatypes.sampleSiteView -import com.jerboa.siFormat -import com.jerboa.ui.components.common.* -import com.jerboa.ui.theme.MEDIUM_PADDING -import com.jerboa.ui.theme.Muted -import com.jerboa.ui.theme.PROFILE_BANNER_SIZE - -@Composable -fun Sidebar(siteView: SiteView) { - val site = siteView.site - Column( - modifier = Modifier.padding(MEDIUM_PADDING), - verticalArrangement = Arrangement.spacedBy(MEDIUM_PADDING) - ) { - Box( - modifier = Modifier.fillMaxWidth(), - contentAlignment = Alignment.BottomStart - ) { - site.banner?.also { - PictrsBannerImage( - url = it, modifier = Modifier.height(PROFILE_BANNER_SIZE) - ) - } - Box(modifier = Modifier.padding(MEDIUM_PADDING)) { - site.icon?.also { - LargerCircularIcon(icon = it) - } - } - } - site.description?.also { - Text( - text = it, - style = MaterialTheme.typography.subtitle1 - ) - } - TimeAgo( - precedingString = "Created", - includeAgo = true, - published = site.published - ) - CommentsAndPosts(siteView = siteView) - site.sidebar?.also { - MyMarkdownText( - markdown = it, - color = Muted, - ) - } - } -} - -@Composable -fun CommentsAndPosts(siteView: SiteView) { - Row { - Text( - text = "${siFormat(siteView.counts.users_active_month)} users / month", - color = Muted, - ) - DotSpacer() - Text( - text = "${siFormat(siteView.counts.posts)} posts", - color = Muted, - ) - DotSpacer() - Text( - text = "${siFormat(siteView.counts.comments)} comments", - color = Muted, - ) - } -} - -@Preview -@Composable -fun SidebarPreview() { - Sidebar(siteView = sampleSiteView) -} diff --git a/app/src/main/java/com/jerboa/ui/components/home/sidebar/SiteSidebar.kt b/app/src/main/java/com/jerboa/ui/components/home/sidebar/SiteSidebar.kt new file mode 100644 index 000000000..cda1460e8 --- /dev/null +++ b/app/src/main/java/com/jerboa/ui/components/home/sidebar/SiteSidebar.kt @@ -0,0 +1,29 @@ +package com.jerboa.ui.components.home.sidebar + +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview +import com.jerboa.datatypes.SiteView +import com.jerboa.datatypes.sampleSiteView +import com.jerboa.ui.components.common.Sidebar + +@Composable +fun SiteSidebar(siteView: SiteView) { + val site = siteView.site + val counts = siteView.counts + Sidebar( + title = site.description, + content = site.sidebar, + banner = site.banner, + icon = site.icon, + published = site.published, + usersActiveMonth = counts.users_active_month, + postCount = counts.posts, + commentCount = counts.comments, + ) +} + +@Preview +@Composable +fun SiteSidebarPreview() { + SiteSidebar(siteView = sampleSiteView) +} diff --git a/app/src/main/java/com/jerboa/ui/components/home/SidebarActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/sidebar/SiteSidebarActivity.kt similarity index 75% rename from app/src/main/java/com/jerboa/ui/components/home/SidebarActivity.kt rename to app/src/main/java/com/jerboa/ui/components/home/sidebar/SiteSidebarActivity.kt index 52213e05a..d196944fe 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/SidebarActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/sidebar/SiteSidebarActivity.kt @@ -5,21 +5,18 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Scaffold import androidx.compose.material.Surface import androidx.compose.runtime.Composable -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavController import com.jerboa.ui.components.common.SimpleTopAppBar +import com.jerboa.ui.components.home.sidebar.SiteSidebar @Composable -fun SidebarActivity( +fun SiteSidebarActivity( siteViewModel: SiteViewModel, navController: NavController, ) { - Log.d("jerboa", "got to sidebar activity") + Log.d("jerboa", "got to site sidebar activity") - val ctx = LocalContext.current - val scope = rememberCoroutineScope() val title = "${siteViewModel.siteRes?.site_view?.site?.name} Sidebar" Surface(color = MaterialTheme.colors.background) { @@ -32,7 +29,7 @@ fun SidebarActivity( }, content = { siteViewModel.siteRes?.site_view?.also { - Sidebar(it) + SiteSidebar(it) } } )