Apply PR changes

This commit is contained in:
Jace 2022-11-03 07:55:26 +08:00
parent 9976cc1323
commit e029ceefc0
2 changed files with 9 additions and 22 deletions

View file

@ -561,14 +561,16 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
} }
ioSafe { ioSafe {
var isLoaded = false // Load all plugins as fast as possible!
PluginManager.loadAllOnlinePlugins(this@MainActivity)
afterPluginsLoadedEvent.invoke(true)
if (settingsManager.getBoolean( if (settingsManager.getBoolean(
getString(R.string.auto_update_plugins_key), getString(R.string.auto_update_plugins_key),
true true
) )
) { ) {
PluginManager.updateAllOnlinePluginsAndLoadThem(this@MainActivity) PluginManager.updateAllOnlinePluginsAndLoadThem(this@MainActivity)
isLoaded = true
} }
//Automatically download not existing plugins //Automatically download not existing plugins
if (settingsManager.getBoolean( if (settingsManager.getBoolean(
@ -576,12 +578,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
false false
) )
) { ) {
PluginManager.downloadNotExistingPluginsAndLoad(this@MainActivity, isLoaded) PluginManager.downloadNotExistingPluginsAndLoad(this@MainActivity)
isLoaded = true
}
if (!isLoaded) {
PluginManager.loadAllOnlinePlugins(this@MainActivity)
} }
} }

View file

@ -8,6 +8,7 @@ import android.os.Build
import android.os.Environment import android.os.Environment
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
@ -219,11 +220,6 @@ object PluginManager {
* 4. Else load the plugin normally * 4. Else load the plugin normally
**/ **/
fun updateAllOnlinePluginsAndLoadThem(activity: Activity) { fun updateAllOnlinePluginsAndLoadThem(activity: Activity) {
// Load all plugins as fast as possible!
loadAllOnlinePlugins(activity)
afterPluginsLoadedEvent.invoke(true)
val urls = (getKey<Array<RepositoryData>>(REPOSITORIES_KEY) val urls = (getKey<Array<RepositoryData>>(REPOSITORIES_KEY)
?: emptyArray()) + PREBUILT_REPOSITORIES ?: emptyArray()) + PREBUILT_REPOSITORIES
@ -283,13 +279,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, isLoaded: Boolean) { fun downloadNotExistingPluginsAndLoad(activity: Activity) {
// Load all plugins as fast as possible, if its not loaded yet.
if (!isLoaded) {
loadAllOnlinePlugins(activity)
afterPluginsLoadedEvent.invoke(true)
}
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
@ -324,7 +314,7 @@ object PluginManager {
//Omit NSFW, if disabled //Omit NSFW, if disabled
sitePlugin.tvTypes?.let { tvtypes -> sitePlugin.tvTypes?.let { tvtypes ->
if (!settingsForProvider.enableAdult) { if (!settingsForProvider.enableAdult) {
if (tvtypes.contains("NSFW")) { if (tvtypes.contains(TvType.NSFW.name)) {
return@outer null return@outer null
} }
} }
@ -616,7 +606,7 @@ object PluginManager {
private fun createNotification( private fun createNotification(
context: Context, context: Context,
extensionNames: List<String>, extensionNames: List<String>,
title: Int @StringRes title: Int
): Notification? { ): Notification? {
try { try {
if (extensionNames.isEmpty()) return null if (extensionNames.isEmpty()) return null