Search in sources :

Example 6 with UpdateListener

use of cn.bmob.v3.listener.UpdateListener in project CoCoin by Nightonke.

the class AccountBookSettingActivity method whetherSyncSettingsFromServer.

// whether sync the settings from server////////////////////////////////////////////////////////////
private void whetherSyncSettingsFromServer() {
    new MaterialDialog.Builder(this).iconRes(R.drawable.cocoin_logo).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.sync_dialog_title).forceStacking(true).content(R.string.sync_dialog_content).positiveText(R.string.sync_dialog_sync_to_local).negativeText(R.string.sync_dialog_sync_to_server).cancelable(false).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            if (which.equals(DialogAction.POSITIVE)) {
                // sync to local
                downloadLogoFromServer();
                User user = getCurrentUser();
                String tip = "";
                boolean accountBookPasswordChanged = false;
                if (!user.getAccountBookPassword().equals(SettingManager.getInstance().getPassword()))
                    accountBookPasswordChanged = true;
                SettingManager.getInstance().setIsMonthLimit(user.getIsMonthLimit());
                monthSB.setChecked(user.getIsMonthLimit());
                SettingManager.getInstance().setMonthLimit(user.getMonthLimit());
                if (SettingManager.getInstance().getIsMonthLimit())
                    monthMaxExpense.withNumber(SettingManager.getInstance().getMonthLimit()).setDuration(1000).start();
                SettingManager.getInstance().setIsColorRemind(user.getIsColorRemind());
                monthColorRemindSB.setChecked(user.getIsColorRemind());
                SettingManager.getInstance().setMonthWarning(user.getMonthWarning());
                if (SettingManager.getInstance().getIsMonthLimit() && SettingManager.getInstance().getIsColorRemind())
                    monthWarning.withNumber(SettingManager.getInstance().getMonthWarning()).setDuration(1000).start();
                SettingManager.getInstance().setRemindColor(user.getRemindColor());
                monthColorRemindTypeIcon.setColor(SettingManager.getInstance().getRemindColor());
                SettingManager.getInstance().setIsForbidden(user.getIsForbidden());
                monthForbiddenSB.setChecked(user.getIsForbidden());
                SettingManager.getInstance().setAccountBookName(user.getAccountBookName());
                accountBookName.setText(user.getAccountBookName());
                SettingManager.getInstance().setPassword(user.getAccountBookPassword());
                // Todo tag sort
                SettingManager.getInstance().setShowPicture(user.getShowPicture());
                showPictureSB.setChecked(user.getShowPicture());
                SettingManager.getInstance().setIsHollow(user.getIsHollow());
                hollowSB.setChecked(user.getIsHollow());
                SettingManager.getInstance().setMainViewMonthExpenseShouldChange(true);
                SettingManager.getInstance().setMainViewRemindColorShouldChange(true);
                SettingManager.getInstance().setMainViewTitleShouldChange(true);
                SettingManager.getInstance().setTodayViewMonthExpenseShouldChange(true);
                SettingManager.getInstance().setTodayViewPieShouldChange(true);
                SettingManager.getInstance().setTodayViewTitleShouldChange(true);
                // SettingManager.getInstance().getMainActivityTagShouldChange();
                if (accountBookPasswordChanged)
                    tip = "\n" + getString(R.string.your_current_account_book_password_is) + SettingManager.getInstance().getPassword();
                new MaterialDialog.Builder(mContext).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.sync_to_local_successfully_dialog_title).content(getString(R.string.sync_to_local_successfully_dialog_content) + tip).positiveText(R.string.ok).show();
            } else if (which.equals(DialogAction.NEGATIVE)) {
                // sync to server
                uploadLogoToServer();
                User user = getCurrentUser();
                user.setIsMonthLimit(SettingManager.getInstance().getIsMonthLimit());
                user.setMonthLimit(SettingManager.getInstance().getMonthLimit());
                user.setIsColorRemind(SettingManager.getInstance().getIsColorRemind());
                user.setMonthWarning(SettingManager.getInstance().getMonthWarning());
                user.setRemindColor(SettingManager.getInstance().getRemindColor());
                user.setIsForbidden(SettingManager.getInstance().getIsForbidden());
                user.setAccountBookName(SettingManager.getInstance().getAccountBookName());
                user.setAccountBookPassword(SettingManager.getInstance().getPassword());
                // Todo tag sort
                user.setShowPicture(SettingManager.getInstance().getShowPicture());
                user.setIsHollow(SettingManager.getInstance().getIsHollow());
                user.update(CoCoinApplication.getAppContext(), user.getObjectId(), new UpdateListener() {

                    @Override
                    public void onSuccess() {
                        showToast(9, "");
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        showToast(10, msg);
                    }
                });
            }
            dialog.dismiss();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Example 7 with UpdateListener

use of cn.bmob.v3.listener.UpdateListener in project CoCoin by Nightonke.

the class RecordManager method updateOldRecordsToServer.

public static long updateOldRecordsToServer() {
    long counter = 0;
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        // already login////////////////////////////////////////////////////////////////////////////////////
        isLastOne = false;
        for (int i = 0; i < RECORDS.size(); i++) {
            if (i == RECORDS.size() - 1)
                isLastOne = true;
            final CoCoinRecord coCoinRecord = RECORDS.get(i);
            if (!coCoinRecord.getIsUploaded()) {
                // has been changed/////////////////////////////////////////////////////////////////////////////////
                if (coCoinRecord.getLocalObjectId() != null) {
                    // there is an old coCoinRecord in server, we should update this coCoinRecord///////////////////////////////////
                    coCoinRecord.setUserId(user.getObjectId());
                    coCoinRecord.update(CoCoinApplication.getAppContext(), coCoinRecord.getLocalObjectId(), new UpdateListener() {

                        @Override
                        public void onSuccess() {
                            if (BuildConfig.DEBUG) {
                                if (BuildConfig.DEBUG)
                                    Log.d("CoCoin", "recordManager.updateOldRecordsToServer update online " + coCoinRecord.toString() + " S");
                            }
                            coCoinRecord.setIsUploaded(true);
                            coCoinRecord.setLocalObjectId(coCoinRecord.getObjectId());
                            db.updateRecord(coCoinRecord);
                            // after updating, get the old records from server//////////////////////////////////////////////////
                            if (isLastOne)
                                getRecordsFromServer();
                        }

                        @Override
                        public void onFailure(int code, String msg) {
                            if (BuildConfig.DEBUG) {
                                if (BuildConfig.DEBUG)
                                    Log.d("CoCoin", "recordManager.updateOldRecordsToServer update online " + coCoinRecord.toString() + " F");
                            }
                            if (BuildConfig.DEBUG) {
                                if (BuildConfig.DEBUG)
                                    Log.d("CoCoin", "recordManager.updateOldRecordsToServer update online code" + code + " msg " + msg);
                            }
                        }
                    });
                } else {
                    counter++;
                    coCoinRecord.setUserId(user.getObjectId());
                    coCoinRecord.save(CoCoinApplication.getAppContext(), new SaveListener() {

                        @Override
                        public void onSuccess() {
                            if (BuildConfig.DEBUG) {
                                if (BuildConfig.DEBUG)
                                    Log.d("CoCoin", "recordManager.updateOldRecordsToServer save online " + coCoinRecord.toString() + " S");
                            }
                            coCoinRecord.setIsUploaded(true);
                            coCoinRecord.setLocalObjectId(coCoinRecord.getObjectId());
                            db.updateRecord(coCoinRecord);
                            // after updating, get the old records from server//////////////////////////////////////////////////
                            if (isLastOne)
                                getRecordsFromServer();
                        }

                        @Override
                        public void onFailure(int code, String msg) {
                            if (BuildConfig.DEBUG) {
                                if (BuildConfig.DEBUG)
                                    Log.d("CoCoin", "recordManager.updateOldRecordsToServer save online " + coCoinRecord.toString() + " F");
                            }
                            if (BuildConfig.DEBUG) {
                                if (BuildConfig.DEBUG)
                                    Log.d("CoCoin", "recordManager.updateOldRecordsToServer save online code" + code + " msg " + msg);
                            }
                        }
                    });
                }
            }
        }
    } else {
    }
    if (BuildConfig.DEBUG) {
        if (BuildConfig.DEBUG)
            Log.d("CoCoin", "recordManager.updateOldRecordsToServer update " + counter + " records to server.");
    }
    if (RECORDS.size() == 0)
        getRecordsFromServer();
    return counter;
}
Also used : SaveListener(cn.bmob.v3.listener.SaveListener) BmobUser(cn.bmob.v3.BmobUser) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Example 8 with UpdateListener

use of cn.bmob.v3.listener.UpdateListener 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 9 with UpdateListener

use of cn.bmob.v3.listener.UpdateListener in project Palm300Heroes by nicolite.

the class BmobModel method updateUserInfo.

/**
 * 更新用户信息
 * @param user 带有用户信息的bean
 */
public static void updateUserInfo(User user, UpdateListener updateListener) {
    User currentUser = BmobUser.getCurrentUser(User.class);
    user.update(currentUser.getObjectId(), updateListener);
}
Also used : User(cn.nicolite.palm300heroes.model.bean.User) BmobUser(cn.bmob.v3.BmobUser)

Example 10 with UpdateListener

use of cn.bmob.v3.listener.UpdateListener in project expression by happy-yuxuan.

the class UIdentifyPhoneActivity method bindMobilePhone.

// 绑定手机
private void bindMobilePhone(String phone) {
    // 开发者在给用户绑定手机号码的时候需要提交两个字段的值:mobilePhoneNumber、mobilePhoneNumberVerified
    MyUser user = new MyUser();
    user.setMobilePhoneNumber(phone);
    user.setMobilePhoneNumberVerified(true);
    MyUser cur = BmobUser.getCurrentUser(MyUser.class);
    user.update(cur.getObjectId(), new UpdateListener() {

        @Override
        public void done(BmobException e) {
            if (e == null) {
                L.i("手机号码绑定成功");
                Toast.makeText(UIdentifyPhoneActivity.this, "手机号码验证成功", Toast.LENGTH_LONG).show();
                finish();
            } else {
                L.i("手机号码失败:" + e.getMessage());
                Toast.makeText(UIdentifyPhoneActivity.this, "sorry 失败了", Toast.LENGTH_LONG).show();
            }
        }
    });
}
Also used : MyUser(com.yuxuan.admin.expression.entity.MyUser) BmobException(cn.bmob.v3.exception.BmobException) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Aggregations

UpdateListener (cn.bmob.v3.listener.UpdateListener)17 BmobUser (cn.bmob.v3.BmobUser)15 BmobException (cn.bmob.v3.exception.BmobException)9 User (com.nightonke.saver.model.User)7 MyUser (com.yuxuan.admin.expression.entity.MyUser)5 Handler (android.os.Handler)3 SaveListener (cn.bmob.v3.listener.SaveListener)3 NonNull (android.support.annotation.NonNull)2 BmobQuery (cn.bmob.v3.BmobQuery)2 BmobFile (cn.bmob.v3.datatype.BmobFile)2 DialogAction (com.afollestad.materialdialogs.DialogAction)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 File (java.io.File)2 DialogInterface (android.content.DialogInterface)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 AlertDialog (android.support.v7.app.AlertDialog)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 OnClick (butterknife.OnClick)1 DeleteListener (cn.bmob.v3.listener.DeleteListener)1