LoginViewModel.java
1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.cnlive.goldenline.viewmodel;
import android.app.Activity;
import android.content.Context;
import android.databinding.BaseObservable;
import android.databinding.ObservableBoolean;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import com.cnlive.goldenline.databinding.ActivityRegisterBinding;
import com.cnlive.goldenline.util.StringUtils;
/**
* Created by ZJL on 2017/5/10.
*/
public class LoginViewModel extends BaseObservable{
public final ObservableBoolean isPhone = new ObservableBoolean();
public final ObservableBoolean isCodeRight = new ObservableBoolean();
private String phone = "";
private Context context;
public LoginViewModel(ActivityRegisterBinding activityRegisterBinding, Context context){
this.context=context;
}
/**
* 处理验证码
*
* @param code
*/
public void formatCode(Editable code) {
if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString()) && code.length() == 6) {
isCodeRight.set(true);
} else {
isCodeRight.set(false);
}
}
public void phoneChanged(Editable phone) {
Log.i("name","titleChanged");
this.phone = phone.toString();
if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString())) {
isPhone.set(true);
} else {
isPhone.set(false);
}
}
public void closeAct(View view){
( (Activity)context).finish();
}
}