homepage improvements

This commit is contained in:
LagradOst 2021-07-29 02:54:27 +02:00
parent 61323b5c56
commit 684f2ed119
9 changed files with 88 additions and 51 deletions

View file

@ -125,6 +125,6 @@ class DownloadFragment : Fragment() {
download_list.layoutManager = GridLayoutManager(context, 1) download_list.layoutManager = GridLayoutManager(context, 1)
downloadsViewModel.updateList(requireContext()) downloadsViewModel.updateList(requireContext())
activity?.fixPaddingStatusbar(download_root) context?.fixPaddingStatusbar(download_root)
} }
} }

View file

@ -4,11 +4,14 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.UIHelper.loadResult
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.getKey
@ -54,9 +57,13 @@ class HomeFragment : Fragment() {
} }
} }
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> = ParentItemAdapter(listOf()) { val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> = ParentItemAdapter(listOf(), { card ->
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
}, {
} })
context?.fixPaddingStatusbar(home_root)
home_master_recycler.adapter = adapter home_master_recycler.adapter = adapter
home_master_recycler.layoutManager = GridLayoutManager(context, 1) home_master_recycler.layoutManager = GridLayoutManager(context, 1)

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.home
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -14,12 +15,13 @@ import kotlinx.android.synthetic.main.homepage_parent.view.*
class ParentItemAdapter( class ParentItemAdapter(
var itemList: List<HomePageList>, var itemList: List<HomePageList>,
private val clickCallback: (SearchResponse) -> Unit private val clickCallback: (SearchResponse) -> Unit,
private val moreInfoClickCallback: (List<SearchResponse>) -> Unit,
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, i: Int): ParentViewHolder { override fun onCreateViewHolder(parent: ViewGroup, i: Int): ParentViewHolder {
val layout = R.layout.homepage_parent val layout = R.layout.homepage_parent
return ParentViewHolder( return ParentViewHolder(
LayoutInflater.from(parent.context).inflate(layout, parent, false), clickCallback LayoutInflater.from(parent.context).inflate(layout, parent, false), clickCallback, moreInfoClickCallback
) )
} }
@ -36,16 +38,23 @@ class ParentItemAdapter(
} }
class ParentViewHolder class ParentViewHolder
constructor(itemView: View, private val clickCallback: (SearchResponse) -> Unit) : constructor(
itemView: View,
private val clickCallback: (SearchResponse) -> Unit,
private val moreInfoClickCallback: (List<SearchResponse>) -> Unit
) :
RecyclerView.ViewHolder(itemView) { RecyclerView.ViewHolder(itemView) {
val title: TextView = itemView.home_parent_item_title val title: TextView = itemView.home_parent_item_title
val recyclerView: RecyclerView = itemView.home_child_recyclerview val recyclerView: RecyclerView = itemView.home_child_recyclerview
private val moreInfo: FrameLayout = itemView.home_child_more_info
fun bind(info: HomePageList) { fun bind(info: HomePageList) {
title.text = info.name title.text = info.name
recyclerView.adapter = HomeChildItemAdapter(info.list, clickCallback) recyclerView.adapter = HomeChildItemAdapter(info.list, clickCallback)
recyclerView.layoutManager = GridLayoutManager(itemView.context, 1)
(recyclerView.adapter as HomeChildItemAdapter).notifyDataSetChanged() (recyclerView.adapter as HomeChildItemAdapter).notifyDataSetChanged()
moreInfo.setOnClickListener {
moreInfoClickCallback.invoke(info.list)
}
} }
} }
} }

View file

@ -1,21 +1,21 @@
package com.lagradost.cloudstream3.ui.search package com.lagradost.cloudstream3.ui.search
import android.app.Activity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.model.GlideUrl
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.AnimeSearchResponse
import com.lagradost.cloudstream3.DubStatus
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.UIHelper.getGridFormatId import com.lagradost.cloudstream3.UIHelper.getGridFormatId
import com.lagradost.cloudstream3.UIHelper.getGridIsCompact import com.lagradost.cloudstream3.UIHelper.getGridIsCompact
import com.lagradost.cloudstream3.UIHelper.loadResult
import com.lagradost.cloudstream3.UIHelper.toPx import com.lagradost.cloudstream3.UIHelper.toPx
import com.lagradost.cloudstream3.ui.AutofitRecyclerView import com.lagradost.cloudstream3.ui.AutofitRecyclerView
import kotlinx.android.synthetic.main.search_result_compact.view.backgroundCard import kotlinx.android.synthetic.main.search_result_compact.view.backgroundCard
@ -25,17 +25,17 @@ import kotlinx.android.synthetic.main.search_result_grid.view.*
import kotlin.math.roundToInt import kotlin.math.roundToInt
class SearchAdapter( class SearchAdapter(
private var activity: Activity,
var cardList: ArrayList<Any>, var cardList: ArrayList<Any>,
private val resView: AutofitRecyclerView, private val resView: AutofitRecyclerView,
) : private val clickCallback: (SearchResponse) -> Unit,
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() { RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val layout = parent.context.getGridFormatId() val layout = parent.context.getGridFormatId()
return CardViewHolder( return CardViewHolder(
LayoutInflater.from(parent.context).inflate(layout, parent, false), LayoutInflater.from(parent.context).inflate(layout, parent, false),
activity, clickCallback,
resView resView
) )
} }
@ -54,8 +54,8 @@ class SearchAdapter(
} }
class CardViewHolder class CardViewHolder
constructor(itemView: View, _activity: Activity, resView: AutofitRecyclerView) : RecyclerView.ViewHolder(itemView) { constructor(itemView: View, private val clickCallback: (SearchResponse) -> Unit, resView: AutofitRecyclerView) :
val activity = _activity RecyclerView.ViewHolder(itemView) {
val cardView: ImageView = itemView.imageView val cardView: ImageView = itemView.imageView
private val cardText: TextView = itemView.imageText private val cardText: TextView = itemView.imageText
private val textType: TextView? = itemView.text_type private val textType: TextView? = itemView.text_type
@ -100,14 +100,13 @@ class SearchAdapter(
val glideUrl = val glideUrl =
GlideUrl(card.posterUrl) GlideUrl(card.posterUrl)
Glide.with(cardView.context) Glide.with(cardView.context)
.load(glideUrl) .load(glideUrl)
.into(cardView) .into(cardView)
} }
bg.setOnClickListener { bg.setOnClickListener {
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName) clickCallback.invoke(card)
} }
when (card) { when (card) {

View file

@ -66,15 +66,16 @@ class SearchFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
activity?.fixPaddingStatusbar(searchRoot) context?.fixPaddingStatusbar(searchRoot)
fixGrid() fixGrid()
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>? = activity?.let { val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>? = activity?.let {
SearchAdapter( SearchAdapter(
it,
ArrayList(), ArrayList(),
cardSpace, cardSpace,
) ) { card ->
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
}
} }
cardSpace.adapter = adapter cardSpace.adapter = adapter
@ -90,7 +91,8 @@ class SearchFragment : Fragment() {
val apiNames = apis.map { it.name } val apiNames = apis.map { it.name }
val builder: AlertDialog.Builder = AlertDialog.Builder(requireContext()) val builder: AlertDialog.Builder = AlertDialog.Builder(requireContext())
builder.setMultiChoiceItems(apiNames.toTypedArray(), builder.setMultiChoiceItems(
apiNames.toTypedArray(),
apiNames.map { a -> apiNamesSetting.contains(a) }.toBooleanArray() apiNames.map { a -> apiNamesSetting.contains(a) }.toBooleanArray()
) { _, position: Int, checked: Boolean -> ) { _, position: Int, checked: Boolean ->
val apiNamesSettingLocal = activity?.getApiSettings() val apiNamesSettingLocal = activity?.getApiSettings()
@ -104,7 +106,8 @@ class SearchFragment : Fragment() {
val edit = settingsManagerLocal.edit() val edit = settingsManagerLocal.edit()
edit.putStringSet(getString(R.string.search_providers_list_key), edit.putStringSet(getString(R.string.search_providers_list_key),
apiNames.filter { a -> apiNamesSettingLocal.contains(a) }.toSet()) apiNames.filter { a -> apiNamesSettingLocal.contains(a) }.toSet()
)
edit.apply() edit.apply()
allApi.providersActive = apiNamesSettingLocal allApi.providersActive = apiNamesSettingLocal
} }
@ -131,8 +134,8 @@ class SearchFragment : Fragment() {
when (it) { when (it) {
is Resource.Success -> { is Resource.Success -> {
it.value.let { data -> it.value.let { data ->
if(data != null) { if (data != null) {
(cardSpace?.adapter as SearchAdapter?)?.cardList = ArrayList( data.filterNotNull()) (cardSpace?.adapter as SearchAdapter?)?.cardList = ArrayList(data.filterNotNull())
cardSpace?.adapter?.notifyDataSetChanged() cardSpace?.adapter?.notifyDataSetChanged()
} }
} }

View file

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" 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="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
</vector>

View file

@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/home_root"
android:orientation="vertical"
tools:context=".ui.home.HomeFragment"> tools:context=".ui.home.HomeFragment">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
@ -13,4 +16,4 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:listitem="@layout/homepage_parent" tools:listitem="@layout/homepage_parent"
/> />
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>

View file

@ -4,30 +4,40 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:orientation="vertical"
android:background="@color/colorPrimary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <FrameLayout
android:id="@+id/home_parent_item_title" android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:layout_width="wrap_content" android:id="@+id/home_child_more_info"
android:layout_height="wrap_content" android:padding="12dp"
android:padding="12sp" android:layout_width="match_parent"
android:textSize="18sp" android:layout_height="wrap_content">
tools:text="Trending" <TextView
/> android:id="@+id/home_parent_item_title"
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="230dp"
android:layout_marginBottom="20dp"
>
<androidx.recyclerview.widget.RecyclerView
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:id="@+id/home_child_recyclerview"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:listitem="@layout/home_result_grid" android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Trending"
/> />
</RelativeLayout> <ImageView
android:layout_marginEnd="5dp"
android:layout_gravity="end|center_vertical"
android:src="@drawable/ic_baseline_arrow_forward_24"
android:layout_width="30dp"
android:layout_height="match_parent" android:contentDescription="@string/home_more_info">
</ImageView>
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:id="@+id/home_child_recyclerview"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:listitem="@layout/home_result_grid"
/>
</LinearLayout> </LinearLayout>

View file

@ -54,4 +54,5 @@
<string name="acra_report_toast">Sorry, the application crashed. An anonymous bug report will be sent to the developers</string> <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="pref_disable_acra">Disable automatic bug reporting</string>
<string name="home_more_info">More info</string>
</resources> </resources>