From 3817f68eb546e00e57553cd0041cf6f33aed2e93 Mon Sep 17 00:00:00 2001 From: isoguzay Date: Tue, 15 Mar 2022 22:45:31 +0300 Subject: [PATCH 1/4] Add multi language support for 14 languages --- layers/ui/src/main/res/values-da/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-de/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-es/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-fi/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-fr/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-it/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-ja/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-ko/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-nl/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-no/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-sv/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-tr/strings.xml | 8 ++++++++ layers/ui/src/main/res/values-zh/strings.xml | 8 ++++++++ layers/ui/src/main/res/values/strings.xml | 3 ++- 14 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 layers/ui/src/main/res/values-da/strings.xml create mode 100644 layers/ui/src/main/res/values-de/strings.xml create mode 100644 layers/ui/src/main/res/values-es/strings.xml create mode 100644 layers/ui/src/main/res/values-fi/strings.xml create mode 100644 layers/ui/src/main/res/values-fr/strings.xml create mode 100644 layers/ui/src/main/res/values-it/strings.xml create mode 100644 layers/ui/src/main/res/values-ja/strings.xml create mode 100644 layers/ui/src/main/res/values-ko/strings.xml create mode 100644 layers/ui/src/main/res/values-nl/strings.xml create mode 100644 layers/ui/src/main/res/values-no/strings.xml create mode 100644 layers/ui/src/main/res/values-sv/strings.xml create mode 100644 layers/ui/src/main/res/values-tr/strings.xml create mode 100644 layers/ui/src/main/res/values-zh/strings.xml diff --git a/layers/ui/src/main/res/values-da/strings.xml b/layers/ui/src/main/res/values-da/strings.xml new file mode 100644 index 0000000..320ea17 --- /dev/null +++ b/layers/ui/src/main/res/values-da/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Søg + Historie + Favoritter + Søg + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-de/strings.xml b/layers/ui/src/main/res/values-de/strings.xml new file mode 100644 index 0000000..ca62da4 --- /dev/null +++ b/layers/ui/src/main/res/values-de/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Suche + Geschichte + Favoriten + Suche + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-es/strings.xml b/layers/ui/src/main/res/values-es/strings.xml new file mode 100644 index 0000000..5cce96b --- /dev/null +++ b/layers/ui/src/main/res/values-es/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Búsqueda + Historia + Favoritos + Búsqueda + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-fi/strings.xml b/layers/ui/src/main/res/values-fi/strings.xml new file mode 100644 index 0000000..e8fc0cd --- /dev/null +++ b/layers/ui/src/main/res/values-fi/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Hae + Historia + Suosikit + Hae + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-fr/strings.xml b/layers/ui/src/main/res/values-fr/strings.xml new file mode 100644 index 0000000..8e90b37 --- /dev/null +++ b/layers/ui/src/main/res/values-fr/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Rechercher + Histoire + Favoris + Rechercher + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-it/strings.xml b/layers/ui/src/main/res/values-it/strings.xml new file mode 100644 index 0000000..2b01f9b --- /dev/null +++ b/layers/ui/src/main/res/values-it/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Ricerca + Storia + Preferiti + Ricerca + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-ja/strings.xml b/layers/ui/src/main/res/values-ja/strings.xml new file mode 100644 index 0000000..4af8d37 --- /dev/null +++ b/layers/ui/src/main/res/values-ja/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + 検索 + 歴史 + お気に入り + 検索 + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-ko/strings.xml b/layers/ui/src/main/res/values-ko/strings.xml new file mode 100644 index 0000000..5d51f73 --- /dev/null +++ b/layers/ui/src/main/res/values-ko/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + 검색 + 역사 + 즐겨찾기 + 검색 + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-nl/strings.xml b/layers/ui/src/main/res/values-nl/strings.xml new file mode 100644 index 0000000..4b3cb71 --- /dev/null +++ b/layers/ui/src/main/res/values-nl/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Zoekopdracht + Geschiedenis + Favorieten + Zoekopdracht + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-no/strings.xml b/layers/ui/src/main/res/values-no/strings.xml new file mode 100644 index 0000000..93bf69c --- /dev/null +++ b/layers/ui/src/main/res/values-no/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Søk + Historie + Favoritter + Søk + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-sv/strings.xml b/layers/ui/src/main/res/values-sv/strings.xml new file mode 100644 index 0000000..d74a2fa --- /dev/null +++ b/layers/ui/src/main/res/values-sv/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Sök + Historia + Favoriter + Sök + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-tr/strings.xml b/layers/ui/src/main/res/values-tr/strings.xml new file mode 100644 index 0000000..898e760 --- /dev/null +++ b/layers/ui/src/main/res/values-tr/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + Arama + Arama Sonuçlarım + Favorilerim + Arama Yap + \ No newline at end of file diff --git a/layers/ui/src/main/res/values-zh/strings.xml b/layers/ui/src/main/res/values-zh/strings.xml new file mode 100644 index 0000000..7bc4647 --- /dev/null +++ b/layers/ui/src/main/res/values-zh/strings.xml @@ -0,0 +1,8 @@ + + + GIFit + 搜索 + 历史 + 收藏夹 + 搜索 + \ No newline at end of file diff --git a/layers/ui/src/main/res/values/strings.xml b/layers/ui/src/main/res/values/strings.xml index a01f75c..ec5be1e 100644 --- a/layers/ui/src/main/res/values/strings.xml +++ b/layers/ui/src/main/res/values/strings.xml @@ -1,7 +1,8 @@ + GIFit Search History Favorites - Trending + Search \ No newline at end of file From 1d6856b3358b6562ad3501ee1517329f26cc2984 Mon Sep 17 00:00:00 2001 From: isoguzay Date: Tue, 15 Mar 2022 22:46:20 +0300 Subject: [PATCH 2/4] Add device manager for get device language --- .../theteampotato/gifit/data/DeviceManager.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 layers/data/src/main/java/com/theteampotato/gifit/data/DeviceManager.kt diff --git a/layers/data/src/main/java/com/theteampotato/gifit/data/DeviceManager.kt b/layers/data/src/main/java/com/theteampotato/gifit/data/DeviceManager.kt new file mode 100644 index 0000000..94c27c1 --- /dev/null +++ b/layers/data/src/main/java/com/theteampotato/gifit/data/DeviceManager.kt @@ -0,0 +1,20 @@ +package com.theteampotato.gifit.data + +import android.content.res.Resources +import android.os.Build + +object DeviceManager { + + val language: String + get() = getDeviceLanguage() + + private fun getDeviceLanguage(): String { + val locale = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) + Resources.getSystem().configuration.locale + else + Resources.getSystem().configuration.locales[0] + + return locale.language + } + +} \ No newline at end of file From d31cb87768e79d2e5586f360b294f7ea163b5a41 Mon Sep 17 00:00:00 2001 From: isoguzay Date: Tue, 15 Mar 2022 22:47:04 +0300 Subject: [PATCH 3/4] Add locale manager for set locale and new locale --- .../theteampotato/gifit/data/LocaleManager.kt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 layers/data/src/main/java/com/theteampotato/gifit/data/LocaleManager.kt diff --git a/layers/data/src/main/java/com/theteampotato/gifit/data/LocaleManager.kt b/layers/data/src/main/java/com/theteampotato/gifit/data/LocaleManager.kt new file mode 100644 index 0000000..f0aa922 --- /dev/null +++ b/layers/data/src/main/java/com/theteampotato/gifit/data/LocaleManager.kt @@ -0,0 +1,49 @@ +package com.theteampotato.gifit.data + +import android.content.Context +import android.content.res.Configuration +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.edit +import com.theteampotato.gifit.data.datastore.APP_LANGUAGE +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map +import java.util.* +import javax.inject.Inject + +class LocaleManager @Inject constructor( + private val activityContext: Context, + private val preferencesDataStore: DataStore +) { + + suspend fun setNewLocale(languageCode: String) { + preferencesDataStore.edit { it[APP_LANGUAGE] = languageCode } + updateResources(languageCode) + } + + suspend fun setLocale() = updateResources(getLanguage()) + + private suspend fun getLanguage() = + preferencesDataStore.data.map { it[APP_LANGUAGE] ?: getSupportedLanguage() }.first() + + private fun getSupportedLanguage(): String { + val isSupportDeviceLanguage = LanguageType.values().any { it.languageCode == DeviceManager.language } + + return if (isSupportDeviceLanguage) DeviceManager.language + else LanguageType.ENGLISH.languageCode + } + + private fun updateResources(language: String) { + activityContext.let { + val locale = Locale(language) + Locale.setDefault(locale) + + val config: Configuration = it.resources?.configuration!! + config.setLocale(locale) + config.setLayoutDirection(locale) + + it.resources?.updateConfiguration(config, it.resources?.displayMetrics) + } + } + +} \ No newline at end of file From 596724b0c678638cc6cd7dbda37833316fdc7e41 Mon Sep 17 00:00:00 2001 From: isoguzay Date: Tue, 15 Mar 2022 22:48:07 +0300 Subject: [PATCH 4/4] Close #69 - Implement multi language support --- .../gifit/navigation/NavigationGraph.kt | 8 +- .../theteampotato/gifit/view/MainActivity.kt | 37 +++--- .../view/LanguageSelectionScreen.kt | 115 ++++++++++++++---- .../gifit/home/view/SearchScreen.kt | 29 +++-- .../theteampotato/gifit/data/LanguageType.kt | 18 +++ .../gifit/data/datastore/LocalDataStore.kt | 1 + .../gifit/data/di/RepositoryModule.kt | 15 ++- .../gifit/ui/view/GIFitSearchBar.kt | 4 +- 8 files changed, 172 insertions(+), 55 deletions(-) create mode 100644 layers/data/src/main/java/com/theteampotato/gifit/data/LanguageType.kt diff --git a/app/src/main/kotlin/com/theteampotato/gifit/navigation/NavigationGraph.kt b/app/src/main/kotlin/com/theteampotato/gifit/navigation/NavigationGraph.kt index e74e1b1..ec720bd 100644 --- a/app/src/main/kotlin/com/theteampotato/gifit/navigation/NavigationGraph.kt +++ b/app/src/main/kotlin/com/theteampotato/gifit/navigation/NavigationGraph.kt @@ -4,7 +4,6 @@ import androidx.compose.runtime.Composable import androidx.navigation.* import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable - import com.theteampotato.gifit.favorites.view.FavoritesScreen import com.theteampotato.gifit.favorites.viewmodel.FavoritesViewModel import com.theteampotato.gifit.history.view.HistoryScreen @@ -15,6 +14,7 @@ import com.theteampotato.gifit.language_selection.view.LanguageSelectionScreen import com.theteampotato.gifit.language_selection.viewmodel.LanguageSelectionViewModel import com.theteampotato.gifit.ui.BottomNavScreen import com.theteampotato.gifit.view.HomeScaffold +import com.theteampotato.gifit.view.LocaleActiveManager const val LANGUAGE_SELECTION = "language_selection" @@ -26,8 +26,9 @@ fun NavigationGraph( languageSelectionViewModel: LanguageSelectionViewModel, searchViewModel: SearchViewModel, historyViewModel: HistoryViewModel, - favoritesViewModel: FavoritesViewModel, + favoritesViewModel: FavoritesViewModel ) { + val localeManager = LocaleActiveManager.current NavHost(navController = navController, startDestination = startDestination) { composable(LANGUAGE_SELECTION) { LanguageSelectionScreen( @@ -36,7 +37,8 @@ fun NavigationGraph( popUpTo(navController.currentDestination?.route!!) { inclusive = true } } }, - viewModel = languageSelectionViewModel + viewModel = languageSelectionViewModel, + localeManager = localeManager ) } composable(BottomNavScreen.FavoritesNavScreen.route) { diff --git a/app/src/main/kotlin/com/theteampotato/gifit/view/MainActivity.kt b/app/src/main/kotlin/com/theteampotato/gifit/view/MainActivity.kt index e458ffb..86e5c7f 100644 --- a/app/src/main/kotlin/com/theteampotato/gifit/view/MainActivity.kt +++ b/app/src/main/kotlin/com/theteampotato/gifit/view/MainActivity.kt @@ -7,16 +7,15 @@ import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material.Scaffold -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.lifecycle.lifecycleScope import androidx.navigation.NavController import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController +import com.theteampotato.gifit.data.LocaleManager +import com.theteampotato.gifit.data.datastore.preferencesDataStore import com.theteampotato.gifit.favorites.viewmodel.FavoritesViewModel import com.theteampotato.gifit.history.viewmodel.HistoryViewModel import com.theteampotato.gifit.home.viewmodel.SearchViewModel @@ -30,6 +29,8 @@ import com.theteampotato.gifit.ui.view.GIFitBottomNavBar import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.delay +val LocaleActiveManager = compositionLocalOf { error("No locale manager found!") } + @AndroidEntryPoint class MainActivity : AppCompatActivity() { @@ -39,9 +40,13 @@ class MainActivity : AppCompatActivity() { private val searchViewModel: SearchViewModel by viewModels() private val splashViewModel: SplashViewModel by viewModels() + lateinit var localeManager: LocaleManager + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + localeManager = LocaleManager(this, preferencesDataStore) + var keepSplashScreen = true var selectedLanguage: String? @@ -52,7 +57,7 @@ class MainActivity : AppCompatActivity() { } lifecycleScope.launchWhenCreated { - //splashViewModel.setIsSelectedLanguage(true) + localeManager.setLocale() selectedLanguage = splashViewModel.getIsSelectedLanguage() @@ -60,16 +65,18 @@ class MainActivity : AppCompatActivity() { keepSplashScreen = false setContent { - val navController = rememberNavController() - GIFitTheme { - NavigationGraph( - navController = navController, - startDestination = getStartDestination(selectedLanguage != null), - languageSelectionViewModel = languageSelectionViewModel, - searchViewModel = searchViewModel, - historyViewModel = historyViewModel, - favoritesViewModel = favoritesViewModel - ) + CompositionLocalProvider(LocaleActiveManager provides localeManager) { + val navController = rememberNavController() + GIFitTheme { + NavigationGraph( + navController = navController, + startDestination = getStartDestination(selectedLanguage != null), + languageSelectionViewModel = languageSelectionViewModel, + searchViewModel = searchViewModel, + historyViewModel = historyViewModel, + favoritesViewModel = favoritesViewModel + ) + } } } } diff --git a/features/language-selection/src/main/java/com/theteampotato/gifit/language_selection/view/LanguageSelectionScreen.kt b/features/language-selection/src/main/java/com/theteampotato/gifit/language_selection/view/LanguageSelectionScreen.kt index 6a97f3b..8900c20 100644 --- a/features/language-selection/src/main/java/com/theteampotato/gifit/language_selection/view/LanguageSelectionScreen.kt +++ b/features/language-selection/src/main/java/com/theteampotato/gifit/language_selection/view/LanguageSelectionScreen.kt @@ -4,7 +4,10 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed -import androidx.compose.material.* +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -16,18 +19,24 @@ import androidx.compose.ui.unit.sp import androidx.constraintlayout.compose.ConstraintLayout import androidx.constraintlayout.compose.Dimension import androidx.hilt.navigation.compose.hiltViewModel - +import com.theteampotato.gifit.data.LocaleManager import com.theteampotato.gifit.language_selection.R import com.theteampotato.gifit.language_selection.viewmodel.LanguageSelectionViewModel import com.theteampotato.gifit.ui.babyBlue import com.theteampotato.gifit.ui.view.GIFitLanguageCard import com.theteampotato.gifit.ui.view.GIFitTranslateModelLoader - +import kotlinx.coroutines.launch import timber.log.Timber @Composable -fun LanguageSelectionScreen(modifier: Modifier = Modifier, navigateToSearch: () -> Unit = {}, viewModel: LanguageSelectionViewModel = hiltViewModel()) { - val supportedLanguageList = remember { mutableStateOf(getSupportedLanguages().sortedBy { it.name }) } +fun LanguageSelectionScreen( + modifier: Modifier = Modifier, + navigateToSearch: () -> Unit = {}, + viewModel: LanguageSelectionViewModel = hiltViewModel(), + localeManager: LocaleManager +) { + val supportedLanguageList = + remember { mutableStateOf(getSupportedLanguages().sortedBy { it.name }) } val selectedIndex = remember { mutableStateOf(-1) } val isContinueSelected = remember { mutableStateOf(false) } @@ -75,13 +84,19 @@ fun LanguageSelectionScreen(modifier: Modifier = Modifier, navigateToSearch: () }) { itemsIndexed(supportedLanguageList.value) { index, supportedLanguage -> supportedLanguage.apply { - GIFitLanguageCard(text = name, painter = painterResource(iconResourceId), isSelected = selectedIndex.value == index, onClicked = { - selectedIndex.value = index - }) + GIFitLanguageCard( + text = name, + painter = painterResource(iconResourceId), + isSelected = selectedIndex.value == index, + onClicked = { + selectedIndex.value = index + }) } } } + val coroutineScope = rememberCoroutineScope() + if (selectedIndex.value != -1) { Column( modifier = Modifier @@ -104,7 +119,11 @@ fun LanguageSelectionScreen(modifier: Modifier = Modifier, navigateToSearch: () onSuccess = { Timber.d("onSuccess()") isContinueSelected.value = false - selectedSourceLanguage.value = supportedLanguageList.value[selectedIndex.value].languageCode + selectedSourceLanguage.value = + supportedLanguageList.value[selectedIndex.value].languageCode + coroutineScope.launch { + localeManager.setNewLocale(selectedSourceLanguage.value!!) + } }, onFailure = { Timber.d("onFailure()") @@ -140,17 +159,69 @@ enum class Language(val languageCode: String) { } private fun getSupportedLanguages() = listOf( - SupportedLanguage(name = "Finnish", iconResourceId = R.drawable.ic_finland, languageCode = Language.FINNISH.languageCode), - SupportedLanguage(name = "Chinese", iconResourceId = R.drawable.ic_china, languageCode = Language.CHINESE.languageCode), - SupportedLanguage(name = "Danish", iconResourceId = R.drawable.ic_denmark, languageCode = Language.DANISH.languageCode), - SupportedLanguage(name = "French", iconResourceId = R.drawable.ic_france, languageCode = Language.FRENCH.languageCode), - SupportedLanguage(name = "German", iconResourceId = R.drawable.ic_germany, languageCode = Language.GERMAN.languageCode), - SupportedLanguage(name = "Spanish", iconResourceId = R.drawable.ic_spain, languageCode = Language.SPANISH.languageCode), - SupportedLanguage(name = "Turkish", iconResourceId = R.drawable.ic_turkey, languageCode = Language.TURKISH.languageCode), - SupportedLanguage(name = "Italian", iconResourceId = R.drawable.ic_italy, languageCode = Language.ITALIAN.languageCode), - SupportedLanguage(name = "Japanese", iconResourceId = R.drawable.ic_japan, languageCode = Language.JAPANESE.languageCode), - SupportedLanguage(name = "Dutch", iconResourceId = R.drawable.ic_netherlands, languageCode = Language.DUTCH.languageCode), - SupportedLanguage(name = "Norwegian", iconResourceId = R.drawable.ic_norway, languageCode = Language.NORWEGIAN.languageCode), - SupportedLanguage(name = "Korean", iconResourceId = R.drawable.ic_south_korea, languageCode = Language.KOREAN.languageCode), - SupportedLanguage(name = "Swedish", iconResourceId = R.drawable.ic_sweden, languageCode = Language.SWEDISH.languageCode) + SupportedLanguage( + name = "Finnish", + iconResourceId = R.drawable.ic_finland, + languageCode = Language.FINNISH.languageCode + ), + SupportedLanguage( + name = "Chinese", + iconResourceId = R.drawable.ic_china, + languageCode = Language.CHINESE.languageCode + ), + SupportedLanguage( + name = "Danish", + iconResourceId = R.drawable.ic_denmark, + languageCode = Language.DANISH.languageCode + ), + SupportedLanguage( + name = "French", + iconResourceId = R.drawable.ic_france, + languageCode = Language.FRENCH.languageCode + ), + SupportedLanguage( + name = "German", + iconResourceId = R.drawable.ic_germany, + languageCode = Language.GERMAN.languageCode + ), + SupportedLanguage( + name = "Spanish", + iconResourceId = R.drawable.ic_spain, + languageCode = Language.SPANISH.languageCode + ), + SupportedLanguage( + name = "Turkish", + iconResourceId = R.drawable.ic_turkey, + languageCode = Language.TURKISH.languageCode + ), + SupportedLanguage( + name = "Italian", + iconResourceId = R.drawable.ic_italy, + languageCode = Language.ITALIAN.languageCode + ), + SupportedLanguage( + name = "Japanese", + iconResourceId = R.drawable.ic_japan, + languageCode = Language.JAPANESE.languageCode + ), + SupportedLanguage( + name = "Dutch", + iconResourceId = R.drawable.ic_netherlands, + languageCode = Language.DUTCH.languageCode + ), + SupportedLanguage( + name = "Norwegian", + iconResourceId = R.drawable.ic_norway, + languageCode = Language.NORWEGIAN.languageCode + ), + SupportedLanguage( + name = "Korean", + iconResourceId = R.drawable.ic_south_korea, + languageCode = Language.KOREAN.languageCode + ), + SupportedLanguage( + name = "Swedish", + iconResourceId = R.drawable.ic_sweden, + languageCode = Language.SWEDISH.languageCode + ) ) \ No newline at end of file diff --git a/features/search/src/main/java/com/theteampotato/gifit/home/view/SearchScreen.kt b/features/search/src/main/java/com/theteampotato/gifit/home/view/SearchScreen.kt index 339f02a..f2c921c 100644 --- a/features/search/src/main/java/com/theteampotato/gifit/home/view/SearchScreen.kt +++ b/features/search/src/main/java/com/theteampotato/gifit/home/view/SearchScreen.kt @@ -1,16 +1,19 @@ package com.theteampotato.gifit.home.view -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel - +import com.theteampotato.gifit.home.R import com.theteampotato.gifit.home.viewmodel.SearchViewModel -import com.theteampotato.gifit.ui.view.* - +import com.theteampotato.gifit.ui.view.GIFitLoader +import com.theteampotato.gifit.ui.view.GIFitSearchBar +import com.theteampotato.gifit.ui.view.ResultCard import timber.log.Timber @Composable @@ -22,7 +25,8 @@ fun SearchScreen(searchTextArgument: String? = null, viewModel: SearchViewModel val isFavoriteState = rememberSaveable() { mutableStateOf(false) } - val searchResult = viewModel.searchKeyword(text = searchText.value.ifBlank { null })?.collectAsState(null) + val searchResult = + viewModel.searchKeyword(text = searchText.value.ifBlank { null })?.collectAsState(null) LaunchedEffect(key1 = searchTextArgument) { Timber.d("Composition") @@ -35,13 +39,18 @@ fun SearchScreen(searchTextArgument: String? = null, viewModel: SearchViewModel Column { GIFitSearchBar( - modifier = Modifier.padding(top = 35.dp, start = horizontalPadding, end = horizontalPadding), + modifier = Modifier.padding( + top = 35.dp, + start = horizontalPadding, + end = horizontalPadding + ), text = searchBarText.value, onSearchQueryChanged = { searchBarText.value = it }, onSearchQueryEntered = { searchText.value = searchBarText.value isSearched.value = true - } + }, + placeholderText = stringResource(id = R.string.search) + "..." ) searchResult?.value?.let { @@ -50,7 +59,11 @@ fun SearchScreen(searchTextArgument: String? = null, viewModel: SearchViewModel isSearched.value = false ResultCard( - modifier = Modifier.padding(top = 15.dp, start = horizontalPadding, end = horizontalPadding), + modifier = Modifier.padding( + top = 15.dp, + start = horizontalPadding, + end = horizontalPadding + ), imageURL = it.gifURL ?: "", translatedText = it.translatedText, isFavorite = it.isFavorite, diff --git a/layers/data/src/main/java/com/theteampotato/gifit/data/LanguageType.kt b/layers/data/src/main/java/com/theteampotato/gifit/data/LanguageType.kt new file mode 100644 index 0000000..7f20942 --- /dev/null +++ b/layers/data/src/main/java/com/theteampotato/gifit/data/LanguageType.kt @@ -0,0 +1,18 @@ +package com.theteampotato.gifit.data + +enum class LanguageType(val languageCode: String) { + ENGLISH("en"), + FINNISH("fi"), + CHINESE("zh"), + DANISH("da"), + FRENCH("fr"), + GERMAN("de"), + SPANISH("es"), + TURKISH("tr"), + ITALIAN("it"), + JAPANESE("ja"), + DUTCH("nl"), + NORWEGIAN("no"), + KOREAN("ko"), + SWEDISH("sv") +} \ No newline at end of file diff --git a/layers/data/src/main/java/com/theteampotato/gifit/data/datastore/LocalDataStore.kt b/layers/data/src/main/java/com/theteampotato/gifit/data/datastore/LocalDataStore.kt index ba625e2..713c3a8 100644 --- a/layers/data/src/main/java/com/theteampotato/gifit/data/datastore/LocalDataStore.kt +++ b/layers/data/src/main/java/com/theteampotato/gifit/data/datastore/LocalDataStore.kt @@ -9,3 +9,4 @@ import androidx.datastore.preferences.preferencesDataStore val Context.preferencesDataStore: DataStore by preferencesDataStore(name = "preferences") val SELECTED_LANGUAGE = stringPreferencesKey("selected_language") +val APP_LANGUAGE = stringPreferencesKey("app_language") diff --git a/layers/data/src/main/java/com/theteampotato/gifit/data/di/RepositoryModule.kt b/layers/data/src/main/java/com/theteampotato/gifit/data/di/RepositoryModule.kt index 80db98f..aa0ea50 100644 --- a/layers/data/src/main/java/com/theteampotato/gifit/data/di/RepositoryModule.kt +++ b/layers/data/src/main/java/com/theteampotato/gifit/data/di/RepositoryModule.kt @@ -1,16 +1,14 @@ package com.theteampotato.gifit.data.di import android.content.Context +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import com.theteampotato.gifit.data.LocaleManager import com.theteampotato.gifit.data.datastore.preferencesDataStore -import com.theteampotato.gifit.data.local.datasource.LocalDataSource -import com.theteampotato.gifit.data.local.repository.GIFitLocalRepository -import com.theteampotato.gifit.data.remote.GiphyService -import com.theteampotato.gifit.data.remote.repository.GIFitRemoteRepository import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext -import dagger.hilt.android.scopes.ViewModelScoped import dagger.hilt.components.SingletonComponent import javax.inject.Singleton @@ -33,4 +31,11 @@ object RepositoryModule { fun providesPreferencesDataStore(@ApplicationContext context: Context) = context.preferencesDataStore + @Provides + @Singleton + fun providesLocaleManager( + @ApplicationContext context: Context, + preferencesDataStore: DataStore + ) = LocaleManager(context, preferencesDataStore) + } \ No newline at end of file diff --git a/layers/ui/src/main/kotlin/com/theteampotato/gifit/ui/view/GIFitSearchBar.kt b/layers/ui/src/main/kotlin/com/theteampotato/gifit/ui/view/GIFitSearchBar.kt index bb8fe39..ecf8b7c 100644 --- a/layers/ui/src/main/kotlin/com/theteampotato/gifit/ui/view/GIFitSearchBar.kt +++ b/layers/ui/src/main/kotlin/com/theteampotato/gifit/ui/view/GIFitSearchBar.kt @@ -25,7 +25,7 @@ fun GIFitSearchBar( text: String, onSearchQueryChanged: (String) -> Unit = {}, onSearchQueryEntered: () -> Unit = {}, - placeholderText: String = "Search..." + placeholderText: String ) { val context = LocalContext.current @@ -66,5 +66,5 @@ fun GIFitSearchBar( @Composable @Preview fun PreviewGIFitSearchBar() { - GIFitSearchBar(text = "Ask Me Anything", onSearchQueryChanged = {}) + GIFitSearchBar(text = "Ask Me Anything", onSearchQueryChanged = {}, placeholderText = "Search...") } \ No newline at end of file