mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
attempt to fix auto regions
This commit is contained in:
parent
c4fdeeb03a
commit
c199d42116
@ -13,6 +13,7 @@ import com.github.libretube.R
|
|||||||
import com.github.libretube.adapters.TrendingAdapter
|
import com.github.libretube.adapters.TrendingAdapter
|
||||||
import com.github.libretube.databinding.FragmentHomeBinding
|
import com.github.libretube.databinding.FragmentHomeBinding
|
||||||
import com.github.libretube.preferences.PreferenceHelper
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
|
import com.github.libretube.util.LocaleHelper
|
||||||
import com.github.libretube.util.RetrofitInstance
|
import com.github.libretube.util.RetrofitInstance
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -49,7 +50,11 @@ class HomeFragment : Fragment() {
|
|||||||
val regionPref = PreferenceHelper.getString(requireContext(), "region", "sys")!!
|
val regionPref = PreferenceHelper.getString(requireContext(), "region", "sys")!!
|
||||||
|
|
||||||
// get the system default country if auto region selected
|
// get the system default country if auto region selected
|
||||||
region = if (regionPref == "sys") Locale.getDefault().country else regionPref
|
region = if (regionPref == "sys") {
|
||||||
|
LocaleHelper
|
||||||
|
.getDetectedCountry(requireContext(), "UK")
|
||||||
|
.uppercase()
|
||||||
|
} else regionPref
|
||||||
|
|
||||||
binding.recview.layoutManager = GridLayoutManager(view.context, grid.toInt())
|
binding.recview.layoutManager = GridLayoutManager(view.context, grid.toInt())
|
||||||
fetchJson()
|
fetchJson()
|
||||||
|
@ -2,6 +2,7 @@ package com.github.libretube.util
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.telephony.TelephonyManager
|
||||||
import com.github.libretube.preferences.PreferenceHelper
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -37,4 +38,50 @@ object LocaleHelper {
|
|||||||
}
|
}
|
||||||
res.updateConfiguration(conf, dm)
|
res.updateConfiguration(conf, dm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDetectedCountry(context: Context, defaultCountryIsoCode: String): String {
|
||||||
|
|
||||||
|
detectSIMCountry(context)?.let {
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
|
||||||
|
detectNetworkCountry(context)?.let {
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
|
||||||
|
detectLocaleCountry(context)?.let {
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultCountryIsoCode
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun detectSIMCountry(context: Context): String? {
|
||||||
|
try {
|
||||||
|
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||||
|
return telephonyManager.simCountryIso
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun detectNetworkCountry(context: Context): String? {
|
||||||
|
try {
|
||||||
|
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||||
|
return telephonyManager.networkCountryIso
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun detectLocaleCountry(context: Context): String? {
|
||||||
|
try {
|
||||||
|
return context.resources.configuration.locales[0].country
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user