general fixes to make app more primate friendly

This commit is contained in:
LagradOst 2021-11-09 22:15:11 +01:00
parent 97641d5459
commit 7466ecbc2f
7 changed files with 43 additions and 17 deletions

View File

@ -55,8 +55,8 @@ object APIHolder {
val restrictedApis = arrayListOf(
TrailersToProvider(), // be aware that this is fuckery
//NyaaProvider(), //torrents in cs3 is wack
ThenosProvider(),
// NyaaProvider(), // torrents in cs3 is wack
// ThenosProvider(), // ddos protection and wacked links
AsiaFlixProvider(),
)
@ -163,9 +163,12 @@ abstract class MainAPI {
/**Set false if links require referer or for some reason cant be played on a chromecast*/
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
/**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 hasQuickSearch = false

View File

@ -33,6 +33,9 @@ class ZoroProvider : MainAPI() {
override val hasDownloadSupport: Boolean
get() = true
override val usesWebView: Boolean
get() = true
override val supportedTypes: Set<TvType>
get() = setOf(
TvType.Anime,

View File

@ -31,6 +31,9 @@ class SflixProvider : MainAPI() {
override val hasDownloadSupport: Boolean
get() = true
override val usesWebView: Boolean
get() = true
override val supportedTypes: Set<TvType>
get() = setOf(
TvType.Movie,

View File

@ -108,7 +108,7 @@ class HomeFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
//homeViewModel =
// ViewModelProvider(this).get(HomeViewModel::class.java)
// ViewModelProvider(this).get(HomeViewModel::class.java)
return inflater.inflate(R.layout.fragment_home, container, false)
}
@ -123,10 +123,14 @@ class HomeFragment : Fragment() {
private fun chooseRandomMainPage() {
val home = currentHomePage
if (home != null && home.items.isNotEmpty()) {
val randomItems = home.items.shuffled().flatMap { it.list }.distinctBy { it.url }.toList().shuffled()
if (randomItems.isNullOrEmpty()) {
val currentList =
home.items.shuffled().filter { !it.list.isNullOrEmpty() }.flatMap { it.list }.distinctBy { it.url }
.toList()
if (currentList.isNullOrEmpty()) {
toggleMainVisibility(false)
} else {
val randomItems = currentList.shuffled()
val randomSize = randomItems.size
home_main_poster_recyclerview.adapter =
HomeChildItemAdapter(randomItems, R.layout.home_result_big_grid) { callback ->
@ -141,7 +145,7 @@ class HomeFragment : Fragment() {
manager.snap { dx ->
home_main_poster_recyclerview?.post {
// 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) {
val login = syncApi.loginInfo(ctx)
val pic = login?.profilePicture
if(pic != null) {
if (pic != null) {
home_profile_picture.setImage(pic)
home_profile_picture_holder.isVisible = true
break

View File

@ -25,7 +25,6 @@ import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.setKey
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.showMultiDialog
import com.lagradost.cloudstream3.utils.SubtitleHelper
@ -224,7 +223,8 @@ class SubtitlesFragment : Fragment() {
Pair(40, "40"),
)
textView.context.showBottomDialog(
//showBottomDialog
textView.context.showDialog(
elevationTypes.map { it.second },
elevationTypes.map { it.first }.indexOf(state.elevation),
(textView as TextView).text.toString(),
@ -254,7 +254,8 @@ class SubtitlesFragment : Fragment() {
Pair(CaptionStyleCompat.EDGE_TYPE_RAISED, "Raised"),
)
textView.context.showBottomDialog(
//showBottomDialog
textView.context.showDialog(
edgeTypes.map { it.second },
edgeTypes.map { it.first }.indexOf(state.edgeType),
(textView as TextView).text.toString(),
@ -304,7 +305,8 @@ class SubtitlesFragment : Fragment() {
Pair(60f,"60$suffix"),
)
textView.context.showBottomDialog(
//showBottomDialog
textView.context.showDialog(
fontSizes.map { it.second },
fontSizes.map { it.first }.indexOf(state.fixedTextSize),
(textView as TextView).text.toString(),
@ -341,7 +343,8 @@ class SubtitlesFragment : Fragment() {
Pair(R.font.poppins_regular, "Poppins"),
)
textView.context.showBottomDialog(
//showBottomDialog
textView.context.showDialog(
fontTypes.map { it.second },
fontTypes.map { it.first }.indexOf(state.typeface),
(textView as TextView).text.toString(),

View File

@ -129,6 +129,7 @@ object SingleSelectionHelper {
)
}
/** Only for a low amount of items */
fun Context.showBottomDialog(
items: List<String>,
selectedIndex: Int,
@ -149,7 +150,7 @@ object SingleSelectionHelper {
name,
showApply,
false,
{ callback.invoke(it.first()) },
{ if(it.isNotEmpty()) callback.invoke(it.first()) },
dismissCallback
)
}

View File

@ -11,7 +11,7 @@ class ProviderTests {
private fun getAllProviders(): List<MainAPI> {
val allApis = APIHolder.apis
allApis.addAll(APIHolder.restrictedApis)
return allApis
return allApis.filter { !it.usesWebView }
}
private fun loadLinks(api: MainAPI, url: String?): Boolean {
@ -80,13 +80,14 @@ class ProviderTests {
when (load) {
is AnimeLoadResponse -> {
val gotNoEpisodes =
load.dubEpisodes.isNullOrEmpty() && load.subEpisodes.isNullOrEmpty()
load.episodes.keys.isEmpty() || load.episodes.keys.any { load.episodes[it].isNullOrEmpty() }
if (gotNoEpisodes) {
println("Api ${api.name} got no episodes on ${load.url}")
continue
}
val url = (load.dubEpisodes ?: load.subEpisodes)?.first()?.url
val url = (load.episodes[load.episodes.keys.first()])?.first()?.url
validResults = loadLinks(api, url)
if (!validResults) continue
}
@ -176,6 +177,7 @@ class ProviderTests {
@Test
fun providerCorrect() {
val invalidProvider = ArrayList<Pair<MainAPI,Exception?>>()
val providers = getAllProviders()
providers.pmap { api ->
try {
@ -184,10 +186,17 @@ class ProviderTests {
println("Success $api")
} else {
System.err.println("Error $api")
invalidProvider.add(Pair(api, null))
}
} catch (e: Exception) {
logError(e)
invalidProvider.add(Pair(api,e))
}
}
println("Invalid providers are: ")
for (provider in invalidProvider) {
println("${provider.first}")
}
}
}