mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Add support to TV for favorites
This commit is contained in:
parent
fb7c9694a9
commit
2e9f5d48e6
4 changed files with 66 additions and 12 deletions
|
@ -76,10 +76,11 @@ class LocalList : SyncAPI {
|
|||
val baseMap = WatchType.values().filter { it != WatchType.NONE }.associate {
|
||||
// None is not something to display
|
||||
it.stringRes to emptyList<SyncAPI.LibraryItem>()
|
||||
} + if (!isTv) {
|
||||
} + mapOf(
|
||||
R.string.favorites_list_name to emptyList()
|
||||
) + if (!isTv) {
|
||||
mapOf(
|
||||
R.string.subscription_list_name to emptyList(),
|
||||
R.string.favorites_list_name to emptyList()
|
||||
)
|
||||
} else {
|
||||
emptyMap()
|
||||
|
@ -91,19 +92,19 @@ class LocalList : SyncAPI {
|
|||
}
|
||||
}
|
||||
|
||||
val favoritesMap = mapOf(R.string.favorites_list_name to getAllFavorites().mapNotNull {
|
||||
it.toLibraryItem()
|
||||
})
|
||||
|
||||
// Don't show subscriptions or favorites on TV
|
||||
val result = if (isTv) {
|
||||
baseMap + watchStatusMap
|
||||
baseMap + watchStatusMap + favoritesMap
|
||||
} else {
|
||||
val subscriptionList = mapOf(R.string.subscription_list_name to getAllSubscriptions().mapNotNull {
|
||||
val subscriptionsMap = mapOf(R.string.subscription_list_name to getAllSubscriptions().mapNotNull {
|
||||
it.toLibraryItem()
|
||||
})
|
||||
|
||||
val favoritesList = mapOf(R.string.favorites_list_name to getAllFavorites().mapNotNull {
|
||||
it.toLibraryItem()
|
||||
})
|
||||
|
||||
baseMap + watchStatusMap + subscriptionList + favoritesList
|
||||
baseMap + watchStatusMap + subscriptionsMap + favoritesMap
|
||||
}
|
||||
|
||||
result
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
|
@ -17,6 +18,7 @@ import androidx.lifecycle.ViewModelProvider
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
|
||||
import com.lagradost.cloudstream3.CommonActivity
|
||||
import com.lagradost.cloudstream3.DubStatus
|
||||
import com.lagradost.cloudstream3.LoadResponse
|
||||
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
|
||||
|
@ -265,6 +267,7 @@ class ResultFragmentTv : Fragment() {
|
|||
resultEpisodesShow.onFocusChangeListener = rightListener
|
||||
resultDescription.onFocusChangeListener = leftListener
|
||||
resultBookmarkButton.onFocusChangeListener = leftListener
|
||||
resultFavoriteButton.onFocusChangeListener = leftListener
|
||||
resultEpisodesShow.setOnClickListener {
|
||||
// toggle, to make it more touch accessable just in case someone thinks that a
|
||||
// tv layout is better but is using a touch device
|
||||
|
@ -283,7 +286,8 @@ class ResultFragmentTv : Fragment() {
|
|||
resultPlaySeries,
|
||||
resultResumeSeries,
|
||||
resultPlayTrailer,
|
||||
resultBookmarkButton
|
||||
resultBookmarkButton,
|
||||
resultFavoriteButton
|
||||
)
|
||||
for (requestView in views) {
|
||||
if (!requestView.isVisible) continue
|
||||
|
@ -424,6 +428,7 @@ class ResultFragmentTv : Fragment() {
|
|||
val aboveCast = listOf(
|
||||
binding?.resultEpisodesShow,
|
||||
binding?.resultBookmarkButton,
|
||||
binding?.resultFavoriteButton,
|
||||
).firstOrNull {
|
||||
it?.isVisible == true
|
||||
}
|
||||
|
@ -532,6 +537,41 @@ class ResultFragmentTv : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
observeNullable(viewModel.favoriteStatus) { isFavorite ->
|
||||
binding?.resultFavoriteButton?.apply {
|
||||
isVisible = isFavorite != null
|
||||
if (isFavorite == null) return@observeNullable
|
||||
|
||||
val drawable = if (isFavorite) {
|
||||
R.drawable.ic_baseline_favorite_24
|
||||
} else {
|
||||
R.drawable.ic_baseline_favorite_border_24
|
||||
}
|
||||
|
||||
val text = if (isFavorite) {
|
||||
R.string.action_remove_from_favorites
|
||||
} else {
|
||||
R.string.action_add_to_favorites
|
||||
}
|
||||
|
||||
setIconResource(drawable)
|
||||
setText(text)
|
||||
setOnClickListener {
|
||||
val isFavorite = viewModel.toggleFavoriteStatus() ?: return@setOnClickListener
|
||||
|
||||
val message = if (isFavorite) {
|
||||
R.string.favorite_added
|
||||
} else {
|
||||
R.string.favorite_removed
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -310,19 +310,30 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
|
|||
style="@style/ResultButtonTV"
|
||||
android:nextFocusRight="@id/result_description"
|
||||
android:nextFocusUp="@id/result_play_trailer"
|
||||
android:nextFocusDown="@id/result_episodes_show"
|
||||
android:nextFocusDown="@id/result_favorite_button"
|
||||
|
||||
android:text="@string/type_none"
|
||||
android:visibility="visible"
|
||||
app:icon="@drawable/ic_baseline_bookmark_24" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/result_favorite_button"
|
||||
style="@style/ResultButtonTV"
|
||||
android:nextFocusRight="@id/result_description"
|
||||
android:nextFocusUp="@id/result_bookmark_button"
|
||||
android:nextFocusDown="@id/result_episodes_show"
|
||||
|
||||
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_episodes_show"
|
||||
style="@style/ResultButtonTV"
|
||||
|
||||
android:nextFocusRight="@id/redirect_to_episodes"
|
||||
android:nextFocusUp="@id/result_bookmark_button"
|
||||
android:nextFocusUp="@id/result_favorite_button"
|
||||
android:nextFocusDown="@id/result_cast_items"
|
||||
|
||||
android:text="@string/episodes"
|
||||
|
|
|
@ -693,4 +693,6 @@
|
|||
<string name="favorites_list_name">Favorites</string>
|
||||
<string name="favorite_added">%s added to favorites</string>
|
||||
<string name="favorite_removed">%s removed from favorites</string>
|
||||
<string name="action_add_to_favorites">Add to favorites</string>
|
||||
<string name="action_remove_from_favorites">Remove from favorites</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue