Search in sources :

Example 6 with SaveListener

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

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

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

the class BmobModel method userLoginByUsername.

/**
 *通过用户名登录
 * @param username 用户名
 * @param password 密码
 */
public static void userLoginByUsername(String username, String password, SaveListener<User> saveListener) {
    User user = new User();
    user.setUsername(username);
    user.setPassword(password);
    user.login(saveListener);
}
Also used : User(cn.nicolite.palm300heroes.model.bean.User) BmobUser(cn.bmob.v3.BmobUser)

Example 9 with SaveListener

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

the class BmobModel method userRegister.

/**
 * 用户注册
 * @param username 用户名
 * @param password 密码
 * @param email 邮箱
 */
public static void userRegister(String username, String password, String email, SaveListener<User> saveListener) {
    BmobUser bmobUser = new User();
    if (DataUtils.compileExChar(username)) {
        ToastUtils.showToastShort("不允许输入特殊字符");
        return;
    }
    bmobUser.setUsername(username);
    bmobUser.setPassword(password);
    bmobUser.setEmail(email);
    bmobUser.signUp(saveListener);
}
Also used : User(cn.nicolite.palm300heroes.model.bean.User) BmobUser(cn.bmob.v3.BmobUser) BmobUser(cn.bmob.v3.BmobUser)

Aggregations

BmobUser (cn.bmob.v3.BmobUser)8 SaveListener (cn.bmob.v3.listener.SaveListener)6 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 User (com.nightonke.saver.model.User)4 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)3 View (android.view.View)3 TextView (android.widget.TextView)3 UpdateListener (cn.bmob.v3.listener.UpdateListener)3 User (cn.nicolite.palm300heroes.model.bean.User)3 Handler (android.os.Handler)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 BmobFile (cn.bmob.v3.datatype.BmobFile)2 MDButton (com.afollestad.materialdialogs.internal.MDButton)2 RiseNumberTextView (com.nightonke.saver.ui.RiseNumberTextView)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 File (java.io.File)2 MaterialIconView (net.steamcrafted.materialiconlib.MaterialIconView)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1