forked from recloudstream/cloudstream
homepage working
This commit is contained in:
parent
684f2ed119
commit
545f1ab793
10 changed files with 200 additions and 105 deletions
|
@ -1,23 +1,29 @@
|
|||
package com.lagradost.cloudstream3.ui.home
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
|
||||
import com.lagradost.cloudstream3.UIHelper.getGridIsCompact
|
||||
import com.lagradost.cloudstream3.UIHelper.loadResult
|
||||
import com.lagradost.cloudstream3.mvvm.Resource
|
||||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||
import com.lagradost.cloudstream3.ui.search.SearchAdapter
|
||||
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.HOMEPAGE_API
|
||||
import kotlinx.android.synthetic.main.fragment_child_downloads.*
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
@ -34,8 +40,31 @@ class HomeFragment : Fragment() {
|
|||
return inflater.inflate(R.layout.fragment_home, container, false)
|
||||
}
|
||||
|
||||
private val configEvent = Event<Int>()
|
||||
private var currentSpan = 1
|
||||
|
||||
private fun fixGrid() {
|
||||
val compactView = activity?.getGridIsCompact() ?: false
|
||||
val spanCountLandscape = if (compactView) 2 else 6
|
||||
val spanCountPortrait = if (compactView) 1 else 3
|
||||
val orientation = resources.configuration.orientation
|
||||
|
||||
currentSpan = if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
spanCountLandscape
|
||||
} else {
|
||||
spanCountPortrait
|
||||
}
|
||||
configEvent.invoke(currentSpan)
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
fixGrid()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
fixGrid()
|
||||
|
||||
observe(homeViewModel.apiName) {
|
||||
context?.setKey(HOMEPAGE_API, it)
|
||||
|
@ -45,7 +74,7 @@ class HomeFragment : Fragment() {
|
|||
when (it) {
|
||||
is Resource.Success -> {
|
||||
val d = it.value
|
||||
(home_master_recycler?.adapter as ParentItemAdapter?)?.itemList = d.items
|
||||
(home_master_recycler?.adapter as ParentItemAdapter?)?.items = d.items
|
||||
home_master_recycler?.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
is Resource.Failure -> {
|
||||
|
@ -59,8 +88,35 @@ class HomeFragment : Fragment() {
|
|||
|
||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> = ParentItemAdapter(listOf(), { card ->
|
||||
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
|
||||
}, {
|
||||
}, { item ->
|
||||
val bottomSheetDialogBuilder = BottomSheetDialog(view.context)
|
||||
bottomSheetDialogBuilder.setContentView(R.layout.home_episodes_expanded)
|
||||
val title = bottomSheetDialogBuilder.findViewById<TextView>(R.id.home_expanded_text)!!
|
||||
title.text = item.name
|
||||
val recycle = bottomSheetDialogBuilder.findViewById<AutofitRecyclerView>(R.id.home_expanded_recycler)!!
|
||||
|
||||
// Span settings
|
||||
recycle.spanCount = currentSpan
|
||||
|
||||
recycle.adapter = SearchAdapter(item.list, recycle) { card ->
|
||||
bottomSheetDialogBuilder.dismiss()
|
||||
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
|
||||
}
|
||||
|
||||
val spanListener = { span: Int ->
|
||||
recycle.spanCount = span
|
||||
(recycle.adapter as SearchAdapter).notifyDataSetChanged()
|
||||
}
|
||||
|
||||
configEvent += spanListener
|
||||
|
||||
bottomSheetDialogBuilder.setOnDismissListener {
|
||||
configEvent -= spanListener
|
||||
}
|
||||
|
||||
(recycle.adapter as SearchAdapter).notifyDataSetChanged()
|
||||
|
||||
bottomSheetDialogBuilder.show()
|
||||
})
|
||||
|
||||
context?.fixPaddingStatusbar(home_root)
|
||||
|
|
|
@ -5,18 +5,16 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lagradost.cloudstream3.HomePageList
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.SearchResponse
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
import kotlinx.android.synthetic.main.homepage_parent.view.*
|
||||
|
||||
class ParentItemAdapter(
|
||||
var itemList: List<HomePageList>,
|
||||
var items: List<HomePageList>,
|
||||
private val clickCallback: (SearchResponse) -> Unit,
|
||||
private val moreInfoClickCallback: (List<SearchResponse>) -> Unit,
|
||||
private val moreInfoClickCallback: (HomePageList) -> Unit,
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, i: Int): ParentViewHolder {
|
||||
val layout = R.layout.homepage_parent
|
||||
|
@ -28,20 +26,20 @@ class ParentItemAdapter(
|
|||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (holder) {
|
||||
is ParentViewHolder -> {
|
||||
holder.bind(itemList[position])
|
||||
holder.bind(items[position])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return itemList.size
|
||||
return items.size
|
||||
}
|
||||
|
||||
class ParentViewHolder
|
||||
constructor(
|
||||
itemView: View,
|
||||
private val clickCallback: (SearchResponse) -> Unit,
|
||||
private val moreInfoClickCallback: (List<SearchResponse>) -> Unit
|
||||
private val moreInfoClickCallback: (HomePageList) -> Unit
|
||||
) :
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
val title: TextView = itemView.home_parent_item_title
|
||||
|
@ -53,7 +51,7 @@ class ParentItemAdapter(
|
|||
(recyclerView.adapter as HomeChildItemAdapter).notifyDataSetChanged()
|
||||
|
||||
moreInfo.setOnClickListener {
|
||||
moreInfoClickCallback.invoke(info.list)
|
||||
moreInfoClickCallback.invoke(info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,10 @@ import kotlinx.android.synthetic.main.search_result_grid.view.*
|
|||
import kotlin.math.roundToInt
|
||||
|
||||
class SearchAdapter(
|
||||
var cardList: ArrayList<Any>,
|
||||
var cardList: List<SearchResponse>,
|
||||
private val resView: AutofitRecyclerView,
|
||||
private val clickCallback: (SearchResponse) -> Unit,
|
||||
) :
|
||||
) :
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
|
@ -70,8 +70,7 @@ class SearchAdapter(
|
|||
private val compactView = itemView.context.getGridIsCompact()
|
||||
private val coverHeight: Int = if (compactView) 80.toPx else (resView.itemWidth / 0.68).roundToInt()
|
||||
|
||||
fun bind(card: Any) {
|
||||
if (card is SearchResponse) { // GENERIC
|
||||
fun bind(card: SearchResponse) {
|
||||
if (!compactView) {
|
||||
cardView.apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
|
@ -122,7 +121,7 @@ class SearchAdapter(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ class SearchFragment : Fragment() {
|
|||
is Resource.Success -> {
|
||||
it.value.let { data ->
|
||||
if (data != null) {
|
||||
(cardSpace?.adapter as SearchAdapter?)?.cardList = ArrayList(data.filterNotNull())
|
||||
(cardSpace?.adapter as SearchAdapter?)?.cardList = data.filterNotNull()
|
||||
cardSpace?.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,15 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.lagradost.cloudstream3.APIHolder.allApi
|
||||
import com.lagradost.cloudstream3.SearchResponse
|
||||
import com.lagradost.cloudstream3.mvvm.Resource
|
||||
import com.lagradost.cloudstream3.mvvm.safeApiCall
|
||||
import com.lagradost.cloudstream3.ui.APIRepository
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class SearchViewModel : ViewModel() {
|
||||
private val _searchResponse: MutableLiveData<Resource<ArrayList<Any>>> = MutableLiveData()
|
||||
val searchResponse: LiveData<Resource<ArrayList<Any>>> get() = _searchResponse
|
||||
private val _searchResponse: MutableLiveData<Resource<ArrayList<SearchResponse>>> = MutableLiveData()
|
||||
val searchResponse: LiveData<Resource<ArrayList<SearchResponse>>> get() = _searchResponse
|
||||
var searchCounter = 0
|
||||
private val repo = APIRepository(allApi)
|
||||
|
||||
|
@ -31,7 +32,7 @@ class SearchViewModel : ViewModel() {
|
|||
val data = repo.search(query)
|
||||
|
||||
if(localSearchCounter != searchCounter) return@launch
|
||||
_searchResponse.postValue(data as Resource<ArrayList<Any>>?)
|
||||
_searchResponse.postValue(data)
|
||||
}
|
||||
|
||||
fun quickSearch(query: String) = viewModelScope.launch {
|
||||
|
@ -45,6 +46,6 @@ class SearchViewModel : ViewModel() {
|
|||
val data = repo.quickSearch(query)
|
||||
|
||||
if(localSearchCounter != searchCounter) return@launch
|
||||
_searchResponse.postValue(data as Resource<ArrayList<Any>>?)
|
||||
_searchResponse.postValue(data)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z"/>
|
||||
</vector>
|
|
@ -1,20 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/homeRoot"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||
android:paddingTop="0dp">
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/homeRoot"
|
||||
>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout android:layout_height="match_parent"
|
||||
android:layout_width="match_parent">
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="0dp"
|
||||
|
@ -55,5 +51,4 @@
|
|||
</fragment>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
|
@ -71,6 +71,7 @@
|
|||
app:spanCount="3"
|
||||
android:paddingEnd="8dp"
|
||||
android:id="@+id/cardSpace"
|
||||
tools:listitem="@layout/search_result_grid"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
</com.lagradost.cloudstream3.ui.AutofitRecyclerView>
|
||||
|
|
39
app/src/main/res/layout/home_episodes_expanded.xml
Normal file
39
app/src/main/res/layout/home_episodes_expanded.xml
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:background="?attr/darkBackground"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<FrameLayout
|
||||
android:padding="12dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/home_expanded_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/textColor"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="Trending"
|
||||
/>
|
||||
<ImageView
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:src="@drawable/ic_baseline_keyboard_arrow_down_24"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/home_expanded_hide">
|
||||
</ImageView>
|
||||
</FrameLayout>
|
||||
<com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/home_expanded_recycler"
|
||||
tools:listitem="@layout/search_result_grid"
|
||||
/>
|
||||
</LinearLayout>
|
|
@ -55,4 +55,5 @@
|
|||
<string name="acra_report_toast">Sorry, the application crashed. An anonymous bug report will be sent to the developers</string>
|
||||
<string name="pref_disable_acra">Disable automatic bug reporting</string>
|
||||
<string name="home_more_info">More info</string>
|
||||
<string name="home_expanded_hide">Hide</string>
|
||||
</resources>
|
Loading…
Reference in a new issue