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

Add ability to share posts. #543

Merged
merged 1 commit into from
Jul 3, 2023
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
13 changes: 13 additions & 0 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,19 @@ fun looksLikeUserUrl(url: String): Pair<String, String>? {
return null
}

/**
* Open a sharesheet for the given URL.
*/
fun shareLink(url: String, ctx: Context) {
val intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url)
type = "text/plain"
}
val shareIntent = Intent.createChooser(intent, null)
ctx.startActivity(shareIntent)
}

fun openLink(url: String, navController: NavController, useCustomTab: Boolean, usePrivateTab: Boolean) {
val parsedUrl = parseUrl(url) ?: return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import com.jerboa.db.AccountViewModel
import com.jerboa.db.AppSettingsViewModel
import com.jerboa.newVote
import com.jerboa.scrollToTop
import com.jerboa.shareLink
import com.jerboa.ui.components.common.ApiEmptyText
import com.jerboa.ui.components.common.ApiErrorText
import com.jerboa.ui.components.common.ConsumeReturn
Expand Down Expand Up @@ -342,6 +343,9 @@ fun CommunityActivity(
)
}
},
onShareClick = { url ->
shareLink(url, ctx)
},
isScrolledToEnd = {
when (val communityRes = communityViewModel.communityRes) {
is ApiState.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.jerboa.fetchInitialData
import com.jerboa.loginFirstToast
import com.jerboa.newVote
import com.jerboa.scrollToTop
import com.jerboa.shareLink
import com.jerboa.ui.components.common.ApiEmptyText
import com.jerboa.ui.components.common.ApiErrorText
import com.jerboa.ui.components.common.ConsumeReturn
Expand Down Expand Up @@ -323,6 +324,9 @@ fun MainPostListingsContent(
onPersonClick = { personId ->
navController.toProfile(id = personId)
},
onShareClick = { url ->
shareLink(url, ctx)
},
isScrolledToEnd = {
homeViewModel.nextPage()
homeViewModel.appendPosts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.jerboa.isScrolledToEnd
import com.jerboa.newVote
import com.jerboa.pagerTabIndicatorOffset2
import com.jerboa.scrollToTop
import com.jerboa.shareLink
import com.jerboa.ui.components.comment.CommentNodes
import com.jerboa.ui.components.comment.edit.CommentEditReturn
import com.jerboa.ui.components.comment.reply.CommentReplyReturn
Expand Down Expand Up @@ -482,6 +483,9 @@ fun UserTabs(
)
}
},
onShareClick = { url ->
shareLink(url, ctx)
},
isScrolledToEnd = {
personProfileViewModel.nextPage()
personProfileViewModel.appendData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import com.jerboa.isModerator
import com.jerboa.newVote
import com.jerboa.scrollToNextParentComment
import com.jerboa.scrollToPreviousParentComment
import com.jerboa.shareLink
import com.jerboa.ui.components.comment.ShowCommentContextButtons
import com.jerboa.ui.components.comment.commentNodeItems
import com.jerboa.ui.components.comment.edit.CommentEditReturn
Expand Down Expand Up @@ -410,6 +411,9 @@ fun PostActivity(
)
}
},
onShareClick = { url ->
shareLink(url, ctx)
},
showReply = true, // Do nothing
isModerator = isModerator(
postView.creator,
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/jerboa/ui/components/post/PostListing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.material.icons.outlined.MoreVert
import androidx.compose.material.icons.outlined.Person
import androidx.compose.material.icons.outlined.PushPin
import androidx.compose.material.icons.outlined.Restore
import androidx.compose.material.icons.outlined.Share
import androidx.compose.material.icons.outlined.Textsms
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Card
Expand Down Expand Up @@ -509,6 +510,7 @@ fun PostFooterLine(
onPersonClick: (personId: Int) -> Unit,
onBlockCreatorClick: (person: Person) -> Unit,
onBlockCommunityClick: (community: Community) -> Unit,
onShareClick: (url: String) -> Unit,
onViewSourceClick: () -> Unit,
modifier: Modifier = Modifier,
showReply: Boolean = false,
Expand Down Expand Up @@ -550,6 +552,10 @@ fun PostFooterLine(
showMoreOptions = false
onBlockCreatorClick(postView.creator)
},
onShareClick = { url ->
showMoreOptions = false
onShareClick(url)
},
onViewSourceClick = {
showMoreOptions = false
onViewSourceClick()
Expand Down Expand Up @@ -711,6 +717,7 @@ fun PostFooterLinePreview() {
onDeletePostClick = {},
onBlockCreatorClick = {},
onBlockCommunityClick = {},
onShareClick = {},
onViewSourceClick = {},
enableDownVotes = true,
viewSource = false,
Expand All @@ -736,6 +743,7 @@ fun PreviewPostListingCard() {
onPersonClick = {},
onBlockCommunityClick = {},
onBlockCreatorClick = {},
onShareClick = {},
isModerator = true,
fullBody = false,
account = null,
Expand Down Expand Up @@ -766,6 +774,7 @@ fun PreviewLinkPostListing() {
onPersonClick = {},
onBlockCommunityClick = {},
onBlockCreatorClick = {},
onShareClick = {},
isModerator = false,
fullBody = false,
account = null,
Expand Down Expand Up @@ -796,6 +805,7 @@ fun PreviewImagePostListingCard() {
onPersonClick = {},
onBlockCommunityClick = {},
onBlockCreatorClick = {},
onShareClick = {},
isModerator = false,
fullBody = false,
account = null,
Expand Down Expand Up @@ -826,6 +836,7 @@ fun PreviewImagePostListingSmallCard() {
onPersonClick = {},
onBlockCommunityClick = {},
onBlockCreatorClick = {},
onShareClick = {},
isModerator = false,
fullBody = false,
account = null,
Expand Down Expand Up @@ -856,6 +867,7 @@ fun PreviewLinkNoThumbnailPostListing() {
onPersonClick = {},
onBlockCommunityClick = {},
onBlockCreatorClick = {},
onShareClick = {},
isModerator = true,
fullBody = false,
account = null,
Expand Down Expand Up @@ -884,6 +896,7 @@ fun PostListing(
onPersonClick: (personId: Int) -> Unit,
onBlockCommunityClick: (community: Community) -> Unit,
onBlockCreatorClick: (person: Person) -> Unit,
onShareClick: (url: String) -> Unit,
showReply: Boolean = false,
isModerator: Boolean,
showCommunityName: Boolean = true,
Expand Down Expand Up @@ -937,6 +950,7 @@ fun PostListing(
onPersonClick = onPersonClick,
onBlockCommunityClick = onBlockCommunityClick,
onBlockCreatorClick = onBlockCreatorClick,
onShareClick = onShareClick,
onViewSourceClick = {
viewSource = !viewSource
},
Expand Down Expand Up @@ -981,6 +995,7 @@ fun PostListing(
onPersonClick = onPersonClick,
onBlockCommunityClick = onBlockCommunityClick,
onBlockCreatorClick = onBlockCreatorClick,
onShareClick = onShareClick,
onViewSourceClick = {
viewSource = !viewSource
},
Expand Down Expand Up @@ -1327,6 +1342,7 @@ fun PostListingCard(
onPersonClick: (personId: Int) -> Unit,
onBlockCommunityClick: (community: Community) -> Unit,
onBlockCreatorClick: (person: Person) -> Unit,
onShareClick: (url: String) -> Unit,
onViewSourceClick: () -> Unit,
viewSource: Boolean,
showReply: Boolean = false,
Expand Down Expand Up @@ -1390,6 +1406,7 @@ fun PostListingCard(
onBlockCommunityClick = onBlockCommunityClick,
onBlockCreatorClick = onBlockCreatorClick,
onViewSourceClick = onViewSourceClick,
onShareClick = onShareClick,
showReply = showReply,
account = account,
modifier = Modifier.padding(horizontal = MEDIUM_PADDING),
Expand Down Expand Up @@ -1446,6 +1463,7 @@ fun PostOptionsDialog(
onReportClick: () -> Unit,
onBlockCreatorClick: () -> Unit,
onBlockCommunityClick: () -> Unit,
onShareClick: (shareUrl: String) -> Unit,
onViewSourceClick: () -> Unit,
isCreator: Boolean,
viewSource: Boolean,
Expand Down Expand Up @@ -1569,6 +1587,18 @@ fun PostOptionsDialog(
onClick = onViewSourceClick,
)
}
postView.post.url?.also { url ->
IconAndTextDrawerItem(
text = stringResource(R.string.post_listing_share_link),
icon = Icons.Outlined.Share,
onClick = { onShareClick(url) },
)
}
IconAndTextDrawerItem(
dessalines marked this conversation as resolved.
Show resolved Hide resolved
text = stringResource(R.string.post_listing_share_post),
icon = Icons.Outlined.Share,
onClick = { onShareClick(postView.post.ap_id) },
)
if (!isCreator) {
IconAndTextDrawerItem(
text = stringResource(R.string.post_listing_report_post),
Expand Down Expand Up @@ -1626,6 +1656,7 @@ fun PostOptionsDialogPreview() {
onEditPostClick = {},
onDeletePostClick = {},
onBlockCommunityClick = {},
onShareClick = {},
onBlockCreatorClick = {},
onViewSourceClick = {},
viewSource = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fun PostListings(
onPersonClick: (personId: Int) -> Unit,
onBlockCommunityClick: (community: Community) -> Unit,
onBlockCreatorClick: (person: Person) -> Unit,
onShareClick: (url: String) -> Unit,
isScrolledToEnd: () -> Unit,
account: Account?,
showCommunityName: Boolean = true,
Expand Down Expand Up @@ -86,6 +87,7 @@ fun PostListings(
onPersonClick = onPersonClick,
onBlockCommunityClick = onBlockCommunityClick,
onBlockCreatorClick = onBlockCreatorClick,
onShareClick = onShareClick,
isModerator = false,
showCommunityName = showCommunityName,
fullBody = false,
Expand Down Expand Up @@ -133,6 +135,7 @@ fun PreviewPostListings() {
onPersonClick = {},
onBlockCommunityClick = {},
onBlockCreatorClick = {},
onShareClick = {},
isScrolledToEnd = {},
account = null,
listState = rememberLazyListState(),
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 @@ -262,6 +262,8 @@
<string name="post_listing_text_copied">Text Copied</string>
<string name="post_listing_report_post">Report Post</string>
<string name="post_listing_restore">Restore</string>
<string name="post_listing_share_link">Share Link</string>
<string name="post_listing_share_post">Share Post</string>
<string name="privateMessage_reply">Reply to message</string>
<string name="private_message_from">"from "</string>
<string name="private_message_reply_back">Back</string>
Expand Down