forked from recloudstream/cloudstream
No setup if no PREBUILT_REPOSITORIES and code cleanup
This commit is contained in:
parent
f56d3e2603
commit
1321009837
5 changed files with 23 additions and 12 deletions
|
@ -10,7 +10,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper
|
import com.fasterxml.jackson.databind.json.JsonMapper
|
||||||
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
import com.lagradost.cloudstream3.mvvm.debugWarning
|
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.aniListApi
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.aniListApi
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi
|
||||||
|
@ -43,7 +42,6 @@ object APIHolder {
|
||||||
|
|
||||||
val allProviders: MutableList<MainAPI> = arrayListOf()
|
val allProviders: MutableList<MainAPI> = arrayListOf()
|
||||||
|
|
||||||
|
|
||||||
fun initAll() {
|
fun initAll() {
|
||||||
for (api in allProviders) {
|
for (api in allProviders) {
|
||||||
api.init()
|
api.init()
|
||||||
|
@ -58,8 +56,18 @@ object APIHolder {
|
||||||
var apis: List<MainAPI> = arrayListOf()
|
var apis: List<MainAPI> = arrayListOf()
|
||||||
var apiMap: Map<String, Int>? = null
|
var apiMap: Map<String, Int>? = null
|
||||||
|
|
||||||
private fun initMap() {
|
fun addPluginMapping(plugin: MainAPI) {
|
||||||
if (apiMap == null)
|
apis = apis + plugin
|
||||||
|
initMap(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removePluginMapping(plugin: MainAPI) {
|
||||||
|
apis = apis.filter { it != plugin }
|
||||||
|
initMap(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initMap(forcedUpdate: Boolean = false) {
|
||||||
|
if (apiMap == null || forcedUpdate)
|
||||||
apiMap = apis.mapIndexed { index, api -> api.name to index }.toMap()
|
apiMap = apis.mapIndexed { index, api -> api.name to index }.toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,11 +78,8 @@ object APIHolder {
|
||||||
fun getApiFromNameNull(apiName: String?): MainAPI? {
|
fun getApiFromNameNull(apiName: String?): MainAPI? {
|
||||||
if (apiName == null) return null
|
if (apiName == null) return null
|
||||||
initMap()
|
initMap()
|
||||||
// Fuck it load from allProviders since they're dynamically loaded
|
return apiMap?.get(apiName)?.let { apis.getOrNull(it) }
|
||||||
// This is required right now because apiMap might be outdated
|
?: allProviders.firstOrNull { it.name == apiName }
|
||||||
// TODO FIX when we switch to LoadPlugin()
|
|
||||||
debugWarning { "FIX LoadPlugin! getApiFromNameNull sucks right now 💀" }
|
|
||||||
return apiMap?.get(apiName)?.let { apis.getOrNull(it) } ?: allProviders.firstOrNull { it.name == apiName }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getApiFromUrlNull(url: String?): MainAPI? {
|
fun getApiFromUrlNull(url: String?): MainAPI? {
|
||||||
|
|
|
@ -41,6 +41,7 @@ import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.CommonActivity.updateLocale
|
import com.lagradost.cloudstream3.CommonActivity.updateLocale
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.network.initClient
|
import com.lagradost.cloudstream3.network.initClient
|
||||||
|
import com.lagradost.cloudstream3.plugins.PREBUILT_REPOSITORIES
|
||||||
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
||||||
|
@ -673,6 +674,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
// If no plugins bring up extensions screen
|
// If no plugins bring up extensions screen
|
||||||
} else if (PluginManager.getPluginsOnline().isEmpty()
|
} else if (PluginManager.getPluginsOnline().isEmpty()
|
||||||
&& PluginManager.getPluginsLocal().isEmpty()
|
&& PluginManager.getPluginsLocal().isEmpty()
|
||||||
|
&& PREBUILT_REPOSITORIES.isNotEmpty()
|
||||||
) {
|
) {
|
||||||
navController.navigate(R.id.navigation_setup_extensions)
|
navController.navigate(R.id.navigation_setup_extensions)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ abstract class Plugin {
|
||||||
Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI")
|
Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI")
|
||||||
element.sourcePlugin = this.`__filename`
|
element.sourcePlugin = this.`__filename`
|
||||||
APIHolder.allProviders.add(element)
|
APIHolder.allProviders.add(element)
|
||||||
|
APIHolder.addPluginMapping(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.plugins.PREBUILT_REPOSITORIES
|
import com.lagradost.cloudstream3.plugins.PREBUILT_REPOSITORIES
|
||||||
import com.lagradost.cloudstream3.ui.settings.AccountClickCallback
|
|
||||||
import kotlinx.android.synthetic.main.repository_item.view.*
|
import kotlinx.android.synthetic.main.repository_item.view.*
|
||||||
|
|
||||||
class RepoAdapter(
|
class RepoAdapter(
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.lagradost.cloudstream3.BuildConfig
|
||||||
import com.lagradost.cloudstream3.CommonActivity
|
import com.lagradost.cloudstream3.CommonActivity
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
||||||
|
import com.lagradost.cloudstream3.plugins.PREBUILT_REPOSITORIES
|
||||||
import com.lagradost.cloudstream3.plugins.PluginManager
|
import com.lagradost.cloudstream3.plugins.PluginManager
|
||||||
import com.lagradost.cloudstream3.ui.settings.appLanguages
|
import com.lagradost.cloudstream3.ui.settings.appLanguages
|
||||||
import com.lagradost.cloudstream3.ui.settings.getCurrentLocale
|
import com.lagradost.cloudstream3.ui.settings.getCurrentLocale
|
||||||
|
@ -80,11 +81,14 @@ class SetupFragmentLanguage : Fragment() {
|
||||||
next_btt?.setOnClickListener {
|
next_btt?.setOnClickListener {
|
||||||
// If no plugins go to plugins page
|
// If no plugins go to plugins page
|
||||||
val nextDestination = if (PluginManager.getPluginsOnline()
|
val nextDestination = if (PluginManager.getPluginsOnline()
|
||||||
.isEmpty()
|
.isEmpty() && PREBUILT_REPOSITORIES.isNotEmpty()
|
||||||
) R.id.action_navigation_global_to_navigation_setup_extensions
|
) R.id.action_navigation_global_to_navigation_setup_extensions
|
||||||
else R.id.action_navigation_setup_language_to_navigation_setup_provider_languages
|
else R.id.action_navigation_setup_language_to_navigation_setup_provider_languages
|
||||||
|
|
||||||
findNavController().navigate(nextDestination, SetupFragmentExtensions.newInstance(true))
|
findNavController().navigate(
|
||||||
|
nextDestination,
|
||||||
|
SetupFragmentExtensions.newInstance(true)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_btt?.setOnClickListener {
|
skip_btt?.setOnClickListener {
|
||||||
|
|
Loading…
Reference in a new issue