Update PluginManager.kt

This commit is contained in:
Jace 2023-07-26 12:03:14 +08:00 committed by GitHub
parent 39bc4f411d
commit 75968ff095
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -289,7 +289,7 @@ object PluginManager {
* 2. Fetch all not downloaded plugins * 2. Fetch all not downloaded plugins
* 3. Download them and reload plugins * 3. Download them and reload plugins
**/ **/
fun downloadNotExistingPluginsAndLoad(activity: Activity) { fun downloadNotExistingPluginsAndLoad(activity: Activity, mode: AutoDownloadMode) {
val newDownloadPlugins = mutableListOf<String>() val newDownloadPlugins = mutableListOf<String>()
val urls = (getKey<Array<RepositoryData>>(REPOSITORIES_KEY) val urls = (getKey<Array<RepositoryData>>(REPOSITORIES_KEY)
?: emptyArray()) + PREBUILT_REPOSITORIES ?: emptyArray()) + PREBUILT_REPOSITORIES
@ -303,6 +303,8 @@ object PluginManager {
// Iterate online repos and returns not downloaded plugins // Iterate online repos and returns not downloaded plugins
val notDownloadedPlugins = onlinePlugins.mapNotNull { onlineData -> val notDownloadedPlugins = onlinePlugins.mapNotNull { onlineData ->
val sitePlugin = onlineData.second val sitePlugin = onlineData.second
val tvtypes = sitePlugin.tvTypes ?: listOf()
//Don't include empty urls //Don't include empty urls
if (sitePlugin.url.isBlank()) { if (sitePlugin.url.isBlank()) {
return@mapNotNull null return@mapNotNull null
@ -317,22 +319,29 @@ object PluginManager {
return@mapNotNull null return@mapNotNull null
} }
//Omit lang not selected on language setting //Omit non-NSFW if mode is set to NSFW only
val lang = sitePlugin.language ?: return@mapNotNull null if (mode == AutoDownloadMode.NsfwOnly) {
//If set to 'universal', don't skip any language if (tvtypes.contains(TvType.NSFW.name) == false) {
if (!providerLang.contains(AllLanguagesName) && !providerLang.contains(lang)) { return@mapNotNull null
return@mapNotNull null
}
//Log.i(TAG, "sitePlugin lang => $lang")
//Omit NSFW, if disabled
sitePlugin.tvTypes?.let { tvtypes ->
if (!settingsForProvider.enableAdult) {
if (tvtypes.contains(TvType.NSFW.name)) {
return@mapNotNull null
}
} }
} }
//Omit NSFW, if disabled
if (!settingsForProvider.enableAdult) {
if (tvtypes.contains(TvType.NSFW.name)) {
return@mapNotNull null
}
}
//Omit lang not selected on language setting
if (mode == AutoDownloadMode.FilterByLang) {
val lang = sitePlugin.language ?: return@mapNotNull null
//If set to 'universal', don't skip any language
if (!providerLang.contains(AllLanguagesName) && !providerLang.contains(lang)) {
return@mapNotNull null
}
//Log.i(TAG, "sitePlugin lang => $lang")
}
val savedData = PluginData( val savedData = PluginData(
url = sitePlugin.url, url = sitePlugin.url,
internalName = sitePlugin.internalName, internalName = sitePlugin.internalName,
@ -692,4 +701,4 @@ object PluginManager {
return null return null
} }
} }
} }