Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding legal / privacy policy info. #1382

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/java/com/jerboa/JerboaAppState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class JerboaAppState(

fun toSiteSideBar() = navController.navigate(Route.SITE_SIDEBAR)

fun toSiteLegal() = navController.navigate(Route.SITE_LEGAL)

fun toCommentReply(replyItem: ReplyItem) {
sendReturnForwards(CommentReplyReturn.COMMENT_SEND, replyItem)
navController.navigate(Route.COMMENT_REPLY)
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import com.jerboa.ui.components.community.CommunityActivity
import com.jerboa.ui.components.community.list.CommunityListActivity
import com.jerboa.ui.components.community.sidebar.CommunitySidebarActivity
import com.jerboa.ui.components.home.BottomNavActivity
import com.jerboa.ui.components.home.legal.SiteLegalActivity
import com.jerboa.ui.components.home.sidebar.SiteSidebarActivity
import com.jerboa.ui.components.imageviewer.ImageViewer
import com.jerboa.ui.components.inbox.InboxActivity
Expand Down Expand Up @@ -559,6 +560,13 @@ class MainActivity : AppCompatActivity() {

composable(route = Route.SITE_SIDEBAR) {
SiteSidebarActivity(
appState = appState,
siteViewModel = siteViewModel,
)
}

composable(route = Route.SITE_LEGAL) {
SiteLegalActivity(
siteViewModel = siteViewModel,
onBackClick = appState::popBackStack,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object Route {
const val COMMENT_REPLY = "commentReply"

const val SITE_SIDEBAR = "siteSidebar"
const val SITE_LEGAL = "siteLegal"
const val COMMENT_EDIT = "commentEdit"
const val POST_EDIT = "postEdit"
const val POST_REMOVE = "postRemove"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.jerboa.ui.components.home.legal

import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
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.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.jerboa.R
import com.jerboa.api.ApiState
import com.jerboa.model.SiteViewModel
import com.jerboa.ui.components.common.ApiEmptyText
import com.jerboa.ui.components.common.ApiErrorText
import com.jerboa.ui.components.common.LoadingBar
import com.jerboa.ui.components.common.MyMarkdownText
import com.jerboa.ui.components.common.SimpleTopAppBar
import com.jerboa.ui.theme.MEDIUM_PADDING
import com.jerboa.ui.theme.muted

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SiteLegalActivity(
siteViewModel: SiteViewModel,
onBackClick: () -> Unit,
) {
Log.d("jerboa", "got to site legal activity")

val scrollState = rememberScrollState()

val title =
when (val siteRes = siteViewModel.siteRes) {
is ApiState.Success -> stringResource(R.string.site_legal_info_name, siteRes.data.site_view.site.name)
else -> {
stringResource(R.string.loading)
}
}

Scaffold(
topBar = {
SimpleTopAppBar(
text = title,
onBackClick,
)
},
content = { padding ->
when (val siteRes = siteViewModel.siteRes) {
ApiState.Empty -> ApiEmptyText()
is ApiState.Failure -> ApiErrorText(siteRes.msg)
ApiState.Loading -> LoadingBar(padding)
is ApiState.Success -> {
Column(
modifier =
Modifier
.padding(padding)
.verticalScroll(scrollState),
) {
siteRes.data.site_view.local_site.legal_information?.let {
MyMarkdownText(
modifier = Modifier.padding(horizontal = MEDIUM_PADDING),
markdown = it,
color = MaterialTheme.colorScheme.onBackground.muted,
onClick = {},
)
}
}
}
else -> {}
}
},
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.jerboa.ui.components.home.sidebar

import android.util.Log
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Policy
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.jerboa.JerboaAppState
import com.jerboa.R
import com.jerboa.api.ApiState
import com.jerboa.model.SiteViewModel
import com.jerboa.ui.components.common.ApiEmptyText
Expand All @@ -14,24 +21,43 @@ import com.jerboa.ui.components.common.SimpleTopAppBar
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SiteSidebarActivity(
appState: JerboaAppState,
siteViewModel: SiteViewModel,
onBackClick: () -> Unit,
) {
Log.d("jerboa", "got to site sidebar activity")

val title =
when (val siteRes = siteViewModel.siteRes) {
is ApiState.Success -> "${siteRes.data.site_view.site.name} Info"
is ApiState.Success -> stringResource(R.string.site_info_name, siteRes.data.site_view.site.name)
else -> {
"Loading..."
stringResource(R.string.loading)
}
}

Scaffold(
topBar = {
SimpleTopAppBar(
text = title,
onBackClick,
onClickBack = appState::popBackStack,
actions = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it to the action bar of the site info page, rather than the top of home. Could go either way.

when (val siteRes = siteViewModel.siteRes) {
is ApiState.Success -> {
if (siteRes.data.site_view.local_site.legal_information != null) {
IconButton(
onClick = {
appState.toSiteLegal()
},
) {
Icon(
Icons.Default.Policy,
contentDescription = title,
)
}
}
}
else -> {}
}
},
)
},
content = { padding ->
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,6 @@
<string name="message">Message</string>
<string name="report_person">Report %1$s</string>
<string name="block_person">Block %1$s</string>
<string name="site_info_name">%1$s info</string>
<string name="site_legal_info_name">%1$s legal info</string>
</resources>