From 77de164538421a38d0d7d917a19b91f17e35e442 Mon Sep 17 00:00:00 2001 From: Jarne Demeulemeester Date: Sat, 15 Oct 2022 00:22:15 +0200 Subject: [PATCH] Make headers in search and favorite fragments translatable --- .../jellyfin/adapters/FavoritesListAdapter.kt | 5 +++-- .../jdtech/jellyfin/models/FavoriteSection.kt | 3 +-- .../dev/jdtech/jellyfin/utils/Constants.kt | 5 +++++ .../jellyfin/viewmodels/FavoriteViewModel.kt | 20 ++++++++++++------- .../viewmodels/SearchResultViewModel.kt | 20 ++++++++++++------- app/src/main/res/values/strings.xml | 1 + 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/FavoritesListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/FavoritesListAdapter.kt index e69f3ec3..76c372d3 100644 --- a/app/src/main/java/dev/jdtech/jellyfin/adapters/FavoritesListAdapter.kt +++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/FavoritesListAdapter.kt @@ -7,6 +7,7 @@ import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import dev.jdtech.jellyfin.databinding.FavoriteSectionBinding import dev.jdtech.jellyfin.models.FavoriteSection +import dev.jdtech.jellyfin.utils.Constants class FavoritesListAdapter( private val onClickListener: ViewItemListAdapter.OnClickListener, @@ -20,11 +21,11 @@ class FavoritesListAdapter( onEpisodeClickListener: HomeEpisodeListAdapter.OnClickListener ) { binding.section = section - if (section.name == "Movies" || section.name == "Shows") { + if (section.id == Constants.FAVORITE_TYPE_MOVIES || section.id == Constants.FAVORITE_TYPE_SHOWS) { binding.itemsRecyclerView.adapter = ViewItemListAdapter(onClickListener, fixedWidth = true) (binding.itemsRecyclerView.adapter as ViewItemListAdapter).submitList(section.items) - } else if (section.name == "Episodes") { + } else if (section.id == Constants.FAVORITE_TYPE_EPISODES) { binding.itemsRecyclerView.adapter = HomeEpisodeListAdapter(onEpisodeClickListener) (binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.items) diff --git a/app/src/main/java/dev/jdtech/jellyfin/models/FavoriteSection.kt b/app/src/main/java/dev/jdtech/jellyfin/models/FavoriteSection.kt index 57279f99..d1926471 100644 --- a/app/src/main/java/dev/jdtech/jellyfin/models/FavoriteSection.kt +++ b/app/src/main/java/dev/jdtech/jellyfin/models/FavoriteSection.kt @@ -1,10 +1,9 @@ package dev.jdtech.jellyfin.models import org.jellyfin.sdk.model.api.BaseItemDto -import java.util.* data class FavoriteSection( - val id: UUID, + val id: Int, val name: String, var items: List ) \ No newline at end of file diff --git a/app/src/main/java/dev/jdtech/jellyfin/utils/Constants.kt b/app/src/main/java/dev/jdtech/jellyfin/utils/Constants.kt index 410da67a..3ab5d43c 100644 --- a/app/src/main/java/dev/jdtech/jellyfin/utils/Constants.kt +++ b/app/src/main/java/dev/jdtech/jellyfin/utils/Constants.kt @@ -22,4 +22,9 @@ object Constants { // caching const val DEFAULT_CACHE_SIZE = 20 + + // favorites + const val FAVORITE_TYPE_MOVIES = 0 + const val FAVORITE_TYPE_SHOWS = 1 + const val FAVORITE_TYPE_EPISODES = 2 } \ No newline at end of file diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/FavoriteViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/FavoriteViewModel.kt index 9f00790d..9a0f3e1e 100644 --- a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/FavoriteViewModel.kt +++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/FavoriteViewModel.kt @@ -1,25 +1,31 @@ package dev.jdtech.jellyfin.viewmodels +import android.content.res.Resources import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import dev.jdtech.jellyfin.BaseApplication +import dev.jdtech.jellyfin.R import dev.jdtech.jellyfin.models.FavoriteSection import dev.jdtech.jellyfin.repository.JellyfinRepository +import dev.jdtech.jellyfin.utils.Constants import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jellyfin.sdk.model.api.BaseItemKind -import java.util.* import javax.inject.Inject @HiltViewModel class FavoriteViewModel @Inject constructor( + application: BaseApplication, private val jellyfinRepository: JellyfinRepository ) : ViewModel() { + private val resources: Resources = application.resources + private val _uiState = MutableStateFlow(UiState.Loading) val uiState = _uiState.asStateFlow() @@ -48,24 +54,24 @@ constructor( withContext(Dispatchers.Default) { FavoriteSection( - UUID.randomUUID(), - "Movies", + Constants.FAVORITE_TYPE_MOVIES, + resources.getString(R.string.movies_label), items.filter { it.type == BaseItemKind.MOVIE }).let { if (it.items.isNotEmpty()) favoriteSections.add( it ) } FavoriteSection( - UUID.randomUUID(), - "Shows", + Constants.FAVORITE_TYPE_SHOWS, + resources.getString(R.string.shows_label), items.filter { it.type == BaseItemKind.SERIES }).let { if (it.items.isNotEmpty()) favoriteSections.add( it ) } FavoriteSection( - UUID.randomUUID(), - "Episodes", + Constants.FAVORITE_TYPE_EPISODES, + resources.getString(R.string.episodes_label), items.filter { it.type == BaseItemKind.EPISODE }).let { if (it.items.isNotEmpty()) favoriteSections.add( it diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SearchResultViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SearchResultViewModel.kt index 5b9dd2e0..739870b6 100644 --- a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SearchResultViewModel.kt +++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SearchResultViewModel.kt @@ -1,25 +1,31 @@ package dev.jdtech.jellyfin.viewmodels +import android.content.res.Resources import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import dev.jdtech.jellyfin.BaseApplication +import dev.jdtech.jellyfin.R import dev.jdtech.jellyfin.models.FavoriteSection import dev.jdtech.jellyfin.repository.JellyfinRepository +import dev.jdtech.jellyfin.utils.Constants import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jellyfin.sdk.model.api.BaseItemKind -import java.util.* import javax.inject.Inject @HiltViewModel class SearchResultViewModel @Inject constructor( + application: BaseApplication, private val jellyfinRepository: JellyfinRepository ) : ViewModel() { + private val resources: Resources = application.resources + private val _uiState = MutableStateFlow(UiState.Loading) val uiState = _uiState.asStateFlow() @@ -44,24 +50,24 @@ constructor( withContext(Dispatchers.Default) { FavoriteSection( - UUID.randomUUID(), - "Movies", + Constants.FAVORITE_TYPE_MOVIES, + resources.getString(R.string.movies_label), items.filter { it.type == BaseItemKind.MOVIE }).let { if (it.items.isNotEmpty()) sections.add( it ) } FavoriteSection( - UUID.randomUUID(), - "Shows", + Constants.FAVORITE_TYPE_SHOWS, + resources.getString(R.string.shows_label), items.filter { it.type == BaseItemKind.SERIES }).let { if (it.items.isNotEmpty()) sections.add( it ) } FavoriteSection( - UUID.randomUUID(), - "Episodes", + Constants.FAVORITE_TYPE_EPISODES, + resources.getString(R.string.episodes_label), items.filter { it.type == BaseItemKind.EPISODE }).let { if (it.items.isNotEmpty()) sections.add( it diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f194eb17..2fddbc53 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -93,6 +93,7 @@ Detail unavailable Movies TV Shows + Episodes Hide Sort by Sort order