mirror of
				https://github.com/recloudstream/cloudstream.git
				synced 2024-08-15 01:53:11 +00:00 
			
		
		
		
	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.json.JsonMapper | ||||
| import com.fasterxml.jackson.module.kotlin.KotlinModule | ||||
| import com.lagradost.cloudstream3.mvvm.debugWarning | ||||
| import com.lagradost.cloudstream3.mvvm.logError | ||||
| import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.aniListApi | ||||
| import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi | ||||
|  | @ -43,7 +42,6 @@ object APIHolder { | |||
| 
 | ||||
|     val allProviders: MutableList<MainAPI> = arrayListOf() | ||||
| 
 | ||||
| 
 | ||||
|     fun initAll() { | ||||
|         for (api in allProviders) { | ||||
|             api.init() | ||||
|  | @ -58,8 +56,18 @@ object APIHolder { | |||
|     var apis: List<MainAPI> = arrayListOf() | ||||
|     var apiMap: Map<String, Int>? = null | ||||
| 
 | ||||
|     private fun initMap() { | ||||
|         if (apiMap == null) | ||||
|     fun addPluginMapping(plugin: MainAPI) { | ||||
|         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() | ||||
|     } | ||||
| 
 | ||||
|  | @ -70,11 +78,8 @@ object APIHolder { | |||
|     fun getApiFromNameNull(apiName: String?): MainAPI? { | ||||
|         if (apiName == null) return null | ||||
|         initMap() | ||||
|         // Fuck it load from allProviders since they're dynamically loaded | ||||
|         // This is required right now because apiMap might be outdated | ||||
|         // 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 } | ||||
|         return apiMap?.get(apiName)?.let { apis.getOrNull(it) } | ||||
|             ?: allProviders.firstOrNull { it.name == apiName } | ||||
|     } | ||||
| 
 | ||||
|     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.mvvm.logError | ||||
| import com.lagradost.cloudstream3.network.initClient | ||||
| import com.lagradost.cloudstream3.plugins.PREBUILT_REPOSITORIES | ||||
| import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver | ||||
| import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis | ||||
| import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers | ||||
|  | @ -673,6 +674,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { | |||
|                 // If no plugins bring up extensions screen | ||||
|             } else if (PluginManager.getPluginsOnline().isEmpty() | ||||
|                 && PluginManager.getPluginsLocal().isEmpty() | ||||
|                 && PREBUILT_REPOSITORIES.isNotEmpty() | ||||
|             ) { | ||||
|                 navController.navigate(R.id.navigation_setup_extensions) | ||||
|             } | ||||
|  |  | |||
|  | @ -35,6 +35,7 @@ abstract class Plugin { | |||
|         Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI") | ||||
|         element.sourcePlugin = this.`__filename` | ||||
|         APIHolder.allProviders.add(element) | ||||
|         APIHolder.addPluginMapping(element) | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  |  | |||
|  | @ -6,7 +6,6 @@ import android.view.ViewGroup | |||
| import androidx.recyclerview.widget.RecyclerView | ||||
| import com.lagradost.cloudstream3.R | ||||
| import com.lagradost.cloudstream3.plugins.PREBUILT_REPOSITORIES | ||||
| import com.lagradost.cloudstream3.ui.settings.AccountClickCallback | ||||
| import kotlinx.android.synthetic.main.repository_item.view.* | ||||
| 
 | ||||
| class RepoAdapter( | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ import com.lagradost.cloudstream3.BuildConfig | |||
| import com.lagradost.cloudstream3.CommonActivity | ||||
| import com.lagradost.cloudstream3.R | ||||
| import com.lagradost.cloudstream3.mvvm.normalSafeApiCall | ||||
| import com.lagradost.cloudstream3.plugins.PREBUILT_REPOSITORIES | ||||
| import com.lagradost.cloudstream3.plugins.PluginManager | ||||
| import com.lagradost.cloudstream3.ui.settings.appLanguages | ||||
| import com.lagradost.cloudstream3.ui.settings.getCurrentLocale | ||||
|  | @ -80,11 +81,14 @@ class SetupFragmentLanguage : Fragment() { | |||
|                 next_btt?.setOnClickListener { | ||||
|                     // If no plugins go to plugins page | ||||
|                     val nextDestination = if (PluginManager.getPluginsOnline() | ||||
|                             .isEmpty() | ||||
|                             .isEmpty() && PREBUILT_REPOSITORIES.isNotEmpty() | ||||
|                     ) R.id.action_navigation_global_to_navigation_setup_extensions | ||||
|                     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 { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue