From 40141f2d27e1d8f369645cde1be145f437a0b882 Mon Sep 17 00:00:00 2001 From: Sarang S Date: Thu, 18 Aug 2022 11:34:55 +0530 Subject: [PATCH] make functions --- .../cloudstream3/plugins/PluginManager.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt index cd5a41c6..bfba56f2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt @@ -7,7 +7,9 @@ import android.content.res.Resources import android.os.Environment import android.widget.Toast import android.app.Activity +import android.content.Context import android.util.Log +import androidx.appcompat.app.AlertDialog import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.AcraApplication.Companion.getKey @@ -22,6 +24,7 @@ import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData import com.lagradost.cloudstream3.utils.VideoDownloadManager.sanitizeFilename import com.lagradost.cloudstream3.APIHolder.removePluginMapping import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES +import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.ExtractorApi import com.lagradost.cloudstream3.utils.extractorApis import kotlinx.coroutines.sync.Mutex @@ -370,6 +373,40 @@ object PluginManager { ) } + private suspend fun downloadAllPluginsFromRepository( + activity: Activity, + repositoryUrl: String + ) { + getRepoPlugins(repositoryUrl)?.apmap { + downloadAndLoadPlugin( + activity, + it.second.url, + it.second.internalName, + repositoryUrl + ) + } + } + + fun Activity.downloadAllPluginsDialog(repositoryUrl: String) { + runOnUiThread { + val context = this + val builder: AlertDialog.Builder = AlertDialog.Builder(this) + builder.setTitle( + "Download all plugins from this repo?" + ) + builder.apply { + // TODO: R.string Yes No + setPositiveButton("Yes") { _, _ -> + showToast(context, R.string.download_started, Toast.LENGTH_LONG) + ioSafe { downloadAllPluginsFromRepository(context, repositoryUrl) } + } + + setNegativeButton("No") { _, _ -> } + } + builder.show() + } + } + /** * @param isFilePath will treat the pluginUrl as as the filepath instead of url * */