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)
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.View
import android.view.ViewGroup
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.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.observe
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.layoutManager = GridLayoutManager(context, 1)

View file

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

View file

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

View file

@ -66,15 +66,16 @@ class SearchFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.fixPaddingStatusbar(searchRoot)
context?.fixPaddingStatusbar(searchRoot)
fixGrid()
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder>? = activity?.let {
SearchAdapter(
it,
ArrayList(),
cardSpace,
)
) { card ->
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
}
}
cardSpace.adapter = adapter
@ -90,7 +91,8 @@ class SearchFragment : Fragment() {
val apiNames = apis.map { it.name }
val builder: AlertDialog.Builder = AlertDialog.Builder(requireContext())
builder.setMultiChoiceItems(apiNames.toTypedArray(),
builder.setMultiChoiceItems(
apiNames.toTypedArray(),
apiNames.map { a -> apiNamesSetting.contains(a) }.toBooleanArray()
) { _, position: Int, checked: Boolean ->
val apiNamesSettingLocal = activity?.getApiSettings()
@ -104,7 +106,8 @@ class SearchFragment : Fragment() {
val edit = settingsManagerLocal.edit()
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()
allApi.providersActive = apiNamesSettingLocal
}

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"?>
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/home_root"
android:orientation="vertical"
tools:context=".ui.home.HomeFragment">
<androidx.recyclerview.widget.RecyclerView
@ -13,4 +16,4 @@
android:layout_height="match_parent"
tools:listitem="@layout/homepage_parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View file

@ -4,23 +4,34 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:id="@+id/home_child_more_info"
android:padding="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/home_parent_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12sp"
android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Trending"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="230dp"
android:layout_marginBottom="20dp"
>
<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"
@ -29,5 +40,4 @@
android:layout_height="wrap_content"
tools:listitem="@layout/home_result_grid"
/>
</RelativeLayout>
</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="pref_disable_acra">Disable automatic bug reporting</string>
<string name="home_more_info">More info</string>
</resources>