Search in sources :

Example 1 with MultiCityAdapter

use of com.xiecc.seeWeather.modules.main.adapter.MultiCityAdapter 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)

Aggregations

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