diff --git a/app/src/main/java/com/maning/gankmm/bean/mob/WeatherBeseEntity.java b/app/src/main/java/com/maning/gankmm/bean/mob/WeatherBeseEntity.java index 6bb0d20..96548f2 100644 --- a/app/src/main/java/com/maning/gankmm/bean/mob/WeatherBeseEntity.java +++ b/app/src/main/java/com/maning/gankmm/bean/mob/WeatherBeseEntity.java @@ -6,7 +6,7 @@ /** * Created by maning on 2017/4/1. */ - +@Deprecated public class WeatherBeseEntity implements Serializable{ diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/WeatherBean.java b/app/src/main/java/com/maning/gankmm/bean/weather/WeatherInfoBean.java similarity index 94% rename from app/src/main/java/com/maning/gankmm/bean/weather/WeatherBean.java rename to app/src/main/java/com/maning/gankmm/bean/weather/WeatherInfoBean.java index 59f0161..6514188 100644 --- a/app/src/main/java/com/maning/gankmm/bean/weather/WeatherBean.java +++ b/app/src/main/java/com/maning/gankmm/bean/weather/WeatherInfoBean.java @@ -1,12 +1,16 @@ package com.maning.gankmm.bean.weather; +import java.io.Serializable; + /** * @author : maning * @date : 2020-10-14 * @desc : 自己组装使用的天气数据 */ -public class WeatherBean { +public class WeatherInfoBean implements Serializable { + + private static final long serialVersionUID = 8274082861209944804L; //天气 private String weather_desc; //温度 diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherBaseBean.java b/app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherBaseBean.java similarity index 97% rename from app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherBaseBean.java rename to app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherBaseBean.java index b28e077..4c208e4 100644 --- a/app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherBaseBean.java +++ b/app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherBaseBean.java @@ -1,4 +1,4 @@ -package com.maning.gankmm.bean.weather; +package com.maning.gankmm.bean.weather.caiyun; import java.util.List; diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherDailyBean.java b/app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherDailyBean.java similarity index 99% rename from app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherDailyBean.java rename to app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherDailyBean.java index a74208e..aa9a5c7 100644 --- a/app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherDailyBean.java +++ b/app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherDailyBean.java @@ -1,4 +1,4 @@ -package com.maning.gankmm.bean.weather; +package com.maning.gankmm.bean.weather.caiyun; import com.google.gson.annotations.SerializedName; diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherRealTimeBean.java b/app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherRealTimeBean.java similarity index 86% rename from app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherRealTimeBean.java rename to app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherRealTimeBean.java index 48cf70c..03daa30 100644 --- a/app/src/main/java/com/maning/gankmm/bean/weather/CaiyunWeatherRealTimeBean.java +++ b/app/src/main/java/com/maning/gankmm/bean/weather/caiyun/CaiyunWeatherRealTimeBean.java @@ -1,4 +1,4 @@ -package com.maning.gankmm.bean.weather; +package com.maning.gankmm.bean.weather.caiyun; /** * @author : maning @@ -69,7 +69,6 @@ public static class RealtimeEntity { private WindEntity wind; private double pressure; private double apparent_temperature; - private PrecipitationEntity precipitation; private AirQualityEntity air_quality; private LifeIndexEntity life_index; @@ -153,14 +152,6 @@ public void setApparent_temperature(double apparent_temperature) { this.apparent_temperature = apparent_temperature; } - public PrecipitationEntity getPrecipitation() { - return precipitation; - } - - public void setPrecipitation(PrecipitationEntity precipitation) { - this.precipitation = precipitation; - } - public AirQualityEntity getAir_quality() { return air_quality; } @@ -203,58 +194,6 @@ public void setDirection(double direction) { } } - public static class PrecipitationEntity { - /** - * local : {"status":"ok","datasource":"gfs","intensity":0} - */ - - private LocalEntity local; - - public LocalEntity getLocal() { - return local; - } - - public void setLocal(LocalEntity local) { - this.local = local; - } - - public static class LocalEntity { - /** - * status : ok - * datasource : gfs - * intensity : 0 - */ - - private String status; - private String datasource; - private int intensity; - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getDatasource() { - return datasource; - } - - public void setDatasource(String datasource) { - this.datasource = datasource; - } - - public int getIntensity() { - return intensity; - } - - public void setIntensity(int intensity) { - this.intensity = intensity; - } - } - } - public static class AirQualityEntity { /** * pm25 : 6 diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/WeatherBaseBean.java b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinBaseBean.java similarity index 85% rename from app/src/main/java/com/maning/gankmm/bean/weather/WeatherBaseBean.java rename to app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinBaseBean.java index a144efe..d5ea1d9 100644 --- a/app/src/main/java/com/maning/gankmm/bean/weather/WeatherBaseBean.java +++ b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinBaseBean.java @@ -1,11 +1,11 @@ -package com.maning.gankmm.bean.weather; +package com.maning.gankmm.bean.weather.zhixin; /** * @author : maning * @date : 2020-10-14 * @desc : */ -public class WeatherBaseBean { +public class ZhixinBaseBean { private String status; private String status_code; diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinLifeSuggestionResultBean.java b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinLifeSuggestionResultBean.java new file mode 100644 index 0000000..ea3b3ca --- /dev/null +++ b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinLifeSuggestionResultBean.java @@ -0,0 +1,125 @@ +package com.maning.gankmm.bean.weather.zhixin; + +import java.util.List; + +/** + * @author : maning + * @date : 2020-10-15 + * @desc : 生活指数 + */ +public class ZhixinLifeSuggestionResultBean extends ZhixinBaseBean { + + + private List results; + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } + + public static class ResultsEntity { + /** + * location : {"id":"WTW3SJ5ZBJUY","name":"上海","country":"CN","path":"上海,上海,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"} + * suggestion : {"car_washing":{"brief":"不宜","details":""},"dressing":{"brief":"较舒适","details":""},"flu":{"brief":"易发","details":""},"sport":{"brief":"较不宜","details":""},"travel":{"brief":"适宜","details":""},"uv":{"brief":"最弱","details":""}} + * last_update : 2020-10-15T08:32:45+08:00 + */ + + private LocationEntity location; + private ZhixinSuggestionEntity suggestion; + private String last_update; + + public LocationEntity getLocation() { + return location; + } + + public void setLocation(LocationEntity location) { + this.location = location; + } + + public ZhixinSuggestionEntity getSuggestion() { + return suggestion; + } + + public void setSuggestion(ZhixinSuggestionEntity suggestion) { + this.suggestion = suggestion; + } + + public String getLast_update() { + return last_update; + } + + public void setLast_update(String last_update) { + this.last_update = last_update; + } + + public static class LocationEntity { + /** + * id : WTW3SJ5ZBJUY + * name : 上海 + * country : CN + * path : 上海,上海,中国 + * timezone : Asia/Shanghai + * timezone_offset : +08:00 + */ + + private String id; + private String name; + private String country; + private String path; + private String timezone; + private String timezone_offset; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getTimezone() { + return timezone; + } + + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + public String getTimezone_offset() { + return timezone_offset; + } + + public void setTimezone_offset(String timezone_offset) { + this.timezone_offset = timezone_offset; + } + } + + } +} diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinSuggestionEntity.java b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinSuggestionEntity.java new file mode 100644 index 0000000..2d7827a --- /dev/null +++ b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinSuggestionEntity.java @@ -0,0 +1,228 @@ +package com.maning.gankmm.bean.weather.zhixin; + +/** + * @author : maning + * @date : 2020-10-15 + * @desc : + */ +public class ZhixinSuggestionEntity { + /** + * car_washing : {"brief":"不宜","details":""} + * dressing : {"brief":"较舒适","details":""} + * flu : {"brief":"易发","details":""} + * sport : {"brief":"较不宜","details":""} + * travel : {"brief":"适宜","details":""} + * uv : {"brief":"最弱","details":""} + */ + + private CarWashingEntity car_washing; + private DressingEntity dressing; + private FluEntity flu; + private SportEntity sport; + private TravelEntity travel; + private UvEntity uv; + + public CarWashingEntity getCar_washing() { + return car_washing; + } + + public void setCar_washing(CarWashingEntity car_washing) { + this.car_washing = car_washing; + } + + public DressingEntity getDressing() { + return dressing; + } + + public void setDressing(DressingEntity dressing) { + this.dressing = dressing; + } + + public FluEntity getFlu() { + return flu; + } + + public void setFlu(FluEntity flu) { + this.flu = flu; + } + + public SportEntity getSport() { + return sport; + } + + public void setSport(SportEntity sport) { + this.sport = sport; + } + + public TravelEntity getTravel() { + return travel; + } + + public void setTravel(TravelEntity travel) { + this.travel = travel; + } + + public UvEntity getUv() { + return uv; + } + + public void setUv(UvEntity uv) { + this.uv = uv; + } + + public static class CarWashingEntity { + /** + * brief : 不宜 + * details : + */ + + private String brief; + private String details; + + public String getBrief() { + return brief; + } + + public void setBrief(String brief) { + this.brief = brief; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + } + + public static class DressingEntity { + /** + * brief : 较舒适 + * details : + */ + + private String brief; + private String details; + + public String getBrief() { + return brief; + } + + public void setBrief(String brief) { + this.brief = brief; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + } + + public static class FluEntity { + /** + * brief : 易发 + * details : + */ + + private String brief; + private String details; + + public String getBrief() { + return brief; + } + + public void setBrief(String brief) { + this.brief = brief; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + } + + public static class SportEntity { + /** + * brief : 较不宜 + * details : + */ + + private String brief; + private String details; + + public String getBrief() { + return brief; + } + + public void setBrief(String brief) { + this.brief = brief; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + } + + public static class TravelEntity { + /** + * brief : 适宜 + * details : + */ + + private String brief; + private String details; + + public String getBrief() { + return brief; + } + + public void setBrief(String brief) { + this.brief = brief; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + } + + public static class UvEntity { + /** + * brief : 最弱 + * details : + */ + + private String brief; + private String details; + + public String getBrief() { + return brief; + } + + public void setBrief(String brief) { + this.brief = brief; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + } +} diff --git a/app/src/main/java/com/maning/gankmm/bean/weather/WeatherNowBean.java b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinWeatherRealtimeBean.java similarity index 98% rename from app/src/main/java/com/maning/gankmm/bean/weather/WeatherNowBean.java rename to app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinWeatherRealtimeBean.java index 5673127..bd44ca4 100644 --- a/app/src/main/java/com/maning/gankmm/bean/weather/WeatherNowBean.java +++ b/app/src/main/java/com/maning/gankmm/bean/weather/zhixin/ZhixinWeatherRealtimeBean.java @@ -1,4 +1,4 @@ -package com.maning.gankmm.bean.weather; +package com.maning.gankmm.bean.weather.zhixin; import java.util.List; @@ -7,7 +7,7 @@ * @date : 2020-10-14 * @desc : 天气实况 */ -public class WeatherNowBean extends WeatherBaseBean{ +public class ZhixinWeatherRealtimeBean extends ZhixinBaseBean { private List results; diff --git a/app/src/main/java/com/maning/gankmm/http/callback/CommonHttpCallback.java b/app/src/main/java/com/maning/gankmm/http/callback/CommonHttpCallback.java index 85c1a50..2030415 100644 --- a/app/src/main/java/com/maning/gankmm/http/callback/CommonHttpCallback.java +++ b/app/src/main/java/com/maning/gankmm/http/callback/CommonHttpCallback.java @@ -3,8 +3,8 @@ import android.text.TextUtils; import com.maning.gankmm.bean.gank2.Gank2BaseBean; -import com.maning.gankmm.bean.weather.CaiyunWeatherBaseBean; -import com.maning.gankmm.bean.weather.WeatherBaseBean; +import com.maning.gankmm.bean.weather.caiyun.CaiyunWeatherBaseBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinBaseBean; import java.net.ConnectException; import java.net.SocketTimeoutException; @@ -44,12 +44,12 @@ public void onResponse(Call call, Response response) { } else { onFail(1000, "彩云天气接口出错啦~~~"); } - } else if (body instanceof WeatherBaseBean) { - WeatherBaseBean weatherBaseBean = (WeatherBaseBean) response.body(); - if (TextUtils.isEmpty(weatherBaseBean.getStatus())) { + } else if (body instanceof ZhixinBaseBean) { + ZhixinBaseBean zhixinBaseBean = (ZhixinBaseBean) response.body(); + if (TextUtils.isEmpty(zhixinBaseBean.getStatus())) { onSuccess(response.body()); } else { - onFail(1000, weatherBaseBean.getStatus()); + onFail(1000, zhixinBaseBean.getStatus()); } } else { onSuccess(body); diff --git a/app/src/main/java/com/maning/gankmm/http/weather/APIWeatherService.java b/app/src/main/java/com/maning/gankmm/http/weather/APIWeatherService.java index f4ec1aa..a1b12e4 100644 --- a/app/src/main/java/com/maning/gankmm/http/weather/APIWeatherService.java +++ b/app/src/main/java/com/maning/gankmm/http/weather/APIWeatherService.java @@ -1,12 +1,12 @@ package com.maning.gankmm.http.weather; -import com.maning.gankmm.bean.weather.CaiyunWeatherRealTimeBean; -import com.maning.gankmm.bean.weather.WeatherNowBean; +import com.maning.gankmm.bean.weather.caiyun.CaiyunWeatherRealTimeBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinLifeSuggestionResultBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinWeatherRealtimeBean; import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Headers; -import retrofit2.http.POST; import retrofit2.http.Path; import retrofit2.http.Query; @@ -20,11 +20,20 @@ public interface APIWeatherService { //https://api.seniverse.com/v3/weather/now.json?key=SkAwmmz_N361lNLX3&location=beijing&language=zh-Hans&unit=c @Headers("Cache-Control: public, max-age=120") @GET("weather/now.json") - Call getWeatherNow( + Call getWeatherNow( @Query("key") String key, @Query("location") String location ); + //https://api.seniverse.com/v3/life/suggestion.json?key=SkAwmmz_N361lNLX3&location=shanghai&language=zh-Hans + @Headers("Cache-Control: public, max-age=120") + @GET("life/suggestion.json") + Call getLifeSuggestion( + @Query("key") String key, + @Query("location") String location + ); + + @Headers("Cache-Control: public, max-age=120") @GET("https://api.caiyunapp.com/v2.5/Ry1gwjRU7ru2kosN/{location}/realtime.json") Call getWeatherFromCaiyun(@Path("location") String location ); diff --git a/app/src/main/java/com/maning/gankmm/http/weather/WeatherApi.java b/app/src/main/java/com/maning/gankmm/http/weather/WeatherApi.java index 1783d54..af09154 100644 --- a/app/src/main/java/com/maning/gankmm/http/weather/WeatherApi.java +++ b/app/src/main/java/com/maning/gankmm/http/weather/WeatherApi.java @@ -2,9 +2,10 @@ import android.text.TextUtils; -import com.maning.gankmm.bean.weather.CaiyunWeatherRealTimeBean; -import com.maning.gankmm.bean.weather.WeatherBean; -import com.maning.gankmm.bean.weather.WeatherNowBean; +import com.maning.gankmm.bean.weather.caiyun.CaiyunWeatherRealTimeBean; +import com.maning.gankmm.bean.weather.WeatherInfoBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinLifeSuggestionResultBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinWeatherRealtimeBean; import com.maning.gankmm.http.BuildApi; import com.maning.gankmm.http.callback.CommonHttpCallback; @@ -18,45 +19,66 @@ public class WeatherApi { public interface OnWeatherCallback { - void onSuccess(WeatherBean weatherBean); + void onSuccess(WeatherInfoBean weatherInfoBean); void onFail(String msg); } - + private static final String ZHIXIN_KEY = "SkAwmmz_N361lNLX3"; + + + /** + * 生活指数 + * + * @param longitude + * @param latitude + */ + public static void getLifeSuggestionFromZhixin(double longitude, double latitude, CommonHttpCallback httpCallback) { + //经纬度(格式是 纬度:经度,英文冒号分隔) + String location = latitude + ":" + longitude; + BuildApi.getWeatherAPIService().getLifeSuggestion(ZHIXIN_KEY, location).enqueue(httpCallback); + } + + /** + * 天气实况 + * + * @param longitude + * @param latitude + * @param onWeatherCallback + */ public static void getWeatherFromZhixin(double longitude, double latitude, final OnWeatherCallback onWeatherCallback) { //经纬度(格式是 纬度:经度,英文冒号分隔) String location = latitude + ":" + longitude; - BuildApi.getWeatherAPIService().getWeatherNow("SkAwmmz_N361lNLX3", location).enqueue(new CommonHttpCallback() { + BuildApi.getWeatherAPIService().getWeatherNow(ZHIXIN_KEY, location).enqueue(new CommonHttpCallback() { @Override - public void onSuccess(WeatherNowBean result) { + public void onSuccess(ZhixinWeatherRealtimeBean result) { if (result == null || result.getResults() == null || result.getResults().size() == 0) { if (onWeatherCallback != null) { onWeatherCallback.onFail("天气数据获取异常"); } return; } - WeatherNowBean.ResultsEntity resultsEntity = result.getResults().get(0); + ZhixinWeatherRealtimeBean.ResultsEntity resultsEntity = result.getResults().get(0); if (resultsEntity == null) { if (onWeatherCallback != null) { onWeatherCallback.onFail("天气数据获取异常"); } return; } - WeatherNowBean.ResultsEntity.NowEntity nowEntity = resultsEntity.getNow(); - - WeatherBean weatherBean = new WeatherBean(); - weatherBean.setWeather_desc(nowEntity.getText()); - weatherBean.setFeels_like(nowEntity.getFeels_like()); - weatherBean.setHumidity(nowEntity.getHumidity()); - weatherBean.setPressure(nowEntity.getPressure()); - weatherBean.setTemperature(nowEntity.getTemperature()); - weatherBean.setVisibility(nowEntity.getVisibility()); - weatherBean.setWind_direction(nowEntity.getWind_direction()); - weatherBean.setWind_scale(nowEntity.getWind_scale()); - weatherBean.setWind_speed(nowEntity.getWind_speed()); + ZhixinWeatherRealtimeBean.ResultsEntity.NowEntity nowEntity = resultsEntity.getNow(); + + WeatherInfoBean weatherInfoBean = new WeatherInfoBean(); + weatherInfoBean.setWeather_desc(nowEntity.getText()); + weatherInfoBean.setFeels_like(nowEntity.getFeels_like()); + weatherInfoBean.setHumidity(nowEntity.getHumidity()); + weatherInfoBean.setPressure(nowEntity.getPressure()); + weatherInfoBean.setTemperature(nowEntity.getTemperature()); + weatherInfoBean.setVisibility(nowEntity.getVisibility()); + weatherInfoBean.setWind_direction(nowEntity.getWind_direction()); + weatherInfoBean.setWind_scale(nowEntity.getWind_scale()); + weatherInfoBean.setWind_speed(nowEntity.getWind_speed()); if (onWeatherCallback != null) { - onWeatherCallback.onSuccess(weatherBean); + onWeatherCallback.onSuccess(weatherInfoBean); } } @@ -69,6 +91,13 @@ public void onFail(int code, String message) { }); } + /** + * 天气实况 + * + * @param longitude + * @param latitude + * @param onWeatherCallback + */ public static void getWeatherFromCaiyun(double longitude, double latitude, final OnWeatherCallback onWeatherCallback) { String location = longitude + "," + latitude; BuildApi.getWeatherAPIService().getWeatherFromCaiyun(location).enqueue(new CommonHttpCallback() { @@ -83,20 +112,20 @@ public void onSuccess(CaiyunWeatherRealTimeBean caiyunWeatherRealTimeBean) { return; } - WeatherBean weatherBean = new WeatherBean(); - weatherBean.setWeather_desc(CaiyunUtils.getWeatherText(realtime.getSkycon())); - weatherBean.setTemperature(String.valueOf(realtime.getTemperature())); - weatherBean.setFeels_like(String.valueOf(realtime.getApparent_temperature())); - weatherBean.setHumidity(String.valueOf(realtime.getHumidity() * 100)); - weatherBean.setPressure(String.valueOf(realtime.getPressure())); - weatherBean.setVisibility(String.valueOf(realtime.getVisibility())); + WeatherInfoBean weatherInfoBean = new WeatherInfoBean(); + weatherInfoBean.setWeather_desc(CaiyunUtils.getWeatherText(realtime.getSkycon())); + weatherInfoBean.setTemperature(String.valueOf(realtime.getTemperature())); + weatherInfoBean.setFeels_like(String.valueOf(realtime.getApparent_temperature())); + weatherInfoBean.setHumidity(String.valueOf(realtime.getHumidity() * 100)); + weatherInfoBean.setPressure(String.valueOf(realtime.getPressure())); + weatherInfoBean.setVisibility(String.valueOf(realtime.getVisibility())); if (realtime.getWind() != null) { - weatherBean.setWind_direction(CaiyunUtils.getWindDirection(realtime.getWind().getDirection())); - weatherBean.setWind_scale(String.valueOf(CaiyunUtils.getWindScale(realtime.getWind().getSpeed()))); - weatherBean.setWind_speed(String.valueOf(realtime.getWind().getSpeed())); + weatherInfoBean.setWind_direction(CaiyunUtils.getWindDirection(realtime.getWind().getDirection())); + weatherInfoBean.setWind_scale(String.valueOf(CaiyunUtils.getWindScale(realtime.getWind().getSpeed()))); + weatherInfoBean.setWind_speed(String.valueOf(realtime.getWind().getSpeed())); } if (onWeatherCallback != null) { - onWeatherCallback.onSuccess(weatherBean); + onWeatherCallback.onSuccess(weatherInfoBean); } } diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java index 3719d0e..c4c5428 100644 --- a/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java @@ -25,10 +25,8 @@ import com.maning.gankmm.R; import com.maning.gankmm.bean.fir.AppUpdateInfo; import com.maning.gankmm.bean.gank2.GankEntity; -import com.maning.gankmm.bean.mob.WeatherBeseEntity; import com.maning.gankmm.bean.mob.MobUserInfo; -import com.maning.gankmm.bean.weather.WeatherBean; -import com.maning.gankmm.bean.weather.WeatherNowBean; +import com.maning.gankmm.bean.weather.WeatherInfoBean; import com.maning.gankmm.constant.Constants; import com.maning.gankmm.skin.SkinBroadcastReceiver; import com.maning.gankmm.skin.SkinManager; @@ -97,12 +95,13 @@ public class MainActivity extends BaseActivity implements IMainView, View.OnClic private NotifyUtil notifyUtils; - private WeatherBeseEntity.WeatherBean weatherEntity; - private List welFareList; private String provinceName; private String cityName; + private double longitude, latitude; + private TextView header_tv_weather; + private WeatherInfoBean weatherInfoBean; @Override protected void onCreate(Bundle savedInstanceState) { @@ -555,13 +554,16 @@ public void onClick(View view) { break; case R.id.rl_weather: //切换城市 - if (weatherEntity != null) { + if (weatherInfoBean != null) { + weatherInfoBean.setCity_name(cityName); + weatherInfoBean.setLatitude(latitude); + weatherInfoBean.setLongitude(longitude); Intent intent_weather = new Intent(MainActivity.this, WeatherActivity.class); - intent_weather.putExtra(WeatherActivity.intentKey_weatherBean, weatherEntity); + intent_weather.putExtra(WeatherActivity.intentKey_weatherBean, weatherInfoBean); intent_weather.putExtra(WeatherActivity.intentKey_weatherProvinceName, provinceName); intent_weather.putExtra(WeatherActivity.intentKey_weatherCityName, cityName); if (welFareList != null && welFareList.size() > 0) { - intent_weather.putStringArrayListExtra(WeatherActivity.intentKey_bg_url, (ArrayList) welFareList); + intent_weather.putStringArrayListExtra(WeatherActivity.intentKey_bgUrls, (ArrayList) welFareList); } startActivity(intent_weather); } @@ -570,26 +572,29 @@ public void onClick(View view) { } @Override - public void initWeatherInfo(WeatherBean weatherBean) { + public void initWeatherInfo(WeatherInfoBean weatherInfoBean) { + this.weatherInfoBean = weatherInfoBean; //天气 - String weather = weatherBean.getWeather_desc(); + String weather = weatherInfoBean.getWeather_desc(); //城市 header_tv_city_name.setText(provinceName + "-" + cityName); //赋值 - header_tv_temperature.setText(weatherBean.getTemperature() + "°"); + header_tv_temperature.setText(weatherInfoBean.getTemperature() + "°"); header_tv_weather.setText(weather); header_iv_weather.setImageDrawable(getResources().getDrawable(SharePreUtil.getIntData(context, weather, R.drawable.icon_weather_none))); //其他数据可能没有 - tv_weather_wind_direction.setText(weatherBean.getWind_direction() + "风"); - tv_weather_wind_scale.setText(weatherBean.getWind_scale() + "级"); - tv_weather_feels_like.setText(weatherBean.getFeels_like() + "°"); - tv_weather_humidity.setText(weatherBean.getHumidity() + "%"); + tv_weather_wind_direction.setText(weatherInfoBean.getWind_direction() + "风"); + tv_weather_wind_scale.setText(weatherInfoBean.getWind_scale() + "级"); + tv_weather_feels_like.setText(weatherInfoBean.getFeels_like() + "°"); + tv_weather_humidity.setText(weatherInfoBean.getHumidity() + "%"); } @Override - public void updateLocationInfo(String provinceName, String cityName) { + public void updateLocationInfo(String provinceName, String cityName, double longitude, double latitude) { this.provinceName = provinceName; this.cityName = cityName; + this.longitude = longitude; + this.latitude = latitude; } @Override diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/WeatherActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/WeatherActivity.java index 7039950..23bf8ab 100644 --- a/app/src/main/java/com/maning/gankmm/ui/activity/WeatherActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/activity/WeatherActivity.java @@ -20,7 +20,8 @@ import com.maning.gankmm.R; import com.maning.gankmm.bean.mob.CalendarInfoEntity; import com.maning.gankmm.bean.gank2.GankEntity; -import com.maning.gankmm.bean.mob.WeatherBeseEntity; +import com.maning.gankmm.bean.weather.WeatherInfoBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinSuggestionEntity; import com.maning.gankmm.ui.adapter.WeatherAdapter; import com.maning.gankmm.ui.base.BaseActivity; import com.maning.gankmm.ui.iView.IWeatherView; @@ -44,7 +45,7 @@ public class WeatherActivity extends BaseActivity implements OnRefreshListener, public static final String intentKey_weatherBean = "intentKey_weatherBean"; public static final String intentKey_weatherProvinceName = "intentKey_weatherProvinceName"; public static final String intentKey_weatherCityName = "intentKey_weatherCityName"; - public static final String intentKey_bg_url = "intentKey_bg_url"; + public static final String intentKey_bgUrls = "intentKey_bgUrls"; private static final String TAG = "WeatherActivity"; private static final float defaultAlpha = 0.0f; private static final float maxAlpha = 1.0f; @@ -65,13 +66,15 @@ public class WeatherActivity extends BaseActivity implements OnRefreshListener, SwipeToLoadLayout swipeToLoadLayout; private CalendarInfoEntity calendarInfoEntity; - private WeatherBeseEntity.WeatherBean weatherEntity; + private WeatherInfoBean weatherInfoBean; + private ZhixinSuggestionEntity lifeSuggestionBean; private WeatherAdapter weatherAdapter; private String bgPicUrl; private String provinceName; private String cityName; - private List welFareList; + private List girlsList; + private double longitude, latitude; private WeatherPresenterImpl weatherPresenter; @@ -98,15 +101,16 @@ protected void onCreate(Bundle savedInstanceState) { public void initPresenter() { weatherPresenter = new WeatherPresenterImpl(this, this); + weatherPresenter.getLifeSuggestion(longitude,latitude); weatherPresenter.getCalendarInfo(); } private void initBackgroundPic() { - if (welFareList != null && welFareList.size() > 0) { + if (girlsList != null && girlsList.size() > 0) { Random random = new Random(); - int randomIndex = random.nextInt(welFareList.size() - 1); - bgPicUrl = welFareList.get(randomIndex).getUrl(); + int randomIndex = random.nextInt(girlsList.size() - 1); + bgPicUrl = girlsList.get(randomIndex).getUrl(); if (!TextUtils.isEmpty(bgPicUrl)) { RequestOptions options = new RequestOptions(); options.centerCrop(); @@ -135,8 +139,8 @@ public void onResourceReady(Bitmap resource, Transition transiti } private void initViews() { - if (weatherEntity != null) { - tvTitle.setText(weatherEntity.getCity()); + if (weatherInfoBean != null) { + tvTitle.setText(weatherInfoBean.getCity_name()); } //初始化RecycleView @@ -180,10 +184,14 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { } private void initIntent() { - weatherEntity = (WeatherBeseEntity.WeatherBean) getIntent().getSerializableExtra(intentKey_weatherBean); - welFareList = (List) getIntent().getSerializableExtra(intentKey_bg_url); + weatherInfoBean = (WeatherInfoBean) getIntent().getSerializableExtra(intentKey_weatherBean); + girlsList = (List) getIntent().getSerializableExtra(intentKey_bgUrls); provinceName = getIntent().getStringExtra(intentKey_weatherProvinceName); cityName = getIntent().getStringExtra(intentKey_weatherCityName); + if (weatherInfoBean != null) { + longitude = weatherInfoBean.getLongitude(); + latitude = weatherInfoBean.getLatitude(); + } } @OnClick(R.id.rl_back) @@ -193,10 +201,10 @@ public void backBtn() { private void initAdapter() { if (weatherAdapter == null) { - weatherAdapter = new WeatherAdapter(this, weatherEntity, calendarInfoEntity); + weatherAdapter = new WeatherAdapter(this, weatherInfoBean, calendarInfoEntity, lifeSuggestionBean); swipeTarget.setAdapter(weatherAdapter); } else { - weatherAdapter.updateDatas(weatherEntity, calendarInfoEntity); + weatherAdapter.updateDatas(weatherInfoBean, calendarInfoEntity, lifeSuggestionBean); } } @@ -204,7 +212,8 @@ private void initAdapter() { @Override public void onRefresh() { if (weatherPresenter != null) { - weatherPresenter.getCityWeather(provinceName, cityName); + weatherPresenter.getCityWeather(provinceName, cityName, longitude, latitude); + weatherPresenter.getLifeSuggestion(longitude, latitude); } } @@ -214,12 +223,18 @@ public void showToast(String msg) { } @Override - public void initWeatherInfo(WeatherBeseEntity.WeatherBean weatherEntity) { - this.weatherEntity = weatherEntity; + public void initWeatherInfo(WeatherInfoBean weatherInfoBean) { + this.weatherInfoBean = weatherInfoBean; initAdapter(); initBackgroundPic(); } + @Override + public void initLifeSuggestionInfo(ZhixinSuggestionEntity lifeSuggestionBean) { + this.lifeSuggestionBean = lifeSuggestionBean; + initAdapter(); + } + @Override public void overRefresh() { swipeToLoadLayout.setRefreshing(false); diff --git a/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java b/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java index f50ce34..bfcf169 100644 --- a/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java +++ b/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java @@ -12,6 +12,8 @@ import com.maning.gankmm.R; import com.maning.gankmm.bean.mob.CalendarInfoEntity; import com.maning.gankmm.bean.mob.WeatherBeseEntity; +import com.maning.gankmm.bean.weather.WeatherInfoBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinSuggestionEntity; import com.maning.gankmm.ui.view.ArcProgressView; import com.yqritc.recyclerviewflexibledivider.VerticalDividerItemDecoration; @@ -25,21 +27,24 @@ public class WeatherAdapter extends RecyclerView.Adapter { private Context mContext; - private WeatherBeseEntity.WeatherBean weatherEntity; + private WeatherInfoBean weatherEntity; private CalendarInfoEntity calendarInfoEntity; private LayoutInflater layoutInflater; + private ZhixinSuggestionEntity lifeSuggestionBean; - public WeatherAdapter(Context context, WeatherBeseEntity.WeatherBean weatherEntity, CalendarInfoEntity calendarInfoEntity) { + public WeatherAdapter(Context context, WeatherInfoBean weatherEntity, CalendarInfoEntity calendarInfoEntity, ZhixinSuggestionEntity lifeSuggestionBean) { this.mContext = context; this.weatherEntity = weatherEntity; this.calendarInfoEntity = calendarInfoEntity; + this.lifeSuggestionBean = lifeSuggestionBean; layoutInflater = LayoutInflater.from(this.mContext); } - public void updateDatas(WeatherBeseEntity.WeatherBean weatherEntity, CalendarInfoEntity calendarInfoEntity) { + public void updateDatas(WeatherInfoBean weatherEntity, CalendarInfoEntity calendarInfoEntity, ZhixinSuggestionEntity lifeSuggestionBean) { this.weatherEntity = weatherEntity; this.calendarInfoEntity = calendarInfoEntity; + this.lifeSuggestionBean = lifeSuggestionBean; notifyDataSetChanged(); } @@ -52,8 +57,8 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType View inflate = layoutInflater.inflate(R.layout.item_weather_later, parent, false); return new WeatherAdapter.MyViewHolder02(inflate); } else if (viewType == 2) { - View inflate = layoutInflater.inflate(R.layout.item_weather_air, parent, false); - return new WeatherAdapter.MyViewHolder03(inflate); + View inflate = layoutInflater.inflate(R.layout.item_weather_suggestion, parent, false); + return new WeatherAdapter.MyViewHolderSuggestion(inflate); } else if (viewType == 3) { View inflate = layoutInflater.inflate(R.layout.item_weather_calendar, parent, false); return new WeatherAdapter.MyViewHolder04(inflate); @@ -66,11 +71,11 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof MyViewHolder01) { final MyViewHolder01 myViewHolder01 = (MyViewHolder01) holder; - myViewHolder01.tv_01.setText(weatherEntity.getTemperature()); - myViewHolder01.tv_02.setText(weatherEntity.getWeather()); - myViewHolder01.tv_03.setText(weatherEntity.getFuture().get(0).getTemperature()); - myViewHolder01.tv_04.setText(weatherEntity.getAirCondition()); - myViewHolder01.tv_05.setText(weatherEntity.getWind()); + myViewHolder01.tv_01.setText(weatherEntity.getTemperature() + "°"); + myViewHolder01.tv_02.setText(weatherEntity.getWeather_desc()); + myViewHolder01.tv_03.setText("湿度:" + weatherEntity.getHumidity() + "%"); + myViewHolder01.tv_04.setText("体感:" + weatherEntity.getFeels_like() + "°"); + myViewHolder01.tv_05.setText(weatherEntity.getWind_direction() + " " + weatherEntity.getWind_scale() + "级"); } else if (holder instanceof MyViewHolder02) { final MyViewHolder02 myViewHolder02 = (MyViewHolder02) holder; @@ -81,13 +86,27 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { myViewHolder02.recycle_later.setItemAnimator(new DefaultItemAnimator()); myViewHolder02.recycle_later.addItemDecoration(new VerticalDividerItemDecoration.Builder(mContext).color(mContext.getResources().getColor(R.color.lineColor)).build()); - Weather2Adapter weather2Adapter = new Weather2Adapter(mContext, weatherEntity); - myViewHolder02.recycle_later.setAdapter(weather2Adapter); - - } else if (holder instanceof MyViewHolder03) { - final MyViewHolder03 myViewHolder03 = (MyViewHolder03) holder; - String pollutionIndex = weatherEntity.getPollutionIndex(); - myViewHolder03.arc_progress.setCurrentCount(500, Integer.parseInt(pollutionIndex)); +// Weather2Adapter weather2Adapter = new Weather2Adapter(mContext, weatherEntity); +// myViewHolder02.recycle_later.setAdapter(weather2Adapter); + + } else if (holder instanceof MyViewHolderSuggestion) { + final MyViewHolderSuggestion viewHolderSuggestion = (MyViewHolderSuggestion) holder; + //生活指数 + if (lifeSuggestionBean != null) { + viewHolderSuggestion.tv_suggestion_01.setText(lifeSuggestionBean.getCar_washing().getBrief()); + viewHolderSuggestion.tv_suggestion_02.setText(lifeSuggestionBean.getDressing().getBrief()); + viewHolderSuggestion.tv_suggestion_03.setText(lifeSuggestionBean.getFlu().getBrief()); + viewHolderSuggestion.tv_suggestion_04.setText(lifeSuggestionBean.getSport().getBrief()); + viewHolderSuggestion.tv_suggestion_05.setText(lifeSuggestionBean.getTravel().getBrief()); + viewHolderSuggestion.tv_suggestion_06.setText(lifeSuggestionBean.getUv().getBrief()); + }else{ + viewHolderSuggestion.tv_suggestion_01.setText("洗车"); + viewHolderSuggestion.tv_suggestion_02.setText("穿衣"); + viewHolderSuggestion.tv_suggestion_03.setText("感冒"); + viewHolderSuggestion.tv_suggestion_04.setText("运动"); + viewHolderSuggestion.tv_suggestion_05.setText("旅游"); + viewHolderSuggestion.tv_suggestion_06.setText("紫外线"); + } } else if (holder instanceof MyViewHolder04) { final MyViewHolder04 myViewHolder04 = (MyViewHolder04) holder; @@ -145,12 +164,33 @@ public MyViewHolder02(View itemView) { } } - public static class MyViewHolder03 extends RecyclerView.ViewHolder { + public static class MyViewHolderSuggestion extends RecyclerView.ViewHolder { + + @Bind(R.id.tv_suggestion_01) + TextView tv_suggestion_01; + @Bind(R.id.tv_suggestion_02) + TextView tv_suggestion_02; + @Bind(R.id.tv_suggestion_03) + TextView tv_suggestion_03; + @Bind(R.id.tv_suggestion_04) + TextView tv_suggestion_04; + @Bind(R.id.tv_suggestion_05) + TextView tv_suggestion_05; + @Bind(R.id.tv_suggestion_06) + TextView tv_suggestion_06; + + public MyViewHolderSuggestion(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + } + } + + public static class MyViewHolderAir extends RecyclerView.ViewHolder { @Bind(R.id.arc_progress) ArcProgressView arc_progress; - public MyViewHolder03(View itemView) { + public MyViewHolderAir(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } diff --git a/app/src/main/java/com/maning/gankmm/ui/iView/IMainView.java b/app/src/main/java/com/maning/gankmm/ui/iView/IMainView.java index 3a7ec4f..8444861 100644 --- a/app/src/main/java/com/maning/gankmm/ui/iView/IMainView.java +++ b/app/src/main/java/com/maning/gankmm/ui/iView/IMainView.java @@ -1,9 +1,7 @@ package com.maning.gankmm.ui.iView; import com.maning.gankmm.bean.fir.AppUpdateInfo; -import com.maning.gankmm.bean.mob.WeatherBeseEntity; -import com.maning.gankmm.bean.weather.WeatherBean; -import com.maning.gankmm.bean.weather.WeatherNowBean; +import com.maning.gankmm.bean.weather.WeatherInfoBean; /** * Created by maning on 16/6/21. @@ -14,8 +12,8 @@ public interface IMainView { void showAppUpdateDialog(AppUpdateInfo appUpdateInfo); - void initWeatherInfo(WeatherBean weatherBean); + void initWeatherInfo(WeatherInfoBean weatherInfoBean); - void updateLocationInfo(String provinceName, String cityName); + void updateLocationInfo(String provinceName, String cityName, double longitude, double latitude); } diff --git a/app/src/main/java/com/maning/gankmm/ui/iView/IWeatherView.java b/app/src/main/java/com/maning/gankmm/ui/iView/IWeatherView.java index 1e99a65..a515528 100644 --- a/app/src/main/java/com/maning/gankmm/ui/iView/IWeatherView.java +++ b/app/src/main/java/com/maning/gankmm/ui/iView/IWeatherView.java @@ -2,6 +2,8 @@ import com.maning.gankmm.bean.mob.CalendarInfoEntity; import com.maning.gankmm.bean.mob.WeatherBeseEntity; +import com.maning.gankmm.bean.weather.WeatherInfoBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinSuggestionEntity; /** * Created by maning on 16/6/21. @@ -10,7 +12,9 @@ public interface IWeatherView { void showToast(String msg); - void initWeatherInfo(WeatherBeseEntity.WeatherBean weatherEntity); + void initWeatherInfo(WeatherInfoBean weatherInfoBean); + + void initLifeSuggestionInfo(ZhixinSuggestionEntity suggestion); void overRefresh(); diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/IWeatherPresenter.java b/app/src/main/java/com/maning/gankmm/ui/presenter/IWeatherPresenter.java index c17d6d6..225b4db 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/IWeatherPresenter.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/IWeatherPresenter.java @@ -5,8 +5,9 @@ */ public interface IWeatherPresenter { - void getCityWeather(String provinceName, String cityName); + void getCityWeather(String provinceName, String cityName, double longitude, double latitude); - //万年历查询 void getCalendarInfo(); + + void getLifeSuggestion(double longitude, double latitude); } diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java index 04b671e..ad72f9e 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java @@ -1,18 +1,13 @@ package com.maning.gankmm.ui.presenter.impl; import android.content.Context; -import android.text.TextUtils; import com.amap.api.location.AMapLocation; import com.maning.gankmm.R; import com.maning.gankmm.app.MyApplication; import com.maning.gankmm.bean.fir.AppUpdateInfo; -import com.maning.gankmm.bean.mob.WeatherBeseEntity; -import com.maning.gankmm.bean.weather.WeatherBean; -import com.maning.gankmm.bean.weather.WeatherNowBean; +import com.maning.gankmm.bean.weather.WeatherInfoBean; import com.maning.gankmm.constant.Constants; -import com.maning.gankmm.http.callback.MyCallBack; -import com.maning.gankmm.http.mob.MobApi; import com.maning.gankmm.http.update.UpdateApi; import com.maning.gankmm.http.callback.CommonHttpCallback; import com.maning.gankmm.http.weather.WeatherApi; @@ -23,8 +18,6 @@ import com.maning.gankmm.utils.PermissionUtils; import com.maning.gankmm.utils.SharePreUtil; -import java.util.List; - /** * Created by maning on 16/6/21. */ @@ -160,11 +153,11 @@ public void onComplete() { @Override public void getCityWeather(String provinceName, String cityName, double longitude, double latitude) { - mView.updateLocationInfo(provinceName, cityName); + mView.updateLocationInfo(provinceName, cityName, longitude, latitude); WeatherApi.getWeatherFromCaiyun(longitude, latitude, new WeatherApi.OnWeatherCallback() { @Override - public void onSuccess(WeatherBean weatherBean) { - mView.initWeatherInfo(weatherBean); + public void onSuccess(WeatherInfoBean weatherInfoBean) { + mView.initWeatherInfo(weatherInfoBean); } @Override diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WeatherPresenterImpl.java b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WeatherPresenterImpl.java index 64f905e..cfa27de 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WeatherPresenterImpl.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/WeatherPresenterImpl.java @@ -4,9 +4,13 @@ import android.text.TextUtils; import com.maning.gankmm.bean.mob.CalendarInfoEntity; -import com.maning.gankmm.bean.mob.WeatherBeseEntity; +import com.maning.gankmm.bean.weather.WeatherInfoBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinLifeSuggestionResultBean; +import com.maning.gankmm.bean.weather.zhixin.ZhixinSuggestionEntity; +import com.maning.gankmm.http.callback.CommonHttpCallback; import com.maning.gankmm.http.callback.MyCallBack; import com.maning.gankmm.http.mob.MobApi; +import com.maning.gankmm.http.weather.WeatherApi; import com.maning.gankmm.ui.iView.IWeatherView; import com.maning.gankmm.ui.presenter.IWeatherPresenter; @@ -25,23 +29,6 @@ public class WeatherPresenterImpl extends BasePresenterImpl implem @Override public void onSuccessList(int what, List results) { mView.overRefresh(); - if (mView == null) { - return; - } - if (results == null) { - return; - } - switch (what) { - case 0x003: - List weathers = results; - if (weathers.size() > 0) { - WeatherBeseEntity.WeatherBean resultBean = weathers.get(0); - if (resultBean != null) { - mView.initWeatherInfo(resultBean); - } - } - break; - } } @Override @@ -63,7 +50,7 @@ public void onSuccess(int what, Object result) { @Override public void onFail(int what, String result) { - if(mView == null){ + if (mView == null) { return; } mView.overRefresh(); @@ -79,8 +66,21 @@ public WeatherPresenterImpl(Context context, IWeatherView iWeatherView) { } @Override - public void getCityWeather(String provinceName, String cityName) { -// MobApi.getCityWeather(cityName, provinceName, 0x003, httpCallBack); + public void getCityWeather(String provinceName, String cityName, double longitude, double latitude) { + WeatherApi.getWeatherFromCaiyun(longitude, latitude, new WeatherApi.OnWeatherCallback() { + @Override + public void onSuccess(WeatherInfoBean weatherInfoBean) { + mView.initWeatherInfo(weatherInfoBean); + mView.overRefresh(); + } + + @Override + public void onFail(String msg) { + mView.showToast(msg); + mView.overRefresh(); + } + }); + } @Override @@ -90,4 +90,24 @@ public void getCalendarInfo() { String date = sdf.format(new java.util.Date()); MobApi.getCalendarInfo(date, 0x001, httpCallBack); } + + @Override + public void getLifeSuggestion(double longitude, double latitude) { + WeatherApi.getLifeSuggestionFromZhixin(longitude, latitude, new CommonHttpCallback() { + @Override + public void onSuccess(ZhixinLifeSuggestionResultBean result) { + ZhixinLifeSuggestionResultBean.ResultsEntity resultsEntity = result.getResults().get(0); + ZhixinSuggestionEntity suggestion = resultsEntity.getSuggestion(); + if (suggestion == null) { + return; + } + mView.initLifeSuggestionInfo(suggestion); + } + + @Override + public void onFail(int code, String message) { + mView.showToast(message); + } + }); + } } diff --git a/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_car_washing.png b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_car_washing.png new file mode 100644 index 0000000..1662ae0 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_car_washing.png differ diff --git a/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_dressing.png b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_dressing.png new file mode 100644 index 0000000..d6667b4 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_dressing.png differ diff --git a/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_flu.png b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_flu.png new file mode 100644 index 0000000..324f742 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_flu.png differ diff --git a/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_sport.png b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_sport.png new file mode 100644 index 0000000..fcff1b6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_sport.png differ diff --git a/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_travel.png b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_travel.png new file mode 100644 index 0000000..a4aebb2 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_travel.png differ diff --git a/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_uv.png b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_uv.png new file mode 100644 index 0000000..4a79f4b Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_weather_suggestion_uv.png differ diff --git a/app/src/main/res/layout/item_weather_suggestion.xml b/app/src/main/res/layout/item_weather_suggestion.xml new file mode 100644 index 0000000..d9c53bf --- /dev/null +++ b/app/src/main/res/layout/item_weather_suggestion.xml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +