mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Tenshi recommendations + bug fixes
This commit is contained in:
parent
4120f8b865
commit
5053dff3f2
10 changed files with 57 additions and 37 deletions
|
@ -43,6 +43,7 @@ import com.lagradost.cloudstream3.utils.DataStore.removeKey
|
|||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setViewPos
|
||||
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.getResourceColor
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||
|
@ -195,6 +196,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
this.window?.navigationBarColor =
|
||||
this.colorFromAttribute(R.attr.primaryGrayBackground)
|
||||
this.updateLocale()
|
||||
backEvent.invoke(true)
|
||||
super.onBackPressed()
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.jsoup.nodes.Document
|
|||
import java.net.URI
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class TenshiProvider : MainAPI() {
|
||||
companion object {
|
||||
|
@ -256,10 +255,18 @@ class TenshiProvider : MainAPI() {
|
|||
)
|
||||
})
|
||||
|
||||
val similarAnime = document.select("ul.anime-loop > li > a")?.mapNotNull { element ->
|
||||
val href = element.attr("href") ?: return@mapNotNull null
|
||||
val title =
|
||||
element.selectFirst("> .overlay > .thumb-title")?.text() ?: return@mapNotNull null
|
||||
val img = element.selectFirst("> img")?.attr("src")
|
||||
AnimeSearchResponse(title, href, this.name, TvType.Anime, img)
|
||||
}
|
||||
|
||||
val type = document.selectFirst("a[href*=\"$mainUrl/type/\"]")?.text()?.trim()
|
||||
|
||||
return newAnimeLoadResponse(canonicalTitle, url, getType(type ?: "")) {
|
||||
recommendations = similarAnime
|
||||
posterUrl = document.selectFirst("img.cover-image")?.attr("src")
|
||||
plot = document.selectFirst(".entry-description > .card-body")?.text()?.trim()
|
||||
tags =
|
||||
|
|
|
@ -115,7 +115,7 @@ class HomeFragment : Fragment() {
|
|||
// Span settings
|
||||
recycle.spanCount = currentSpan
|
||||
|
||||
recycle.adapter = SearchAdapter(item.list, recycle) { callback ->
|
||||
recycle.adapter = SearchAdapter(item.list.toMutableList(), recycle) { callback ->
|
||||
handleSearchClickCallback(this, callback)
|
||||
if (callback.action == SEARCH_ACTION_LOAD || callback.action == SEARCH_ACTION_PLAY_FILE) {
|
||||
bottomSheetDialogBuilder.dismissSafe(this)
|
||||
|
|
|
@ -152,10 +152,7 @@ class QuickSearchFragment(var isMainApis: Boolean = false) : Fragment() {
|
|||
is Resource.Success -> {
|
||||
it.value.let { data ->
|
||||
if (data.isNotEmpty()) {
|
||||
(search_autofit_results?.adapter as SearchAdapter?)?.apply {
|
||||
cardList = data.toList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
(search_autofit_results?.adapter as SearchAdapter?)?.updateList(data)
|
||||
}
|
||||
}
|
||||
searchExitIcon.alpha = 1f
|
||||
|
|
|
@ -392,10 +392,6 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
downloadButton?.dispose()
|
||||
updateUIListener = null
|
||||
super.onDestroy()
|
||||
activity?.let {
|
||||
it.window?.navigationBarColor =
|
||||
it.colorFromAttribute(R.attr.primaryGrayBackground)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -499,18 +495,16 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
result_recommendations?.isGone = isInvalid
|
||||
result_recommendations_btt?.isGone = isInvalid
|
||||
result_recommendations_btt?.setOnClickListener {
|
||||
if(result_overlapping_panels?.getSelectedPanel()?.ordinal == 1) {
|
||||
if (result_overlapping_panels?.getSelectedPanel()?.ordinal == 1) {
|
||||
result_overlapping_panels?.openEndPanel()
|
||||
} else {
|
||||
result_overlapping_panels?.closePanels()
|
||||
}
|
||||
}
|
||||
result_overlapping_panels?.setEndPanelLockState(if (isInvalid) OverlappingPanelsLayout.LockState.CLOSE else OverlappingPanelsLayout.LockState.UNLOCKED)
|
||||
|
||||
rec?.let { list ->
|
||||
(result_recommendations?.adapter as SearchAdapter?)?.apply {
|
||||
cardList = list
|
||||
notifyDataSetChanged()
|
||||
result_recommendations.post {
|
||||
rec?.let { list ->
|
||||
(result_recommendations?.adapter as SearchAdapter?)?.updateList(list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -540,13 +534,12 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
|
||||
private fun updateUI() {
|
||||
viewModel.reloadEpisodes()
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
fixGrid()
|
||||
result_recommendations?.spanCount = 3
|
||||
result_overlapping_panels?.setStartPanelLockState(OverlappingPanelsLayout.LockState.CLOSE)
|
||||
|
@ -955,7 +948,6 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
|
|||
viewModel.loadEpisode(episodeClick.data, false)
|
||||
}
|
||||
|
||||
|
||||
ACTION_DOWNLOAD_MIRROR -> {
|
||||
acquireSingleExtractorLink(
|
||||
sortUrls(
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lagradost.cloudstream3.SearchResponse
|
||||
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||
|
@ -22,7 +23,7 @@ const val SEARCH_ACTION_FOCUSED = 4
|
|||
class SearchClickCallback(val action: Int, val view: View, val position : Int, val card: SearchResponse)
|
||||
|
||||
class SearchAdapter(
|
||||
var cardList: List<SearchResponse>,
|
||||
private val cardList: MutableList<SearchResponse>,
|
||||
private val resView: AutofitRecyclerView,
|
||||
private val clickCallback: (SearchClickCallback) -> Unit,
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
@ -48,6 +49,17 @@ class SearchAdapter(
|
|||
return cardList.size
|
||||
}
|
||||
|
||||
fun updateList(newList: List<SearchResponse>) {
|
||||
val diffResult = DiffUtil.calculateDiff(
|
||||
SearchResponseDiffCallback(this.cardList, newList)
|
||||
)
|
||||
|
||||
cardList.clear()
|
||||
cardList.addAll(newList)
|
||||
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
}
|
||||
|
||||
class CardViewHolder
|
||||
constructor(
|
||||
itemView: View,
|
||||
|
@ -74,3 +86,16 @@ class SearchAdapter(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SearchResponseDiffCallback(private val oldList: List<SearchResponse>, private val newList: List<SearchResponse>) :
|
||||
DiffUtil.Callback() {
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) =
|
||||
oldList[oldItemPosition].name == newList[newItemPosition].name
|
||||
|
||||
override fun getOldListSize() = oldList.size
|
||||
|
||||
override fun getNewListSize() = newList.size
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) =
|
||||
oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
|
@ -346,10 +346,7 @@ class SearchFragment : Fragment() {
|
|||
is Resource.Success -> {
|
||||
it.value.let { data ->
|
||||
if (data.isNotEmpty()) {
|
||||
(search_autofit_results?.adapter as SearchAdapter?)?.apply {
|
||||
cardList = data.toList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
(search_autofit_results?.adapter as SearchAdapter?)?.updateList(data)
|
||||
}
|
||||
}
|
||||
searchExitIcon.alpha = 1f
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.widget.ImageView
|
|||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.core.view.isVisible
|
||||
import com.lagradost.cloudstream3.*
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
|
||||
|
@ -40,17 +41,15 @@ object SearchResultBuilder {
|
|||
|
||||
// Do logic
|
||||
|
||||
bar?.visibility = View.GONE
|
||||
playImg?.visibility = View.GONE
|
||||
textIsDub?.visibility = View.GONE
|
||||
textIsSub?.visibility = View.GONE
|
||||
bar?.isVisible = false
|
||||
playImg?.isVisible = false
|
||||
textIsDub?.isVisible = false
|
||||
textIsSub?.isVisible = false
|
||||
|
||||
cardText?.text = card.name
|
||||
|
||||
//imageTextProvider.text = card.apiName
|
||||
if (!card.posterUrl.isNullOrEmpty()) {
|
||||
cardView.setImage(card.posterUrl)
|
||||
} else {
|
||||
cardView.isVisible = true
|
||||
if (!cardView.setImage(card.posterUrl)) {
|
||||
cardView.setImageResource(R.drawable.default_cover)
|
||||
}
|
||||
|
||||
|
|
|
@ -119,16 +119,18 @@ object UIHelper {
|
|||
return color
|
||||
}
|
||||
|
||||
fun ImageView?.setImage(url: String?) {
|
||||
if (this == null || url.isNullOrBlank()) return
|
||||
try {
|
||||
fun ImageView?.setImage(url: String?) : Boolean {
|
||||
if (this == null || url.isNullOrBlank()) return false
|
||||
return try {
|
||||
GlideApp.with(this.context)
|
||||
.load(GlideUrl(url)).transition(
|
||||
DrawableTransitionOptions.withCrossFade()
|
||||
)
|
||||
.into(this)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
logError(e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,10 @@
|
|||
app:shimmer_highlight_alpha="0.3"
|
||||
app:shimmer_duration="@integer/loading_time"
|
||||
app:shimmer_auto_start="true"
|
||||
android:paddingTop="40dp"
|
||||
android:id="@+id/result_loading"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="15dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
|
Loading…
Reference in a new issue