Add some providers

This commit is contained in:
Tommaso Berlose
2020-10-04 11:43:36 +02:00
parent c04040e242
commit 1dee4cc8e5
34 changed files with 213 additions and 3 deletions

View File

@ -102,6 +102,12 @@ class WeatherTabFragment : Fragment() {
checkLocationPermission()
})
viewModel.weatherProvider.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
label_weather_provider.text = WeatherHelper.getProviderName(requireContext(), Constants.WeatherProvider.fromInt(it)!!)
}
})
viewModel.weatherProviderApi.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
checkWeatherProviderConfig()
@ -198,6 +204,21 @@ class WeatherTabFragment : Fragment() {
Preferences.showWeather = enabled
}
action_weather_provider.setOnClickListener {
if (Preferences.showWeather) {
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_weather_provider_api)).setSelectedValue(Preferences.weatherProvider)
(0 until 11).forEach {
val item = Constants.WeatherProvider.fromInt(it)
dialog.addItem(WeatherHelper.getProviderName(requireContext(), item!!), it)
}
dialog.addOnSelectItemListener { value ->
Preferences.weatherProvider = value
checkWeatherProviderConfig()
}.show()
}
}
action_weather_provider_api_key.setOnClickListener {
if (Preferences.showWeather) {
startActivityForResult(

View File

@ -67,6 +67,7 @@ class MainViewModel : ViewModel() {
val showWeatherWarning = Preferences.asLiveData(Preferences::showWeatherWarning)
val weatherIconPack = Preferences.asLiveData(Preferences::weatherIconPack)
val weatherProvider = Preferences.asLiveData(Preferences::weatherProvider)
// Glance
val showGlance = Preferences.asLiveData(Preferences::showGlance)