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

Refactor location #52

Merged
merged 2 commits into from
Jun 19, 2023
Merged
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 @@ -8,7 +8,6 @@ import com.architectcoders.aacboard.data.datasource.local.LocationDataSource
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import kotlinx.coroutines.suspendCancellableCoroutine
import java.util.Locale
import kotlin.coroutines.resume

class LocationDataSourceImpl(private val context: Context) : LocationDataSource {
Expand All @@ -34,10 +33,6 @@ class LocationDataSourceImpl(private val context: Context) : LocationDataSource
val addresses = this?.let {
geocoder.getFromLocation(latitude, longitude, 1)
}
val countryCode = addresses?.firstOrNull()?.countryCode

return Locale.getAvailableLocales().firstOrNull { locale ->
locale.country == countryCode
}?.language ?: Locale.getDefault().language
return addresses?.firstOrNull()?.countryCode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@ class RegionRepositoryImpl(

override suspend fun getUserLanguage(): String {
return if (appPermissionChecker.check(AppPermissionChecker.Permission.COARSE_LOCATION)) {
locationDataSource.getUserLanguage()?.lowercase() ?: DEFAULT_USER_LANGUAGE
val languageByLocation = locationDataSource.getUserLanguage()?.lowercase()
?: ArasaacAvailableLanguages.EN.value

ArasaacAvailableLanguages.values().first { arasaacLanguage ->
arasaacLanguage.value == languageByLocation
}.value

} else {
DEFAULT_USER_LANGUAGE
ArasaacAvailableLanguages.EN.value
}
}

companion object {
private const val DEFAULT_USER_LANGUAGE = "en"

enum class ArasaacAvailableLanguages(val value: String) {
AN("an"), AR("ar"), BG("bg"), CA("ca"), DE("de"),
EL("el"), EN("en"), ES("es"), ET("et"), EU("eu"),
FA("fa"), FR("fr"), GL("gl"), HE("he"), HR("hr"),
HU("hu"), IT("it"), KO("ko"), LT("lt"), LV("lv"),
MK("mk"), NL("nl"), PL("pl"), PT("pt"), RO("ro"),
RU("ru"), SK("sk"), SQ("sq"), SV("sv"), SR("sr"),
VAL("val"), UK("uk"), ZH("zh")
}
}