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());
}
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);
}
}
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());
}
}
}
});
}
Aggregations