Skip to content

Commit

Permalink
Use TV results layout on emulator (#710)
Browse files Browse the repository at this point in the history
* Use TV results layout on emulator

* Add subscription support to emulator

* Update
  • Loading branch information
Luna712 authored Oct 28, 2023
1 parent 137d833 commit f0e4294
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -287,7 +289,8 @@ class ResultFragmentTv : Fragment() {
resultResumeSeries,
resultPlayTrailer,
resultBookmarkButton,
resultFavoriteButton
resultFavoriteButton,
resultSubscribeButton
)
for (requestView in views) {
if (!requestView.isVisible) continue
Expand Down Expand Up @@ -429,6 +432,7 @@ class ResultFragmentTv : Fragment() {
binding?.resultEpisodesShow,
binding?.resultBookmarkButton,
binding?.resultFavoriteButton,
binding?.resultSubscribeButton,
).firstOrNull {
it?.isVisible == true
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/res/layout/fragment_result_tv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit f0e4294

Please sign in to comment.