Skip to content

Commit

Permalink
Adding community sidebars. Fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Jan 20, 2022
1 parent f55288b commit dcb18e7
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 99 deletions.
13 changes: 11 additions & 2 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
) {
Expand Down
80 changes: 80 additions & 0 deletions app/src/main/java/com/jerboa/ui/components/common/AppBars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
}
}
38 changes: 34 additions & 4 deletions app/src/main/java/com/jerboa/ui/components/community/Community.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -135,6 +134,13 @@ fun CommunityHeader(
)
}

if (showMoreOptions) {
CommunityMoreDialog(
onDismissRequest = { showMoreOptions = false },
navController = navController,
)
}

TopAppBar(
title = {
CommunityHeaderTitle(
Expand Down Expand Up @@ -162,6 +168,7 @@ fun CommunityHeader(
)
}
IconButton(onClick = {
showMoreOptions = !showMoreOptions
}) {
Icon(
Icons.Default.MoreVert,
Expand Down Expand Up @@ -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 = {},
)
}
Original file line number Diff line number Diff line change
@@ -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,
)
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
)
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/ui/components/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ fun HomeMoreDialog(
text = "View Sidebar",
icon = Icons.Default.Info,
onClick = {
navController.navigate("sidebar")
navController.navigate("siteSidebar")
onDismissRequest()
},
)
Expand Down
85 changes: 0 additions & 85 deletions app/src/main/java/com/jerboa/ui/components/home/Sidebar.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit dcb18e7

Please sign in to comment.