use of com.xiecc.seeWeather.modules.main.domain.Weather in project SeeWeather by xcc3641.
the class DetailCityActivity method initViewWithData.
private void initViewWithData() {
Intent intent = getIntent();
Weather weather = (Weather) intent.getSerializableExtra(IntentKey.WEATHER);
if (weather == null) {
finish();
}
safeSetTitle(weather.basic.city);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
WeatherAdapter mAdapter = new WeatherAdapter(weather);
mRecyclerView.setAdapter(mAdapter);
}
use of com.xiecc.seeWeather.modules.main.domain.Weather in project SeeWeather by xcc3641.
the class MultiCityFragment method initView.
private void initView() {
mWeathers = new ArrayList<>();
mAdapter = new MultiCityAdapter(mWeathers);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setAdapter(mAdapter);
mAdapter.setMultiCityClick(new MultiCityAdapter.onMultiCityClick() {
@Override
public void longClick(String city) {
new AlertDialog.Builder(getActivity()).setMessage("是否删除该城市?").setPositiveButton("删除", (dialog, which) -> {
OrmLite.getInstance().delete(new WhereBuilder(CityORM.class).where("name=?", city));
multiLoad();
Snackbar.make(getView(), String.format(Locale.CHINA, "已经将%s删掉了 Ծ‸ Ծ", city), Snackbar.LENGTH_LONG).setAction("撤销", v -> {
OrmLite.getInstance().save(new CityORM(city));
multiLoad();
}).show();
}).show();
}
@Override
public void click(Weather weather) {
DetailCityActivity.launch(getActivity(), weather);
}
});
if (mRefreshLayout != null) {
mRefreshLayout.setColorSchemeResources(android.R.color.holo_orange_light, android.R.color.holo_red_light, android.R.color.holo_green_light, android.R.color.holo_blue_bright);
mRefreshLayout.setOnRefreshListener(() -> mRefreshLayout.postDelayed(this::multiLoad, 1000));
}
}
use of com.xiecc.seeWeather.modules.main.domain.Weather in project SeeWeather by xcc3641.
the class MultiCityFragment method multiLoad.
private void multiLoad() {
mWeathers.clear();
Observable.create((ObservableOnSubscribe<CityORM>) emitter -> {
try {
for (CityORM cityORM : OrmLite.getInstance().query(CityORM.class)) {
emitter.onNext(cityORM);
}
emitter.onComplete();
} catch (Exception e) {
emitter.onError(e);
}
}).doOnSubscribe(subscription -> mRefreshLayout.setRefreshing(true)).map(city -> Util.replaceCity(city.getName())).distinct().flatMap(cityName -> RetrofitSingleton.getInstance().fetchWeather(cityName)).filter(weather -> !C.UNKNOWN_CITY.equals(weather.status)).take(3).compose(RxUtil.fragmentLifecycle(this)).doOnNext(weather -> mWeathers.add(weather)).doOnComplete(() -> {
mRefreshLayout.setRefreshing(false);
mAdapter.notifyDataSetChanged();
if (mAdapter.isEmpty()) {
mLayout.setVisibility(View.VISIBLE);
} else {
mLayout.setVisibility(View.GONE);
}
}).doOnError(error -> {
if (mAdapter.isEmpty() && mLayout != null) {
mLayout.setVisibility(View.VISIBLE);
}
}).subscribe();
}
Aggregations