No plugin loading on bad status

This commit is contained in:
Blatzar 2022-08-08 20:52:03 +02:00
parent a1dd6cc106
commit 2c399e6916
4 changed files with 54 additions and 33 deletions

View file

@ -424,9 +424,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
app.initClient(this) app.initClient(this)
PluginManager.updateAllOnlinePlugins(this) PluginManager.updateAllOnlinePluginsAndLoadThem(this)
PluginManager.loadAllLocalPlugins(this) PluginManager.loadAllLocalPlugins(this)
PluginManager.loadAllOnlinePlugins(this)
// ioSafe { // ioSafe {
// val plugins = // val plugins =

View file

@ -16,7 +16,7 @@ import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.plugins.RepositoryManager.ONLINE_PLUGINS_FOLDER import com.lagradost.cloudstream3.plugins.RepositoryManager.ONLINE_PLUGINS_FOLDER
import com.lagradost.cloudstream3.plugins.RepositoryManager.downloadPluginToFile import com.lagradost.cloudstream3.plugins.RepositoryManager.downloadPluginToFile
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.apmap import com.lagradost.cloudstream3.apmap
import com.lagradost.cloudstream3.plugins.RepositoryManager.getRepoPlugins import com.lagradost.cloudstream3.plugins.RepositoryManager.getRepoPlugins
@ -115,40 +115,66 @@ object PluginManager {
} }
} }
// Helper class for updateAllOnlinePluginsAndLoadThem
private data class OnlinePluginData(
val savedData: PluginData,
val onlineData: Pair<String, SitePlugin>,
) {
val isOutdated =
onlineData.second.apiVersion != savedData.version || onlineData.second.version == PLUGIN_VERSION_ALWAYS_UPDATE
val isDisabled = onlineData.second.status == PROVIDER_STATUS_DOWN
}
/** /**
* Needs to be run before other plugin loading because plugin loading can not be overwritten * Needs to be run before other plugin loading because plugin loading can not be overwritten
* 1. Gets all online data about the downloaded plugins
* 2. If disabled do nothing
* 3. If outdated download and load the plugin
* 4. Else load the plugin normally
**/ **/
fun updateAllOnlinePlugins(activity: Activity) { fun updateAllOnlinePluginsAndLoadThem(activity: Activity) {
val urls = getKey<Array<RepositoryData>>(REPOSITORIES_KEY) ?: emptyArray() val urls = getKey<Array<RepositoryData>>(REPOSITORIES_KEY) ?: emptyArray()
val onlinePlugins = urls.toList().apmap { val onlinePlugins = urls.toList().apmap {
getRepoPlugins(it.url)?.toList() ?: emptyList() getRepoPlugins(it.url)?.toList() ?: emptyList()
}.flatten() }.flatten().distinctBy { it.second.url }
// Iterates over all offline plugins, compares to remote repo and returns the plugins which are outdated // Iterates over all offline plugins, compares to remote repo and returns the plugins which are outdated
val outdatedPlugins = getPluginsOnline().map { savedData -> val outdatedPlugins = getPluginsOnline().map { savedData ->
onlinePlugins.filter { onlineData -> savedData.internalName == onlineData.second.internalName } onlinePlugins.filter { onlineData -> savedData.internalName == onlineData.second.internalName }
.mapNotNull { onlineData -> .map { onlineData ->
val isOutdated = OnlinePluginData(savedData, onlineData)
onlineData.second.apiVersion != savedData.version || onlineData.second.version == PLUGIN_VERSION_ALWAYS_UPDATE
if (isOutdated) savedData to onlineData else null
} }
}.flatten() }.flatten().distinctBy { it.onlineData.second.url }
Log.i(TAG, "Outdated plugins: $outdatedPlugins") Log.i(TAG, "Outdated plugins: ${outdatedPlugins.filter { it.isOutdated }}")
outdatedPlugins.apmap { outdatedPlugins.apmap {
downloadAndLoadPlugin( if (it.isDisabled) {
activity, return@apmap
it.second.second.url, } else if (it.isOutdated) {
it.first.internalName, downloadAndLoadPlugin(
it.second.first activity,
) it.onlineData.second.url,
it.savedData.internalName,
it.onlineData.first
)
} else {
loadPlugin(
activity,
File(it.savedData.filePath),
it.savedData
)
}
} }
Log.i(TAG, "Plugin update done!") Log.i(TAG, "Plugin update done!")
} }
/**
* Use updateAllOnlinePluginsAndLoadThem
* */
fun loadAllOnlinePlugins(activity: Activity) { fun loadAllOnlinePlugins(activity: Activity) {
File(activity.filesDir, ONLINE_PLUGINS_FOLDER).listFiles()?.sortedBy { it.name } File(activity.filesDir, ONLINE_PLUGINS_FOLDER).listFiles()?.sortedBy { it.name }
?.apmap { file -> ?.apmap { file ->

View file

@ -6,13 +6,8 @@ import android.view.ViewGroup
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.plugins.PluginData
import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.plugins.SitePlugin
import com.lagradost.cloudstream3.ui.result.ActorAdaptor
import com.lagradost.cloudstream3.ui.result.DiffCallback
import com.lagradost.cloudstream3.ui.result.UiText
import kotlinx.android.synthetic.main.repository_item.view.* import kotlinx.android.synthetic.main.repository_item.view.*
@ -70,6 +65,9 @@ class PluginAdapter(
data: PluginViewData, data: PluginViewData,
) { ) {
val metadata = data.plugin.second val metadata = data.plugin.second
val alpha = if (metadata.status == PROVIDER_STATUS_DOWN) 0.6f else 1f
itemView.main_text?.alpha = alpha
itemView.sub_text?.alpha = alpha
val drawableInt = if (data.isDownloaded) val drawableInt = if (data.isDownloaded)
R.drawable.ic_baseline_delete_outline_24 R.drawable.ic_baseline_delete_outline_24

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/repository_item_root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
@ -28,24 +29,21 @@
tools:text="https://github.com/..." /> tools:text="https://github.com/..." />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:visibility="gone"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/nsfw_marker" android:id="@+id/nsfw_marker"
style="@style/SearchBox" style="@style/SearchBox"
android:background="@drawable/sub_bg_color" android:layout_gravity="center"
android:text="@string/is_adult" /> android:gravity="center"
android:text="@string/is_adult"
android:visibility="gone"
tools:visibility="visible" />
<ImageView <ImageView
android:layout_marginStart="10dp"
android:id="@+id/action_button" android:id="@+id/action_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
tools:src="@drawable/ic_baseline_add_24"> android:layout_marginStart="10dp"
</ImageView> tools:src="@drawable/ic_baseline_add_24" />
</LinearLayout> </LinearLayout>