Search in sources :

Example 1 with Skin

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

the class HeroSkinPresenter method showSkin.

public void showSkin(final String UNCode, boolean isForce) {
    final SkinDao skinDao = getDaoSession().getSkinDao();
    if (!isForce && getView() != null) {
        List<Skin> list = skinDao.queryBuilder().where(SkinDao.Properties.UNCode.eq(UNCode)).list();
        if (!ListUtils.isEmpty(list)) {
            getView().showSkin(list);
            return;
        }
    }
    BmobQuery<Skin> query = new BmobQuery<>(Constants.BMOB_SKin);
    query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<Skin>() {

        @Override
        public void done(final List<Skin> list, BmobException e) {
            if (getView() != null) {
                if (e == null) {
                    getView().showSkin(list);
                    if (!isSaving) {
                        isSaving = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                List<Skin> oldList = skinDao.queryBuilder().where(SkinDao.Properties.UNCode.eq(UNCode)).list();
                                for (Skin skin : oldList) {
                                    skinDao.delete(skin);
                                }
                                for (Skin skin : list) {
                                    skinDao.insert(skin);
                                }
                                isSaving = false;
                            }
                        }).start();
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) SkinDao(cn.nicolite.palm300heroes.db.dao.SkinDao) BmobQuery(cn.bmob.v3.BmobQuery) Skin(cn.nicolite.palm300heroes.model.bean.Skin) List(java.util.List)

Example 2 with Skin

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

the class SkinAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final SkinViewHolder holder, final int position) {
    Skin skin = dataList.get(position);
    holder.getSkinPicture().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            List<String> images = new ArrayList<>();
            for (Skin skin : dataList) {
                images.add(UrlHead + Uri.encode(skin.getUrl()));
            }
            Utils.showImage(context, images, null, position);
        }
    });
    Glide.with(context).load(UrlHead + Uri.encode(skin.getUrl())).crossFade().into(holder.getSkinPicture());
    holder.getSkinName().setText(skin.getName());
    holder.getSkinPrice().setText(skin.getPrice());
}
Also used : Skin(cn.nicolite.palm300heroes.model.bean.Skin) ArrayList(java.util.ArrayList) List(java.util.List) ImageView(android.widget.ImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

Skin (cn.nicolite.palm300heroes.model.bean.Skin)2 List (java.util.List)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 BmobQuery (cn.bmob.v3.BmobQuery)1 BmobException (cn.bmob.v3.exception.BmobException)1 SkinDao (cn.nicolite.palm300heroes.db.dao.SkinDao)1 ArrayList (java.util.ArrayList)1