Skip to content

Commit

Permalink
Fix nsfw visibility (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
CranberrySoup committed Jun 30, 2024
1 parent ad27eb3 commit 1a05651
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.databinding.RepositoryItemBinding
import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.plugins.VotingApi.getVotes
Expand Down Expand Up @@ -150,7 +151,7 @@ class PluginAdapter(
R.drawable.ic_baseline_delete_outline_24
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.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.MainAPI.Companion.settingsForProvider
import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.amap
import com.lagradost.cloudstream3.mvvm.launchSafe
import com.lagradost.cloudstream3.plugins.PluginManager
Expand Down Expand Up @@ -97,6 +99,7 @@ class PluginsViewModel : ViewModel() {
R.string.batch_download_nothing_to_download_format,
txt(R.string.plugin)
)

else -> txt(
R.string.batch_download_start_format,
list.size,
Expand Down Expand Up @@ -182,10 +185,14 @@ class PluginsViewModel : ViewModel() {
}

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 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 ->
PluginViewData(plugin, isDownloaded(context, plugin.second.internalName, plugin.first))
}
Expand All @@ -201,7 +208,7 @@ class PluginsViewModel : ViewModel() {
if (tvTypes.isEmpty()) return this
return this.filter {
(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())
}
}
Expand Down

0 comments on commit 1a05651

Please sign in to comment.