forked from recloudstream/cloudstream
homepage random main
This commit is contained in:
parent
545f1ab793
commit
3bbcdfef1f
7 changed files with 237 additions and 14 deletions
|
@ -101,6 +101,10 @@ object UIHelper {
|
|||
}
|
||||
}
|
||||
|
||||
fun Activity?.loadSearchResult(card : SearchResponse) {
|
||||
(this as AppCompatActivity?)?.loadResult(card.url, card.slug, card.apiName)
|
||||
}
|
||||
|
||||
fun Context.getStatusBarHeight(): Int {
|
||||
var result = 0
|
||||
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
package com.lagradost.cloudstream3.ui.home
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
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.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.lagradost.cloudstream3.AnimeSearchResponse
|
||||
import com.lagradost.cloudstream3.HomePageResponse
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.SearchResponse
|
||||
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
|
||||
import com.lagradost.cloudstream3.UIHelper.getGridIsCompact
|
||||
import com.lagradost.cloudstream3.UIHelper.loadResult
|
||||
import com.lagradost.cloudstream3.UIHelper.loadSearchResult
|
||||
import com.lagradost.cloudstream3.mvvm.Resource
|
||||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||
|
@ -42,6 +48,67 @@ class HomeFragment : Fragment() {
|
|||
|
||||
private val configEvent = Event<Int>()
|
||||
private var currentSpan = 1
|
||||
private var currentHomePage: HomePageResponse? = null
|
||||
var currentMainIndex = 0
|
||||
var currentMainList: ArrayList<SearchResponse> = ArrayList()
|
||||
|
||||
private fun toggleMainVisibility(visible: Boolean) {
|
||||
home_main_holder.visibility = if (visible) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun chooseRandomMainPage(item: SearchResponse? = null): SearchResponse? {
|
||||
val home = currentHomePage
|
||||
if (home != null && home.items.isNotEmpty()) {
|
||||
var random: SearchResponse? = item
|
||||
|
||||
var breakCount = 0
|
||||
val MAX_BREAK_COUNT = 10
|
||||
|
||||
while (random?.posterUrl == null) {
|
||||
random = home.items.random().list.random()
|
||||
breakCount++
|
||||
if (breakCount > MAX_BREAK_COUNT) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (random?.posterUrl != null) {
|
||||
home_main_poster.setOnClickListener {
|
||||
activity.loadSearchResult(random)
|
||||
}
|
||||
home_main_play.setOnClickListener {
|
||||
activity.loadSearchResult(random)
|
||||
}
|
||||
home_main_info.setOnClickListener {
|
||||
activity.loadSearchResult(random)
|
||||
}
|
||||
|
||||
home_main_text.text = random.name + if (random is AnimeSearchResponse) {
|
||||
random.dubStatus?.joinToString(prefix = " • ", separator = " | ") { it.name }
|
||||
} else ""
|
||||
val glideUrl =
|
||||
GlideUrl(random.posterUrl)
|
||||
requireContext().let {
|
||||
Glide.with(it)
|
||||
.load(glideUrl)
|
||||
.into(home_main_poster)
|
||||
/*
|
||||
Glide.with(it)
|
||||
.load(glideUrl)
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(80, 3)))
|
||||
.into(result_poster_blur)*/
|
||||
}
|
||||
|
||||
toggleMainVisibility(true)
|
||||
return random
|
||||
} else {
|
||||
toggleMainVisibility(false)
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun fixGrid() {
|
||||
val compactView = activity?.getGridIsCompact() ?: false
|
||||
|
@ -66,6 +133,30 @@ class HomeFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
fixGrid()
|
||||
|
||||
home_reroll_next.setOnClickListener {
|
||||
currentMainIndex++
|
||||
if (currentMainIndex >= currentMainList.size) {
|
||||
val newItem = chooseRandomMainPage()
|
||||
if (newItem != null) {
|
||||
currentMainList.add(newItem)
|
||||
}
|
||||
currentMainIndex = currentMainList.size - 1
|
||||
}
|
||||
chooseRandomMainPage(currentMainList[currentMainIndex])
|
||||
}
|
||||
|
||||
home_reroll_prev.setOnClickListener {
|
||||
currentMainIndex--
|
||||
if (currentMainIndex < 0) {
|
||||
val newItem = chooseRandomMainPage()
|
||||
if (newItem != null) {
|
||||
currentMainList.add(0, newItem)
|
||||
}
|
||||
currentMainIndex = 0
|
||||
}
|
||||
chooseRandomMainPage(currentMainList[currentMainIndex])
|
||||
}
|
||||
|
||||
observe(homeViewModel.apiName) {
|
||||
context?.setKey(HOMEPAGE_API, it)
|
||||
}
|
||||
|
@ -74,8 +165,14 @@ class HomeFragment : Fragment() {
|
|||
when (it) {
|
||||
is Resource.Success -> {
|
||||
val d = it.value
|
||||
currentHomePage = d
|
||||
(home_master_recycler?.adapter as ParentItemAdapter?)?.items = d.items
|
||||
home_master_recycler?.adapter?.notifyDataSetChanged()
|
||||
currentMainList.clear()
|
||||
chooseRandomMainPage()?.let { response ->
|
||||
currentMainList.add(response)
|
||||
}
|
||||
currentMainIndex = 0
|
||||
}
|
||||
is Resource.Failure -> {
|
||||
|
||||
|
@ -87,20 +184,25 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
|
||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> = ParentItemAdapter(listOf(), { card ->
|
||||
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
|
||||
activity.loadSearchResult(card)
|
||||
}, { 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)!!
|
||||
val titleHolder = bottomSheetDialogBuilder.findViewById<FrameLayout>(R.id.home_expanded_drag_down)!!
|
||||
|
||||
titleHolder.setOnClickListener {
|
||||
bottomSheetDialogBuilder.dismiss()
|
||||
}
|
||||
|
||||
// Span settings
|
||||
recycle.spanCount = currentSpan
|
||||
|
||||
recycle.adapter = SearchAdapter(item.list, recycle) { card ->
|
||||
bottomSheetDialogBuilder.dismiss()
|
||||
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
|
||||
activity.loadSearchResult(card)
|
||||
}
|
||||
|
||||
val spanListener = { span: Int ->
|
||||
|
|
|
@ -24,6 +24,7 @@ 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.UIHelper.loadSearchResult
|
||||
import com.lagradost.cloudstream3.mvvm.Resource
|
||||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import kotlinx.android.synthetic.main.fragment_search.*
|
||||
|
@ -74,7 +75,7 @@ class SearchFragment : Fragment() {
|
|||
ArrayList(),
|
||||
cardSpace,
|
||||
) { card ->
|
||||
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
|
||||
activity.loadSearchResult(card)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
5
app/src/main/res/drawable/ic_outline_info_24.xml
Normal file
5
app/src/main/res/drawable/ic_outline_info_24.xml
Normal file
|
@ -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="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
|
||||
</vector>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
<androidx.core.widget.NestedScrollView
|
||||
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"
|
||||
|
@ -7,13 +7,118 @@
|
|||
android:layout_height="match_parent"
|
||||
|
||||
android:id="@+id/home_root"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ui.home.HomeFragment">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/home_main_holder"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:layout_marginTop="10dp"
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:id="@+id/home_main_poster"
|
||||
tools:src="@drawable/example_poster"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="212dp"
|
||||
android:contentDescription="@string/home_main_poster">
|
||||
</ImageView>
|
||||
<TextView
|
||||
android:id="@+id/home_main_text"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
tools:text="Perfect Run"
|
||||
android:textStyle="bold"
|
||||
android:layout_margin="5dp"
|
||||
android:textSize="15sp"
|
||||
android:textColor="@color/textColor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<LinearLayout
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:id="@+id/home_reroll_prev"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_baseline_arrow_back_24"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:padding="10dp"
|
||||
android:contentDescription="@string/home_next_random">
|
||||
</ImageView>
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:layout_margin="5dp"
|
||||
android:visibility="visible"
|
||||
android:layout_gravity="center"
|
||||
app:cornerRadius="4dp"
|
||||
android:id="@+id/home_main_play"
|
||||
android:text="@string/home_play"
|
||||
android:textStyle="bold"
|
||||
|
||||
app:rippleColor="?attr/grayBackground"
|
||||
android:textColor="?attr/grayBackground"
|
||||
app:iconTint="?attr/grayBackground"
|
||||
android:textAllCaps="false"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
app:iconGravity="textStart"
|
||||
app:strokeColor="?attr/grayBackground"
|
||||
app:backgroundTint="?attr/textColor"
|
||||
app:icon="@drawable/ic_baseline_play_arrow_24"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="50dp">
|
||||
</com.google.android.material.button.MaterialButton>
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:layout_margin="5dp"
|
||||
android:visibility="visible"
|
||||
android:layout_gravity="center"
|
||||
app:cornerRadius="4dp"
|
||||
android:text="@string/home_info"
|
||||
app:icon="@drawable/ic_outline_info_24"
|
||||
android:textStyle="bold"
|
||||
|
||||
android:id="@+id/home_main_info"
|
||||
app:rippleColor="?attr/textColor"
|
||||
android:textColor="?attr/textColor"
|
||||
app:iconTint="?attr/textColor"
|
||||
android:textAllCaps="false"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:backgroundTint="?attr/grayBackground"
|
||||
app:iconGravity="textStart"
|
||||
app:strokeColor="?attr/textColor"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="50dp">
|
||||
</com.google.android.material.button.MaterialButton>
|
||||
<ImageView
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="2dp"
|
||||
android:id="@+id/home_reroll_next"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_baseline_arrow_forward_24"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:padding="10dp"
|
||||
android:contentDescription="@string/home_next_random">
|
||||
</ImageView>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/home_master_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/homepage_parent"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
|
@ -8,6 +8,8 @@
|
|||
android:layout_height="wrap_content">
|
||||
|
||||
<FrameLayout
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:id="@+id/home_expanded_drag_down"
|
||||
android:padding="12dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
|
|
@ -56,4 +56,8 @@
|
|||
<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>
|
||||
<string name="home_main_poster">Main Poster</string>
|
||||
<string name="home_play">Play</string>
|
||||
<string name="home_info">Info</string>
|
||||
<string name="home_next_random">Next Random</string>
|
||||
</resources>
|
Loading…
Reference in a new issue