From 4e65574607bdf72c8defc4704bb7afe36929b37e Mon Sep 17 00:00:00 2001 From: Hugo <446022570@qq.com> Date: Tue, 24 May 2016 10:20:29 +0800 Subject: [PATCH] fix net onErrorReturn --- app/app.iml | 16 ++++++++-------- .../modules/main/ui/MainActivity.java | 17 ++++++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/app.iml b/app/app.iml index 6c6ed3f..7f0efb4 100644 --- a/app/app.iml +++ b/app/app.iml @@ -65,14 +65,6 @@ - - - - - - - - @@ -81,6 +73,14 @@ + + + + + + + + diff --git a/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java b/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java index ba9b1ac..bba2811 100644 --- a/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java +++ b/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java @@ -48,7 +48,6 @@ import com.xiecc.seeWeather.base.BaseActivity; import com.xiecc.seeWeather.base.C; import com.xiecc.seeWeather.common.PLog; import com.xiecc.seeWeather.common.utils.CheckVersion; -import com.xiecc.seeWeather.common.utils.RxUtils; import com.xiecc.seeWeather.common.utils.Util; import com.xiecc.seeWeather.component.ImageLoader; import com.xiecc.seeWeather.component.RetrofitSingleton; @@ -324,7 +323,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig @Override public void onError(Throwable e) { - + PLog.e(e.toString()); } @Override @@ -382,10 +381,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig */ private Observable fetchDataByCache() { return Observable.defer(() -> { - Weather weather = (Weather) aCache.getAsObject(C.WEATHER_CACHE); - return Observable.just(weather); - } - ).compose(RxUtils.rxSchedulerHelper()); + Weather weather = (Weather) aCache.getAsObject(C.WEATHER_CACHE); + return Observable.just(weather); + }); } /** @@ -394,7 +392,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig private Observable fetchDataByNetWork() { String cityName = Util.replaceCity(mSetting.getCityName()); return RetrofitSingleton.getInstance() - .fetchWeather(cityName); + .fetchWeather(cityName) + .onErrorReturn(throwable -> { + PLog.e(throwable.getMessage()); + throwable.printStackTrace(); + return null; + }); } private void showFabDialog() {