Search in sources :

Example 16 with BmobException

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

the class LostAndFoundPresenter method getLostList.

@Override
public void getLostList(int SKIP, int skip) {
    BmobQuery<Lost> query = new BmobQuery<Lost>();
    // query.setCachePolicy(BmobQuery.CachePolicy.CACHE_THEN_NETWORK);   // 先从缓存获取数据,如果没有,再从网络获取。
    // 按照时间降序
    query.order("-createdAt");
    // 每次加载条数
    query.setLimit(SKIP);
    // 偏移量
    query.setSkip(skip);
    Subscription subscription = query.findObjects(new FindListener<Lost>() {

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

Example 17 with BmobException

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

the class SignUpPresenter method signUpServer.

@Override
public void signUpServer(String phone, String password, String sex, String schoolName, Integer schoolId) {
    // SmartUser smartUser = new SmartUser();
    // smartUser.setPhone(phone);
    // smartUser.setPassword(password);
    // smartUser.setSex(sex);
    // smartUser.setSchoolName(schoolName);
    // smartUser.setSchoolId(schoolId);
    // smartUser.save(new SaveListener<String>() {
    // @Override
    // public void done(String s, BmobException e) {
    // if (e == null) {
    // if (mView != null) mView.hideLoading(false);
    // } else {
    // if (mView != null) {
    // mView.showMessage(e.getMessage());
    // mView.hideLoading(true);
    // }
    // }
    // }
    // });
    BmobUser bmobUser = new BmobUser();
    bmobUser.setUsername(phone);
    bmobUser.setPassword(password);
    bmobUser.signUp(new SaveListener<SmartUser>() {

        @Override
        public void done(SmartUser s, BmobException e) {
            if (e == null) {
                SmartUser newUser = new SmartUser();
                newUser.setSex(sex);
                newUser.setSchoolId(schoolId);
                newUser.setSchoolName(schoolName);
                SmartUser bmobUser = BmobUser.getCurrentUser(SmartUser.class);
                if (bmobUser != null) {
                    newUser.update(bmobUser.getObjectId(), new UpdateListener() {

                        @Override
                        public void done(BmobException e) {
                            if (e == null) {
                                if (mView != null)
                                    mView.hideLoading(false);
                            } else {
                                if (mView != null) {
                                    mView.showMessage(e.getMessage());
                                    mView.hideLoading(true);
                                }
                            }
                        }
                    });
                } else {
                    if (mView != null) {
                        mView.showMessage(e.getMessage());
                        mView.hideLoading(true);
                    }
                }
            } else {
                if (mView != null) {
                    mView.showMessage(e.getMessage());
                    mView.hideLoading(true);
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) SmartUser(com.itculturalfestival.smartcampus.entity.db.SmartUser) BmobUser(cn.bmob.v3.BmobUser) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Example 18 with BmobException

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

the class UserInfoActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    PermissionUtils.getInstance().requestPermission(this, 100, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (requestCode == REQUEST_CODE_CHOOSE_PICTURE && resultCode == RESULT_OK) {
        List<Uri> uriList = Matisse.obtainResult(data);
        for (Uri uri : uriList) {
            Intent intent = new Intent();
            intent.setAction("com.android.camera.action.CROP");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            // mUri是已经选择的图片Uri
            intent.setDataAndType(uri, "image/*");
            intent.putExtra("crop", "true");
            // 裁剪框比例
            intent.putExtra("aspectX", 1);
            intent.putExtra("aspectY", 1);
            // 输出图片大小
            intent.putExtra("outputX", 150);
            intent.putExtra("outputY", 150);
            intent.putExtra("return-data", true);
            startActivityForResult(intent, REQUEST_CODE_PICTURE_CUT);
        }
    } else if (requestCode == REQUEST_CODE_PICTURE_CUT && resultCode == RESULT_OK) {
        try {
            Bitmap bitmap = data.getParcelableExtra("data");
            File file = new File(Environment.getExternalStorageDirectory(), "P300Heroes/");
            if (!file.exists()) {
                boolean mkdir = file.mkdir();
                if (!mkdir) {
                    ToastUtils.showToastShort("创建文件失败,请检查是否给予文件读写权限!");
                    return;
                }
            }
            File file2 = new File(Environment.getExternalStorageDirectory(), "P300Heroes/cache/");
            if (!file2.exists()) {
                boolean mkdir = file2.mkdir();
                if (!mkdir) {
                    ToastUtils.showToastShort("创建文件失败,请检查是否给予文件读写权限!");
                    return;
                }
            }
            final File file1 = new File(file, userData.getUsername() + "_" + System.currentTimeMillis() + ".jpg");
            FileOutputStream fileOutputStream = new FileOutputStream(file1);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
            final BmobFile bmobFile = new BmobFile(file1);
            bmobFile.uploadblock(new UploadFileListener() {

                @Override
                public void done(BmobException e) {
                    if (e == null) {
                        user.setAvatar(bmobFile);
                        Glide.with(UserInfoActivity.this).load(file1).bitmapTransform(new CropCircleTransformation(UserInfoActivity.this)).centerCrop().crossFade().into(userAvatar);
                        saveUserInfo(user);
                        if (file1.exists() && file1.isFile()) {
                            file1.delete();
                        }
                    } else {
                        ToastUtils.showToastShort("图片上传失败!" + e.toString());
                    }
                }

                @Override
                public void onProgress(Integer value) {
                    super.onProgress(value);
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) BmobException(cn.bmob.v3.exception.BmobException) FileOutputStream(java.io.FileOutputStream) UploadFileListener(cn.bmob.v3.listener.UploadFileListener) CropCircleTransformation(jp.wasabeef.glide.transformations.CropCircleTransformation) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File) BmobFile(cn.bmob.v3.datatype.BmobFile)

Example 19 with BmobException

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

the class TalentPresenter method showTalent.

public void showTalent(boolean isForce) {
    final TalentDao talentDao = getDaoSession().getTalentDao();
    if (!isForce && talentDao.count() > 0) {
        if (getView() != null) {
            List<Talent> list = talentDao.queryBuilder().orderAsc(TalentDao.Properties.Position).list();
            getView().showTalentList(list);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    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 (getView() != null) {
                getView().closeLoading();
                if (e == null) {
                    getView().showTalentList(list);
                    if (!saveFlag) {
                        saveFlag = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                for (Talent talent : list) {
                                    talentDao.insert(talent);
                                }
                                saveFlag = false;
                            }
                        });
                    }
                } else {
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : TalentDao(cn.nicolite.palm300heroes.db.dao.TalentDao) BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) Talent(cn.nicolite.palm300heroes.model.bean.Talent)

Example 20 with BmobException

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

the class EquJJCPresenter method showEquJJCList.

public void showEquJJCList(boolean isForce) {
    final EquipmentDao equipmentDao = getDaoSession().getEquipmentDao();
    if (!isForce && equipmentDao.count() > 0) {
        if (getView() != null) {
            List<Equipment> equipmentList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).orderAsc(EquipmentDao.Properties.Id).list();
            getView().showEquJJCList(equipmentList);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    BmobQuery<Equipment> query = new BmobQuery<>(Constants.BMOB_EQUIPMENT);
    query.addWhereEqualTo("type", "JJC").order("id").setLimit(300).findObjects(new FindListener<Equipment>() {

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

                            @Override
                            public void run() {
                                List<Equipment> jjcList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).list();
                                for (Equipment equipment : jjcList) {
                                    equipmentDao.delete(equipment);
                                }
                                for (Equipment equipment : list) {
                                    equipmentDao.insert(equipment);
                                }
                                saveFlag = false;
                            }
                        }).start();
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) Equipment(cn.nicolite.palm300heroes.model.bean.Equipment) BmobQuery(cn.bmob.v3.BmobQuery) EquipmentDao(cn.nicolite.palm300heroes.db.dao.EquipmentDao) List(java.util.List)

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