Search in sources :

Example 1 with BmobException

use of cn.bmob.v3.exception.BmobException in project SmartCampus by Vegen.

the class HomePresenter method getBanner.

@Override
public void getBanner() {
    BmobQuery<Banner> query = new BmobQuery<Banner>();
    // 先从缓存获取数据,如果没有,再从网络获取。
    query.setCachePolicy(BmobQuery.CachePolicy.CACHE_THEN_NETWORK);
    // 按照时间降序
    query.order("-createdAt");
    Subscription subscription = query.findObjects(new FindListener<Banner>() {

        @Override
        public void done(List<Banner> list, BmobException e) {
            if (mView != null) {
                if (e == null) {
                    // 请求成功
                    mView.showBanner(list);
                    mView.hideLoading(false);
                } else {
                    mView.showMessage(HttpError.getErrorMessage(e));
                    mView.hideLoading(true);
                }
            }
        }
    });
    mHttpLinkers.add(new SubscriptionHolder(subscription));
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) Banner(com.itculturalfestival.smartcampus.entity.db.Banner) SubscriptionHolder(com.itculturalfestival.smartcampus.network.SubscriptionHolder) Subscription(rx.Subscription)

Example 2 with BmobException

use of cn.bmob.v3.exception.BmobException in project Palm300Heroes by nicolite.

the class LoginActivity method login.

private void login(final String username, String password) {
    ToastUtils.showToastShort("登录中...");
    BmobUser bmobUser = new User();
    bmobUser.setPassword(password);
    if (username.contains("@")) {
        BmobModel.userLoginByEmail(username, password, new LogInListener<User>() {

            @Override
            public void done(User user, BmobException e) {
                if (e == null) {
                    ToastUtils.showToastShort("登录成功");
                    Intent intent = new Intent();
                    intent.putExtra("user_data", user);
                    LoginActivity.this.setResult(1, intent);
                    finish();
                } else {
                    ToastUtils.showToastShort("登录失败,邮箱或者密码不正确!");
                }
            }
        });
    } else {
        BmobModel.userLoginByUsername(username, password, new SaveListener<User>() {

            @Override
            public void done(User user, BmobException e) {
                if (e == null) {
                    ToastUtils.showToastShort("登录成功");
                    Intent intent = new Intent();
                    intent.putExtra("user_data", user);
                    LoginActivity.this.setResult(1, intent);
                    finish();
                } else {
                    ToastUtils.showToastShort("登录失败:用户名或者密码不正确!");
                }
            }
        });
    }
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) User(cn.nicolite.palm300heroes.model.bean.User) BmobUser(cn.bmob.v3.BmobUser) BmobUser(cn.bmob.v3.BmobUser) Intent(android.content.Intent)

Example 3 with BmobException

use of cn.bmob.v3.exception.BmobException in project Palm300Heroes by nicolite.

the class UserInfoActivity method onViewClicked.

@OnClick({ R.id.rl_user_avatar, R.id.rl_nickName, R.id.rl_user_pwd, R.id.rl_user_gender, R.id.user_logout })
public void onViewClicked(View view) {
    switch(view.getId()) {
        case R.id.rl_user_avatar:
            Matisse.from(this).choose(MimeType.of(MimeType.PNG, MimeType.JPEG)).countable(true).maxSelectable(1).restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED).thumbnailScale(0.85f).imageEngine(new GlideEngine()).forResult(REQUEST_CODE_CHOOSE_PICTURE);
            break;
        case R.id.rl_nickName:
            LinearLayout editor = (LinearLayout) getLayoutInflater().inflate(R.layout.item_single_eidtor, null, false);
            final EditText edInput = (EditText) editor.findViewById(R.id.ed_input);
            new AlertDialog.Builder(this).setTitle("请输入昵称").setView(editor).setPositiveButton("确定", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    String nickNameText = edInput.getText().toString();
                    if (TextUtils.isEmpty(nickNameText)) {
                        ToastUtils.showToastShort("昵称不能为空");
                        return;
                    }
                    nickName.setText(nickNameText);
                    user.setNickName(nickNameText);
                    saveUserInfo(user);
                }
            }).setNegativeButton("取消", null).show();
            break;
        case R.id.rl_user_pwd:
            LinearLayout changePwd = (LinearLayout) getLayoutInflater().inflate(R.layout.item_change_password, null, false);
            final EditText originPwd = (EditText) changePwd.findViewById(R.id.et_origin_pwd);
            final EditText newPwd = (EditText) changePwd.findViewById(R.id.et_new_pwd);
            final EditText newPwd2 = (EditText) changePwd.findViewById(R.id.et_new_pwd2);
            new AlertDialog.Builder(this).setTitle("修改密码").setView(changePwd).setPositiveButton("确认", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    String originPassword = originPwd.getText().toString();
                    String newPassword = newPwd.getText().toString();
                    String newPassword2 = newPwd2.getText().toString();
                    if (TextUtils.isEmpty(originPassword) || TextUtils.isEmpty(newPassword) || TextUtils.isEmpty(newPassword2)) {
                        ToastUtils.showToastShort("请填写完整");
                        return;
                    } else if (!newPassword.equals(newPassword2)) {
                        ToastUtils.showToastShort("两次输入的密码不一致");
                        return;
                    }
                    BmobUser.updateCurrentUserPassword(originPassword, newPassword, new UpdateListener() {

                        @Override
                        public void done(BmobException e) {
                            if (e == null) {
                                ToastUtils.showToastShort("修改成功!");
                                BmobUser.logOut();
                                UserInfoActivity.this.setResult(2);
                                finish();
                            } else {
                                ToastUtils.showToastShort("修改失败!");
                            }
                        }
                    });
                }
            }).setNegativeButton("取消", null).show();
            break;
        case R.id.rl_user_gender:
            final String[] items = { "男", "女" };
            selected = userData.getGender() == null ? 0 : (userData.getGender() ? 0 : 1);
            new AlertDialog.Builder(this).setTitle("请选择").setSingleChoiceItems(items, selected, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    selected = i;
                }
            }).setPositiveButton("确定", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    userGender.setImageResource(items[selected].equals("男") ? R.drawable.male : R.drawable.female);
                    user.setGender(items[selected].equals("男"));
                    saveUserInfo(user);
                }
            }).setNegativeButton("取消", null).show();
            break;
        case R.id.user_logout:
            BmobUser.logOut();
            UserInfoActivity.this.setResult(2);
            finish();
            break;
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.support.v7.app.AlertDialog) BmobException(cn.bmob.v3.exception.BmobException) GlideEngine(com.zhihu.matisse.engine.impl.GlideEngine) DialogInterface(android.content.DialogInterface) UpdateListener(cn.bmob.v3.listener.UpdateListener) LinearLayout(android.widget.LinearLayout) OnClick(butterknife.OnClick)

Example 4 with BmobException

use of cn.bmob.v3.exception.BmobException in project Palm300Heroes by nicolite.

the class UpdateDataModel method updateTalent.

public static void updateTalent() {
    BmobQuery<Talent> query = new BmobQuery<>(Constants.BMOB_TALENT);
    query.setLimit(45).order("position").findObjects(new FindListener<Talent>() {

        @Override
        public void done(final List<Talent> list, BmobException e) {
            if (e == null) {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        TalentDao talentDao = daoSession.getTalentDao();
                        talentDao.deleteAll();
                        for (Talent talent : list) {
                            talentDao.insert(talent);
                        }
                        progress.incrementAndGet();
                    }
                });
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) TalentDao(cn.nicolite.palm300heroes.db.dao.TalentDao) BmobQuery(cn.bmob.v3.BmobQuery) Talent(cn.nicolite.palm300heroes.model.bean.Talent)

Example 5 with BmobException

use of cn.bmob.v3.exception.BmobException in project Palm300Heroes by nicolite.

the class FightSkillPresenter method showFightSkill.

public void showFightSkill(boolean isForce) {
    final FightSkillDao fightSkillDao = getDaoSession().getFightSkillDao();
    if (!isForce && fightSkillDao.count() > 0) {
        if (getView() != null) {
            List<FightSkill> list = fightSkillDao.queryBuilder().orderAsc(FightSkillDao.Properties.Position).list();
            getView().showFightSkill(list);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    BmobQuery<FightSkill> query = new BmobQuery<>(Constants.BMOB_FIGHT_SKILL);
    query.setLimit(20).order("position").findObjects(new FindListener<FightSkill>() {

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

                            @Override
                            public void run() {
                                fightSkillDao.deleteAll();
                                for (FightSkill fightSkill : list) {
                                    fightSkillDao.insert(fightSkill);
                                }
                                saveFlag = false;
                            }
                        }).start();
                    }
                } else {
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) FightSkillDao(cn.nicolite.palm300heroes.db.dao.FightSkillDao) FightSkill(cn.nicolite.palm300heroes.model.bean.FightSkill)

Aggregations

BmobException (cn.bmob.v3.exception.BmobException)32 BmobQuery (cn.bmob.v3.BmobQuery)16 BmobUser (cn.bmob.v3.BmobUser)12 MyUser (com.yuxuan.admin.expression.entity.MyUser)10 UpdateListener (cn.bmob.v3.listener.UpdateListener)9 List (java.util.List)6 Intent (android.content.Intent)5 UserDqInfomation (com.yuxuan.admin.expression.entity.UserDqInfomation)4 ArrayList (java.util.ArrayList)4 MyUser (com.fafu.zhengxianyou.livingincampus.bean.MyUser)3 DialogInterface (android.content.DialogInterface)2 TalentDao (cn.nicolite.palm300heroes.db.dao.TalentDao)2 Talent (cn.nicolite.palm300heroes.model.bean.Talent)2 SubscriptionHolder (com.itculturalfestival.smartcampus.network.SubscriptionHolder)2 MyOrdersData (com.yuxuan.admin.expression.entity.MyOrdersData)2 Subscription (rx.Subscription)2 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1