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 androidx.recyclerview.widget.RecyclerView
|
||||||
import dev.jdtech.jellyfin.databinding.FavoriteSectionBinding
|
import dev.jdtech.jellyfin.databinding.FavoriteSectionBinding
|
||||||
import dev.jdtech.jellyfin.models.FavoriteSection
|
import dev.jdtech.jellyfin.models.FavoriteSection
|
||||||
|
import dev.jdtech.jellyfin.utils.Constants
|
||||||
|
|
||||||
class FavoritesListAdapter(
|
class FavoritesListAdapter(
|
||||||
private val onClickListener: ViewItemListAdapter.OnClickListener,
|
private val onClickListener: ViewItemListAdapter.OnClickListener,
|
||||||
|
@ -20,11 +21,11 @@ class FavoritesListAdapter(
|
||||||
onEpisodeClickListener: HomeEpisodeListAdapter.OnClickListener
|
onEpisodeClickListener: HomeEpisodeListAdapter.OnClickListener
|
||||||
) {
|
) {
|
||||||
binding.section = section
|
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 =
|
binding.itemsRecyclerView.adapter =
|
||||||
ViewItemListAdapter(onClickListener, fixedWidth = true)
|
ViewItemListAdapter(onClickListener, fixedWidth = true)
|
||||||
(binding.itemsRecyclerView.adapter as ViewItemListAdapter).submitList(section.items)
|
(binding.itemsRecyclerView.adapter as ViewItemListAdapter).submitList(section.items)
|
||||||
} else if (section.name == "Episodes") {
|
} else if (section.id == Constants.FAVORITE_TYPE_EPISODES) {
|
||||||
binding.itemsRecyclerView.adapter =
|
binding.itemsRecyclerView.adapter =
|
||||||
HomeEpisodeListAdapter(onEpisodeClickListener)
|
HomeEpisodeListAdapter(onEpisodeClickListener)
|
||||||
(binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.items)
|
(binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.items)
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package dev.jdtech.jellyfin.models
|
package dev.jdtech.jellyfin.models
|
||||||
|
|
||||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
data class FavoriteSection(
|
data class FavoriteSection(
|
||||||
val id: UUID,
|
val id: Int,
|
||||||
val name: String,
|
val name: String,
|
||||||
var items: List<BaseItemDto>
|
var items: List<BaseItemDto>
|
||||||
)
|
)
|
|
@ -22,4 +22,9 @@ object Constants {
|
||||||
|
|
||||||
// caching
|
// caching
|
||||||
const val DEFAULT_CACHE_SIZE = 20
|
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
|
package dev.jdtech.jellyfin.viewmodels
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
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.models.FavoriteSection
|
||||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||||
|
import dev.jdtech.jellyfin.utils.Constants
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class FavoriteViewModel
|
class FavoriteViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
|
application: BaseApplication,
|
||||||
private val jellyfinRepository: JellyfinRepository
|
private val jellyfinRepository: JellyfinRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
private val resources: Resources = application.resources
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
|
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
|
||||||
val uiState = _uiState.asStateFlow()
|
val uiState = _uiState.asStateFlow()
|
||||||
|
|
||||||
|
@ -48,24 +54,24 @@ constructor(
|
||||||
|
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
FavoriteSection(
|
FavoriteSection(
|
||||||
UUID.randomUUID(),
|
Constants.FAVORITE_TYPE_MOVIES,
|
||||||
"Movies",
|
resources.getString(R.string.movies_label),
|
||||||
items.filter { it.type == BaseItemKind.MOVIE }).let {
|
items.filter { it.type == BaseItemKind.MOVIE }).let {
|
||||||
if (it.items.isNotEmpty()) favoriteSections.add(
|
if (it.items.isNotEmpty()) favoriteSections.add(
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
FavoriteSection(
|
FavoriteSection(
|
||||||
UUID.randomUUID(),
|
Constants.FAVORITE_TYPE_SHOWS,
|
||||||
"Shows",
|
resources.getString(R.string.shows_label),
|
||||||
items.filter { it.type == BaseItemKind.SERIES }).let {
|
items.filter { it.type == BaseItemKind.SERIES }).let {
|
||||||
if (it.items.isNotEmpty()) favoriteSections.add(
|
if (it.items.isNotEmpty()) favoriteSections.add(
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
FavoriteSection(
|
FavoriteSection(
|
||||||
UUID.randomUUID(),
|
Constants.FAVORITE_TYPE_EPISODES,
|
||||||
"Episodes",
|
resources.getString(R.string.episodes_label),
|
||||||
items.filter { it.type == BaseItemKind.EPISODE }).let {
|
items.filter { it.type == BaseItemKind.EPISODE }).let {
|
||||||
if (it.items.isNotEmpty()) favoriteSections.add(
|
if (it.items.isNotEmpty()) favoriteSections.add(
|
||||||
it
|
it
|
||||||
|
|
|
@ -1,25 +1,31 @@
|
||||||
package dev.jdtech.jellyfin.viewmodels
|
package dev.jdtech.jellyfin.viewmodels
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
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.models.FavoriteSection
|
||||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||||
|
import dev.jdtech.jellyfin.utils.Constants
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SearchResultViewModel
|
class SearchResultViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
|
application: BaseApplication,
|
||||||
private val jellyfinRepository: JellyfinRepository
|
private val jellyfinRepository: JellyfinRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
private val resources: Resources = application.resources
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
|
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
|
||||||
val uiState = _uiState.asStateFlow()
|
val uiState = _uiState.asStateFlow()
|
||||||
|
|
||||||
|
@ -44,24 +50,24 @@ constructor(
|
||||||
|
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
FavoriteSection(
|
FavoriteSection(
|
||||||
UUID.randomUUID(),
|
Constants.FAVORITE_TYPE_MOVIES,
|
||||||
"Movies",
|
resources.getString(R.string.movies_label),
|
||||||
items.filter { it.type == BaseItemKind.MOVIE }).let {
|
items.filter { it.type == BaseItemKind.MOVIE }).let {
|
||||||
if (it.items.isNotEmpty()) sections.add(
|
if (it.items.isNotEmpty()) sections.add(
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
FavoriteSection(
|
FavoriteSection(
|
||||||
UUID.randomUUID(),
|
Constants.FAVORITE_TYPE_SHOWS,
|
||||||
"Shows",
|
resources.getString(R.string.shows_label),
|
||||||
items.filter { it.type == BaseItemKind.SERIES }).let {
|
items.filter { it.type == BaseItemKind.SERIES }).let {
|
||||||
if (it.items.isNotEmpty()) sections.add(
|
if (it.items.isNotEmpty()) sections.add(
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
FavoriteSection(
|
FavoriteSection(
|
||||||
UUID.randomUUID(),
|
Constants.FAVORITE_TYPE_EPISODES,
|
||||||
"Episodes",
|
resources.getString(R.string.episodes_label),
|
||||||
items.filter { it.type == BaseItemKind.EPISODE }).let {
|
items.filter { it.type == BaseItemKind.EPISODE }).let {
|
||||||
if (it.items.isNotEmpty()) sections.add(
|
if (it.items.isNotEmpty()) sections.add(
|
||||||
it
|
it
|
||||||
|
|
|
@ -93,6 +93,7 @@
|
||||||
<string name="error_getting_person_id">Detail unavailable</string>
|
<string name="error_getting_person_id">Detail unavailable</string>
|
||||||
<string name="movies_label">Movies</string>
|
<string name="movies_label">Movies</string>
|
||||||
<string name="shows_label">TV Shows</string>
|
<string name="shows_label">TV Shows</string>
|
||||||
|
<string name="episodes_label">Episodes</string>
|
||||||
<string name="hide">Hide</string>
|
<string name="hide">Hide</string>
|
||||||
<string name="sort_by">Sort by</string>
|
<string name="sort_by">Sort by</string>
|
||||||
<string name="sort_order">Sort order</string>
|
<string name="sort_order">Sort order</string>
|
||||||
|
|
Loading…
Reference in a new issue