Skip to content

Commit

Permalink
Merge pull request #52 from fesave/feature/refactor_location
Browse files Browse the repository at this point in the history
Refactor location
  • Loading branch information
fesave committed Jun 19, 2023
2 parents 259188c + 02bba60 commit 1bcf9fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
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")
}
}

0 comments on commit 1bcf9fe

Please sign in to comment.