Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation by country #809

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import com.michaldrabik.ui_base.utilities.extensions.openWebUrl
import com.michaldrabik.ui_base.utilities.extensions.showErrorSnackbar
import com.michaldrabik.ui_base.utilities.extensions.showInfoSnackbar
import com.michaldrabik.ui_base.utilities.extensions.visibleIf
import com.michaldrabik.ui_settings.helpers.AppLanguage
import com.michaldrabik.ui_model.locale.AppLanguage
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.debounce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.michaldrabik.showly2.ui.main

import com.michaldrabik.showly2.utilities.deeplink.DeepLinkBundle
import com.michaldrabik.ui_base.utilities.events.Event
import com.michaldrabik.ui_settings.helpers.AppLanguage
import com.michaldrabik.ui_model.locale.AppLanguage

// TODO Split events into their Channel
data class MainUiState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.michaldrabik.ui_base.utilities.extensions.combine
import com.michaldrabik.ui_base.utilities.extensions.launchDelayed
import com.michaldrabik.ui_base.utilities.extensions.rethrowCancellation
import com.michaldrabik.ui_model.Tip
import com.michaldrabik.ui_settings.helpers.AppLanguage
import com.michaldrabik.ui_model.locale.AppLanguage
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down 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.locale.language.code)
AppCompatDelegate.setApplicationLocales(locale)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import com.michaldrabik.repository.RatingsRepository
import com.michaldrabik.repository.UserTraktManager
import com.michaldrabik.repository.settings.SettingsRepository
import com.michaldrabik.showly2.BuildConfig
import com.michaldrabik.ui_base.common.AppCountry
import com.michaldrabik.ui_model.locale.AppCountry
import com.michaldrabik.ui_base.utilities.extensions.withApiAtLeast
import com.michaldrabik.ui_settings.helpers.AppLanguage
import com.michaldrabik.ui_model.locale.AppLanguage
import com.michaldrabik.ui_model.locale.AppLocale
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.CoroutineExceptionHandler
Expand Down Expand Up @@ -60,7 +61,7 @@ class MainInitialsCase @Inject constructor(
if (!country.isNullOrBlank()) {
AppCountry.values().forEach { appCountry ->
if (appCountry.code.equals(country, ignoreCase = true)) {
settingsRepository.country = appCountry.code
settingsRepository.locale = AppLocale(settingsRepository.locale.language, appCountry)
return
}
}
Expand All @@ -77,7 +78,7 @@ class MainInitialsCase @Inject constructor(
}

fun setLanguage(appLanguage: AppLanguage) {
settingsRepository.language = appLanguage.code
settingsRepository.locale = AppLocale(appLanguage, settingsRepository.locale.country)
val locales = LocaleListCompat.forLanguageTags(appLanguage.code)
AppCompatDelegate.setApplicationLocales(locales)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.FrameLayout
import com.michaldrabik.showly2.databinding.ViewWelcomeLanguageBinding
import com.michaldrabik.ui_base.utilities.extensions.onClick
import com.michaldrabik.ui_settings.helpers.AppLanguage
import com.michaldrabik.ui_model.locale.AppLanguage

class WelcomeLanguageView : FrameLayout {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.michaldrabik.showly2.R
import com.michaldrabik.showly2.databinding.ViewWelcomeNoteBinding
import com.michaldrabik.ui_base.utilities.extensions.getLocaleStringResource
import com.michaldrabik.ui_base.utilities.extensions.onClick
import com.michaldrabik.ui_settings.helpers.AppLanguage
import com.michaldrabik.ui_model.locale.AppLanguage
import java.util.Locale

class WelcomeNoteView : FrameLayout {
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 @@ -5,7 +5,7 @@ import android.content.Context.MODE_PRIVATE
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

const val DATABASE_VERSION = 41
const val DATABASE_VERSION = 42
const val DATABASE_NAME = "SHOWLY2_DB_2"

class Migrations(context: Context) {
Expand Down Expand Up @@ -770,6 +770,16 @@ class Migrations(context: Context) {
}
}

private val migration42 = object : Migration(41, 42) {
override fun migrate(database: SupportSQLiteDatabase) {
with(database) {
execSQL("ALTER TABLE movies_translations ADD COLUMN country TEXT")
execSQL("ALTER TABLE shows_translations ADD COLUMN country TEXT")
execSQL("ALTER TABLE episodes_translations ADD COLUMN country TEXT")
}
}
}

fun getAll() = listOf(
migration2,
migration3,
Expand Down Expand Up @@ -810,6 +820,7 @@ class Migrations(context: Context) {
migration38,
migration39,
migration40,
migration41
migration41,
migration42
)
}
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,7 +44,7 @@ class PeopleRepository @Inject constructor(
return mappers.person.fromDatabase(local, person.characters)
}

val language = settingsRepository.language
val language = settingsRepository.locale.language.code
val remotePerson = remoteSource.tmdb.fetchPersonDetails(person.ids.tmdb.id)
var bioTranslation: String? = null
if (language != Config.DEFAULT_LANGUAGE) {
Expand Down
Loading