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 {
|
val baseMap = WatchType.values().filter { it != WatchType.NONE }.associate {
|
||||||
// None is not something to display
|
// None is not something to display
|
||||||
it.stringRes to emptyList<SyncAPI.LibraryItem>()
|
it.stringRes to emptyList<SyncAPI.LibraryItem>()
|
||||||
} + if (!isTv) {
|
} + mapOf(
|
||||||
|
R.string.favorites_list_name to emptyList()
|
||||||
|
) + if (!isTv) {
|
||||||
mapOf(
|
mapOf(
|
||||||
R.string.subscription_list_name to emptyList(),
|
R.string.subscription_list_name to emptyList(),
|
||||||
R.string.favorites_list_name to emptyList()
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
emptyMap()
|
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
|
// Don't show subscriptions or favorites on TV
|
||||||
val result = if (isTv) {
|
val result = if (isTv) {
|
||||||
baseMap + watchStatusMap
|
baseMap + watchStatusMap + favoritesMap
|
||||||
} else {
|
} 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()
|
it.toLibraryItem()
|
||||||
})
|
})
|
||||||
|
|
||||||
val favoritesList = mapOf(R.string.favorites_list_name to getAllFavorites().mapNotNull {
|
baseMap + watchStatusMap + subscriptionsMap + favoritesMap
|
||||||
it.toLibraryItem()
|
|
||||||
})
|
|
||||||
|
|
||||||
baseMap + watchStatusMap + subscriptionList + favoritesList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -17,6 +18,7 @@ import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
|
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
|
||||||
|
import com.lagradost.cloudstream3.CommonActivity
|
||||||
import com.lagradost.cloudstream3.DubStatus
|
import com.lagradost.cloudstream3.DubStatus
|
||||||
import com.lagradost.cloudstream3.LoadResponse
|
import com.lagradost.cloudstream3.LoadResponse
|
||||||
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
|
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
|
||||||
|
@ -265,6 +267,7 @@ class ResultFragmentTv : Fragment() {
|
||||||
resultEpisodesShow.onFocusChangeListener = rightListener
|
resultEpisodesShow.onFocusChangeListener = rightListener
|
||||||
resultDescription.onFocusChangeListener = leftListener
|
resultDescription.onFocusChangeListener = leftListener
|
||||||
resultBookmarkButton.onFocusChangeListener = leftListener
|
resultBookmarkButton.onFocusChangeListener = leftListener
|
||||||
|
resultFavoriteButton.onFocusChangeListener = leftListener
|
||||||
resultEpisodesShow.setOnClickListener {
|
resultEpisodesShow.setOnClickListener {
|
||||||
// toggle, to make it more touch accessable just in case someone thinks that a
|
// toggle, to make it more touch accessable just in case someone thinks that a
|
||||||
// tv layout is better but is using a touch device
|
// tv layout is better but is using a touch device
|
||||||
|
@ -283,7 +286,8 @@ class ResultFragmentTv : Fragment() {
|
||||||
resultPlaySeries,
|
resultPlaySeries,
|
||||||
resultResumeSeries,
|
resultResumeSeries,
|
||||||
resultPlayTrailer,
|
resultPlayTrailer,
|
||||||
resultBookmarkButton
|
resultBookmarkButton,
|
||||||
|
resultFavoriteButton
|
||||||
)
|
)
|
||||||
for (requestView in views) {
|
for (requestView in views) {
|
||||||
if (!requestView.isVisible) continue
|
if (!requestView.isVisible) continue
|
||||||
|
@ -424,6 +428,7 @@ class ResultFragmentTv : Fragment() {
|
||||||
val aboveCast = listOf(
|
val aboveCast = listOf(
|
||||||
binding?.resultEpisodesShow,
|
binding?.resultEpisodesShow,
|
||||||
binding?.resultBookmarkButton,
|
binding?.resultBookmarkButton,
|
||||||
|
binding?.resultFavoriteButton,
|
||||||
).firstOrNull {
|
).firstOrNull {
|
||||||
it?.isVisible == true
|
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 ->
|
observeNullable(viewModel.movie) { data ->
|
||||||
binding?.apply {
|
binding?.apply {
|
||||||
resultPlayMovie.isVisible = data is Resource.Success
|
resultPlayMovie.isVisible = data is Resource.Success
|
||||||
|
|
|
@ -310,19 +310,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_play_trailer"
|
android:nextFocusUp="@id/result_play_trailer"
|
||||||
android:nextFocusDown="@id/result_episodes_show"
|
android:nextFocusDown="@id/result_favorite_button"
|
||||||
|
|
||||||
android:text="@string/type_none"
|
android:text="@string/type_none"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
app:icon="@drawable/ic_baseline_bookmark_24" />
|
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
|
<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_bookmark_button"
|
android:nextFocusUp="@id/result_favorite_button"
|
||||||
android:nextFocusDown="@id/result_cast_items"
|
android:nextFocusDown="@id/result_cast_items"
|
||||||
|
|
||||||
android:text="@string/episodes"
|
android:text="@string/episodes"
|
||||||
|
|
|
@ -693,4 +693,6 @@
|
||||||
<string name="favorites_list_name">Favorites</string>
|
<string name="favorites_list_name">Favorites</string>
|
||||||
<string name="favorite_added">%s added to favorites</string>
|
<string name="favorite_added">%s added to favorites</string>
|
||||||
<string name="favorite_removed">%s removed from 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>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue