Fix nsfw visibility (#1162)

This commit is contained in:
CranberrySoup 2024-06-30 15:08:06 +00:00 committed by GitHub
parent ad27eb3b0e
commit 1a05651510
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.databinding.RepositoryItemBinding import com.lagradost.cloudstream3.databinding.RepositoryItemBinding
import com.lagradost.cloudstream3.plugins.PluginManager import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.plugins.VotingApi.getVotes import com.lagradost.cloudstream3.plugins.VotingApi.getVotes
@ -150,7 +151,7 @@ class PluginAdapter(
R.drawable.ic_baseline_delete_outline_24 R.drawable.ic_baseline_delete_outline_24
else R.drawable.netflix_download else R.drawable.netflix_download
binding.nsfwMarker.isVisible = metadata.tvTypes?.contains("NSFW") ?: false binding.nsfwMarker.isVisible = metadata.tvTypes?.contains(TvType.NSFW.name) ?: false
binding.actionButton.setImageResource(drawableInt) binding.actionButton.setImageResource(drawableInt)
binding.actionButton.setOnClickListener { binding.actionButton.setOnClickListener {

View file

@ -8,10 +8,12 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.MainAPI.Companion.settingsForProvider import com.lagradost.cloudstream3.MainAPI.Companion.settingsForProvider
import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.amap import com.lagradost.cloudstream3.amap
import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.launchSafe
import com.lagradost.cloudstream3.plugins.PluginManager import com.lagradost.cloudstream3.plugins.PluginManager
@ -97,6 +99,7 @@ class PluginsViewModel : ViewModel() {
R.string.batch_download_nothing_to_download_format, R.string.batch_download_nothing_to_download_format,
txt(R.string.plugin) txt(R.string.plugin)
) )
else -> txt( else -> txt(
R.string.batch_download_start_format, R.string.batch_download_start_format,
list.size, list.size,
@ -182,10 +185,14 @@ class PluginsViewModel : ViewModel() {
} }
private suspend fun updatePluginListPrivate(context: Context, repositoryUrl: String) { private suspend fun updatePluginListPrivate(context: Context, repositoryUrl: String) {
val isAdult = settingsForProvider.enableAdult val isAdult = PreferenceManager.getDefaultSharedPreferences(context)
.getStringSet(context.getString(R.string.prefer_media_type_key), emptySet())
?.contains(TvType.NSFW.ordinal.toString()) == true
val plugins = getPlugins(repositoryUrl) val plugins = getPlugins(repositoryUrl)
val list = plugins.filter { val list = plugins.filter {
return@filter !(it.second.tvTypes?.contains("NSFW") == true && !isAdult) // Show all non-nsfw plugins or all if nsfw is enabled
it.second.tvTypes?.contains(TvType.NSFW.name) != true || isAdult
}.map { plugin -> }.map { plugin ->
PluginViewData(plugin, isDownloaded(context, plugin.second.internalName, plugin.first)) PluginViewData(plugin, isDownloaded(context, plugin.second.internalName, plugin.first))
} }
@ -201,7 +208,7 @@ class PluginsViewModel : ViewModel() {
if (tvTypes.isEmpty()) return this if (tvTypes.isEmpty()) return this
return this.filter { return this.filter {
(it.plugin.second.tvTypes?.any { type -> tvTypes.contains(type) } == true) || (it.plugin.second.tvTypes?.any { type -> tvTypes.contains(type) } == true) ||
(tvTypes.contains("Others") && (it.plugin.second.tvTypes (tvTypes.contains(TvType.Others.name) && (it.plugin.second.tvTypes
?: emptyList()).isEmpty()) ?: emptyList()).isEmpty())
} }
} }