Make headers in search and favorite fragments translatable
This commit is contained in:
parent
185bd51f6c
commit
77de164538
6 changed files with 36 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -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<BaseItemDto>
|
||||
)
|
|
@ -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
|
||||
}
|
|
@ -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>(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
|
||||
|
|
|
@ -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>(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
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
<string name="error_getting_person_id">Detail unavailable</string>
|
||||
<string name="movies_label">Movies</string>
|
||||
<string name="shows_label">TV Shows</string>
|
||||
<string name="episodes_label">Episodes</string>
|
||||
<string name="hide">Hide</string>
|
||||
<string name="sort_by">Sort by</string>
|
||||
<string name="sort_order">Sort order</string>
|
||||
|
|
Loading…
Reference in a new issue