diff --git a/app/src/main/java/io/betterapps/graysky/data/binding/ObservableWeather.kt b/app/src/main/java/io/betterapps/graysky/data/binding/ObservableWeather.kt index fda9d09..7069510 100644 --- a/app/src/main/java/io/betterapps/graysky/data/binding/ObservableWeather.kt +++ b/app/src/main/java/io/betterapps/graysky/data/binding/ObservableWeather.kt @@ -1,8 +1,9 @@ package io.betterapps.graysky.data.binding -import io.betterapps.graysky.data.coroutines.Status +import androidx.databinding.ObservableField +import androidx.databinding.ObservableInt data class ObservableWeather( - var progressStatus: Status, - var errorMsg: String? + val progressStatus: ObservableInt, + var errorMsg: ObservableField ) \ No newline at end of file diff --git a/app/src/main/java/io/betterapps/graysky/ui/weatherforecast/WeatherForecastFragment.kt b/app/src/main/java/io/betterapps/graysky/ui/weatherforecast/WeatherForecastFragment.kt index 51be9e8..371c7ec 100644 --- a/app/src/main/java/io/betterapps/graysky/ui/weatherforecast/WeatherForecastFragment.kt +++ b/app/src/main/java/io/betterapps/graysky/ui/weatherforecast/WeatherForecastFragment.kt @@ -7,6 +7,8 @@ import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import androidx.databinding.DataBindingUtil +import androidx.databinding.ObservableField +import androidx.databinding.ObservableInt import androidx.fragment.app.Fragment import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager @@ -64,7 +66,7 @@ class WeatherForecastFragment : Fragment() { // lazy inject val weatherViewModel: WeatherViewModel by viewModel() - private val observableWeather = ObservableWeather(Status.LOADING,null) + private val observableWeather = ObservableWeather(ObservableInt(View.VISIBLE), ObservableField("")) override fun onCreateView( inflater: LayoutInflater, @@ -79,12 +81,13 @@ class WeatherForecastFragment : Fragment() { distanceFromUserLocation = arguments?.getDouble(ARG_DISTANCE)!! position = arguments!!.getInt(ARG_POSITION_LIST, 0) - val binding: ForecastWeatherFragmentBinding = DataBindingUtil.inflate(inflater, - R.layout.forecast_weather_fragment, container, false) + val binding: ForecastWeatherFragmentBinding = DataBindingUtil.inflate( + inflater, + R.layout.forecast_weather_fragment, container, false + ) binding.obsWeather = observableWeather return binding.root - // return inflater.inflate(R.layout.forecast_weather_fragment, container, false) } @@ -146,7 +149,9 @@ class WeatherForecastFragment : Fragment() { resource: Resource ) { Timber.d("processWeatherResults , resource.status = ${resource.status}") - observableWeather.progressStatus = resource.status + observableWeather.progressStatus.set(if (resource.status == Status.LOADING) View.VISIBLE else View.GONE) + observableWeather.errorMsg.set(resource.message) + when (resource.status) { Status.LOADING -> { // forecast_weather_progressbar.visibility = View.VISIBLE @@ -160,7 +165,7 @@ class WeatherForecastFragment : Fragment() { Status.ERROR -> { // forecast_weather_progressbar.visibility = View.INVISIBLE // forecast_weather_error_textview.visibility = View.VISIBLE - observableWeather.errorMsg = resource.message + // observableWeather.errorMsg = resource.message // forecast_weather_error_textview.text = resource.message } } diff --git a/app/src/main/res/layout/forecast_weather_fragment.xml b/app/src/main/res/layout/forecast_weather_fragment.xml index 9c0c1b8..9026b34 100644 --- a/app/src/main/res/layout/forecast_weather_fragment.xml +++ b/app/src/main/res/layout/forecast_weather_fragment.xml @@ -53,7 +53,7 @@ android:id="@+id/forecast_weather_progressbar" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:visibility="@{obsWeather.progressStatus == Status.LOADING ? View.VISIBLE : View.GONE}" + android:visibility="@{obsWeather.progressStatus}" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintRight_toRightOf="parent"