mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
[Feature] Random button on Homepage. (#919)
* [Feature] Random button on Homepage. * commit missing edits * applied PR suggestions * [Feature] Add option to hide title on video player. * Toggle visibility of Random button on Homepage * fixes
This commit is contained in:
parent
83d8e2bb4d
commit
9fb4b74b79
8 changed files with 69 additions and 7 deletions
|
@ -15,6 +15,7 @@ import androidx.core.view.isVisible
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearSnapHelper
|
import androidx.recyclerview.widget.LinearSnapHelper
|
||||||
|
@ -97,6 +98,7 @@ class HomeFragment : Fragment() {
|
||||||
companion object {
|
companion object {
|
||||||
val configEvent = Event<Int>()
|
val configEvent = Event<Int>()
|
||||||
var currentSpan = 1
|
var currentSpan = 1
|
||||||
|
val listHomepageItems = mutableListOf<SearchResponse>()
|
||||||
|
|
||||||
fun Activity.loadHomepageList(item: HomePageList) {
|
fun Activity.loadHomepageList(item: HomePageList) {
|
||||||
val context = this
|
val context = this
|
||||||
|
@ -358,6 +360,7 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentApiName: String? = null
|
private var currentApiName: String? = null
|
||||||
|
private var toggleRandomButton = false
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
@ -367,6 +370,21 @@ class HomeFragment : Fragment() {
|
||||||
home_change_api?.setOnClickListener(apiChangeClickListener)
|
home_change_api?.setOnClickListener(apiChangeClickListener)
|
||||||
home_change_api_loading?.setOnClickListener(apiChangeClickListener)
|
home_change_api_loading?.setOnClickListener(apiChangeClickListener)
|
||||||
home_api_fab?.setOnClickListener(apiChangeClickListener)
|
home_api_fab?.setOnClickListener(apiChangeClickListener)
|
||||||
|
home_random?.setOnClickListener {
|
||||||
|
if (listHomepageItems.isNotEmpty()) {
|
||||||
|
activity.loadSearchResult(listHomepageItems.random())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Disable Random button, if its toggled off on settings
|
||||||
|
context?.let {
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(it)
|
||||||
|
toggleRandomButton = settingsManager.getBoolean(getString(R.string.random_button_key), false)
|
||||||
|
home_random?.isVisible = toggleRandomButton
|
||||||
|
if (!toggleRandomButton) {
|
||||||
|
home_random?.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
observe(homeViewModel.apiName) { apiName ->
|
observe(homeViewModel.apiName) { apiName ->
|
||||||
currentApiName = apiName
|
currentApiName = apiName
|
||||||
|
@ -441,11 +459,13 @@ class HomeFragment : Fragment() {
|
||||||
home_loading_shimmer?.stopShimmer()
|
home_loading_shimmer?.stopShimmer()
|
||||||
|
|
||||||
val d = data.value
|
val d = data.value
|
||||||
|
listHomepageItems.clear()
|
||||||
|
|
||||||
currentHomePage = d
|
currentHomePage = d
|
||||||
(home_master_recycler?.adapter as? ParentItemAdapter?)?.updateList(
|
(home_master_recycler?.adapter as? ParentItemAdapter?)?.updateList(
|
||||||
d?.items?.mapNotNull {
|
d?.items?.mapNotNull {
|
||||||
try {
|
try {
|
||||||
|
listHomepageItems.addAll(it.list.filterSearchResponse())
|
||||||
HomePageList(it.name, it.list.filterSearchResponse())
|
HomePageList(it.name, it.list.filterSearchResponse())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logError(e)
|
logError(e)
|
||||||
|
@ -456,6 +476,9 @@ class HomeFragment : Fragment() {
|
||||||
home_loading?.isVisible = false
|
home_loading?.isVisible = false
|
||||||
home_loading_error?.isVisible = false
|
home_loading_error?.isVisible = false
|
||||||
home_loaded?.isVisible = true
|
home_loaded?.isVisible = true
|
||||||
|
if (toggleRandomButton) {
|
||||||
|
home_random?.isVisible = listHomepageItems.isNotEmpty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is Resource.Failure -> {
|
is Resource.Failure -> {
|
||||||
home_loading_shimmer?.stopShimmer()
|
home_loading_shimmer?.stopShimmer()
|
||||||
|
@ -791,9 +814,11 @@ class HomeFragment : Fragment() {
|
||||||
val dy = scrollY - oldScrollY
|
val dy = scrollY - oldScrollY
|
||||||
if (dy > 0) { //check for scroll down
|
if (dy > 0) { //check for scroll down
|
||||||
home_api_fab?.shrink() // hide
|
home_api_fab?.shrink() // hide
|
||||||
|
home_random?.shrink()
|
||||||
} else if (dy < -5) {
|
} else if (dy < -5) {
|
||||||
if (view?.context?.isTvSettings() == false) {
|
if (view?.context?.isTvSettings() == false) {
|
||||||
home_api_fab?.extend() // show
|
home_api_fab?.extend() // show
|
||||||
|
home_random?.extend()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -499,13 +499,21 @@ open class FullScreenPlayer : AbstractPlayerFragment() {
|
||||||
|
|
||||||
private fun updateUIVisibility() {
|
private fun updateUIVisibility() {
|
||||||
val isGone = isLocked || !isShowing
|
val isGone = isLocked || !isShowing
|
||||||
|
var togglePlayerTitleGone = isGone
|
||||||
|
context?.let {
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(it)
|
||||||
|
val limitTitle = settingsManager.getInt(getString(R.string.prefer_limit_title_key), 0)
|
||||||
|
if (limitTitle < 0) {
|
||||||
|
togglePlayerTitleGone = true
|
||||||
|
}
|
||||||
|
}
|
||||||
player_lock_holder?.isGone = isGone
|
player_lock_holder?.isGone = isGone
|
||||||
player_video_bar?.isGone = isGone
|
player_video_bar?.isGone = isGone
|
||||||
player_pause_play_holder?.isGone = isGone
|
player_pause_play_holder?.isGone = isGone
|
||||||
player_pause_play?.isGone = isGone
|
player_pause_play?.isGone = isGone
|
||||||
//player_buffering?.isGone = isGone
|
//player_buffering?.isGone = isGone
|
||||||
player_top_holder?.isGone = isGone
|
player_top_holder?.isGone = isGone
|
||||||
player_video_title?.isGone = isGone
|
player_video_title?.isGone = togglePlayerTitleGone
|
||||||
player_video_title_rez?.isGone = isGone
|
player_video_title_rez?.isGone = isGone
|
||||||
player_episode_filler?.isGone = isGone
|
player_episode_filler?.isGone = isGone
|
||||||
player_center_menu?.isGone = isGone
|
player_center_menu?.isGone = isGone
|
||||||
|
|
|
@ -569,11 +569,17 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
//Truncate video title if it exceeds limit
|
|
||||||
val differenceInLength = playerVideoTitle.length - limitTitle
|
//Hide title, if set in setting
|
||||||
val margin = 3 //If the difference is smaller than or equal to this value, ignore it
|
if (limitTitle < 0) {
|
||||||
if (limitTitle > 0 && differenceInLength > margin) {
|
player_video_title?.visibility = View.GONE
|
||||||
playerVideoTitle = playerVideoTitle.substring(0, limitTitle - 1) + "..."
|
} else {
|
||||||
|
//Truncate video title if it exceeds limit
|
||||||
|
val differenceInLength = playerVideoTitle.length - limitTitle
|
||||||
|
val margin = 3 //If the difference is smaller than or equal to this value, ignore it
|
||||||
|
if (limitTitle > 0 && differenceInLength > margin) {
|
||||||
|
playerVideoTitle = playerVideoTitle.substring(0, limitTitle-1) + "..."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player_episode_filler_holder?.isVisible = isFiller ?: false
|
player_episode_filler_holder?.isVisible = isFiller ?: false
|
||||||
|
|
|
@ -512,4 +512,14 @@
|
||||||
style="@style/ExtendedFloatingActionButton"
|
style="@style/ExtendedFloatingActionButton"
|
||||||
android:textColor="?attr/textColor"
|
android:textColor="?attr/textColor"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible"
|
||||||
|
android:text="@string/home_random"
|
||||||
|
android:id="@+id/home_random"
|
||||||
|
android:layout_gravity="bottom|start"
|
||||||
|
app:icon="@drawable/ic_baseline_play_arrow_24"
|
||||||
|
style="@style/ExtendedFloatingActionButton"
|
||||||
|
android:textColor="?attr/textColor"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
|
@ -133,6 +133,7 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
android:visibility="visible"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:text="Hello world" />
|
tools:text="Hello world" />
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
<item>32 characters</item>
|
<item>32 characters</item>
|
||||||
<item>64 characters</item>
|
<item>64 characters</item>
|
||||||
<item>128 characters</item>
|
<item>128 characters</item>
|
||||||
|
<item>Hide Title</item>
|
||||||
</array>
|
</array>
|
||||||
<array name="limit_title_pref_values">
|
<array name="limit_title_pref_values">
|
||||||
<item>0</item>
|
<item>0</item>
|
||||||
|
@ -72,6 +73,7 @@
|
||||||
<item>32</item>
|
<item>32</item>
|
||||||
<item>64</item>
|
<item>64</item>
|
||||||
<item>128</item>
|
<item>128</item>
|
||||||
|
<item>-1</item>
|
||||||
</array>
|
</array>
|
||||||
|
|
||||||
<array name="video_buffer_length_names">
|
<array name="video_buffer_length_names">
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
<string name="swipe_vertical_enabled_key" translatable="false">swipe_vertical_enabled_key</string>
|
<string name="swipe_vertical_enabled_key" translatable="false">swipe_vertical_enabled_key</string>
|
||||||
<string name="display_sub_key" translatable="false">display_sub_key</string>
|
<string name="display_sub_key" translatable="false">display_sub_key</string>
|
||||||
<string name="show_fillers_key" translatable="false">show_fillers_key</string>
|
<string name="show_fillers_key" translatable="false">show_fillers_key</string>
|
||||||
|
<string name="random_button_key" translatable="false">random_button_key</string>
|
||||||
<string name="provider_lang_key" translatable="false">provider_lang_key</string>
|
<string name="provider_lang_key" translatable="false">provider_lang_key</string>
|
||||||
<string name="dns_key" translatable="false">dns_key</string>
|
<string name="dns_key" translatable="false">dns_key</string>
|
||||||
<string name="download_path_key" translatable="false">download_path_key</string>
|
<string name="download_path_key" translatable="false">download_path_key</string>
|
||||||
|
@ -352,7 +353,7 @@
|
||||||
<string name="skip_update">Skip this Update</string>
|
<string name="skip_update">Skip this Update</string>
|
||||||
<string name="update">Update</string>
|
<string name="update">Update</string>
|
||||||
<string name="watch_quality_pref">Preferred watch quality</string>
|
<string name="watch_quality_pref">Preferred watch quality</string>
|
||||||
<string name="limit_title">Limit title characters on player</string>
|
<string name="limit_title">Video player title max chars.</string>
|
||||||
<string name="video_buffer_size_settings">Video buffer size</string>
|
<string name="video_buffer_size_settings">Video buffer size</string>
|
||||||
<string name="video_buffer_length_settings">Video buffer length</string>
|
<string name="video_buffer_length_settings">Video buffer length</string>
|
||||||
<string name="video_buffer_disk_settings">Video cache on disk</string>
|
<string name="video_buffer_disk_settings">Video cache on disk</string>
|
||||||
|
@ -393,6 +394,8 @@
|
||||||
CloudStream 3 at your own risk.
|
CloudStream 3 at your own risk.
|
||||||
</string>
|
</string>
|
||||||
<string name="general">General</string>
|
<string name="general">General</string>
|
||||||
|
<string name="random_button_settings">Random Button</string>
|
||||||
|
<string name="random_button_settings_desc">Show random button on Homepage</string>
|
||||||
<string name="provider_lang_settings">Provider Languages</string>
|
<string name="provider_lang_settings">Provider Languages</string>
|
||||||
<string name="app_layout">App Layout</string>
|
<string name="app_layout">App Layout</string>
|
||||||
<string name="preferred_media_settings">Preferred Media</string>
|
<string name="preferred_media_settings">Preferred Media</string>
|
||||||
|
@ -467,6 +470,7 @@
|
||||||
<string name="actor_background">Background</string>
|
<string name="actor_background">Background</string>
|
||||||
|
|
||||||
<string name="home_source">Source</string>
|
<string name="home_source">Source</string>
|
||||||
|
<string name="home_random">Random</string>
|
||||||
|
|
||||||
<string name="coming_soon">Coming soon…</string>
|
<string name="coming_soon">Coming soon…</string>
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,12 @@
|
||||||
android:key="general"
|
android:key="general"
|
||||||
android:title="@string/general"
|
android:title="@string/general"
|
||||||
app:isPreferenceVisible="true">
|
app:isPreferenceVisible="true">
|
||||||
|
<SwitchPreference
|
||||||
|
android:icon="@drawable/ic_baseline_play_arrow_24"
|
||||||
|
app:key="@string/random_button_key"
|
||||||
|
android:title="@string/random_button_settings"
|
||||||
|
android:summary="@string/random_button_settings_desc"
|
||||||
|
app:defaultValue="false" />
|
||||||
<Preference
|
<Preference
|
||||||
android:icon="@drawable/ic_baseline_language_24"
|
android:icon="@drawable/ic_baseline_language_24"
|
||||||
android:key="@string/provider_lang_key"
|
android:key="@string/provider_lang_key"
|
||||||
|
|
Loading…
Reference in a new issue