Skip to content

Commit

Permalink
Switch blurNSFW and postActionBarMode to use enums. (#1369)
Browse files Browse the repository at this point in the history
- Fixed some naming.
- Also cleaned up imports.
- Fixes #1352
  • Loading branch information
dessalines committed Feb 11, 2024
1 parent 5e0d924 commit 998e30f
Show file tree
Hide file tree
Showing 34 changed files with 268 additions and 192 deletions.
28 changes: 14 additions & 14 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ class MainActivity : AppCompatActivity() {
siteViewModel = siteViewModel,
useCustomTabs = appSettings.useCustomTabs,
usePrivateTabs = appSettings.usePrivateTabs,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
showPostLinkPreviews = appSettings.showPostLinkPreviews,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}
Expand Down Expand Up @@ -277,10 +277,10 @@ class MainActivity : AppCompatActivity() {
siteViewModel = siteViewModel,
useCustomTabs = appSettings.useCustomTabs,
usePrivateTabs = appSettings.usePrivateTabs,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
showPostLinkPreviews = appSettings.showPostLinkPreviews,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}
Expand Down Expand Up @@ -316,12 +316,12 @@ class MainActivity : AppCompatActivity() {
siteViewModel = siteViewModel,
useCustomTabs = appSettings.useCustomTabs,
usePrivateTabs = appSettings.usePrivateTabs,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
showPostLinkPreviews = appSettings.showPostLinkPreviews,
drawerState = drawerState,
onBack = appState::popBackStack,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}
Expand Down Expand Up @@ -355,11 +355,11 @@ class MainActivity : AppCompatActivity() {
siteViewModel = siteViewModel,
useCustomTabs = appSettings.useCustomTabs,
usePrivateTabs = appSettings.usePrivateTabs,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
showPostLinkPreviews = appSettings.showPostLinkPreviews,
drawerState = drawerState,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionbarMode = appSettings.postActionbarMode,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}
Expand All @@ -378,7 +378,7 @@ class MainActivity : AppCompatActivity() {
CommunityListActivity(
appState = appState,
selectMode = args.select,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
drawerState = drawerState,
followList = siteViewModel.getFollowList(),
)
Expand Down Expand Up @@ -433,7 +433,7 @@ class MainActivity : AppCompatActivity() {
appState = appState,
accountViewModel = accountViewModel,
siteViewModel = siteViewModel,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
drawerState = drawerState,
)
}
Expand Down Expand Up @@ -469,9 +469,9 @@ class MainActivity : AppCompatActivity() {
siteViewModel = siteViewModel,
useCustomTabs = appSettings.useCustomTabs,
usePrivateTabs = appSettings.usePrivateTabs,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
showPostLinkPreview = appSettings.showPostLinkPreviews,
postActionbarMode = appSettings.postActionbarMode,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}
Expand Down Expand Up @@ -503,9 +503,9 @@ class MainActivity : AppCompatActivity() {
showParentCommentNavigationButtons = appSettings.showParentCommentNavigationButtons,
navigateParentCommentsWithVolumeButtons = appSettings.navigateParentCommentsWithVolumeButtons,
siteViewModel = siteViewModel,
blurNSFW = appSettings.blurNSFW,
blurNSFW = appSettings.blurNSFW.toEnum(),
showPostLinkPreview = appSettings.showPostLinkPreviews,
postActionbarMode = appSettings.postActionbarMode,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
)
}
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 @@ -39,7 +39,7 @@ val APP_SETTINGS_DEFAULT =
backConfirmationMode = 1,
markAsReadOnScroll = false,
showPostLinkPreviews = true,
postActionbarMode = 0,
postActionBarMode = 0,
autoPlayGifs = false,
swipeToActionPreset = SwipeToActionPreset.DEFAULT.ordinal,
)
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 @@ -114,7 +114,7 @@ data class AppSettings(
name = "post_actionbar_mode",
defaultValue = "0",
)
val postActionbarMode: Int,
val postActionBarMode: Int,
@ColumnInfo(
name = "auto_play_gifs",
defaultValue = "0",
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/jerboa/feat/BlurNSFW.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.jerboa.feat

import androidx.annotation.StringRes
import com.jerboa.R
import it.vercruysse.lemmyapi.v0x19.datatypes.PostView

enum class BlurNSFW(
@StringRes val resId: Int,
) {
Nothing(R.string.app_settings_nothing),
NSFW(R.string.app_settings_blur_nsfw),
NsfwExceptFromNsfwCommunities(R.string.app_settings_blur_nsfw_except_from_nsfw_communities),
}

fun BlurNSFW.changeBlurTypeInsideCommunity() =
if (this == BlurNSFW.NsfwExceptFromNsfwCommunities) {
BlurNSFW.Nothing
} else {
this
}

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

fun BlurNSFW.needBlur(
isCommunityNsfw: Boolean,
isPostNsfw: Boolean = isCommunityNsfw,
): Boolean {
return when (this) {
BlurNSFW.Nothing -> false
BlurNSFW.NSFW, BlurNSFW.NsfwExceptFromNsfwCommunities -> isPostNsfw
}
}
36 changes: 0 additions & 36 deletions app/src/main/java/com/jerboa/feat/BlurTypes.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.jerboa.feat
import androidx.annotation.StringRes
import com.jerboa.R

enum class PostActionbarMode(
enum class PostActionBarMode(
@StringRes val resId: Int,
) {
RightHandShort(R.string.post_actionbar_mode_short_right),
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/jerboa/feat/SwipeToAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.jerboa.feat
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Comment
import androidx.compose.material.icons.outlined.Bookmark
import androidx.compose.material.icons.outlined.Comment
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
Expand Down
22 changes: 16 additions & 6 deletions app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.jerboa.datatypes.sampleReplyCommentView
import com.jerboa.datatypes.sampleSecondReplyCommentView
import com.jerboa.db.entity.Account
import com.jerboa.db.entity.AnonAccount
import com.jerboa.feat.BlurNSFW
import com.jerboa.feat.InstantScores
import com.jerboa.feat.SwipeToActionPreset
import com.jerboa.feat.SwipeToActionType
Expand All @@ -81,7 +82,16 @@ import com.jerboa.ui.theme.SMALL_PADDING
import com.jerboa.ui.theme.XXL_PADDING
import com.jerboa.ui.theme.colorList
import com.jerboa.ui.theme.muted
import it.vercruysse.lemmyapi.v0x19.datatypes.*
import it.vercruysse.lemmyapi.v0x19.datatypes.Comment
import it.vercruysse.lemmyapi.v0x19.datatypes.CommentId
import it.vercruysse.lemmyapi.v0x19.datatypes.CommentView
import it.vercruysse.lemmyapi.v0x19.datatypes.Community
import it.vercruysse.lemmyapi.v0x19.datatypes.CommunityModeratorView
import it.vercruysse.lemmyapi.v0x19.datatypes.Person
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonId
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonView
import it.vercruysse.lemmyapi.v0x19.datatypes.Post
import it.vercruysse.lemmyapi.v0x19.datatypes.PostId

@Composable
fun CommentNodeHeader(
Expand Down Expand Up @@ -217,7 +227,7 @@ fun LazyListScope.commentNodeItem(
showActionBar: (commentId: CommentId) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Int,
blurNSFW: BlurNSFW,
showScores: Boolean,
swipeToActionPreset: SwipeToActionPreset,
) {
Expand Down Expand Up @@ -524,7 +534,7 @@ fun LazyListScope.missingCommentNodeItem(
showActionBar: (commentId: CommentId) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Int,
blurNSFW: BlurNSFW,
showScores: Boolean,
swipeToActionPreset: SwipeToActionPreset,
) {
Expand Down Expand Up @@ -692,7 +702,7 @@ fun PostAndCommunityContextHeader(
community: Community,
onCommunityClick: (community: Community) -> Unit,
onPostClick: (postId: PostId) -> Unit,
blurNSFW: Int,
blurNSFW: BlurNSFW,
) {
Column(
modifier = Modifier.padding(top = LARGE_PADDING),
Expand Down Expand Up @@ -724,7 +734,7 @@ fun PostAndCommunityContextHeaderPreview() {
community = sampleCommunity,
onCommunityClick = {},
onPostClick = {},
blurNSFW = 1,
blurNSFW = BlurNSFW.NSFW,
)
}

Expand Down Expand Up @@ -929,7 +939,7 @@ fun CommentNodesPreview() {
showActionBar = { _ -> true },
enableDownVotes = true,
showAvatar = true,
blurNSFW = 1,
blurNSFW = BlurNSFW.NSFW,
account = AnonAccount,
showScores = true,
swipeToActionPreset = SwipeToActionPreset.DEFAULT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.jerboa.CommentNodeData
import com.jerboa.MissingCommentNode
import com.jerboa.datatypes.BanFromCommunityData
import com.jerboa.db.entity.Account
import com.jerboa.feat.BlurNSFW
import com.jerboa.feat.SwipeToActionPreset
import it.vercruysse.lemmyapi.v0x19.datatypes.CommentId
import it.vercruysse.lemmyapi.v0x19.datatypes.CommentView
Expand Down Expand Up @@ -63,7 +64,7 @@ fun CommentNodes(
showActionBar: (commentId: CommentId) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Int,
blurNSFW: BlurNSFW,
showScores: Boolean,
swipeToActionPreset: SwipeToActionPreset,
) {
Expand Down Expand Up @@ -154,7 +155,7 @@ fun LazyListScope.commentNodeItems(
showActionBar: (commentId: CommentId) -> Boolean,
enableDownVotes: Boolean,
showAvatar: Boolean,
blurNSFW: Int,
blurNSFW: BlurNSFW,
showScores: Boolean,
swipeToActionPreset: SwipeToActionPreset,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.ui.tooling.preview.Preview
import com.jerboa.R
import com.jerboa.datatypes.samplePersonMentionView
import com.jerboa.db.entity.Account
import com.jerboa.feat.BlurNSFW
import com.jerboa.feat.VoteType
import com.jerboa.feat.canMod
import com.jerboa.ui.components.comment.CommentBody
Expand Down Expand Up @@ -262,7 +263,7 @@ fun CommentMentionNode(
onBlockCreatorClick: (creator: Person) -> Unit,
account: Account,
showAvatar: Boolean,
blurNSFW: Int,
blurNSFW: BlurNSFW,
enableDownvotes: Boolean,
showScores: Boolean,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.ui.tooling.preview.Preview
import com.jerboa.R
import com.jerboa.datatypes.sampleCommentReplyView
import com.jerboa.db.entity.Account
import com.jerboa.feat.BlurNSFW
import com.jerboa.feat.VoteType
import com.jerboa.ui.components.comment.CommentBody
import com.jerboa.ui.components.comment.PostAndCommunityContextHeader
Expand Down Expand Up @@ -242,7 +243,7 @@ fun CommentReplyNodeInbox(
onBlockCreatorClick: (creator: Person) -> Unit,
account: Account,
showAvatar: Boolean,
blurNSFW: Int,
blurNSFW: BlurNSFW,
enableDownvotes: Boolean,
showScores: Boolean,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
Expand Down
Loading

0 comments on commit 998e30f

Please sign in to comment.