Skip to content

Commit

Permalink
Use image previewer when clicking on images in small cards and list view
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Jun 14, 2023
1 parent fea2b83 commit 8491511
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.jerboa.VoteType
import com.jerboa.db.AccountViewModel
import com.jerboa.db.AppSettingsViewModel
import com.jerboa.loginFirstToast
import com.jerboa.openLink
import com.jerboa.scrollToTop
import com.jerboa.ui.components.common.BottomAppBarAll
import com.jerboa.ui.components.common.getCurrentAccount
Expand Down Expand Up @@ -146,9 +145,6 @@ fun CommunityActivity(
onPostClick = { postView ->
navController.navigate(route = "post/${postView.post.id}")
},
onPostLinkClick = { url ->
openLink(url, ctx, appSettingsViewModel.appSettings.value?.useCustomTabs ?: true, appSettingsViewModel.appSettings.value?.usePrivateTabs ?: false)
},
onSaveClick = { postView ->
account?.also { acct ->
communityViewModel.savePost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import com.jerboa.db.AccountViewModel
import com.jerboa.db.AppSettingsViewModel
import com.jerboa.fetchInitialData
import com.jerboa.loginFirstToast
import com.jerboa.openLink
import com.jerboa.scrollToTop
import com.jerboa.ui.components.common.BottomAppBarAll
import com.jerboa.ui.components.common.getCurrentAccount
Expand Down Expand Up @@ -208,9 +207,6 @@ fun MainPostListingsContent(
onPostClick = { postView ->
navController.navigate(route = "post/${postView.post.id}")
},
onPostLinkClick = { url ->
openLink(url, ctx, appSettingsViewModel.appSettings.value?.useCustomTabs ?: true, appSettingsViewModel.appSettings.value?.usePrivateTabs ?: false)
},
onSaveClick = { postView ->
account?.also { acct ->
homeViewModel.savePost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.jerboa.db.AppSettingsViewModel
import com.jerboa.getLocalizedStringForUserTab
import com.jerboa.isScrolledToEnd
import com.jerboa.loginFirstToast
import com.jerboa.openLink
import com.jerboa.pagerTabIndicatorOffset2
import com.jerboa.scrollToTop
import com.jerboa.ui.components.comment.CommentNodes
Expand Down Expand Up @@ -325,9 +324,6 @@ fun UserTabs(
onPostClick = { postView ->
navController.navigate(route = "post/${postView.post.id}")
},
onPostLinkClick = { url ->
openLink(url, ctx, appSettingsViewModel.appSettings.value?.useCustomTabs ?: true, appSettingsViewModel.appSettings.value?.usePrivateTabs ?: false)
},
onSaveClick = { postView ->
account?.also { acct ->
personProfileViewModel.savePost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.jerboa.db.AppSettingsViewModel
import com.jerboa.getCommentParentId
import com.jerboa.getDepthFromComment
import com.jerboa.isModerator
import com.jerboa.openLink
import com.jerboa.ui.components.comment.ShowCommentContextButtons
import com.jerboa.ui.components.comment.commentNodeItems
import com.jerboa.ui.components.comment.edit.CommentEditViewModel
Expand Down Expand Up @@ -152,9 +151,6 @@ fun PostActivity(
navController.navigate("commentReply")
},
onPostClick = {},
onPostLinkClick = { url ->
openLink(url, ctx, appSettingsViewModel.appSettings.value?.useCustomTabs ?: true, appSettingsViewModel.appSettings.value?.usePrivateTabs ?: false)
},
onSaveClick = {
account?.also { acct ->
postViewModel.savePost(
Expand Down
33 changes: 9 additions & 24 deletions app/src/main/java/com/jerboa/ui/components/post/PostListing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ fun PostNodeHeader(
fun PostTitleBlock(
postView: PostView,
expandedImage: Boolean,
onPostLinkClick: (url: String) -> Unit,
account: Account?,
) {
val imagePost = postView.post.url?.let { isImage(it) } ?: run { false }
Expand All @@ -266,7 +265,6 @@ fun PostTitleBlock(
} else {
PostTitleAndThumbnail(
postView = postView,
onPostLinkClick = onPostLinkClick,
account = account,
)
}
Expand Down Expand Up @@ -333,7 +331,6 @@ fun PostTitleAndImageLink(
@Composable
fun PostTitleAndThumbnail(
postView: PostView,
onPostLinkClick: (url: String) -> Unit,
account: Account?,
) {
Column(
Expand Down Expand Up @@ -361,7 +358,7 @@ fun PostTitleAndThumbnail(
}
}
}
ThumbnailTile(postView = postView, onPostLinkClick = onPostLinkClick)
ThumbnailTile(postView = postView)
}
}
}
Expand All @@ -371,7 +368,6 @@ fun PostBody(
postView: PostView,
fullBody: Boolean,
expandedImage: Boolean,
onPostLinkClick: (rl: String) -> Unit,
account: Account?,
) {
val post = postView.post
Expand All @@ -381,7 +377,6 @@ fun PostBody(
PostTitleBlock(
postView = postView,
expandedImage = expandedImage,
onPostLinkClick = onPostLinkClick,
account = account,
)

Expand Down Expand Up @@ -430,7 +425,6 @@ fun PostBody(
fun PreviewStoryTitleAndMetadata() {
PostBody(
postView = samplePostView,
onPostLinkClick = {},
fullBody = false,
expandedImage = false,
account = null,
Expand Down Expand Up @@ -660,7 +654,6 @@ fun PreviewPostListingCard() {
onDownvoteClick = {},
onReplyClick = {},
onPostClick = {},
onPostLinkClick = {},
onSaveClick = {},
onCommunityClick = {},
onEditPostClick = {},
Expand Down Expand Up @@ -688,7 +681,6 @@ fun PreviewLinkPostListing() {
onDownvoteClick = {},
onReplyClick = {},
onPostClick = {},
onPostLinkClick = {},
onSaveClick = {},
onCommunityClick = {},
onEditPostClick = {},
Expand Down Expand Up @@ -716,7 +708,6 @@ fun PreviewImagePostListingCard() {
onDownvoteClick = {},
onReplyClick = {},
onPostClick = {},
onPostLinkClick = {},
onSaveClick = {},
onCommunityClick = {},
onEditPostClick = {},
Expand Down Expand Up @@ -744,7 +735,6 @@ fun PreviewImagePostListingSmallCard() {
onDownvoteClick = {},
onReplyClick = {},
onPostClick = {},
onPostLinkClick = {},
onSaveClick = {},
onCommunityClick = {},
onEditPostClick = {},
Expand Down Expand Up @@ -772,7 +762,6 @@ fun PreviewLinkNoThumbnailPostListing() {
onDownvoteClick = {},
onReplyClick = {},
onPostClick = {},
onPostLinkClick = {},
onSaveClick = {},
onCommunityClick = {},
onEditPostClick = {},
Expand All @@ -798,7 +787,6 @@ fun PostListing(
onDownvoteClick: (postView: PostView) -> Unit,
onReplyClick: (postView: PostView) -> Unit = {},
onPostClick: (postView: PostView) -> Unit,
onPostLinkClick: (url: String) -> Unit,
onSaveClick: (postView: PostView) -> Unit,
onCommunityClick: (community: CommunitySafe) -> Unit,
onEditPostClick: (postView: PostView) -> Unit,
Expand Down Expand Up @@ -849,7 +837,6 @@ fun PostListing(
},
onReplyClick = onReplyClick,
onPostClick = onPostClick,
onPostLinkClick = onPostLinkClick,
onSaveClick = onSaveClick,
onCommunityClick = onCommunityClick,
onEditPostClick = onEditPostClick,
Expand Down Expand Up @@ -886,7 +873,6 @@ fun PostListing(
},
onReplyClick = onReplyClick,
onPostClick = onPostClick,
onPostLinkClick = onPostLinkClick,
onSaveClick = onSaveClick,
onCommunityClick = onCommunityClick,
onEditPostClick = onEditPostClick,
Expand Down Expand Up @@ -922,7 +908,6 @@ fun PostListing(
onDownvoteClick(it)
},
onPostClick = onPostClick,
onPostLinkClick = onPostLinkClick,
onCommunityClick = onCommunityClick,
onPersonClick = onPersonClick,
isModerator = isModerator,
Expand Down Expand Up @@ -987,7 +972,6 @@ fun PostListingList(
onUpvoteClick: (postView: PostView) -> Unit,
onDownvoteClick: (postView: PostView) -> Unit,
onPostClick: (postView: PostView) -> Unit,
onPostLinkClick: (url: String) -> Unit,
onCommunityClick: (community: CommunitySafe) -> Unit,
onPersonClick: (personId: Int) -> Unit,
isModerator: Boolean,
Expand Down Expand Up @@ -1088,20 +1072,25 @@ fun PostListingList(
)
}
}
ThumbnailTile(postView, onPostLinkClick)
ThumbnailTile(postView)
}
}
}

@Composable
private fun ThumbnailTile(
postView: PostView,
onPostLinkClick: (url: String) -> Unit,
) {
postView.post.url?.also { url ->
var showImageDialog by remember { mutableStateOf(false) }

if (showImageDialog) {
ImageViewerDialog(url, onBackRequest = { showImageDialog = false })
}

val postLinkPicMod = Modifier
.size(POST_LINK_PIC_SIZE)
.clickable { onPostLinkClick(url) }
.clickable { showImageDialog = true }

postView.post.thumbnail_url?.also { thumbnail ->
PictrsThumbnailImage(
Expand Down Expand Up @@ -1147,7 +1136,6 @@ fun PostListingListPreview() {
onUpvoteClick = {},
onDownvoteClick = {},
onPostClick = {},
onPostLinkClick = {},
onCommunityClick = {},
onPersonClick = {},
isModerator = false,
Expand All @@ -1174,7 +1162,6 @@ fun PostListingListWithThumbPreview() {
onUpvoteClick = {},
onDownvoteClick = {},
onPostClick = {},
onPostLinkClick = {},
onCommunityClick = {},
onPersonClick = {},
isModerator = false,
Expand All @@ -1192,7 +1179,6 @@ fun PostListingCard(
onDownvoteClick: (postView: PostView) -> Unit,
onReplyClick: (postView: PostView) -> Unit = {},
onPostClick: (postView: PostView) -> Unit,
onPostLinkClick: (url: String) -> Unit,
onSaveClick: (postView: PostView) -> Unit,
onCommunityClick: (community: CommunitySafe) -> Unit,
onEditPostClick: (postView: PostView) -> Unit,
Expand Down Expand Up @@ -1232,7 +1218,6 @@ fun PostListingCard(
// Title + metadata
PostBody(
postView = postView,
onPostLinkClick = onPostLinkClick,
fullBody = fullBody,
expandedImage = expandedImage,
account = account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ fun PostListings(
onUpvoteClick: (postView: PostView) -> Unit,
onDownvoteClick: (postView: PostView) -> Unit,
onPostClick: (postView: PostView) -> Unit,
onPostLinkClick: (url: String) -> Unit,
onSaveClick: (postView: PostView) -> Unit,
onEditPostClick: (postView: PostView) -> Unit,
onDeletePostClick: (postView: PostView) -> Unit,
Expand Down Expand Up @@ -97,7 +96,6 @@ fun PostListings(
onUpvoteClick = onUpvoteClick,
onDownvoteClick = onDownvoteClick,
onPostClick = onPostClick,
onPostLinkClick = onPostLinkClick,
onSaveClick = onSaveClick,
onCommunityClick = onCommunityClick,
onEditPostClick = onEditPostClick,
Expand Down Expand Up @@ -143,7 +141,6 @@ fun PreviewPostListings() {
onUpvoteClick = {},
onDownvoteClick = {},
onPostClick = {},
onPostLinkClick = {},
onSaveClick = {},
onEditPostClick = {},
onDeletePostClick = {},
Expand Down

0 comments on commit 8491511

Please sign in to comment.