mirror of
				https://github.com/recloudstream/cloudstream.git
				synced 2024-08-15 01:53:11 +00:00 
			
		
		
		
	Several crashfixes
This commit is contained in:
		
							parent
							
								
									f49d9de09b
								
							
						
					
					
						commit
						6a5286e363
					
				
					 3 changed files with 24 additions and 11 deletions
				
			
		|  | @ -16,6 +16,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi | |||
| import com.lagradost.cloudstream3.ui.player.SubtitleData | ||||
| import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings | ||||
| import com.lagradost.cloudstream3.utils.AppUtils.toJson | ||||
| import com.lagradost.cloudstream3.utils.Coroutines.threadSafeListOf | ||||
| import com.lagradost.cloudstream3.utils.ExtractorLink | ||||
| import com.lagradost.cloudstream3.utils.SubtitleHelper | ||||
| import okhttp3.Interceptor | ||||
|  | @ -39,7 +40,7 @@ object APIHolder { | |||
|     private const val defProvider = 0 | ||||
| 
 | ||||
|     // ConcurrentModificationException is possible!!! | ||||
|     val allProviders: MutableList<MainAPI> = arrayListOf() | ||||
|     val allProviders = threadSafeListOf<MainAPI>() | ||||
| 
 | ||||
|     fun initAll() { | ||||
|         for (api in allProviders) { | ||||
|  | @ -52,7 +53,7 @@ object APIHolder { | |||
|         return this.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } | ||||
|     } | ||||
| 
 | ||||
|     var apis: List<MainAPI> = arrayListOf() | ||||
|     var apis: List<MainAPI> = threadSafeListOf() | ||||
|     var apiMap: Map<String, Int>? = null | ||||
| 
 | ||||
|     fun addPluginMapping(plugin: MainAPI) { | ||||
|  | @ -72,16 +73,19 @@ object APIHolder { | |||
| 
 | ||||
|     fun getApiFromNameNull(apiName: String?): MainAPI? { | ||||
|         if (apiName == null) return null | ||||
|         initMap() | ||||
|         return apiMap?.get(apiName)?.let { apis.getOrNull(it) } | ||||
|             ?: allProviders.firstOrNull { it.name == apiName } | ||||
|         synchronized(allProviders) { | ||||
|             initMap() | ||||
|             return apiMap?.get(apiName)?.let { apis.getOrNull(it) } | ||||
|                 ?: allProviders.firstOrNull { it.name == apiName } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     fun getApiFromUrlNull(url: String?): MainAPI? { | ||||
|         if (url == null) return null | ||||
|         for (api in allProviders) { | ||||
|             if (url.startsWith(api.mainUrl)) | ||||
|                 return api | ||||
|         synchronized(allProviders) { | ||||
|             allProviders.forEach { api -> | ||||
|                 if (url.startsWith(api.mainUrl)) return api | ||||
|             } | ||||
|         } | ||||
|         return null | ||||
|     } | ||||
|  |  | |||
|  | @ -10,6 +10,7 @@ import com.lagradost.cloudstream3.app | |||
| import com.lagradost.cloudstream3.mvvm.logError | ||||
| import com.lagradost.cloudstream3.utils.Coroutines.main | ||||
| import com.lagradost.cloudstream3.utils.Coroutines.mainWork | ||||
| import com.lagradost.cloudstream3.utils.Coroutines.threadSafeListOf | ||||
| import com.lagradost.nicehttp.requestCreator | ||||
| import kotlinx.coroutines.delay | ||||
| import kotlinx.coroutines.runBlocking | ||||
|  | @ -96,7 +97,7 @@ class WebViewResolver( | |||
|         } | ||||
| 
 | ||||
|         var fixedRequest: Request? = null | ||||
|         val extraRequestList = mutableListOf<Request>() | ||||
|         val extraRequestList = threadSafeListOf<Request>() | ||||
| 
 | ||||
|         main { | ||||
|             // Useful for debugging | ||||
|  |  | |||
|  | @ -4,9 +4,8 @@ import android.os.Handler | |||
| import android.os.Looper | ||||
| import com.lagradost.cloudstream3.mvvm.launchSafe | ||||
| import com.lagradost.cloudstream3.mvvm.logError | ||||
| import com.lagradost.cloudstream3.utils.Coroutines.ioSafe | ||||
| import com.lagradost.cloudstream3.utils.Coroutines.main | ||||
| import kotlinx.coroutines.* | ||||
| import java.util.Collections.synchronizedList | ||||
| 
 | ||||
| object Coroutines { | ||||
|     fun <T> T.main(work: suspend ((T) -> Unit)): Job { | ||||
|  | @ -56,4 +55,13 @@ object Coroutines { | |||
|             work() | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Safe to add and remove how you want | ||||
|      * If you want to iterate over the list then you need to do: | ||||
|      * synchronized(allProviders) { code here } | ||||
|      **/ | ||||
|     fun <T> threadSafeListOf(vararg items: T): MutableList<T> { | ||||
|         return synchronizedList(items.toMutableList()) | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue