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 all 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
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
35 changes: 35 additions & 0 deletions app/src/main/java/com/jerboa/feat/BlurTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.jerboa.feat

import android.os.Parcelable
import androidx.annotation.StringRes
import com.jerboa.R
import com.jerboa.datatypes.types.PostView
import com.jerboa.toEnum
import kotlinx.parcelize.Parcelize

@Parcelize
enum class BlurTypes(@StringRes val resId: Int) : Parcelable {
Nothing(R.string.app_settings_nothing),
NSFW(R.string.app_settings_blur_nsfw),
NsfwExceptFromNsfwCommunities(R.string.app_settings_blur_nsfw_except_from_nsfw_communities),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this type, as discussed we keep only, blur nothing, blur nsfw and blur nsfw but not in community view

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MV-GH I didn't understand you, only these 3 options remain. 4 option (ExceptFromNsfwInsideCommunity) it technical option. In community activity I swap NsfwExceptFromNsfwCommunities option for it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not how I meant that second approach. The second approach was, turn NSFWExceptInsideCommunity into Nothing if passed to communityActiviity else convert it to NSFW and then you only have to handle those two cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

else convert it to NSFW and then you only have to handle those two cases

I can't figure out how and where to do this. In Main Activity for every Activity?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes but you can do it once under appsetting and pass that. except for community activity where you then pass the other option. But first I have to know if Dessalines would accept such approach.

@dessalines Would you be against the above approach or do you rather that we have a extra param indicating that this is community view. Or do you have a better approach in mind?

Copy link
Member

Choose a reason for hiding this comment

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

NSFWExceptInsideCommunity into Nothing if passed to communityActiviity

Yes that seems fine. No point in adding an extra enum when it can figure that out by context, in the CommunityActivity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MV-GH Am I understanding correctly that "NsfwExceptFromNsfwCommunities" works as "Nothing" only for nsfw communities, otherwise it works as "NSFW"? If this is true then I can't change it in MainActivity because I need the community type.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For what do you need the communityType? You map it there either to Nothing or NSFW ordinals depending if its for CommunityView

Copy link
Contributor Author

@MakcNmyc MakcNmyc Oct 9, 2023

Choose a reason for hiding this comment

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

@MV-GH what behavior should there be with the nsfw posts if Community.nsfw = false and blur option = "NsfwExceptFromNsfwCommunities"? Doesn't it then transform into, a "NSFW" not in "Nothing"?
I mean not communityType but Community.nsfw parameter

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the community nsfw option, we don't care anymore if the post comes from a nsfw community or not. And if the function receives NsfwExceptFromNsfwCommunity then throw with message likr this type should ve already been transformed into another

;

companion object {
fun changeBlurTypeInsideCommunity(blurTypes: Int): Int =
if (blurTypes.toEnum<BlurTypes>() == NsfwExceptFromNsfwCommunities) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

compare on ordinal

Copy link
Collaborator

Choose a reason for hiding this comment

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

and blurType

Nothing.ordinal
} else {
blurTypes
}
}
}

fun BlurTypes.needBlur(postView: PostView) =
this.needBlur(postView.community.nsfw, postView.post.nsfw)

fun BlurTypes.needBlur(isCommunityNsfw: Boolean, isPostNsfw: Boolean = isCommunityNsfw): Boolean {
return when (this) {
BlurTypes.Nothing -> false
BlurTypes.NSFW, BlurTypes.NsfwExceptFromNsfwCommunities -> isPostNsfw
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,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 @@ -446,7 +446,7 @@ fun LazyListScope.missingCommentNodeItem(
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showScores: Boolean,
) {
val commentId = node.missingCommentView.commentId
Expand Down Expand Up @@ -602,7 +602,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 @@ -634,7 +634,7 @@ fun PostAndCommunityContextHeaderPreview() {
community = sampleCommunity,
onCommunityClick = {},
onPostClick = {},
blurNSFW = true,
blurNSFW = 1,
)
}

Expand Down Expand Up @@ -788,7 +788,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 @@ -52,7 +52,7 @@ fun CommentNodes(
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
showScores: Boolean,
) {
LazyColumn(state = listState) {
Expand Down Expand Up @@ -131,7 +131,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 @@ -232,7 +232,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 @@ -231,7 +231,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 @@ -20,6 +20,9 @@ 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.BlurTypes
import com.jerboa.feat.needBlur
import com.jerboa.toEnum
import com.jerboa.ui.components.common.LargerCircularIcon
import com.jerboa.ui.components.common.PictrsBannerImage
import com.jerboa.ui.components.common.SortOptionsDropdown
Expand All @@ -31,7 +34,7 @@ fun CommunityTopSection(
communityView: CommunityView,
modifier: Modifier = Modifier,
onClickFollowCommunity: (communityView: CommunityView) -> Unit,
blurNSFW: Boolean,
blurNSFW: Int,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
Expand All @@ -45,11 +48,11 @@ fun CommunityTopSection(
PictrsBannerImage(
url = it,
modifier = Modifier.height(DRAWER_BANNER_SIZE),
blur = blurNSFW && communityView.community.nsfw,
blur = blurNSFW.toEnum<BlurTypes>().needBlur(communityView.community.nsfw),
)
}
communityView.community.icon?.also {
LargerCircularIcon(icon = it, blur = blurNSFW && communityView.community.nsfw)
LargerCircularIcon(icon = it, blur = blurNSFW.toEnum<BlurTypes>().needBlur(communityView.community.nsfw))
}
}
Column(
Expand Down Expand Up @@ -119,7 +122,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 @@ -48,6 +48,7 @@ import com.jerboa.datatypes.types.SavePost
import com.jerboa.datatypes.types.SubscribedType
import com.jerboa.db.entity.getJWT
import com.jerboa.db.entity.isAnon
import com.jerboa.feat.BlurTypes
import com.jerboa.feat.doIfReadyElseDisplayInfo
import com.jerboa.feat.shareLink
import com.jerboa.hostName
Expand Down Expand Up @@ -83,7 +84,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 Expand Up @@ -264,7 +265,7 @@ fun CommunityActivity(
)
}
},
blurNSFW = blurNSFW,
blurNSFW = BlurTypes.changeBlurTypeInsideCommunity(blurNSFW),
)
}

Expand Down Expand Up @@ -432,7 +433,7 @@ fun CommunityActivity(
showAvatar = siteViewModel.showAvatar(),
useCustomTabs = useCustomTabs,
usePrivateTabs = usePrivateTabs,
blurNSFW = blurNSFW,
blurNSFW = BlurTypes.changeBlurTypeInsideCommunity(blurNSFW),
showPostLinkPreviews = showPostLinkPreviews,
appState = appState,
markAsReadOnScroll = markAsReadOnScroll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ 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.feat.BlurTypes
import com.jerboa.feat.needBlur
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 +76,7 @@ fun CommunityLink(
onClick: (community: Community) -> Unit,
clickable: Boolean = true,
showDefaultIcon: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand All @@ -90,7 +93,7 @@ fun CommunityLink(
contentDescription = null,
size = size,
thumbnailSize = thumbnailSize,
blur = blurNSFW && community.nsfw,
blur = blurNSFW.toEnum<BlurTypes>().needBlur(community.nsfw),
)
} ?: run {
if (showDefaultIcon) {
Expand Down Expand Up @@ -118,7 +121,7 @@ fun CommunityLinkLarger(
community: Community,
onClick: (community: Community) -> Unit,
showDefaultIcon: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
) {
CommunityLink(
community = community,
Expand All @@ -141,7 +144,7 @@ fun CommunityLinkLargerWithUserCount(
communityView: CommunityView,
onClick: (community: Community) -> Unit,
showDefaultIcon: Boolean,
blurNSFW: Boolean,
blurNSFW: Int,
) {
CommunityLink(
community = communityView.community,
Expand All @@ -167,7 +170,7 @@ fun CommunityLinkPreview() {
community = sampleCommunity,
onClick = {},
showDefaultIcon = true,
blurNSFW = true,
blurNSFW = 1,
)
}

Expand All @@ -178,6 +181,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,
followList: ImmutableList<CommunityFollowerView>,
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 @@ -86,7 +86,7 @@ fun HomeActivity(
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
drawerState: DrawerState,
blurNSFW: Boolean,
blurNSFW: Int,
showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
postActionbarMode: Int,
Expand Down Expand Up @@ -197,7 +197,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 @@ -85,7 +85,7 @@ fun InboxActivity(
drawerState: DrawerState,
siteViewModel: SiteViewModel,
accountViewModel: AccountViewModel,
blurNSFW: Boolean,
blurNSFW: Int,
) {
Log.d("jerboa", "got to inbox activity")

Expand Down Expand Up @@ -202,7 +202,7 @@ fun InboxTabs(
scope: CoroutineScope,
snackbarHostState: SnackbarHostState,
padding: PaddingValues,
blurNSFW: Boolean,
blurNSFW: Int,
) {
val tabTitles = InboxTab.entries.map { getLocalizedStringForInboxTab(ctx, it) }
val pagerState = rememberPagerState { tabTitles.size }
Expand Down
Loading