forked from recloudstream/cloudstream
		
	general fixes to make app more primate friendly
This commit is contained in:
		
							parent
							
								
									97641d5459
								
							
						
					
					
						commit
						7466ecbc2f
					
				
					 7 changed files with 43 additions and 17 deletions
				
			
		|  | @ -55,8 +55,8 @@ object APIHolder { | ||||||
| 
 | 
 | ||||||
|     val restrictedApis = arrayListOf( |     val restrictedApis = arrayListOf( | ||||||
|         TrailersToProvider(), // be aware that this is fuckery |         TrailersToProvider(), // be aware that this is fuckery | ||||||
|         //NyaaProvider(), //torrents in cs3 is wack |         // NyaaProvider(), // torrents in cs3 is wack | ||||||
|         ThenosProvider(), |         // ThenosProvider(), // ddos protection and wacked links | ||||||
|         AsiaFlixProvider(), |         AsiaFlixProvider(), | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|  | @ -163,9 +163,12 @@ abstract class MainAPI { | ||||||
|     /**Set false if links require referer or for some reason cant be played on a chromecast*/ |     /**Set false if links require referer or for some reason cant be played on a chromecast*/ | ||||||
|     open val hasChromecastSupport = true |     open val hasChromecastSupport = true | ||||||
| 
 | 
 | ||||||
|     /**If all links are m3u8 then set this to false*/ |     /**If all links are encrypted then set this to false*/ | ||||||
|     open val hasDownloadSupport = true |     open val hasDownloadSupport = true | ||||||
| 
 | 
 | ||||||
|  |     /**Used for testing and can be used to disable the providers if WebView is not available*/ | ||||||
|  |     open val usesWebView = false | ||||||
|  | 
 | ||||||
|     open val hasMainPage = false |     open val hasMainPage = false | ||||||
|     open val hasQuickSearch = false |     open val hasQuickSearch = false | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -33,6 +33,9 @@ class ZoroProvider : MainAPI() { | ||||||
|     override val hasDownloadSupport: Boolean |     override val hasDownloadSupport: Boolean | ||||||
|         get() = true |         get() = true | ||||||
| 
 | 
 | ||||||
|  |     override val usesWebView: Boolean | ||||||
|  |         get() = true | ||||||
|  | 
 | ||||||
|     override val supportedTypes: Set<TvType> |     override val supportedTypes: Set<TvType> | ||||||
|         get() = setOf( |         get() = setOf( | ||||||
|             TvType.Anime, |             TvType.Anime, | ||||||
|  |  | ||||||
|  | @ -31,6 +31,9 @@ class SflixProvider : MainAPI() { | ||||||
|     override val hasDownloadSupport: Boolean |     override val hasDownloadSupport: Boolean | ||||||
|         get() = true |         get() = true | ||||||
| 
 | 
 | ||||||
|  |     override val usesWebView: Boolean | ||||||
|  |         get() = true | ||||||
|  | 
 | ||||||
|     override val supportedTypes: Set<TvType> |     override val supportedTypes: Set<TvType> | ||||||
|         get() = setOf( |         get() = setOf( | ||||||
|             TvType.Movie, |             TvType.Movie, | ||||||
|  |  | ||||||
|  | @ -108,7 +108,7 @@ class HomeFragment : Fragment() { | ||||||
|         savedInstanceState: Bundle? |         savedInstanceState: Bundle? | ||||||
|     ): View? { |     ): View? { | ||||||
|         //homeViewModel = |         //homeViewModel = | ||||||
|        //     ViewModelProvider(this).get(HomeViewModel::class.java) |         //     ViewModelProvider(this).get(HomeViewModel::class.java) | ||||||
| 
 | 
 | ||||||
|         return inflater.inflate(R.layout.fragment_home, container, false) |         return inflater.inflate(R.layout.fragment_home, container, false) | ||||||
|     } |     } | ||||||
|  | @ -123,10 +123,14 @@ class HomeFragment : Fragment() { | ||||||
|     private fun chooseRandomMainPage() { |     private fun chooseRandomMainPage() { | ||||||
|         val home = currentHomePage |         val home = currentHomePage | ||||||
|         if (home != null && home.items.isNotEmpty()) { |         if (home != null && home.items.isNotEmpty()) { | ||||||
|             val randomItems = home.items.shuffled().flatMap { it.list }.distinctBy { it.url }.toList().shuffled() |             val currentList = | ||||||
|             if (randomItems.isNullOrEmpty()) { |                 home.items.shuffled().filter { !it.list.isNullOrEmpty() }.flatMap { it.list }.distinctBy { it.url } | ||||||
|  |                     .toList() | ||||||
|  | 
 | ||||||
|  |             if (currentList.isNullOrEmpty()) { | ||||||
|                 toggleMainVisibility(false) |                 toggleMainVisibility(false) | ||||||
|             } else { |             } else { | ||||||
|  |                 val randomItems = currentList.shuffled() | ||||||
|                 val randomSize = randomItems.size |                 val randomSize = randomItems.size | ||||||
|                 home_main_poster_recyclerview.adapter = |                 home_main_poster_recyclerview.adapter = | ||||||
|                     HomeChildItemAdapter(randomItems, R.layout.home_result_big_grid) { callback -> |                     HomeChildItemAdapter(randomItems, R.layout.home_result_big_grid) { callback -> | ||||||
|  | @ -141,7 +145,7 @@ class HomeFragment : Fragment() { | ||||||
|                             manager.snap { dx -> |                             manager.snap { dx -> | ||||||
|                                 home_main_poster_recyclerview?.post { |                                 home_main_poster_recyclerview?.post { | ||||||
|                                     // this is the best I can do, fuck android for not including instant scroll |                                     // this is the best I can do, fuck android for not including instant scroll | ||||||
|                                     home_main_poster_recyclerview?.smoothScrollBy(dx,0) |                                     home_main_poster_recyclerview?.smoothScrollBy(dx, 0) | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|  | @ -429,7 +433,7 @@ class HomeFragment : Fragment() { | ||||||
|             for (syncApi in OAuth2Interface.OAuth2Apis) { |             for (syncApi in OAuth2Interface.OAuth2Apis) { | ||||||
|                 val login = syncApi.loginInfo(ctx) |                 val login = syncApi.loginInfo(ctx) | ||||||
|                 val pic = login?.profilePicture |                 val pic = login?.profilePicture | ||||||
|                 if(pic != null) { |                 if (pic != null) { | ||||||
|                     home_profile_picture.setImage(pic) |                     home_profile_picture.setImage(pic) | ||||||
|                     home_profile_picture_holder.isVisible = true |                     home_profile_picture_holder.isVisible = true | ||||||
|                     break |                     break | ||||||
|  |  | ||||||
|  | @ -25,7 +25,6 @@ import com.lagradost.cloudstream3.R | ||||||
| import com.lagradost.cloudstream3.utils.DataStore.getKey | import com.lagradost.cloudstream3.utils.DataStore.getKey | ||||||
| import com.lagradost.cloudstream3.utils.DataStore.setKey | import com.lagradost.cloudstream3.utils.DataStore.setKey | ||||||
| import com.lagradost.cloudstream3.utils.Event | import com.lagradost.cloudstream3.utils.Event | ||||||
| import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog |  | ||||||
| import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog | import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog | ||||||
| import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog | import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog | ||||||
| import com.lagradost.cloudstream3.utils.SubtitleHelper | import com.lagradost.cloudstream3.utils.SubtitleHelper | ||||||
|  | @ -224,7 +223,8 @@ class SubtitlesFragment : Fragment() { | ||||||
|                 Pair(40, "40"), |                 Pair(40, "40"), | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             textView.context.showBottomDialog( |             //showBottomDialog | ||||||
|  |             textView.context.showDialog( | ||||||
|                 elevationTypes.map { it.second }, |                 elevationTypes.map { it.second }, | ||||||
|                 elevationTypes.map { it.first }.indexOf(state.elevation), |                 elevationTypes.map { it.first }.indexOf(state.elevation), | ||||||
|                 (textView as TextView).text.toString(), |                 (textView as TextView).text.toString(), | ||||||
|  | @ -254,7 +254,8 @@ class SubtitlesFragment : Fragment() { | ||||||
|                 Pair(CaptionStyleCompat.EDGE_TYPE_RAISED, "Raised"), |                 Pair(CaptionStyleCompat.EDGE_TYPE_RAISED, "Raised"), | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             textView.context.showBottomDialog( |             //showBottomDialog | ||||||
|  |             textView.context.showDialog( | ||||||
|                 edgeTypes.map { it.second }, |                 edgeTypes.map { it.second }, | ||||||
|                 edgeTypes.map { it.first }.indexOf(state.edgeType), |                 edgeTypes.map { it.first }.indexOf(state.edgeType), | ||||||
|                 (textView as TextView).text.toString(), |                 (textView as TextView).text.toString(), | ||||||
|  | @ -304,7 +305,8 @@ class SubtitlesFragment : Fragment() { | ||||||
|                 Pair(60f,"60$suffix"), |                 Pair(60f,"60$suffix"), | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             textView.context.showBottomDialog( |             //showBottomDialog | ||||||
|  |             textView.context.showDialog( | ||||||
|                 fontSizes.map { it.second }, |                 fontSizes.map { it.second }, | ||||||
|                 fontSizes.map { it.first }.indexOf(state.fixedTextSize), |                 fontSizes.map { it.first }.indexOf(state.fixedTextSize), | ||||||
|                 (textView as TextView).text.toString(), |                 (textView as TextView).text.toString(), | ||||||
|  | @ -341,7 +343,8 @@ class SubtitlesFragment : Fragment() { | ||||||
|                 Pair(R.font.poppins_regular, "Poppins"), |                 Pair(R.font.poppins_regular, "Poppins"), | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             textView.context.showBottomDialog( |             //showBottomDialog | ||||||
|  |             textView.context.showDialog( | ||||||
|                 fontTypes.map { it.second }, |                 fontTypes.map { it.second }, | ||||||
|                 fontTypes.map { it.first }.indexOf(state.typeface), |                 fontTypes.map { it.first }.indexOf(state.typeface), | ||||||
|                 (textView as TextView).text.toString(), |                 (textView as TextView).text.toString(), | ||||||
|  |  | ||||||
|  | @ -129,6 +129,7 @@ object SingleSelectionHelper { | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** Only for a low amount of items */ | ||||||
|     fun Context.showBottomDialog( |     fun Context.showBottomDialog( | ||||||
|         items: List<String>, |         items: List<String>, | ||||||
|         selectedIndex: Int, |         selectedIndex: Int, | ||||||
|  | @ -149,7 +150,7 @@ object SingleSelectionHelper { | ||||||
|             name, |             name, | ||||||
|             showApply, |             showApply, | ||||||
|             false, |             false, | ||||||
|             { callback.invoke(it.first()) }, |             { if(it.isNotEmpty()) callback.invoke(it.first()) }, | ||||||
|             dismissCallback |             dismissCallback | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ class ProviderTests { | ||||||
|     private fun getAllProviders(): List<MainAPI> { |     private fun getAllProviders(): List<MainAPI> { | ||||||
|         val allApis = APIHolder.apis |         val allApis = APIHolder.apis | ||||||
|         allApis.addAll(APIHolder.restrictedApis) |         allApis.addAll(APIHolder.restrictedApis) | ||||||
|         return allApis |         return allApis.filter { !it.usesWebView } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private fun loadLinks(api: MainAPI, url: String?): Boolean { |     private fun loadLinks(api: MainAPI, url: String?): Boolean { | ||||||
|  | @ -80,13 +80,14 @@ class ProviderTests { | ||||||
|                 when (load) { |                 when (load) { | ||||||
|                     is AnimeLoadResponse -> { |                     is AnimeLoadResponse -> { | ||||||
|                         val gotNoEpisodes = |                         val gotNoEpisodes = | ||||||
|                             load.dubEpisodes.isNullOrEmpty() && load.subEpisodes.isNullOrEmpty() |                             load.episodes.keys.isEmpty() || load.episodes.keys.any { load.episodes[it].isNullOrEmpty() } | ||||||
|  | 
 | ||||||
|                         if (gotNoEpisodes) { |                         if (gotNoEpisodes) { | ||||||
|                             println("Api ${api.name} got no episodes on ${load.url}") |                             println("Api ${api.name} got no episodes on ${load.url}") | ||||||
|                             continue |                             continue | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|                         val url = (load.dubEpisodes ?: load.subEpisodes)?.first()?.url |                         val url = (load.episodes[load.episodes.keys.first()])?.first()?.url | ||||||
|                         validResults = loadLinks(api, url) |                         validResults = loadLinks(api, url) | ||||||
|                         if (!validResults) continue |                         if (!validResults) continue | ||||||
|                     } |                     } | ||||||
|  | @ -176,6 +177,7 @@ class ProviderTests { | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     fun providerCorrect() { |     fun providerCorrect() { | ||||||
|  |         val invalidProvider = ArrayList<Pair<MainAPI,Exception?>>() | ||||||
|         val providers = getAllProviders() |         val providers = getAllProviders() | ||||||
|         providers.pmap { api -> |         providers.pmap { api -> | ||||||
|             try { |             try { | ||||||
|  | @ -184,10 +186,17 @@ class ProviderTests { | ||||||
|                     println("Success $api") |                     println("Success $api") | ||||||
|                 } else { |                 } else { | ||||||
|                     System.err.println("Error $api") |                     System.err.println("Error $api") | ||||||
|  |                     invalidProvider.add(Pair(api, null)) | ||||||
|                 } |                 } | ||||||
|             } catch (e: Exception) { |             } catch (e: Exception) { | ||||||
|                 logError(e) |                 logError(e) | ||||||
|  |                 invalidProvider.add(Pair(api,e)) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         println("Invalid providers are: ") | ||||||
|  |         for (provider in invalidProvider) { | ||||||
|  |             println("${provider.first}") | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue