Skip to content

Commit

Permalink
Add switch to mark new posts as NSFW / toggle tag on existing posts (#…
Browse files Browse the repository at this point in the history
…833)

* Added a switch do CreatePost.kt and PostEdit.kt to mark a new post as NSFW and change the tag of an existing post. Added logic in the corresponding Activities.
Closes #679

* Changed switch to checkbox, changed arrangement to "SpaceBetween", moved composable out of CreatePost.kt and PostEdit.kt to reduce unnecessary redundancy.
  • Loading branch information
sockenklaus authored Jun 23, 2023
1 parent e66e1c1 commit 5eae33d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.jerboa.ui.components.post.composables

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.jerboa.R

@Composable
fun CheckboxIsNsfw(
checked: Boolean,
onCheckedChange: (checked: Boolean) -> Unit,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth(),
) {
Text(
text = stringResource(R.string.create_post_tag_nsfw),
)
Checkbox(
checked = checked,
onCheckedChange = onCheckedChange,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.jerboa.db.Account
import com.jerboa.ui.components.common.CircularIcon
import com.jerboa.ui.components.common.MarkdownTextField
import com.jerboa.ui.components.common.PickImage
import com.jerboa.ui.components.post.composables.CheckboxIsNsfw
import com.jerboa.ui.theme.ICON_SIZE
import com.jerboa.ui.theme.MEDIUM_PADDING
import com.jerboa.ui.theme.THUMBNAIL_SIZE
Expand Down Expand Up @@ -120,6 +121,8 @@ fun CreatePostBody(
padding: PaddingValues,
suggestedTitle: String?,
suggestedTitleLoading: Boolean,
isNsfw: Boolean,
onIsNsfwChange: (isNsfw: Boolean) -> Unit,
) {
val nameField = validatePostName(name)
val urlField = validateUrl(url)
Expand Down Expand Up @@ -237,6 +240,10 @@ fun CreatePostBody(
},
)
}
CheckboxIsNsfw(
checked = isNsfw,
onCheckedChange = onIsNsfwChange,
)
}
}

Expand Down Expand Up @@ -267,6 +274,8 @@ fun CreatePostBodyPreview() {
padding = PaddingValues(),
suggestedTitle = null,
suggestedTitleLoading = false,
isNsfw = false,
onIsNsfwChange = {},
)
}

Expand All @@ -286,5 +295,7 @@ fun CreatePostBodyPreviewNoCommunity() {
suggestedTitleLoading = false,
account = null,
padding = PaddingValues(),
isNsfw = false,
onIsNsfwChange = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fun CreatePostActivity(
),
)
}
var isNsfw by rememberSaveable { mutableStateOf(false) }
var formValid by rememberSaveable { mutableStateOf(false) }

LaunchedEffect(initialUrl) {
Expand Down Expand Up @@ -107,6 +108,7 @@ fun CreatePostActivity(
url = urlOut,
body = bodyOut,
auth = acct.jwt,
nsfw = isNsfw,
),
navController,
)
Expand Down Expand Up @@ -154,6 +156,8 @@ fun CreatePostActivity(
},
account = account,
padding = padding,
isNsfw = isNsfw,
onIsNsfwChange = { isNsfw = it },
)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.jerboa.R
import com.jerboa.db.Account
import com.jerboa.ui.components.common.MarkdownTextField
import com.jerboa.ui.components.common.PickImage
import com.jerboa.ui.components.post.composables.CheckboxIsNsfw
import com.jerboa.ui.theme.MEDIUM_PADDING
import com.jerboa.validatePostName
import com.jerboa.validateUrl
Expand Down Expand Up @@ -91,6 +92,8 @@ fun EditPostBody(
formValid: (valid: Boolean) -> Unit,
account: Account?,
modifier: Modifier = Modifier,
isNsfw: Boolean,
onIsNsfwChange: (isNsfw: Boolean) -> Unit,
) {
val nameField = validatePostName(name)
val urlField = validateUrl(url)
Expand Down Expand Up @@ -144,6 +147,10 @@ fun EditPostBody(
focusImmediate = false,
placeholder = stringResource(R.string.post_edit_body_placeholder),
)
CheckboxIsNsfw(
checked = isNsfw,
onCheckedChange = onIsNsfwChange,
)
}
}

Expand All @@ -160,5 +167,7 @@ fun EditPostBodyPreview() {
onPickedImage = {},
onUrlChange = {},
account = null,
isNsfw = false,
onIsNsfwChange = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fun PostEditActivity(
val pv = postEditViewModel.postView
var name by rememberSaveable { mutableStateOf(pv?.post?.name.orEmpty()) }
var url by rememberSaveable { mutableStateOf(pv?.post?.url.orEmpty()) }
var isNsfw by rememberSaveable { mutableStateOf(pv?.post?.nsfw ?: false) }
var body by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(
TextFieldValue(
Expand Down Expand Up @@ -84,6 +85,7 @@ fun PostEditActivity(
url = urlOut,
body = bodyOut,
auth = acct.jwt,
nsfw = isNsfw,
),
navController = navController,
postViewModel = postViewModel,
Expand Down Expand Up @@ -120,6 +122,8 @@ fun PostEditActivity(
modifier = Modifier
.padding(padding)
.imePadding(),
isNsfw = isNsfw,
onIsNsfwChange = { isNsfw = it },
)
},
)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,5 @@
<string name="inbox_activity_mentions">Erwähnungen</string>
<string name="inbox_activity_messages">Nachrichten</string>
<string name="bookmarks_activity_saved">Gespeichert</string>
<string name="create_post_tag_nsfw">Markiere Post als NSFW</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<string name="create_post_community">Community</string>
<string name="create_post_copy_suggested_title">copy suggested title: %1$s</string>
<string name="create_post_create_post">Create post</string>
<string name="create_post_tag_nsfw">Mark post as NSFW</string>
<string name="create_report_back">Back</string>
<string name="create_report_report">Report</string>
<string name="create_report_type_your_reason">Type your reason</string>
Expand Down

0 comments on commit 5eae33d

Please sign in to comment.