mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Use TV results layout on emulator (#710)
* Use TV results layout on emulator * Add subscription support to emulator * Update
This commit is contained in:
parent
137d833d4a
commit
f0e429436f
4 changed files with 60 additions and 4 deletions
|
@ -28,6 +28,7 @@ import com.lagradost.cloudstream3.databinding.FragmentResultTvBinding
|
|||
import com.lagradost.cloudstream3.mvvm.Resource
|
||||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import com.lagradost.cloudstream3.mvvm.observeNullable
|
||||
import com.lagradost.cloudstream3.services.SubscriptionWorkManager
|
||||
import com.lagradost.cloudstream3.ui.WatchType
|
||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup
|
||||
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.SearchAdapter
|
||||
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.html
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.isRtl
|
||||
|
@ -287,7 +289,8 @@ class ResultFragmentTv : Fragment() {
|
|||
resultResumeSeries,
|
||||
resultPlayTrailer,
|
||||
resultBookmarkButton,
|
||||
resultFavoriteButton
|
||||
resultFavoriteButton,
|
||||
resultSubscribeButton
|
||||
)
|
||||
for (requestView in views) {
|
||||
if (!requestView.isVisible) continue
|
||||
|
@ -429,6 +432,7 @@ class ResultFragmentTv : Fragment() {
|
|||
binding?.resultEpisodesShow,
|
||||
binding?.resultBookmarkButton,
|
||||
binding?.resultFavoriteButton,
|
||||
binding?.resultSubscribeButton,
|
||||
).firstOrNull {
|
||||
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 ->
|
||||
binding?.apply {
|
||||
resultPlayMovie.isVisible = data is Resource.Success
|
||||
|
|
|
@ -583,7 +583,7 @@ object AppUtils {
|
|||
//private val viewModel: ResultViewModel by activityViewModels()
|
||||
|
||||
private fun getResultsId(): Int {
|
||||
return if (isTrueTvSettings()) {
|
||||
return if (isTvSettings()) {
|
||||
R.id.global_to_navigation_results_tv
|
||||
} else {
|
||||
R.id.global_to_navigation_results_phone
|
||||
|
|
|
@ -325,19 +325,30 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
|
|||
style="@style/ResultButtonTV"
|
||||
android:nextFocusRight="@id/result_description"
|
||||
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:visibility="visible"
|
||||
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
|
||||
android:id="@+id/result_episodes_show"
|
||||
style="@style/ResultButtonTV"
|
||||
|
||||
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:text="@string/episodes"
|
||||
|
|
|
@ -667,6 +667,8 @@
|
|||
<string name="subscription_new">Subscribed to %s</string>
|
||||
<string name="subscription_deleted">Unsubscribed from %s</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="wifi">Wi-Fi</string>
|
||||
<string name="mobile_data">Mobile data</string>
|
||||
|
|
Loading…
Reference in a new issue