From a2b85349e0b703ba86d26df265718680294c48e7 Mon Sep 17 00:00:00 2001 From: Fanyangkong Date: Sun, 3 Mar 2019 22:46:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E6=BB=91=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=88=87=E6=8D=A2=E5=9F=8E=E5=B8=82=E5=90=8E=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E5=88=B7=E6=96=B0=E4=BC=9A=E6=98=BE=E7=A4=BA=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=E5=9F=8E=E5=B8=82=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coolweatherjetpack/ui/area/ChooseAreaFragment.kt | 2 +- .../coolweatherjetpack/ui/weather/WeatherActivity.kt | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/coolweather/coolweatherjetpack/ui/area/ChooseAreaFragment.kt b/app/src/main/java/com/coolweather/coolweatherjetpack/ui/area/ChooseAreaFragment.kt index d16b7bf..504ca4b 100755 --- a/app/src/main/java/com/coolweather/coolweatherjetpack/ui/area/ChooseAreaFragment.kt +++ b/app/src/main/java/com/coolweather/coolweatherjetpack/ui/area/ChooseAreaFragment.kt @@ -61,7 +61,7 @@ class ChooseAreaFragment : Fragment() { val weatherActivity = activity as WeatherActivity weatherActivity.drawerLayout.closeDrawers() weatherActivity.swipeRefresh.isRefreshing = true - weatherActivity.observeWeather(weatherActivity.viewModel.refreshWeather(weatherId, MainActivity.KEY), true) + weatherActivity.observeWeather(weatherId, weatherActivity.viewModel.refreshWeather(weatherId, MainActivity.KEY), true) } } } diff --git a/app/src/main/java/com/coolweather/coolweatherjetpack/ui/weather/WeatherActivity.kt b/app/src/main/java/com/coolweather/coolweatherjetpack/ui/weather/WeatherActivity.kt index 91acc69..67dd775 100755 --- a/app/src/main/java/com/coolweather/coolweatherjetpack/ui/weather/WeatherActivity.kt +++ b/app/src/main/java/com/coolweather/coolweatherjetpack/ui/weather/WeatherActivity.kt @@ -46,19 +46,19 @@ class WeatherActivity : AppCompatActivity() { } else { mWeatherId = intent.getStringExtra("weather_id") weatherLayout.visibility = View.INVISIBLE - observeWeather(viewModel.getWeather(mWeatherId, MainActivity.KEY), false) + observeWeather(mWeatherId, viewModel.getWeather(mWeatherId, MainActivity.KEY), false) } observeBindPic(viewModel.getBingPic()) swipeRefresh.setColorSchemeResources(R.color.colorPrimary) swipeRefresh.setOnRefreshListener { - observeWeather(viewModel.refreshWeather(mWeatherId, MainActivity.KEY), true) + observeWeather(mWeatherId, viewModel.refreshWeather(mWeatherId, MainActivity.KEY), true) } navButton.setOnClickListener { drawerLayout.openDrawer(GravityCompat.START) } } - fun observeWeather(liveData: LiveData>, refresh: Boolean) { + fun observeWeather(weatherId: String, liveData: LiveData>, refresh: Boolean) { if (viewModel.weather == null || refresh) { liveData.observe(this, Observer { result -> if (result?.status == Resource.LOADING) { @@ -66,6 +66,7 @@ class WeatherActivity : AppCompatActivity() { showWeatherInfo(result.data) swipeRefresh.isRefreshing = false viewModel.weather = result.data + mWeatherId = weatherId } else { Toast.makeText(this, result?.message, Toast.LENGTH_SHORT).show() swipeRefresh.isRefreshing = false @@ -73,6 +74,7 @@ class WeatherActivity : AppCompatActivity() { }) } else { showWeatherInfo(viewModel.weather!!) + mWeatherId = weatherId swipeRefresh.isRefreshing = false } }