make functions

This commit is contained in:
Sarang S 2022-08-18 11:34:55 +05:30
parent 3f134dc0b2
commit 40141f2d27

View file

@ -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
* */