Add ability to always show sensitive content

This commit is contained in:
Adam Williams 2023-06-11 00:21:50 +01:00
parent b9df1e1a89
commit 43c4520316
4 changed files with 29 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import androidx.viewbinding.ViewBinding
@ -164,6 +165,9 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
binding: PostFragmentBinding,
request: RequestBuilder<Drawable>,
) {
val alwaysShowNsfw =
PreferenceManager.getDefaultSharedPreferences(binding.root.context.applicationContext)
.getBoolean("always_show_nsfw", false)
// Standard layout
binding.postPager.visibility = View.VISIBLE
@ -178,7 +182,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
binding.postIndicator.visibility = View.GONE
}
if (status?.sensitive == true) {
if (status?.sensitive == true && !alwaysShowNsfw) {
setupSensitiveLayout()
} else {
// GONE is the default, but have to set it again because of how RecyclerViews work
@ -843,6 +847,10 @@ class AlbumViewPagerAdapter(
override fun getItemCount() = media_attachments.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val alwaysShowNsfw =
PreferenceManager.getDefaultSharedPreferences(holder.binding.root.context)
.getBoolean("always_show_nsfw", false)
media_attachments[position].apply {
val video = type == Attachment.AttachmentType.video
val blurhashBitMap = blurhash?.let {
@ -853,7 +861,7 @@ class AlbumViewPagerAdapter(
meta?.original?.height
)
}
if (sensitive == false) {
if (sensitive == false || alwaysShowNsfw) {
val imageUrl = if(video) preview_url else url
if(opened){
Glide.with(holder.binding.root)

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"
android:fillColor="?attr/colorOnBackground"
/>
</vector>

View File

@ -35,6 +35,8 @@
<!-- Theme Preferences: dark theme option -->
<string name="dark_theme">Dark</string>
<string name="always_show_nsfw">Always show sensitive content</string>
<!-- Notifications: follow notification -->
<string name="followed_notification">%1$s followed you</string>
@ -327,4 +329,5 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="change_profile_picture">Change your profile picture</string>
<string name="contains_nsfw">Contains NSFW media</string>
<string name="switch_accounts">Switch accounts</string>
<string name="summary_always_show_nsfw">NSFW/CW posts will not be blurred, and will be shown by default.</string>
</resources>

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
@ -23,6 +24,10 @@
app:title="@string/language"
app:icon="@drawable/translate_black_24dp" />
<CheckBoxPreference app:key="always_show_nsfw" app:title="@string/always_show_nsfw"
app:icon="@drawable/eye_black_24dp" android:defaultValue="false"
android:summary="@string/summary_always_show_nsfw"/>
<Preference android:title="@string/notifications_settings"
android:key="notification"
android:summary="@string/notifications_settings_summary"