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;
}
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("登录失败:用户名或者密码不正确!");
}
}
});
}
}
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);
}
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);
}
Aggregations