Search in sources :

Example 1 with Hero

use of cn.nicolite.palm300heroes.model.bean.Hero in project Palm300Heroes by nicolite.

the class HeroAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final HeroViewHolder holder, int position) {
    Hero heroes = dataList.get(position);
    Glide.with(context).load(Constants.HERO_HEAD_ICON_URL + Uri.encode(heroes.getAvatarUrl())).crossFade().into(holder.heroesAvatar);
    holder.heroesName.setText(heroes.getHeroName());
}
Also used : Hero(cn.nicolite.palm300heroes.model.bean.Hero)

Example 2 with Hero

use of cn.nicolite.palm300heroes.model.bean.Hero in project Palm300Heroes by nicolite.

the class HeroListFragment method doBusiness.

@Override
protected void doBusiness() {
    heroListPresenter = new HeroListPresenter(this, this);
    // 根据屏幕宽度计算一行能放多少个
    int spanCount = (int) (ScreenUtils.getScreenWidth(context) / ScreenUtils.dp2px(context, 80));
    // 防止每行个数为0
    if (spanCount == 0) {
        spanCount = 4;
    }
    lRecyclerView.setLayoutManager(new GridLayoutManager(context, spanCount, OrientationHelper.VERTICAL, false));
    lRecyclerViewAdapter = new LRecyclerViewAdapter(new HeroAdapter(context, dataList));
    lRecyclerView.setAdapter(lRecyclerViewAdapter);
    lRecyclerView.setLoadMoreEnabled(false);
    lRecyclerView.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            heroListPresenter.showHeroList(true);
        }
    });
    lRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
        }
    });
    lRecyclerView.setOnNetWorkErrorListener(new OnNetWorkErrorListener() {

        @Override
        public void reload() {
        }
    });
    lRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Hero hero = dataList.get(position);
            Bundle bundle = new Bundle();
            bundle.putString("heroName", hero.getHeroName());
            bundle.putString("heroType", hero.getHeroType());
            bundle.putString("heroUNCode", hero.getUNCode());
            bundle.putString("heroImage", hero.getPictureUrl());
            bundle.putString("heroBackground", hero.getBackground());
            bundle.putString("heroCoins", hero.getCoinsPrice());
            bundle.putString("heroDiamond", hero.getDiamondPrice());
            startActivity(HeroesDetailActivity.class, bundle);
        }
    });
    if (isFirstVisible && ListUtils.isEmpty(dataList)) {
        heroListPresenter.showHeroList(false);
    }
}
Also used : OnLoadMoreListener(com.github.jdsjlzx.interfaces.OnLoadMoreListener) OnNetWorkErrorListener(com.github.jdsjlzx.interfaces.OnNetWorkErrorListener) OnItemClickListener(com.github.jdsjlzx.interfaces.OnItemClickListener) Bundle(android.os.Bundle) HeroListPresenter(cn.nicolite.palm300heroes.presenter.HeroListPresenter) BindView(butterknife.BindView) IHeroListView(cn.nicolite.palm300heroes.view.iview.IHeroListView) LRecyclerView(com.github.jdsjlzx.recyclerview.LRecyclerView) View(android.view.View) LRecyclerViewAdapter(com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter) GridLayoutManager(android.support.v7.widget.GridLayoutManager) HeroesDetailActivity(cn.nicolite.palm300heroes.view.activity.HeroesDetailActivity) HeroAdapter(cn.nicolite.palm300heroes.view.adapter.HeroAdapter) Hero(cn.nicolite.palm300heroes.model.bean.Hero) OnRefreshListener(com.github.jdsjlzx.interfaces.OnRefreshListener)

Example 3 with Hero

use of cn.nicolite.palm300heroes.model.bean.Hero in project Palm300Heroes by nicolite.

the class HeroListPresenter method showHeroList.

public void showHeroList(boolean isForce) {
    final HeroDao heroDao = getDaoSession().getHeroDao();
    if (!isForce && heroDao.count() > 0) {
        if (getView() != null) {
            List<Hero> heroList = heroDao.queryBuilder().orderDesc(HeroDao.Properties.Position).list();
            getView().showHeroList(heroList);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    BmobQuery<Hero> query = new BmobQuery<>(Constants.BMOB_HERO);
    query.setLimit(300).order("-position").findObjects(new FindListener<Hero>() {

        @Override
        public void done(final List<Hero> list, BmobException e) {
            if (getView() != null) {
                getView().closeLoading();
                if (e == null) {
                    getView().showHeroList(list);
                    if (!saveFlag) {
                        saveFlag = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                heroDao.deleteAll();
                                for (Hero hero : list) {
                                    heroDao.insert(hero);
                                }
                                saveFlag = false;
                            }
                        }).start();
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) Hero(cn.nicolite.palm300heroes.model.bean.Hero) HeroDao(cn.nicolite.palm300heroes.db.dao.HeroDao)

Aggregations

Hero (cn.nicolite.palm300heroes.model.bean.Hero)3 Bundle (android.os.Bundle)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 View (android.view.View)1 BindView (butterknife.BindView)1 BmobQuery (cn.bmob.v3.BmobQuery)1 BmobException (cn.bmob.v3.exception.BmobException)1 HeroDao (cn.nicolite.palm300heroes.db.dao.HeroDao)1 HeroListPresenter (cn.nicolite.palm300heroes.presenter.HeroListPresenter)1 HeroesDetailActivity (cn.nicolite.palm300heroes.view.activity.HeroesDetailActivity)1 HeroAdapter (cn.nicolite.palm300heroes.view.adapter.HeroAdapter)1 IHeroListView (cn.nicolite.palm300heroes.view.iview.IHeroListView)1 OnItemClickListener (com.github.jdsjlzx.interfaces.OnItemClickListener)1 OnLoadMoreListener (com.github.jdsjlzx.interfaces.OnLoadMoreListener)1 OnNetWorkErrorListener (com.github.jdsjlzx.interfaces.OnNetWorkErrorListener)1 OnRefreshListener (com.github.jdsjlzx.interfaces.OnRefreshListener)1 LRecyclerView (com.github.jdsjlzx.recyclerview.LRecyclerView)1 LRecyclerViewAdapter (com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter)1