Skip to content

Commit

Permalink
Add translation by country
Browse files Browse the repository at this point in the history
  • Loading branch information
VSeryi committed May 3, 2024
1 parent f823e3c commit 9e9649f
Show file tree
Hide file tree
Showing 33 changed files with 195 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MainViewModel @Inject constructor(
private fun checkApi13Locale(isInitialRun: Boolean) {
if (!isInitialRun && !settingsRepository.isLocaleInitialised) {
settingsRepository.isLocaleInitialised = true
val locale = LocaleListCompat.forLanguageTags(settingsRepository.language)
val locale = LocaleListCompat.forLanguageTags(settingsRepository.languageCode)
AppCompatDelegate.setApplicationLocales(locale)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MainInitialsCase @Inject constructor(
}

fun setLanguage(appLanguage: AppLanguage) {
settingsRepository.language = appLanguage.code
settingsRepository.languageCode = appLanguage.code
val locales = LocaleListCompat.forLanguageTags(appLanguage.code)
AppCompatDelegate.setApplicationLocales(locales)
}
Expand All @@ -98,15 +98,15 @@ class MainInitialsCase @Inject constructor(
val languagesCodes = arrayOf(locales[0], locales[1])
.filterNotNull()
.map { it.language.lowercase() }
if (languagesCodes.any { it != Locale(Config.DEFAULT_LANGUAGE).language }) {
if (languagesCodes.any { it != Locale(Config.DEFAULT_LANGUAGE_CODE).language }) {
val languageCodes = appLanguages.map { it.code }
languagesCodes.forEach { language ->
if (language in languageCodes) {
return appLanguages.first { it.code == language }
}
}
appLanguages
.filter { it.code != Config.DEFAULT_LANGUAGE }
.filter { it.code != Config.DEFAULT_LANGUAGE_CODE }
.forEach { appLanguage ->
if (appLanguage.code in languagesCodes) {
return appLanguage
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/java/com/michaldrabik/common/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ object Config {
const val SEARCH_RECENTS_AMOUNT = 5
const val FANART_GALLERY_IMAGES_LIMIT = 20
const val PULL_TO_REFRESH_COOLDOWN_MS = 10_000
const val DEFAULT_LANGUAGE = "en"
const val DEFAULT_LANGUAGE_CODE = "en"
const val DEFAULT_COUNTRY = "us"
const val DEFAULT_DATE_FORMAT = "DEFAULT_24"
const val DEFAULT_LIST_VIEW_MODE = "LIST_NORMAL"
const val DEFAULT_LISTS_GRID_SPAN = 2
const val HOST_ACTIVITY_NAME = "com.michaldrabik.showly2.ui.main.MainActivity"

val DEFAULT_LANGUAGE by lazy { Pair(DEFAULT_LANGUAGE_CODE, DEFAULT_COUNTRY)}

const val SHOW_WHATS_NEW = true
const val SHOW_TIPS_DEBUG = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import com.michaldrabik.data_local.sources.EpisodeTranslationsLocalDataSource
@Dao
interface EpisodeTranslationsDao : BaseDao<EpisodeTranslation>, EpisodeTranslationsLocalDataSource {

@Query("SELECT * FROM episodes_translations WHERE id_trakt == :traktEpisodeId AND id_trakt_show == :traktShowId AND language == :language")
override suspend fun getById(traktEpisodeId: Long, traktShowId: Long, language: String): EpisodeTranslation?
@Query("SELECT * FROM episodes_translations WHERE id_trakt == :traktEpisodeId AND id_trakt_show == :traktShowId AND language == :language AND country == :country")
override suspend fun getById(traktEpisodeId: Long, traktShowId: Long, language: String, country: String): EpisodeTranslation?

@Query("SELECT * FROM episodes_translations WHERE id_trakt IN (:traktEpisodeIds) AND id_trakt_show == :traktShowId AND language == :language")
override suspend fun getByIds(traktEpisodeIds: List<Long>, traktShowId: Long, language: String): List<EpisodeTranslation>
@Query("SELECT * FROM episodes_translations WHERE id_trakt IN (:traktEpisodeIds) AND id_trakt_show == :traktShowId AND language == :language AND country == :country")
override suspend fun getByIds(traktEpisodeIds: List<Long>, traktShowId: Long, language: String, country: String): List<EpisodeTranslation>

@Insert(onConflict = OnConflictStrategy.REPLACE)
override suspend fun insertSingle(translation: EpisodeTranslation)

@Query("DELETE FROM episodes_translations WHERE language IN (:languages)")
override suspend fun deleteByLanguage(languages: List<String>)

@Query("DELETE FROM episodes_translations WHERE country IN (:countries)")
override suspend fun deleteByCountry(countries: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import com.michaldrabik.data_local.sources.MovieTranslationsLocalDataSource
@Dao
interface MovieTranslationsDao : BaseDao<MovieTranslation>, MovieTranslationsLocalDataSource {

@Query("SELECT * FROM movies_translations WHERE id_trakt == :traktId AND language == :language")
override suspend fun getById(traktId: Long, language: String): MovieTranslation?
@Query("SELECT * FROM movies_translations WHERE id_trakt == :traktId AND language == :language AND country == :country")
override suspend fun getById(traktId: Long, language: String, country: String): MovieTranslation?

@Query("SELECT * FROM movies_translations WHERE language == :language")
override suspend fun getAll(language: String): List<MovieTranslation>
@Query("SELECT * FROM movies_translations WHERE language == :language AND country == :country")
override suspend fun getAll(language: String, country: String): List<MovieTranslation>

@Insert(onConflict = OnConflictStrategy.REPLACE)
override suspend fun insertSingle(translation: MovieTranslation)

@Query("DELETE FROM movies_translations WHERE language IN (:languages)")
override suspend fun deleteByLanguage(languages: List<String>)

@Query("DELETE FROM movies_translations WHERE country IN (:countries)")
override suspend fun deleteByCountry(countries: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import com.michaldrabik.data_local.sources.ShowTranslationsLocalDataSource
@Dao
interface ShowTranslationsDao : BaseDao<ShowTranslation>, ShowTranslationsLocalDataSource {

@Query("SELECT * FROM shows_translations WHERE id_trakt == :traktId AND language == :language")
override suspend fun getById(traktId: Long, language: String): ShowTranslation?
@Query("SELECT * FROM shows_translations WHERE id_trakt == :traktId AND language == :language AND country == :country")
override suspend fun getById(traktId: Long, language: String, country: String): ShowTranslation?

@Query("SELECT * FROM shows_translations WHERE language == :language")
override suspend fun getAll(language: String): List<ShowTranslation>
@Query("SELECT * FROM shows_translations WHERE language == :language AND country == :country")
override suspend fun getAll(language: String, country: String): List<ShowTranslation>

@Insert(onConflict = REPLACE)
override suspend fun insertSingle(translation: ShowTranslation)

@Query("DELETE FROM shows_translations WHERE language IN (:languages)")
override suspend fun deleteByLanguage(languages: List<String>)

@Query("DELETE FROM shows_translations WHERE country IN (:countries)")
override suspend fun deleteByCountry(countries: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class EpisodeTranslation(
@ColumnInfo(name = "id_trakt_show") val idTraktShow: Long,
@ColumnInfo(name = "title") val title: String,
@ColumnInfo(name = "language") val language: String,
@ColumnInfo(name = "country") val country: String,
@ColumnInfo(name = "overview") val overview: String,
@ColumnInfo(name = "created_at") val createdAt: Long,
@ColumnInfo(name = "updated_at") val updatedAt: Long
Expand All @@ -38,6 +39,7 @@ data class EpisodeTranslation(
traktShowId: Long,
title: String,
language: String,
country: String,
overview: String,
createdAt: Long
) =
Expand All @@ -46,6 +48,7 @@ data class EpisodeTranslation(
idTraktShow = traktShowId,
title = title,
language = language,
country = country,
overview = overview,
createdAt = createdAt,
updatedAt = createdAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class MovieTranslation(
@ColumnInfo(name = "id_trakt") val idTrakt: Long,
@ColumnInfo(name = "title") val title: String,
@ColumnInfo(name = "language") val language: String,
@ColumnInfo(name = "country") val country: String,
@ColumnInfo(name = "overview") val overview: String,
@ColumnInfo(name = "created_at") val createdAt: Long,
@ColumnInfo(name = "updated_at") val updatedAt: Long
Expand All @@ -33,13 +34,15 @@ data class MovieTranslation(
traktId: Long,
title: String,
language: String,
country: String,
overview: String,
createdAt: Long
) =
MovieTranslation(
idTrakt = traktId,
title = title,
language = language,
country = country,
overview = overview,
createdAt = createdAt,
updatedAt = createdAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class ShowTranslation(
@ColumnInfo(name = "id_trakt") val idTrakt: Long,
@ColumnInfo(name = "title") val title: String,
@ColumnInfo(name = "language") val language: String,
@ColumnInfo(name = "country") val country: String,
@ColumnInfo(name = "overview") val overview: String,
@ColumnInfo(name = "created_at") val createdAt: Long,
@ColumnInfo(name = "updated_at") val updatedAt: Long
Expand All @@ -33,13 +34,15 @@ data class ShowTranslation(
traktId: Long,
title: String,
language: String,
country: String,
overview: String,
createdAt: Long
) =
ShowTranslation(
idTrakt = traktId,
title = title,
language = language,
country = country,
overview = overview,
createdAt = createdAt,
updatedAt = createdAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import com.michaldrabik.data_local.database.model.EpisodeTranslation

interface EpisodeTranslationsLocalDataSource {

suspend fun getById(traktEpisodeId: Long, traktShowId: Long, language: String): EpisodeTranslation?
suspend fun getById(traktEpisodeId: Long, traktShowId: Long, language: String, country: String): EpisodeTranslation?

suspend fun getByIds(traktEpisodeIds: List<Long>, traktShowId: Long, language: String): List<EpisodeTranslation>
suspend fun getByIds(traktEpisodeIds: List<Long>, traktShowId: Long, language: String, country: String): List<EpisodeTranslation>

suspend fun insertSingle(translation: EpisodeTranslation)

suspend fun deleteByLanguage(languages: List<String>)

suspend fun deleteByCountry(countries: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import com.michaldrabik.data_local.database.model.MovieTranslation

interface MovieTranslationsLocalDataSource {

suspend fun getById(traktId: Long, language: String): MovieTranslation?
suspend fun getById(traktId: Long, language: String, country: String): MovieTranslation?

suspend fun getAll(language: String): List<MovieTranslation>
suspend fun getAll(language: String, country: String): List<MovieTranslation>

suspend fun insertSingle(translation: MovieTranslation)

suspend fun deleteByLanguage(languages: List<String>)

suspend fun deleteByCountry(countries: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import com.michaldrabik.data_local.database.model.ShowTranslation

interface ShowTranslationsLocalDataSource {

suspend fun getById(traktId: Long, language: String): ShowTranslation?
suspend fun getById(traktId: Long, language: String, country: String): ShowTranslation?

suspend fun getAll(language: String): List<ShowTranslation>
suspend fun getAll(language: String, country: String): List<ShowTranslation>

suspend fun insertSingle(translation: ShowTranslation)

suspend fun deleteByLanguage(languages: List<String>)

suspend fun deleteByCountry(countries: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class PeopleRepository @Inject constructor(
return mappers.person.fromDatabase(local, person.characters)
}

val language = settingsRepository.language
val language = settingsRepository.languageCode
val remotePerson = remoteSource.tmdb.fetchPersonDetails(person.ids.tmdb.id)
var bioTranslation: String? = null
if (language != Config.DEFAULT_LANGUAGE) {
if (language != Config.DEFAULT_LANGUAGE_CODE) {
val translations = remoteSource.tmdb.fetchPersonTranslations(person.ids.tmdb.id)
bioTranslation = translations[language]?.biography
}
Expand Down
Loading

0 comments on commit 9e9649f

Please sign in to comment.