add recommendations to home fragment
This commit is contained in:
		@ -646,6 +646,23 @@ object Crunchyroll {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    suspend fun recommendations(n: Int = 20, start: Int = 0): RecommendationsList {
 | 
			
		||||
        val recommendationsEndpoint = "/content/v1/$accountID/recommendations"
 | 
			
		||||
        val parameters = listOf(
 | 
			
		||||
            "locale" to Preferences.preferredLocale.toLanguageTag(),
 | 
			
		||||
            "n" to n,
 | 
			
		||||
            "start" to start,
 | 
			
		||||
            "variant_id" to 0
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return try {
 | 
			
		||||
            requestGet(recommendationsEndpoint, parameters)
 | 
			
		||||
        }catch (ex: SerializationException) {
 | 
			
		||||
            Log.e(TAG, "SerializationException in recommendations().", ex)
 | 
			
		||||
            NoneRecommendationsList
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Account/Profile functions
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
@ -124,6 +124,7 @@ typealias SimilarToResult = Collection<Item>
 | 
			
		||||
typealias DiscSeasonList = Collection<SeasonListItem>
 | 
			
		||||
typealias Watchlist = Collection<Item>
 | 
			
		||||
typealias ContinueWatchingList = Collection<ContinueWatchingItem>
 | 
			
		||||
typealias RecommendationsList = Collection<Item>
 | 
			
		||||
 | 
			
		||||
@Serializable
 | 
			
		||||
data class UpNextSeriesItem(
 | 
			
		||||
@ -224,6 +225,7 @@ val NoneBrowseResult = BrowseResult(0, emptyList())
 | 
			
		||||
val NoneSimilarToResult = SimilarToResult(0, emptyList())
 | 
			
		||||
val NoneDiscSeasonList = DiscSeasonList(0, emptyList())
 | 
			
		||||
val NoneContinueWatchingList = ContinueWatchingList(0, emptyList())
 | 
			
		||||
val NoneRecommendationsList = RecommendationsList(0, emptyList())
 | 
			
		||||
 | 
			
		||||
val NoneUpNextSeriesItem = UpNextSeriesItem(
 | 
			
		||||
    playhead = 0,
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,7 @@ class HomeFragment : Fragment() {
 | 
			
		||||
 | 
			
		||||
        binding.recyclerUpNext.addItemDecoration(MediaItemDecoration(9))
 | 
			
		||||
        binding.recyclerWatchlist.addItemDecoration(MediaItemDecoration(9))
 | 
			
		||||
        binding.recyclerRecommendations.addItemDecoration(MediaItemDecoration(9))
 | 
			
		||||
        binding.recyclerNewTitles.addItemDecoration(MediaItemDecoration(9))
 | 
			
		||||
        binding.recyclerTopTen.addItemDecoration(MediaItemDecoration(9))
 | 
			
		||||
 | 
			
		||||
@ -79,6 +80,12 @@ class HomeFragment : Fragment() {
 | 
			
		||||
            }
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        binding.recyclerRecommendations.adapter = MediaItemListAdapter(
 | 
			
		||||
            MediaItemListAdapter.OnClickListener {
 | 
			
		||||
                activity?.showFragment(MediaFragment(it.id))
 | 
			
		||||
            }
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        binding.recyclerNewTitles.adapter = MediaItemListAdapter(
 | 
			
		||||
            MediaItemListAdapter.OnClickListener {
 | 
			
		||||
                activity?.showFragment(MediaFragment(it.id))
 | 
			
		||||
@ -129,6 +136,9 @@ class HomeFragment : Fragment() {
 | 
			
		||||
        val adapterWatchlist = binding.recyclerWatchlist.adapter as MediaItemListAdapter
 | 
			
		||||
        adapterWatchlist.submitList(uiState.watchlistItems.toItemMediaList())
 | 
			
		||||
 | 
			
		||||
        val adapterRecommendations = binding.recyclerRecommendations.adapter as MediaItemListAdapter
 | 
			
		||||
        adapterRecommendations.submitList(uiState.recommendationsItems.toItemMediaList())
 | 
			
		||||
 | 
			
		||||
        val adapterNewTitles = binding.recyclerNewTitles.adapter as MediaItemListAdapter
 | 
			
		||||
        adapterNewTitles.submitList(uiState.recentlyAddedItems.toItemMediaList())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -40,6 +40,7 @@ class HomeViewModel : ViewModel()  {
 | 
			
		||||
        data class Normal(
 | 
			
		||||
            val upNextItems: List<ContinueWatchingItem>,
 | 
			
		||||
            val watchlistItems: List<Item>,
 | 
			
		||||
            val recommendationsItems: List<Item>,
 | 
			
		||||
            val recentlyAddedItems: List<Item>,
 | 
			
		||||
            val topTenItems: List<Item>,
 | 
			
		||||
            val highlightItem: Item,
 | 
			
		||||
@ -63,6 +64,9 @@ class HomeViewModel : ViewModel()  {
 | 
			
		||||
                // run the loading in parallel to speed up the process
 | 
			
		||||
                val upNextJob = viewModelScope.async { Crunchyroll.upNextAccount().items }
 | 
			
		||||
                val watchlistJob = viewModelScope.async { Crunchyroll.watchlist(50).items }
 | 
			
		||||
                val recommendationsJob = viewModelScope.async {
 | 
			
		||||
                    Crunchyroll.recommendations(20).items
 | 
			
		||||
                }
 | 
			
		||||
                val recentlyAddedJob = viewModelScope.async {
 | 
			
		||||
                    Crunchyroll.browse(sortBy = SortBy.NEWLY_ADDED, n = 50).items
 | 
			
		||||
                }
 | 
			
		||||
@ -76,8 +80,9 @@ class HomeViewModel : ViewModel()  {
 | 
			
		||||
                val highlightItemIsWatchlist = Crunchyroll.isWatchlist(highlightItem.id)
 | 
			
		||||
 | 
			
		||||
                uiState.emit(UiState.Normal(
 | 
			
		||||
                    upNextJob.await(), watchlistJob.await(), recentlyAddedJob.await(),
 | 
			
		||||
                    topTenJob.await(), highlightItem, highlightItemIsWatchlist
 | 
			
		||||
                    upNextJob.await(), watchlistJob.await(), recommendationsJob.await(),
 | 
			
		||||
                    recentlyAddedJob.await(), topTenJob.await(), highlightItem,
 | 
			
		||||
                    highlightItemIsWatchlist
 | 
			
		||||
                ))
 | 
			
		||||
            } catch (e: Exception) {
 | 
			
		||||
                uiState.emit(UiState.Error(e.message))
 | 
			
		||||
 | 
			
		||||
@ -462,7 +462,6 @@ class PlayerActivity : AppCompatActivity() {
 | 
			
		||||
                    playerBinding.buttonNextEp.isVisible = false
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun showButtonSkipOp() {
 | 
			
		||||
 | 
			
		||||
@ -163,6 +163,34 @@
 | 
			
		||||
                    tools:listitem="@layout/item_media" />
 | 
			
		||||
            </LinearLayout>
 | 
			
		||||
 | 
			
		||||
            <LinearLayout
 | 
			
		||||
                android:id="@+id/linear_recommendations"
 | 
			
		||||
                android:layout_width="match_parent"
 | 
			
		||||
                android:layout_height="match_parent"
 | 
			
		||||
                android:orientation="vertical"
 | 
			
		||||
                android:paddingBottom="7dp">
 | 
			
		||||
 | 
			
		||||
                <TextView
 | 
			
		||||
                    android:id="@+id/text_recommendations"
 | 
			
		||||
                    android:layout_width="match_parent"
 | 
			
		||||
                    android:layout_height="wrap_content"
 | 
			
		||||
                    android:paddingStart="10dp"
 | 
			
		||||
                    android:paddingTop="15dp"
 | 
			
		||||
                    android:paddingEnd="5dp"
 | 
			
		||||
                    android:paddingBottom="5dp"
 | 
			
		||||
                    android:text="@string/recommendations"
 | 
			
		||||
                    android:textSize="16sp"
 | 
			
		||||
                    android:textStyle="bold" />
 | 
			
		||||
 | 
			
		||||
                <androidx.recyclerview.widget.RecyclerView
 | 
			
		||||
                    android:id="@+id/recycler_recommendations"
 | 
			
		||||
                    android:layout_width="match_parent"
 | 
			
		||||
                    android:layout_height="match_parent"
 | 
			
		||||
                    android:orientation="horizontal"
 | 
			
		||||
                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
 | 
			
		||||
                    tools:listitem="@layout/item_media" />
 | 
			
		||||
            </LinearLayout>
 | 
			
		||||
 | 
			
		||||
            <LinearLayout
 | 
			
		||||
                android:id="@+id/linear_new_titles"
 | 
			
		||||
                android:layout_width="match_parent"
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@
 | 
			
		||||
    <string name="highlight_media">Highlight</string>
 | 
			
		||||
    <string name="up_next">Weiterschauen</string>
 | 
			
		||||
    <string name="my_list">Meine Liste</string>
 | 
			
		||||
    <string name="recommendations">Empfehlungen</string>
 | 
			
		||||
    <string name="new_episodes">Neue Episoden</string>
 | 
			
		||||
    <string name="new_simulcasts">Neue Simulcasts</string>
 | 
			
		||||
    <string name="new_titles">Neue Titel</string>
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@
 | 
			
		||||
    <string name="highlight_media">Highlight</string>
 | 
			
		||||
    <string name="up_next">Up next</string>
 | 
			
		||||
    <string name="my_list">My list</string>
 | 
			
		||||
    <string name="recommendations">Recommendations</string>
 | 
			
		||||
    <string name="new_episodes">New episodes</string>
 | 
			
		||||
    <string name="new_simulcasts">New simulcasts</string>
 | 
			
		||||
    <string name="new_titles">New titles</string>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user