diff --git a/app/src/main/java/com/jerboa/ui/components/post/composables/PostComposables.kt b/app/src/main/java/com/jerboa/ui/components/post/composables/PostComposables.kt
new file mode 100644
index 000000000..aba6fe853
--- /dev/null
+++ b/app/src/main/java/com/jerboa/ui/components/post/composables/PostComposables.kt
@@ -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,
+ )
+ }
+}
diff --git a/app/src/main/java/com/jerboa/ui/components/post/create/CreatePost.kt b/app/src/main/java/com/jerboa/ui/components/post/create/CreatePost.kt
index a987bd0a3..278216177 100644
--- a/app/src/main/java/com/jerboa/ui/components/post/create/CreatePost.kt
+++ b/app/src/main/java/com/jerboa/ui/components/post/create/CreatePost.kt
@@ -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
@@ -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)
@@ -237,6 +240,10 @@ fun CreatePostBody(
},
)
}
+ CheckboxIsNsfw(
+ checked = isNsfw,
+ onCheckedChange = onIsNsfwChange,
+ )
}
}
@@ -267,6 +274,8 @@ fun CreatePostBodyPreview() {
padding = PaddingValues(),
suggestedTitle = null,
suggestedTitleLoading = false,
+ isNsfw = false,
+ onIsNsfwChange = {},
)
}
@@ -286,5 +295,7 @@ fun CreatePostBodyPreviewNoCommunity() {
suggestedTitleLoading = false,
account = null,
padding = PaddingValues(),
+ isNsfw = false,
+ onIsNsfwChange = {},
)
}
diff --git a/app/src/main/java/com/jerboa/ui/components/post/create/CreatePostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/create/CreatePostActivity.kt
index 7d4f62ec1..92acee8c1 100644
--- a/app/src/main/java/com/jerboa/ui/components/post/create/CreatePostActivity.kt
+++ b/app/src/main/java/com/jerboa/ui/components/post/create/CreatePostActivity.kt
@@ -60,6 +60,7 @@ fun CreatePostActivity(
),
)
}
+ var isNsfw by rememberSaveable { mutableStateOf(false) }
var formValid by rememberSaveable { mutableStateOf(false) }
LaunchedEffect(initialUrl) {
@@ -107,6 +108,7 @@ fun CreatePostActivity(
url = urlOut,
body = bodyOut,
auth = acct.jwt,
+ nsfw = isNsfw,
),
navController,
)
@@ -154,6 +156,8 @@ fun CreatePostActivity(
},
account = account,
padding = padding,
+ isNsfw = isNsfw,
+ onIsNsfwChange = { isNsfw = it },
)
},
)
diff --git a/app/src/main/java/com/jerboa/ui/components/post/edit/PostEdit.kt b/app/src/main/java/com/jerboa/ui/components/post/edit/PostEdit.kt
index bbb5aeadd..db0c6fa84 100644
--- a/app/src/main/java/com/jerboa/ui/components/post/edit/PostEdit.kt
+++ b/app/src/main/java/com/jerboa/ui/components/post/edit/PostEdit.kt
@@ -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
@@ -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)
@@ -144,6 +147,10 @@ fun EditPostBody(
focusImmediate = false,
placeholder = stringResource(R.string.post_edit_body_placeholder),
)
+ CheckboxIsNsfw(
+ checked = isNsfw,
+ onCheckedChange = onIsNsfwChange,
+ )
}
}
@@ -160,5 +167,7 @@ fun EditPostBodyPreview() {
onPickedImage = {},
onUrlChange = {},
account = null,
+ isNsfw = false,
+ onIsNsfwChange = {},
)
}
diff --git a/app/src/main/java/com/jerboa/ui/components/post/edit/PostEditActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/edit/PostEditActivity.kt
index afd29e216..953fcff6e 100644
--- a/app/src/main/java/com/jerboa/ui/components/post/edit/PostEditActivity.kt
+++ b/app/src/main/java/com/jerboa/ui/components/post/edit/PostEditActivity.kt
@@ -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(
@@ -84,6 +85,7 @@ fun PostEditActivity(
url = urlOut,
body = bodyOut,
auth = acct.jwt,
+ nsfw = isNsfw,
),
navController = navController,
postViewModel = postViewModel,
@@ -120,6 +122,8 @@ fun PostEditActivity(
modifier = Modifier
.padding(padding)
.imePadding(),
+ isNsfw = isNsfw,
+ onIsNsfwChange = { isNsfw = it },
)
},
)
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 966cedf60..14a0604e8 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -312,4 +312,5 @@
Erwähnungen
Nachrichten
Gespeichert
+ Markiere Post als NSFW
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ce5c1e5d2..de7e04f19 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -117,6 +117,7 @@
Community
copy suggested title: %1$s
Create post
+ Mark post as NSFW
Back
Report
Type your reason