Search in sources :

Example 1 with Weather

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);
}
Also used : Weather(com.xiecc.seeWeather.modules.main.domain.Weather) WeatherAdapter(com.xiecc.seeWeather.modules.main.adapter.WeatherAdapter) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 2 with Weather

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));
    }
}
Also used : LinearLayout(android.widget.LinearLayout) BaseFragment(com.xiecc.seeWeather.base.BaseFragment) MultiUpdateEvent(com.xiecc.seeWeather.modules.main.domain.MultiUpdateEvent) Bundle(android.os.Bundle) ButterKnife(butterknife.ButterKnife) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) R(com.xiecc.seeWeather.R) C(com.xiecc.seeWeather.common.C) BindView(butterknife.BindView) ArrayList(java.util.ArrayList) RetrofitSingleton(com.xiecc.seeWeather.component.RetrofitSingleton) Util(com.xiecc.seeWeather.common.utils.Util) Locale(java.util.Locale) MultiCityAdapter(com.xiecc.seeWeather.modules.main.adapter.MultiCityAdapter) RxUtil(com.xiecc.seeWeather.common.utils.RxUtil) View(android.view.View) Observable(io.reactivex.Observable) Weather(com.xiecc.seeWeather.modules.main.domain.Weather) RxBus(com.xiecc.seeWeather.component.RxBus) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) LayoutInflater(android.view.LayoutInflater) OrmLite(com.xiecc.seeWeather.component.OrmLite) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewGroup(android.view.ViewGroup) CityORM(com.xiecc.seeWeather.modules.main.domain.CityORM) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) WhereBuilder(com.litesuits.orm.db.assit.WhereBuilder) Weather(com.xiecc.seeWeather.modules.main.domain.Weather) CityORM(com.xiecc.seeWeather.modules.main.domain.CityORM) WhereBuilder(com.litesuits.orm.db.assit.WhereBuilder) WhereBuilder(com.litesuits.orm.db.assit.WhereBuilder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MultiCityAdapter(com.xiecc.seeWeather.modules.main.adapter.MultiCityAdapter)

Example 3 with Weather

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();
}
Also used : LinearLayout(android.widget.LinearLayout) BaseFragment(com.xiecc.seeWeather.base.BaseFragment) MultiUpdateEvent(com.xiecc.seeWeather.modules.main.domain.MultiUpdateEvent) Bundle(android.os.Bundle) ButterKnife(butterknife.ButterKnife) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) R(com.xiecc.seeWeather.R) C(com.xiecc.seeWeather.common.C) BindView(butterknife.BindView) ArrayList(java.util.ArrayList) RetrofitSingleton(com.xiecc.seeWeather.component.RetrofitSingleton) Util(com.xiecc.seeWeather.common.utils.Util) Locale(java.util.Locale) MultiCityAdapter(com.xiecc.seeWeather.modules.main.adapter.MultiCityAdapter) RxUtil(com.xiecc.seeWeather.common.utils.RxUtil) View(android.view.View) Observable(io.reactivex.Observable) Weather(com.xiecc.seeWeather.modules.main.domain.Weather) RxBus(com.xiecc.seeWeather.component.RxBus) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) LayoutInflater(android.view.LayoutInflater) OrmLite(com.xiecc.seeWeather.component.OrmLite) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewGroup(android.view.ViewGroup) CityORM(com.xiecc.seeWeather.modules.main.domain.CityORM) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) WhereBuilder(com.litesuits.orm.db.assit.WhereBuilder) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) CityORM(com.xiecc.seeWeather.modules.main.domain.CityORM)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 Weather (com.xiecc.seeWeather.modules.main.domain.Weather)3 Bundle (android.os.Bundle)2 Nullable (android.support.annotation.Nullable)2 Snackbar (android.support.design.widget.Snackbar)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 LinearLayout (android.widget.LinearLayout)2 BindView (butterknife.BindView)2 ButterKnife (butterknife.ButterKnife)2 WhereBuilder (com.litesuits.orm.db.assit.WhereBuilder)2 R (com.xiecc.seeWeather.R)2 BaseFragment (com.xiecc.seeWeather.base.BaseFragment)2 C (com.xiecc.seeWeather.common.C)2 RxUtil (com.xiecc.seeWeather.common.utils.RxUtil)2 Util (com.xiecc.seeWeather.common.utils.Util)2