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 BlurNsfwExceptFromNsfwCommunities to blur types #1229

Merged
merged 18 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import com.jerboa.api.ApiState
import com.jerboa.datatypes.types.*
import com.jerboa.db.APP_SETTINGS_DEFAULT
import com.jerboa.db.entity.AppSettings
import com.jerboa.feat.BlurNsfwTypes
import com.jerboa.ui.components.common.Route
import com.jerboa.ui.components.inbox.InboxTab
import com.jerboa.ui.components.person.UserTab
Expand Down Expand Up @@ -939,6 +940,15 @@ fun nsfwCheck(postView: PostView): Boolean {
return postView.post.nsfw || postView.community.nsfw
}

fun needNsfwBlur(settings: BlurNsfwTypes, isCommunityNsfw: Boolean, isPostNsfw: Boolean = isCommunityNsfw): Boolean {
MV-GH marked this conversation as resolved.
Show resolved Hide resolved
return isPostNsfw && when(settings){
BlurNsfwTypes.DoNotBlur -> false
BlurNsfwTypes.BlurEverywhere -> true
BlurNsfwTypes.BlurEverywhereExceptNsfw -> !isCommunityNsfw
BlurNsfwTypes.BlurOnlyNsfwCommunity -> isCommunityNsfw
}
}

@RequiresApi(Build.VERSION_CODES.Q)
@Throws(IOException::class)
fun saveMediaQ(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/db/AppDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ val APP_SETTINGS_DEFAULT = AppSettings(
useCustomTabs = true,
usePrivateTabs = false,
secureWindow = false,
blurNSFW = true,
blurNSFW = 1,
dessalines marked this conversation as resolved.
Show resolved Hide resolved
showTextDescriptionsInNavbar = true,
backConfirmationMode = 1,
markAsReadOnScroll = false,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/db/entity/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ data class AppSettings(
name = "blur_nsfw",
defaultValue = "1",
)
val blurNSFW: Boolean,
val blurNSFW: Int,
@ColumnInfo(
name = "show_text_descriptions_in_navbar",
defaultValue = "1",
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/jerboa/feat/BlurNsfwTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jerboa.feat

import android.os.Parcelable
import androidx.annotation.StringRes
import com.jerboa.R
import kotlinx.parcelize.Parcelize

@Parcelize
enum class BlurNsfwTypes(@StringRes val resId: Int) : Parcelable {
MV-GH marked this conversation as resolved.
Show resolved Hide resolved
DoNotBlur(R.string.app_settings_do_not_blur),
BlurEverywhere(R.string.app_settings_blur_everywhere),
BlurEverywhereExceptNsfw(R.string.app_settings_blur_everywhere_except_nsfw),
BlurOnlyNsfwCommunity(R.string.app_settings_blur_only_nsfw_community),
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fun LazyListScope.commentNodeItem(
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showScores: Boolean,
) {
val commentView = node.commentView
Expand Down Expand Up @@ -483,7 +483,7 @@ fun PostAndCommunityContextHeader(
community: Community,
onCommunityClick: (community: Community) -> Unit,
onPostClick: (postId: Int) -> Unit,
blurNSFW: Boolean,
blurNSFW: Int,
) {
Column(
modifier = Modifier.padding(top = LARGE_PADDING),
Expand Down Expand Up @@ -515,7 +515,7 @@ fun PostAndCommunityContextHeaderPreview() {
community = sampleCommunity,
onCommunityClick = {},
onPostClick = {},
blurNSFW = true,
blurNSFW = 1,
)
}

Expand Down Expand Up @@ -690,7 +690,7 @@ fun CommentNodesPreview() {
showActionBar = { _ -> true },
enableDownVotes = true,
showAvatar = true,
blurNSFW = true,
blurNSFW = 1,
account = AnonAccount,
showScores = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun CommentNodes(
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showScores: Boolean,
) {
LazyColumn(state = listState) {
Expand Down Expand Up @@ -129,7 +129,7 @@ fun LazyListScope.commentNodeItems(
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showScores: Boolean,
) {
nodes.forEach { node ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ fun CommentMentionNode(
onBlockCreatorClick: (creator: Person) -> Unit,
account: Account,
showAvatar: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
enableDownvotes: Boolean,
showScores: Boolean,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fun CommentReplyNodeInbox(
onBlockCreatorClick: (creator: Person) -> Unit,
account: Account,
showAvatar: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
enableDownvotes: Boolean,
showScores: Boolean,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import com.jerboa.datatypes.sampleCommunityView
import com.jerboa.datatypes.types.CommunityView
import com.jerboa.datatypes.types.SortType
import com.jerboa.datatypes.types.SubscribedType
import com.jerboa.feat.BlurNsfwTypes
import com.jerboa.feat.PostActionbarMode
import com.jerboa.needNsfwBlur
import com.jerboa.toEnum
import com.jerboa.ui.components.common.LargerCircularIcon
import com.jerboa.ui.components.common.MenuItem
import com.jerboa.ui.components.common.PictrsBannerImage
Expand All @@ -31,7 +35,7 @@ fun CommunityTopSection(
communityView: CommunityView,
modifier: Modifier = Modifier,
onClickFollowCommunity: (communityView: CommunityView) -> Unit,
blurNSFW: Boolean,
blurNSFW: Int,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
Expand All @@ -45,11 +49,11 @@ fun CommunityTopSection(
PictrsBannerImage(
url = it,
modifier = Modifier.height(DRAWER_BANNER_SIZE),
blur = blurNSFW && communityView.community.nsfw,
blur = needNsfwBlur(blurNSFW.toEnum(), communityView.community.nsfw),
)
}
communityView.community.icon?.also {
LargerCircularIcon(icon = it, blur = blurNSFW && communityView.community.nsfw)
LargerCircularIcon(icon = it, blur = needNsfwBlur(blurNSFW.toEnum(), communityView.community.nsfw))
}
}
Column(
Expand Down Expand Up @@ -119,7 +123,7 @@ fun CommunityTopSectionPreview() {
CommunityTopSection(
communityView = sampleCommunityView,
onClickFollowCommunity = {},
blurNSFW = true,
blurNSFW = 1,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun CommunityActivity(
showVotingArrowsInListView: Boolean,
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
Copy link
Member

Choose a reason for hiding this comment

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

Why can't these use the BlurType enum?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't do it either for other enums, see postActionMode below it

Copy link
Member

Choose a reason for hiding this comment

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

mmk, I'll test this shortly.

showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
postActionbarMode: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import com.jerboa.datatypes.sampleCommunity
import com.jerboa.datatypes.sampleCommunityView
import com.jerboa.datatypes.types.Community
import com.jerboa.datatypes.types.CommunityView
import com.jerboa.needNsfwBlur
import com.jerboa.toEnum
import com.jerboa.ui.components.common.CircularIcon
import com.jerboa.ui.theme.DRAWER_ITEM_SPACING
import com.jerboa.ui.theme.ICON_SIZE
Expand Down Expand Up @@ -73,7 +75,7 @@ fun CommunityLink(
onClick: (community: Community) -> Unit,
clickable: Boolean = true,
showDefaultIcon: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand All @@ -90,7 +92,7 @@ fun CommunityLink(
contentDescription = null,
size = size,
thumbnailSize = thumbnailSize,
blur = blurNSFW && community.nsfw,
blur = needNsfwBlur(blurNSFW.toEnum(), community.nsfw),
)
} ?: run {
if (showDefaultIcon) {
Expand Down Expand Up @@ -118,7 +120,7 @@ fun CommunityLinkLarger(
community: Community,
onClick: (community: Community) -> Unit,
showDefaultIcon: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
) {
CommunityLink(
community = community,
Expand All @@ -141,7 +143,7 @@ fun CommunityLinkLargerWithUserCount(
communityView: CommunityView,
onClick: (community: Community) -> Unit,
showDefaultIcon: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
) {
CommunityLink(
community = communityView.community,
Expand All @@ -167,7 +169,7 @@ fun CommunityLinkPreview() {
community = sampleCommunity,
onClick = {},
showDefaultIcon = true,
blurNSFW = true,
blurNSFW = 1,
)
}

Expand All @@ -178,6 +180,6 @@ fun CommunityLinkWithUsersPreview() {
communityView = sampleCommunityView,
onClick = {},
showDefaultIcon = true,
blurNSFW = true,
blurNSFW = 1,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun CommunityListings(
communities: List<CommunityView>,
onClickCommunity: (community: Community) -> Unit,
modifier: Modifier = Modifier,
blurNSFW: Boolean,
blurNSFW: Int,
) {
val listState = rememberLazyListState()

Expand Down Expand Up @@ -111,7 +111,7 @@ fun CommunityListingsPreview() {
CommunityListings(
communities = communities,
onClickCommunity = {},
blurNSFW = true,
blurNSFW = 1,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun CommunityListActivity(
accountViewModel: AccountViewModel,
selectMode: Boolean = false,
siteViewModel: SiteViewModel,
blurNSFW: Boolean,
blurNSFW: Int,
drawerState: DrawerState,
) {
Log.d("jerboa", "got to community list activity")
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/jerboa/ui/components/drawer/Drawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fun Drawer(
onCommunityClick: (community: Community) -> Unit,
onClickSettings: () -> Unit,
isOpen: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showBottomNav: Boolean,
closeDrawer: () -> Unit,
onSelectTab: (NavTab) -> Unit,
Expand Down Expand Up @@ -136,7 +136,7 @@ fun DrawerContent(
onClickSettings: () -> Unit,
myUserInfo: MyUserInfo?,
unreadCount: Int,
blurNSFW: Boolean,
blurNSFW: Int,
showBottomNav: Boolean,
closeDrawer: () -> Unit,
onSelectTab: (NavTab) -> Unit,
Expand Down Expand Up @@ -180,7 +180,7 @@ fun DrawerItemsMain(
onClickListingType: (ListingType) -> Unit,
onCommunityClick: (community: Community) -> Unit,
unreadCount: Int,
blurNSFW: Boolean,
blurNSFW: Int,
showBottomNav: Boolean,
closeDrawer: () -> Unit,
onSelectTab: (NavTab) -> Unit,
Expand Down Expand Up @@ -292,7 +292,7 @@ fun DrawerItemsMainPreview() {
onCommunityClick = {},
onClickSettings = {},
unreadCount = 2,
blurNSFW = true,
blurNSFW = 1,
showBottomNav = false,
closeDrawer = {},
onSelectTab = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun MainDrawer(
onCommunityClick: (Int) -> Unit,
onClickLogin: () -> Unit,
onSelectTab: (NavTab) -> Unit,
blurNSFW: Boolean,
blurNSFW: Int,
showBottomNav: Boolean,
) {
val account = getCurrentAccount(accountViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fun HomeActivity(
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
drawerState: DrawerState,
blurNSFW: Boolean,
blurNSFW: Int,
showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
postActionbarMode: Int,
Expand Down Expand Up @@ -205,7 +205,7 @@ fun MainPostListingsContent(
showVotingArrowsInListView: Boolean,
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showPostLinkPreviews: Boolean,
snackbarHostState: SnackbarHostState,
markAsReadOnScroll: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun InboxActivity(
drawerState: DrawerState,
siteViewModel: SiteViewModel,
accountViewModel: AccountViewModel,
blurNSFW: Boolean,
blurNSFW: Int,
) {
Log.d("jerboa", "got to inbox activity")

Expand Down Expand Up @@ -222,7 +222,7 @@ fun InboxTabs(
scope: CoroutineScope,
snackbarHostState: SnackbarHostState,
padding: PaddingValues,
blurNSFW: Boolean,
blurNSFW: Int,
) {
val transferPrivateMessageDepsViaRoot = appState.rootChannel<PrivateMessageDeps>()
val transferCommentReplyDepsViaRoot = appState.rootChannel<CommentReplyDeps>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fun PersonProfileActivity(
showVotingArrowsInListView: Boolean,
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showPostLinkPreviews: Boolean,
drawerState: DrawerState,
markAsReadOnScroll: Boolean,
Expand Down Expand Up @@ -322,7 +322,7 @@ fun UserTabs(
showAvatar: Boolean,
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
snackbarHostState: SnackbarHostState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fun PostActivity(
showVotingArrowsInListView: Boolean,
showParentCommentNavigationButtons: Boolean,
navigateParentCommentsWithVolumeButtons: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showPostLinkPreview: Boolean,
postActionbarMode: Int,
) {
Expand Down
Loading