mirror of
https://github.com/xcc3641/SeeWeather.git
synced 2026-10-17 05:21:18 +08:00
divide the weather object
This commit is contained in:
@@ -26,7 +26,7 @@ import com.xiecc.seeWeather.modules.city.domain.City;
|
||||
import com.xiecc.seeWeather.modules.city.domain.Province;
|
||||
import com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent;
|
||||
import com.xiecc.seeWeather.modules.main.domain.CityORM;
|
||||
import com.xiecc.seeWeather.modules.main.domain.MultiUpdate;
|
||||
import com.xiecc.seeWeather.modules.main.domain.MultiUpdateEvent;
|
||||
import io.reactivex.BackpressureStrategy;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.FlowableOnSubscribe;
|
||||
@@ -109,7 +109,7 @@ public class ChoiceCityActivity extends ToolbarActivity {
|
||||
String city = Util.replaceCity(cityList.get(pos).mCityName);
|
||||
if (isChecked) {
|
||||
OrmLite.getInstance().save(new CityORM(city));
|
||||
RxBus.getDefault().post(new MultiUpdate());
|
||||
RxBus.getDefault().post(new MultiUpdateEvent());
|
||||
} else {
|
||||
SharedPreferenceUtil.getInstance().setCityName(city);
|
||||
RxBus.getDefault().post(new ChangeCityEvent());
|
||||
|
||||
@@ -270,7 +270,7 @@ public class WeatherAdapter extends AnimRecyclerViewAdapter<RecyclerView.ViewHol
|
||||
}
|
||||
}
|
||||
ImageLoader.load(mContext,
|
||||
SharedPreferenceUtil.getInstance().getInt(weather.dailyForecast.get(i).cond.txtD, R.mipmap.none),
|
||||
SharedPreferenceUtil.getInstance().getInt(weather.dailyForecast.get(i).cond.txt, R.mipmap.none),
|
||||
forecastIcon[i]);
|
||||
forecastTemp[i].setText(
|
||||
String.format("%s℃ - %s℃",
|
||||
@@ -278,7 +278,7 @@ public class WeatherAdapter extends AnimRecyclerViewAdapter<RecyclerView.ViewHol
|
||||
weather.dailyForecast.get(i).tmp.max));
|
||||
forecastTxt[i].setText(
|
||||
String.format("%s。 %s %s %s km/h。 降水几率 %s%%。",
|
||||
weather.dailyForecast.get(i).cond.txtD,
|
||||
weather.dailyForecast.get(i).cond.txt,
|
||||
weather.dailyForecast.get(i).wind.sc,
|
||||
weather.dailyForecast.get(i).wind.dir,
|
||||
weather.dailyForecast.get(i).wind.spd,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AqiEntity implements Serializable {
|
||||
|
||||
@SerializedName("city")
|
||||
public CityEntity city;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BasicEntity implements Serializable {
|
||||
@SerializedName("city")
|
||||
public String city;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CityEntity implements Serializable {
|
||||
@SerializedName("aqi")
|
||||
public String aqi;
|
||||
@SerializedName("co")
|
||||
public String co;
|
||||
@SerializedName("no2")
|
||||
public String no2;
|
||||
@SerializedName("o3")
|
||||
public String o3;
|
||||
@SerializedName("pm10")
|
||||
public String pm10;
|
||||
@SerializedName("pm25")
|
||||
public String pm25;
|
||||
@SerializedName("qlty")
|
||||
public String qlty;
|
||||
@SerializedName("so2")
|
||||
public String so2;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CondEntity implements Serializable {
|
||||
@SerializedName("code")
|
||||
public String code;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DailyForecastEntity implements Serializable {
|
||||
|
||||
@SerializedName("cond")
|
||||
public CondEntity cond;
|
||||
@SerializedName("date")
|
||||
public String date;
|
||||
@SerializedName("hum")
|
||||
public String hum;
|
||||
@SerializedName("pcpn")
|
||||
public String pcpn;
|
||||
@SerializedName("pop")
|
||||
public String pop;
|
||||
@SerializedName("pres")
|
||||
public String pres;
|
||||
/**
|
||||
* max : 19
|
||||
* min : 7
|
||||
*/
|
||||
|
||||
@SerializedName("tmp")
|
||||
public TmpEntity tmp;
|
||||
@SerializedName("vis")
|
||||
public String vis;
|
||||
|
||||
@SerializedName("wind")
|
||||
public WindEntity wind;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class HourlyForecastEntity implements Serializable {
|
||||
@SerializedName("date")
|
||||
public String date;
|
||||
@SerializedName("hum")
|
||||
public String hum;
|
||||
@SerializedName("pop")
|
||||
public String pop;
|
||||
@SerializedName("pres")
|
||||
public String pres;
|
||||
@SerializedName("tmp")
|
||||
public String tmp;
|
||||
|
||||
@SerializedName("wind")
|
||||
public WindEntity wind;
|
||||
}
|
||||
+1
-1
@@ -7,5 +7,5 @@ package com.xiecc.seeWeather.modules.main.domain;
|
||||
* GitHub: https://github.com/xcc3641
|
||||
* Info:
|
||||
*/
|
||||
public class MultiUpdate {
|
||||
public class MultiUpdateEvent {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class NowEntity implements Serializable {
|
||||
|
||||
@SerializedName("cond")
|
||||
public CondEntity cond;
|
||||
@SerializedName("fl")
|
||||
public String fl;
|
||||
@SerializedName("hum")
|
||||
public String hum;
|
||||
@SerializedName("pcpn")
|
||||
public String pcpn;
|
||||
@SerializedName("pres")
|
||||
public String pres;
|
||||
@SerializedName("tmp")
|
||||
public String tmp;
|
||||
@SerializedName("vis")
|
||||
public String vis;
|
||||
@SerializedName("wind")
|
||||
public WindEntity wind;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SuggestionEntity implements Serializable {
|
||||
@SerializedName("comf")
|
||||
public ComfEntity comf;
|
||||
|
||||
@SerializedName("cw")
|
||||
public CwEntity cw;
|
||||
/**
|
||||
* brf : 较冷
|
||||
* txt : 建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。
|
||||
*/
|
||||
|
||||
@SerializedName("drsg")
|
||||
public DrsgEntity drsg;
|
||||
/**
|
||||
* brf : 较易发
|
||||
* txt : 昼夜温差较大,较易发生感冒,请适当增减衣服。体质较弱的朋友请注意防护。
|
||||
*/
|
||||
|
||||
@SerializedName("flu")
|
||||
public FluEntity flu;
|
||||
/**
|
||||
* brf : 较适宜
|
||||
* txt : 阴天,较适宜进行各种户内外运动。
|
||||
*/
|
||||
|
||||
@SerializedName("sport")
|
||||
public SportEntity sport;
|
||||
/**
|
||||
* brf : 适宜
|
||||
* txt : 天气较好,温度适宜,总体来说还是好天气哦,这样的天气适宜旅游,您可以尽情地享受大自然的风光。
|
||||
*/
|
||||
|
||||
@SerializedName("trav")
|
||||
public TravEntity trav;
|
||||
/**
|
||||
* brf : 最弱
|
||||
* txt : 属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。
|
||||
*/
|
||||
|
||||
@SerializedName("uv")
|
||||
public UvEntity uv;
|
||||
|
||||
public static class ComfEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class CwEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class DrsgEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class FluEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class SportEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class TravEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class UvEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TmpEntity implements Serializable {
|
||||
@SerializedName("max")
|
||||
public String max;
|
||||
@SerializedName("min")
|
||||
public String min;
|
||||
}
|
||||
@@ -30,322 +30,4 @@ public class Weather implements Serializable {
|
||||
public boolean isValid() {
|
||||
return aqi != null && now != null && basic != null && suggestion != null;
|
||||
}
|
||||
|
||||
public static class AqiEntity implements Serializable {
|
||||
|
||||
@SerializedName("city")
|
||||
public CityEntity city;
|
||||
|
||||
public static class CityEntity implements Serializable {
|
||||
@SerializedName("aqi")
|
||||
public String aqi;
|
||||
@SerializedName("co")
|
||||
public String co;
|
||||
@SerializedName("no2")
|
||||
public String no2;
|
||||
@SerializedName("o3")
|
||||
public String o3;
|
||||
@SerializedName("pm10")
|
||||
public String pm10;
|
||||
@SerializedName("pm25")
|
||||
public String pm25;
|
||||
@SerializedName("qlty")
|
||||
public String qlty;
|
||||
@SerializedName("so2")
|
||||
public String so2;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BasicEntity implements Serializable {
|
||||
@SerializedName("city")
|
||||
public String city;
|
||||
@SerializedName("cnty")
|
||||
public String cnty;
|
||||
@SerializedName("id")
|
||||
public String id;
|
||||
@SerializedName("lat")
|
||||
public String lat;
|
||||
@SerializedName("lon")
|
||||
public String lon;
|
||||
/**
|
||||
* loc : 2016-02-18 21:04
|
||||
* utc : 2016-02-18 13:04
|
||||
*/
|
||||
|
||||
@SerializedName("update")
|
||||
public UpdateEntity update;
|
||||
|
||||
public static class UpdateEntity implements Serializable {
|
||||
@SerializedName("loc")
|
||||
public String loc;
|
||||
@SerializedName("utc")
|
||||
public String utc;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NowEntity implements Serializable {
|
||||
/**
|
||||
* code : 101
|
||||
* txt : 多云
|
||||
*/
|
||||
|
||||
@SerializedName("cond")
|
||||
public CondEntity cond;
|
||||
@SerializedName("fl")
|
||||
public String fl;
|
||||
@SerializedName("hum")
|
||||
public String hum;
|
||||
@SerializedName("pcpn")
|
||||
public String pcpn;
|
||||
@SerializedName("pres")
|
||||
public String pres;
|
||||
@SerializedName("tmp")
|
||||
public String tmp;
|
||||
@SerializedName("vis")
|
||||
public String vis;
|
||||
/**
|
||||
* deg : 20
|
||||
* dir : 西北风
|
||||
* sc : 4-5
|
||||
* spd : 17
|
||||
*/
|
||||
|
||||
@SerializedName("wind")
|
||||
public WindEntity wind;
|
||||
|
||||
public static class CondEntity implements Serializable {
|
||||
@SerializedName("code")
|
||||
public String code;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class WindEntity implements Serializable {
|
||||
@SerializedName("deg")
|
||||
public String deg;
|
||||
@SerializedName("dir")
|
||||
public String dir;
|
||||
@SerializedName("sc")
|
||||
public String sc;
|
||||
@SerializedName("spd")
|
||||
public String spd;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuggestionEntity implements Serializable {
|
||||
/**
|
||||
* brf : 较舒适
|
||||
* txt : 白天天气阴沉,会感到有点儿凉,但大部分人完全可以接受。
|
||||
*/
|
||||
|
||||
@SerializedName("comf")
|
||||
public ComfEntity comf;
|
||||
/**
|
||||
* brf : 较适宜
|
||||
* txt : 较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。
|
||||
*/
|
||||
|
||||
@SerializedName("cw")
|
||||
public CwEntity cw;
|
||||
/**
|
||||
* brf : 较冷
|
||||
* txt : 建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。
|
||||
*/
|
||||
|
||||
@SerializedName("drsg")
|
||||
public DrsgEntity drsg;
|
||||
/**
|
||||
* brf : 较易发
|
||||
* txt : 昼夜温差较大,较易发生感冒,请适当增减衣服。体质较弱的朋友请注意防护。
|
||||
*/
|
||||
|
||||
@SerializedName("flu")
|
||||
public FluEntity flu;
|
||||
/**
|
||||
* brf : 较适宜
|
||||
* txt : 阴天,较适宜进行各种户内外运动。
|
||||
*/
|
||||
|
||||
@SerializedName("sport")
|
||||
public SportEntity sport;
|
||||
/**
|
||||
* brf : 适宜
|
||||
* txt : 天气较好,温度适宜,总体来说还是好天气哦,这样的天气适宜旅游,您可以尽情地享受大自然的风光。
|
||||
*/
|
||||
|
||||
@SerializedName("trav")
|
||||
public TravEntity trav;
|
||||
/**
|
||||
* brf : 最弱
|
||||
* txt : 属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。
|
||||
*/
|
||||
|
||||
@SerializedName("uv")
|
||||
public UvEntity uv;
|
||||
|
||||
public static class ComfEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class CwEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class DrsgEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class FluEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class SportEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class TravEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
|
||||
public static class UvEntity implements Serializable {
|
||||
@SerializedName("brf")
|
||||
public String brf;
|
||||
@SerializedName("txt")
|
||||
public String txt;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DailyForecastEntity implements Serializable {
|
||||
/**
|
||||
* sr : 07:30
|
||||
* ss : 18:44
|
||||
*/
|
||||
|
||||
@SerializedName("astro")
|
||||
public AstroEntity astro;
|
||||
/**
|
||||
* code_d : 100
|
||||
* code_n : 104
|
||||
* txt_d : 晴
|
||||
* txt_n : 阴
|
||||
*/
|
||||
|
||||
@SerializedName("cond")
|
||||
public CondEntity cond;
|
||||
@SerializedName("date")
|
||||
public String date;
|
||||
@SerializedName("hum")
|
||||
public String hum;
|
||||
@SerializedName("pcpn")
|
||||
public String pcpn;
|
||||
@SerializedName("pop")
|
||||
public String pop;
|
||||
@SerializedName("pres")
|
||||
public String pres;
|
||||
/**
|
||||
* max : 19
|
||||
* min : 7
|
||||
*/
|
||||
|
||||
@SerializedName("tmp")
|
||||
public TmpEntity tmp;
|
||||
@SerializedName("vis")
|
||||
public String vis;
|
||||
/**
|
||||
* deg : 54
|
||||
* dir : 无持续风向
|
||||
* sc : 微风
|
||||
* spd : 6
|
||||
*/
|
||||
|
||||
@SerializedName("wind")
|
||||
public WindEntity wind;
|
||||
|
||||
public static class AstroEntity implements Serializable {
|
||||
@SerializedName("sr")
|
||||
public String sr;
|
||||
@SerializedName("ss")
|
||||
public String ss;
|
||||
}
|
||||
|
||||
public static class CondEntity implements Serializable {
|
||||
@SerializedName("code_d")
|
||||
public String codeD;
|
||||
@SerializedName("code_n")
|
||||
public String codeN;
|
||||
@SerializedName("txt_d")
|
||||
public String txtD;
|
||||
@SerializedName("txt_n")
|
||||
public String txtN;
|
||||
}
|
||||
|
||||
public static class TmpEntity implements Serializable {
|
||||
@SerializedName("max")
|
||||
public String max;
|
||||
@SerializedName("min")
|
||||
public String min;
|
||||
}
|
||||
|
||||
public static class WindEntity implements Serializable {
|
||||
@SerializedName("deg")
|
||||
public String deg;
|
||||
@SerializedName("dir")
|
||||
public String dir;
|
||||
@SerializedName("sc")
|
||||
public String sc;
|
||||
@SerializedName("spd")
|
||||
public String spd;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HourlyForecastEntity implements Serializable {
|
||||
@SerializedName("date")
|
||||
public String date;
|
||||
@SerializedName("hum")
|
||||
public String hum;
|
||||
@SerializedName("pop")
|
||||
public String pop;
|
||||
@SerializedName("pres")
|
||||
public String pres;
|
||||
@SerializedName("tmp")
|
||||
public String tmp;
|
||||
/**
|
||||
* deg : 13
|
||||
* dir : 东北风
|
||||
* sc : 微风
|
||||
* spd : 16
|
||||
*/
|
||||
|
||||
@SerializedName("wind")
|
||||
public WindEntity wind;
|
||||
|
||||
public static class WindEntity implements Serializable {
|
||||
@SerializedName("deg")
|
||||
public String deg;
|
||||
@SerializedName("dir")
|
||||
public String dir;
|
||||
@SerializedName("sc")
|
||||
public String sc;
|
||||
@SerializedName("spd")
|
||||
public String spd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
public class WeatherAPI {
|
||||
|
||||
@SerializedName("HeWeather5") @Expose
|
||||
public List<Weather> mWeathers
|
||||
= new ArrayList<>();
|
||||
@SerializedName("HeWeather5")
|
||||
@Expose
|
||||
public List<Weather> mWeathers = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xiecc.seeWeather.modules.main.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class WindEntity implements Serializable {
|
||||
@SerializedName("deg")
|
||||
public String deg;
|
||||
@SerializedName("dir")
|
||||
public String dir;
|
||||
@SerializedName("sc")
|
||||
public String sc;
|
||||
@SerializedName("spd")
|
||||
public String spd;
|
||||
}
|
||||
@@ -14,13 +14,10 @@ import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationClientOption;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.tbruyelle.rxpermissions2.RxPermissions;
|
||||
import com.xiecc.seeWeather.R;
|
||||
import com.xiecc.seeWeather.base.BaseApplication;
|
||||
import com.xiecc.seeWeather.base.BaseFragment;
|
||||
import com.xiecc.seeWeather.common.utils.CheckVersion;
|
||||
import com.xiecc.seeWeather.common.utils.RxUtil;
|
||||
@@ -43,7 +40,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
* GitHub: https://github.com/xcc3641
|
||||
* Info:
|
||||
*/
|
||||
public class MainFragment extends BaseFragment implements AMapLocationListener {
|
||||
public class MainFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.recyclerview)
|
||||
RecyclerView mRecyclerView;
|
||||
@@ -57,8 +54,9 @@ public class MainFragment extends BaseFragment implements AMapLocationListener {
|
||||
private static Weather mWeather = new Weather();
|
||||
private WeatherAdapter mAdapter;
|
||||
//声明AMapLocationClient类对象
|
||||
public AMapLocationClient mLocationClient = null;
|
||||
public AMapLocationClientOption mLocationOption = null;
|
||||
|
||||
public AMapLocationClient mLocationClient;
|
||||
public AMapLocationClientOption mLocationOption;
|
||||
|
||||
private View view;
|
||||
|
||||
@@ -84,6 +82,7 @@ public class MainFragment extends BaseFragment implements AMapLocationListener {
|
||||
initView();
|
||||
new RxPermissions(getActivity())
|
||||
.request(Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
.doOnNext(o -> mRefreshLayout.setRefreshing(true))
|
||||
.doOnNext(granted -> {
|
||||
if (granted) {
|
||||
location();
|
||||
@@ -98,14 +97,12 @@ public class MainFragment extends BaseFragment implements AMapLocationListener {
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
RxBus.getDefault()
|
||||
.toObservable(ChangeCityEvent.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter(event -> isVisible())
|
||||
.doOnNext(event -> {
|
||||
if (mRefreshLayout != null) {
|
||||
mRefreshLayout.setRefreshing(true);
|
||||
}
|
||||
mRefreshLayout.setRefreshing(true);
|
||||
load();
|
||||
})
|
||||
.subscribe();
|
||||
@@ -172,55 +169,37 @@ public class MainFragment extends BaseFragment implements AMapLocationListener {
|
||||
* 高德定位
|
||||
*/
|
||||
private void location() {
|
||||
mRefreshLayout.setRefreshing(true);
|
||||
//初始化定位
|
||||
mLocationClient = new AMapLocationClient(BaseApplication.getAppContext());
|
||||
//设置定位回调监听
|
||||
mLocationClient.setLocationListener(this);
|
||||
mLocationClient = new AMapLocationClient(getActivity());
|
||||
mLocationOption = new AMapLocationClientOption();
|
||||
//设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
|
||||
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
|
||||
//设置是否返回地址信息(默认返回地址信息)
|
||||
mLocationOption.setNeedAddress(true);
|
||||
//设置是否只定位一次,默认为false\
|
||||
mLocationOption.setOnceLocation(false);
|
||||
//设置是否强制刷新WIFI,默认为强制刷新
|
||||
mLocationOption.setWifiActiveScan(true);
|
||||
//设置是否允许模拟位置,默认为false,不允许模拟位置
|
||||
mLocationOption.setMockEnable(false);
|
||||
mLocationOption.setOnceLocation(true);
|
||||
mLocationOption.setWifiActiveScan(false);
|
||||
//设置定位间隔 单位毫秒
|
||||
int tempTime = SharedPreferenceUtil.getInstance().getAutoUpdate();
|
||||
if (tempTime == 0) {
|
||||
tempTime = 100;
|
||||
}
|
||||
mLocationOption.setInterval(tempTime * SharedPreferenceUtil.ONE_HOUR);
|
||||
//给定位客户端对象设置定位参数
|
||||
int autoUpdateTime = SharedPreferenceUtil.getInstance().getAutoUpdate();
|
||||
mLocationOption.setInterval((autoUpdateTime == 0 ? 100 : autoUpdateTime) * SharedPreferenceUtil.ONE_HOUR);
|
||||
mLocationClient.setLocationOption(mLocationOption);
|
||||
//启动定位
|
||||
mLocationClient.startLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(AMapLocation aMapLocation) {
|
||||
if (aMapLocation != null) {
|
||||
if (aMapLocation.getErrorCode() == 0) {
|
||||
//定位成功回调信息,设置相关消息
|
||||
aMapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见定位类型表
|
||||
SharedPreferenceUtil.getInstance().setCityName(Util.replaceCity(aMapLocation.getCity()));
|
||||
} else {
|
||||
if (isAdded()) {
|
||||
ToastUtil.showShort(getString(R.string.errorLocation));
|
||||
mLocationClient.setLocationListener(aMapLocation -> {
|
||||
if (aMapLocation != null) {
|
||||
if (aMapLocation.getErrorCode() == 0) {
|
||||
aMapLocation.getLocationType();
|
||||
SharedPreferenceUtil.getInstance().setCityName(Util.replaceCity(aMapLocation.getCity()));
|
||||
} else {
|
||||
if (isAdded()) {
|
||||
ToastUtil.showShort(getString(R.string.errorLocation));
|
||||
}
|
||||
}
|
||||
load();
|
||||
}
|
||||
load();
|
||||
}
|
||||
});
|
||||
mLocationClient.startLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mLocationClient = null;
|
||||
mLocationOption = null;
|
||||
mLocationClient.onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.xiecc.seeWeather.component.RetrofitSingleton;
|
||||
import com.xiecc.seeWeather.component.RxBus;
|
||||
import com.xiecc.seeWeather.modules.main.adapter.MultiCityAdapter;
|
||||
import com.xiecc.seeWeather.modules.main.domain.CityORM;
|
||||
import com.xiecc.seeWeather.modules.main.domain.MultiUpdate;
|
||||
import com.xiecc.seeWeather.modules.main.domain.MultiUpdateEvent;
|
||||
import com.xiecc.seeWeather.modules.main.domain.Weather;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
@@ -75,7 +75,7 @@ public class MultiCityFragment extends BaseFragment {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
RxBus.getDefault()
|
||||
.toObservable(MultiUpdate.class)
|
||||
.toObservable(MultiUpdateEvent.class)
|
||||
.doOnNext(event -> multiLoad())
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user