Use TV results layout on emulator (#710)

* Use TV results layout on emulator

* Add subscription support to emulator

* Update
This commit is contained in:
Luna712 2023-10-28 17:20:04 -06:00 committed by GitHub
parent 137d833d4a
commit f0e429436f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 4 deletions

View file

@ -28,6 +28,7 @@ import com.lagradost.cloudstream3.databinding.FragmentResultTvBinding
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.mvvm.observeNullable import com.lagradost.cloudstream3.mvvm.observeNullable
import com.lagradost.cloudstream3.services.SubscriptionWorkManager
import com.lagradost.cloudstream3.ui.WatchType import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup
import com.lagradost.cloudstream3.ui.player.ExtractorLinkGenerator import com.lagradost.cloudstream3.ui.player.ExtractorLinkGenerator
@ -37,6 +38,7 @@ import com.lagradost.cloudstream3.ui.result.ResultFragment.updateUIEvent
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_FOCUSED import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_FOCUSED
import com.lagradost.cloudstream3.ui.search.SearchAdapter import com.lagradost.cloudstream3.ui.search.SearchAdapter
import com.lagradost.cloudstream3.ui.search.SearchHelper import com.lagradost.cloudstream3.ui.search.SearchHelper
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isEmulatorSettings
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
import com.lagradost.cloudstream3.utils.AppUtils.html import com.lagradost.cloudstream3.utils.AppUtils.html
import com.lagradost.cloudstream3.utils.AppUtils.isRtl import com.lagradost.cloudstream3.utils.AppUtils.isRtl
@ -287,7 +289,8 @@ class ResultFragmentTv : Fragment() {
resultResumeSeries, resultResumeSeries,
resultPlayTrailer, resultPlayTrailer,
resultBookmarkButton, resultBookmarkButton,
resultFavoriteButton resultFavoriteButton,
resultSubscribeButton
) )
for (requestView in views) { for (requestView in views) {
if (!requestView.isVisible) continue if (!requestView.isVisible) continue
@ -429,6 +432,7 @@ class ResultFragmentTv : Fragment() {
binding?.resultEpisodesShow, binding?.resultEpisodesShow,
binding?.resultBookmarkButton, binding?.resultBookmarkButton,
binding?.resultFavoriteButton, binding?.resultFavoriteButton,
binding?.resultSubscribeButton,
).firstOrNull { ).firstOrNull {
it?.isVisible == true it?.isVisible == true
} }
@ -574,6 +578,45 @@ class ResultFragmentTv : Fragment() {
} }
} }
observeNullable(viewModel.subscribeStatus) { isSubscribed ->
binding?.resultSubscribeButton?.apply {
isVisible = isSubscribed != null && context.isEmulatorSettings()
if (isSubscribed == null) return@observeNullable
val drawable = if (isSubscribed) {
R.drawable.ic_baseline_notifications_active_24
} else {
R.drawable.baseline_notifications_none_24
}
val text = if (isSubscribed) {
R.string.action_unsubscribe
} else {
R.string.action_subscribe
}
setIconResource(drawable)
setText(text)
setOnClickListener {
viewModel.toggleSubscriptionStatus(context) { newStatus: Boolean? ->
if (newStatus == null) return@toggleSubscriptionStatus
val message = if (newStatus) {
// Kinda icky to have this here, but it works.
SubscriptionWorkManager.enqueuePeriodicWork(context)
R.string.subscription_new
} else {
R.string.subscription_deleted
}
val name = (viewModel.page.value as? Resource.Success)?.value?.title
?: txt(R.string.no_data).asStringNull(context) ?: ""
CommonActivity.showToast(txt(message, name), Toast.LENGTH_SHORT)
}
}
}
}
observeNullable(viewModel.movie) { data -> observeNullable(viewModel.movie) { data ->
binding?.apply { binding?.apply {
resultPlayMovie.isVisible = data is Resource.Success resultPlayMovie.isVisible = data is Resource.Success

View file

@ -583,7 +583,7 @@ object AppUtils {
//private val viewModel: ResultViewModel by activityViewModels() //private val viewModel: ResultViewModel by activityViewModels()
private fun getResultsId(): Int { private fun getResultsId(): Int {
return if (isTrueTvSettings()) { return if (isTvSettings()) {
R.id.global_to_navigation_results_tv R.id.global_to_navigation_results_tv
} else { } else {
R.id.global_to_navigation_results_phone R.id.global_to_navigation_results_phone

View file

@ -325,19 +325,30 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
style="@style/ResultButtonTV" style="@style/ResultButtonTV"
android:nextFocusRight="@id/result_description" android:nextFocusRight="@id/result_description"
android:nextFocusUp="@id/result_bookmark_button" android:nextFocusUp="@id/result_bookmark_button"
android:nextFocusDown="@id/result_episodes_show" android:nextFocusDown="@id/result_subscribe_button"
android:text="@string/action_add_to_favorites" android:text="@string/action_add_to_favorites"
android:visibility="visible" android:visibility="visible"
app:icon="@drawable/ic_baseline_favorite_border_24" /> app:icon="@drawable/ic_baseline_favorite_border_24" />
<com.google.android.material.button.MaterialButton
android:id="@+id/result_subscribe_button"
style="@style/ResultButtonTV"
android:nextFocusRight="@id/result_description"
android:nextFocusUp="@id/result_favorite_button"
android:nextFocusDown="@id/result_episodes_show"
android:text="@string/action_subscribe"
android:visibility="visible"
app:icon="@drawable/ic_baseline_favorite_border_24" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/result_episodes_show" android:id="@+id/result_episodes_show"
style="@style/ResultButtonTV" style="@style/ResultButtonTV"
android:nextFocusRight="@id/redirect_to_episodes" android:nextFocusRight="@id/redirect_to_episodes"
android:nextFocusUp="@id/result_favorite_button" android:nextFocusUp="@id/result_subscribe_button"
android:nextFocusDown="@id/result_cast_items" android:nextFocusDown="@id/result_cast_items"
android:text="@string/episodes" android:text="@string/episodes"

View file

@ -667,6 +667,8 @@
<string name="subscription_new">Subscribed to %s</string> <string name="subscription_new">Subscribed to %s</string>
<string name="subscription_deleted">Unsubscribed from %s</string> <string name="subscription_deleted">Unsubscribed from %s</string>
<string name="subscription_episode_released">Episode %d released!</string> <string name="subscription_episode_released">Episode %d released!</string>
<string name="action_subscribe">Subscribe</string>
<string name="action_unsubscribe">Unsubscribe</string>
<string name="profile_number">Profile %d</string> <string name="profile_number">Profile %d</string>
<string name="wifi">Wi-Fi</string> <string name="wifi">Wi-Fi</string>
<string name="mobile_data">Mobile data</string> <string name="mobile_data">Mobile data</string>