From cd6c79b96187365ccf1f7290493f8db1195861bb Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Sun, 13 Feb 2022 15:51:55 +0100 Subject: [PATCH] fixed #652 (downloaded subtitles) and migration tool --- .../animeproviders/WcoProvider.kt | 4 +- .../ui/download/DownloadButtonSetup.kt | 3 +- .../ui/home/HomeParentItemAdapter.kt | 16 +++++- .../cloudstream3/ui/player/CS3IPlayer.kt | 15 +++--- .../ui/quicksearch/QuickSearchFragment.kt | 51 ++++++++++++------- .../cloudstream3/ui/result/EpisodeAdapter.kt | 2 +- .../cloudstream3/ui/result/ResultFragment.kt | 4 +- 7 files changed, 61 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt index 5f78caa2..e9266eab 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt @@ -124,7 +124,7 @@ class WcoProvider : MainAPI() { while (!document.select(".pagination").isEmpty()) { val link = document.select("a.page-link[rel=\"next\"]") - if (!link.isEmpty()) { + if (!link.isEmpty() && returnValue.size < 40) { val extraResponse = app.get(fixUrl(link[0].attr("href"))).text document = Jsoup.parse(extraResponse) returnValue.addAll(parseSearchPage(document)) @@ -132,7 +132,7 @@ class WcoProvider : MainAPI() { break } } - return returnValue + return returnValue.distinctBy { it.url } } override suspend fun quickSearch(query: String): List { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt index d844bd41..1ab9beb2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt @@ -129,8 +129,7 @@ object DownloadButtonSetup { displayName = keyInfo.displayName, relativePath = keyInfo.relativePath, ) - ), - 0 + ) ) ) //R.id.global_to_navigation_player, PlayerFragment.newInstance( diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt index 58df0b49..1a10a7cc 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt @@ -43,11 +43,23 @@ class ParentItemAdapter( } fun updateList(newList: List) { + // this moves all bad results to the bottom + val endList = mutableListOf() + val newFilteredList = mutableListOf() + for (item in newList) { + if(item.list.isEmpty()) { + endList.add(item) + } else { + newFilteredList.add(item) + } + } + newFilteredList.addAll(endList) + val diffResult = DiffUtil.calculateDiff( - SearchDiffCallback(this.items, newList)) + SearchDiffCallback(this.items, newFilteredList)) items.clear() - items.addAll(newList) + items.addAll(newFilteredList) diffResult.dispatchUpdatesTo(this) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index 97744299..e81834ab 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -120,14 +120,13 @@ class CS3IPlayer : IPlayer { Handler(it).post { try { seekTime(1L) - } catch (e : Exception) { + } catch (e: Exception) { logError(e) } } - } catch (e : Exception) { + } catch (e: Exception) { logError(e) } - } } @@ -287,7 +286,7 @@ class CS3IPlayer : IPlayer { } companion object { - var requestSubtitleUpdate : (() -> Unit)? = null + var requestSubtitleUpdate: (() -> Unit)? = null private fun createOnlineSource(link: ExtractorLink): DataSource.Factory { // Because Trailers.to seems to fail with http/1.1 the normal one uses. @@ -660,8 +659,8 @@ class CS3IPlayer : IPlayer { val offlineSourceFactory = context.createOfflineSource() val (subSources, activeSubtitles) = getSubSources( - offlineSourceFactory, - offlineSourceFactory, + onlineSourceFactory = offlineSourceFactory, + offlineSourceFactory = offlineSourceFactory, subtitleHelper, ) @@ -740,8 +739,8 @@ class CS3IPlayer : IPlayer { val offlineSourceFactory = context.createOfflineSource() val (subSources, activeSubtitles) = getSubSources( - offlineSourceFactory, - onlineSourceFactory, + onlineSourceFactory = onlineSourceFactory, + offlineSourceFactory = offlineSourceFactory, subtitleHelper ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt index 09c9e4fc..07314883 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/quicksearch/QuickSearchFragment.kt @@ -12,6 +12,8 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.lagradost.cloudstream3.APIHolder.apis +import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings import com.lagradost.cloudstream3.HomePageList import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.mvvm.Resource @@ -34,7 +36,16 @@ class QuickSearchFragment(var isMainApis: Boolean = false) : Fragment() { fun pushSearch(activity: Activity?, autoSearch: String? = null) { activity.navigate(R.id.global_to_navigation_quick_search, Bundle().apply { putBoolean("mainapi", true) - putString("autosearch", autoSearch) + autoSearch?.let { + putString( + "autosearch", + it.trim() + .removeSuffix("(DUB)") + .removeSuffix("(SUB)") + .removeSuffix("(Dub)") + .removeSuffix("(Sub)").trim() + ) + } }) } @@ -120,18 +131,24 @@ class QuickSearchFragment(var isMainApis: Boolean = false) : Fragment() { }) val searchExitIcon = - quick_search.findViewById(androidx.appcompat.R.id.search_close_btn) + quick_search?.findViewById(androidx.appcompat.R.id.search_close_btn) val searchMagIcon = - quick_search.findViewById(androidx.appcompat.R.id.search_mag_icon) + quick_search?.findViewById(androidx.appcompat.R.id.search_mag_icon) - searchMagIcon.scaleX = 0.65f - searchMagIcon.scaleY = 0.65f - quick_search.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + searchMagIcon?.scaleX = 0.65f + searchMagIcon?.scaleY = 0.65f + quick_search?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { + val active = if (isMainApis) { + val langs = context?.getApiProviderLangSettings() + apis.filter { langs?.contains(it.lang) == true }.map { it.name }.toSet() + } else emptySet() + searchViewModel.searchAndCancel( query = query, isMainApis = isMainApis, - ignoreSettings = true + ignoreSettings = false, + providersActive = active ) quick_search?.let { UIHelper.hideKeyboard(it) @@ -152,26 +169,26 @@ class QuickSearchFragment(var isMainApis: Boolean = false) : Fragment() { is Resource.Success -> { it.value.let { data -> if (data.isNotEmpty()) { - (search_autofit_results?.adapter as SearchAdapter?)?.updateList(data) + (search_autofit_results?.adapter as? SearchAdapter?)?.updateList(data) } } - searchExitIcon.alpha = 1f - quick_search_loading_bar.alpha = 0f + searchExitIcon?.alpha = 1f + quick_search_loading_bar?.alpha = 0f } is Resource.Failure -> { // Toast.makeText(activity, "Server error", Toast.LENGTH_LONG).show() - searchExitIcon.alpha = 1f - quick_search_loading_bar.alpha = 0f + searchExitIcon?.alpha = 1f + quick_search_loading_bar?.alpha = 0f } is Resource.Loading -> { - searchExitIcon.alpha = 0f - quick_search_loading_bar.alpha = 1f + searchExitIcon?.alpha = 0f + quick_search_loading_bar?.alpha = 1f } } } - quick_search_master_recycler.adapter = masterAdapter - quick_search_master_recycler.layoutManager = GridLayoutManager(context, 1) + quick_search_master_recycler?.adapter = masterAdapter + quick_search_master_recycler?.layoutManager = GridLayoutManager(context, 1) //quick_search.setOnQueryTextFocusChangeListener { _, b -> // if (b) { @@ -185,7 +202,7 @@ class QuickSearchFragment(var isMainApis: Boolean = false) : Fragment() { } arguments?.getString("autosearch")?.let { - quick_search.setQuery(it, true) + quick_search?.setQuery(it, true) arguments?.remove("autosearch") } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt index 21a375cb..c567bc16 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt @@ -223,7 +223,7 @@ class EpisodeAdapter( card.episode, card.season, card.id, - 0, + card.parentId, card.rating, card.description, System.currentTimeMillis(), diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index 05a29440..90a7ade9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -118,7 +118,7 @@ data class ResultEpisode( val description: String?, val isFiller: Boolean?, val tvType: TvType, - val parentId: Int?, + val parentId: Int, ) fun ResultEpisode.getRealPosition(): Long { @@ -151,7 +151,7 @@ fun buildResultEpisode( description: String?, isFiller: Boolean?, tvType: TvType, - parentId: Int?, + parentId: Int, ): ResultEpisode { val posDur = getViewPos(id) return ResultEpisode(