From 43c45203167f6d4538f56f1d1e7c28d5d29adc01 Mon Sep 17 00:00:00 2001 From: Adam Williams Date: Sun, 11 Jun 2023 00:21:50 +0100 Subject: [PATCH 1/3] Add ability to always show sensitive content --- .../org/pixeldroid/app/posts/StatusViewHolder.kt | 14 +++++++++++--- app/src/main/res/drawable/eye_black_24dp.xml | 9 +++++++++ app/src/main/res/values/strings.xml | 5 ++++- app/src/main/res/xml/root_preferences.xml | 5 +++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/eye_black_24dp.xml diff --git a/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt b/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt index af29b15b..5ea2834f 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt @@ -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, ) { + 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) @@ -939,4 +947,4 @@ class AlbumViewPagerAdapter( override val image: ImageView = binding.imageImageView override val videoPlayButton: ImageView = binding.videoPlayButton } -} \ No newline at end of file +} diff --git a/app/src/main/res/drawable/eye_black_24dp.xml b/app/src/main/res/drawable/eye_black_24dp.xml new file mode 100644 index 00000000..e3b1e75a --- /dev/null +++ b/app/src/main/res/drawable/eye_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba9f8bbd..2d56dece 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,6 +35,8 @@ Dark + Always show sensitive content + %1$s followed you @@ -327,4 +329,5 @@ For more info about Pixelfed, you can check here: https://pixelfed.org" Change your profile picture Contains NSFW media Switch accounts - \ No newline at end of file + NSFW/CW posts will not be blurred, and will be shown by default. + diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 11ed9ee1..c7df4cde 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -1,3 +1,4 @@ + @@ -23,6 +24,10 @@ app:title="@string/language" app:icon="@drawable/translate_black_24dp" /> + + Date: Sun, 11 Jun 2023 23:02:30 +0200 Subject: [PATCH 2/3] Reuse value from settings --- .../main/java/org/pixeldroid/app/posts/AlbumActivity.kt | 4 +++- .../java/org/pixeldroid/app/posts/StatusViewHolder.kt | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/posts/AlbumActivity.kt b/app/src/main/java/org/pixeldroid/app/posts/AlbumActivity.kt index 3b577d97..b40dfbdb 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/AlbumActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/AlbumActivity.kt @@ -17,7 +17,9 @@ class AlbumActivity : BaseActivity() { val index = intent.getIntExtra("index", 0) binding.albumPager.adapter = AlbumViewPagerAdapter(mediaAttachments, sensitive = false, - opened = true + opened = true, + //In the activity, we assume we want to show everything + alwaysShowNsfw = true ) binding.albumPager.currentItem = index diff --git a/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt b/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt index 5ea2834f..924d0a66 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/StatusViewHolder.kt @@ -173,7 +173,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold binding.postPager.visibility = View.VISIBLE //Attach the given tabs to the view pager - binding.postPager.adapter = AlbumViewPagerAdapter(status?.media_attachments ?: emptyList(), status?.sensitive, false) + binding.postPager.adapter = AlbumViewPagerAdapter(status?.media_attachments ?: emptyList(), status?.sensitive, false, alwaysShowNsfw) if((status?.media_attachments?.size ?: 0) > 1) { binding.postIndicator.setViewPager(binding.postPager) @@ -831,7 +831,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold class AlbumViewPagerAdapter( private val media_attachments: List, private var sensitive: Boolean?, - private val opened: Boolean, + private val opened: Boolean, private val alwaysShowNsfw: Boolean, ) : RecyclerView.Adapter() { @@ -847,10 +847,6 @@ 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 { From d03314f734f0f3af337ef8ec4bbdda6e8d9dc02f Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Tue, 13 Jun 2023 21:56:33 +0200 Subject: [PATCH 3/3] Dependencies --- build.gradle | 2 +- gradle/verification-metadata.xml | 424 +++++++++++++++++++++++++++++++ 2 files changed, 425 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3f21518a..e19143ad 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.0.0-beta05' + classpath 'com.android.tools.build:gradle:8.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index a3add835..fd01fe5f 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -413,6 +413,14 @@ + + + + + + + + @@ -424,6 +432,14 @@ + + + + + + + + @@ -524,6 +540,14 @@ + + + + + + + + @@ -548,6 +572,14 @@ + + + + + + + + @@ -572,6 +604,14 @@ + + + + + + + + @@ -596,6 +636,14 @@ + + + + + + + + @@ -629,6 +677,14 @@ + + + + + + + + @@ -662,6 +718,14 @@ + + + + + + + + @@ -695,6 +759,14 @@ + + + + + + + + @@ -2300,6 +2372,14 @@ + + + + + + + + @@ -2324,6 +2404,14 @@ + + + + + + + + @@ -2348,6 +2436,14 @@ + + + + + + + + @@ -2372,6 +2468,14 @@ + + + + + + + + @@ -2396,6 +2500,14 @@ + + + + + + + + @@ -2436,6 +2548,14 @@ + + + + + + + + @@ -2460,6 +2580,14 @@ + + + + + + + + @@ -2484,6 +2612,14 @@ + + + + + + + + @@ -2508,6 +2644,14 @@ + + + + + + + + @@ -2532,6 +2676,14 @@ + + + + + + + + @@ -2556,6 +2708,14 @@ + + + + + + + + @@ -2580,6 +2740,14 @@ + + + + + + + + @@ -2604,6 +2772,14 @@ + + + + + + + + @@ -2628,6 +2804,14 @@ + + + + + + + + @@ -2652,6 +2836,14 @@ + + + + + + + + @@ -2676,6 +2868,14 @@ + + + + + + + + @@ -2700,6 +2900,14 @@ + + + + + + + + @@ -2724,6 +2932,14 @@ + + + + + + + + @@ -2748,6 +2964,14 @@ + + + + + + + + @@ -2772,6 +2996,14 @@ + + + + + + + + @@ -2796,6 +3028,14 @@ + + + + + + + + @@ -2820,6 +3060,14 @@ + + + + + + + + @@ -2852,6 +3100,14 @@ + + + + + + + + @@ -2876,6 +3132,14 @@ + + + + + + + + @@ -2900,6 +3164,14 @@ + + + + + + + + @@ -2924,6 +3196,14 @@ + + + + + + + + @@ -2972,6 +3252,14 @@ + + + + + + + + @@ -2996,6 +3284,14 @@ + + + + + + + + @@ -3020,6 +3316,14 @@ + + + + + + + + @@ -3044,6 +3348,14 @@ + + + + + + + + @@ -3068,6 +3380,14 @@ + + + + + + + + @@ -3092,6 +3412,14 @@ + + + + + + + + @@ -3116,6 +3444,14 @@ + + + + + + + + @@ -3140,6 +3476,14 @@ + + + + + + + + @@ -3164,6 +3508,14 @@ + + + + + + + + @@ -3188,6 +3540,14 @@ + + + + + + + + @@ -3212,6 +3572,14 @@ + + + + + + + + @@ -3236,6 +3604,14 @@ + + + + + + + + @@ -3260,6 +3636,14 @@ + + + + + + + + @@ -3284,6 +3668,14 @@ + + + + + + + + @@ -3308,6 +3700,14 @@ + + + + + + + + @@ -3332,6 +3732,14 @@ + + + + + + + + @@ -3356,6 +3764,14 @@ + + + + + + + + @@ -3380,6 +3796,14 @@ + + + + + + + +