Commit 9e6408474a2695c4b900e4e970221780e979ed3d

Authored by 张建亮
1 parent e9fd4c63

张建亮gradle添加databinding,修改登录界面为databinding

app/build.gradle
@@ -9,7 +9,6 @@ buildscript { @@ -9,7 +9,6 @@ buildscript {
9 } 9 }
10 10
11 apply plugin: 'com.android.application' 11 apply plugin: 'com.android.application'
12 -apply plugin: 'android-apt'  
13 apply plugin: 'io.fabric' 12 apply plugin: 'io.fabric'
14 13
15 android { 14 android {
@@ -83,6 +82,9 @@ android { @@ -83,6 +82,9 @@ android {
83 lintOptions { 82 lintOptions {
84 checkReleaseBuilds false 83 checkReleaseBuilds false
85 } 84 }
  85 + dataBinding {
  86 + enabled = true
  87 + }
86 } 88 }
87 89
88 repositories { 90 repositories {
@@ -94,19 +96,25 @@ dependencies { @@ -94,19 +96,25 @@ dependencies {
94 compile fileTree(include: ['*.jar'], dir: 'libs') 96 compile fileTree(include: ['*.jar'], dir: 'libs')
95 compile project(':PushSDK') 97 compile project(':PushSDK')
96 compile files('libs/libcnliveuser.jar') 98 compile files('libs/libcnliveuser.jar')
97 - compile "com.android.support:appcompat-v7:23.4.0"  
98 - compile "com.android.support:recyclerview-v7:23.4.0"  
99 - compile "com.android.support:design:23.4.0"  
100 - compile "com.android.support:support-v4:23.4.0"  
101 - compile "com.android.support:gridlayout-v7:23.4.0"  
102 99
103 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 100 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
104 exclude group: 'com.android.support', module: 'support-annotations' 101 exclude group: 'com.android.support', module: 'support-annotations'
105 }) 102 })
  103 +
  104 + compile(name: 'turquoise-release', ext: 'aar')
106 testCompile 'org.testng:testng:6.9.6' 105 testCompile 'org.testng:testng:6.9.6'
  106 + provided files('runtime/MiguSDK2.0_203.jar')
  107 +
  108 + compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
  109 + transitive = true;
  110 + }
107 111
  112 + compile 'com.android.support:appcompat-v7:23.4.0'
  113 + compile 'com.android.support:recyclerview-v7:23.4.0'
  114 + compile 'com.android.support:design:23.4.0'
  115 + compile 'com.android.support:support-v4:23.4.0'
  116 + compile 'com.android.support:gridlayout-v7:23.4.0'
108 compile 'com.jakewharton:butterknife:8.2.1' 117 compile 'com.jakewharton:butterknife:8.2.1'
109 - apt 'com.jakewharton:butterknife-compiler:8.2.1'  
110 compile 'com.squareup.okhttp:okhttp:2.0.0' 118 compile 'com.squareup.okhttp:okhttp:2.0.0'
111 compile 'com.facebook.fresco:imagepipeline-okhttp:0.9.0' 119 compile 'com.facebook.fresco:imagepipeline-okhttp:0.9.0'
112 compile 'com.squareup.retrofit:retrofit:1.9.0' 120 compile 'com.squareup.retrofit:retrofit:1.9.0'
@@ -122,16 +130,11 @@ dependencies { @@ -122,16 +130,11 @@ dependencies {
122 compile 'org.igniterealtime.smack:smack-tcp:4.1.5' 130 compile 'org.igniterealtime.smack:smack-tcp:4.1.5'
123 compile 'com.timehop.stickyheadersrecyclerview:library:[0.4.3]@aar' 131 compile 'com.timehop.stickyheadersrecyclerview:library:[0.4.3]@aar'
124 compile 'com.github.iwgang:countdownview:2.1.3' 132 compile 'com.github.iwgang:countdownview:2.1.3'
125 - compile(name: 'turquoise-release', ext: 'aar')  
126 - testCompile 'org.testng:testng:6.9.6'  
127 - testCompile 'junit:junit:4.12'  
128 - provided files('runtime/MiguSDK2.0_203.jar')  
129 compile 'com.android.support:multidex:1.0.0' 133 compile 'com.android.support:multidex:1.0.0'
130 compile 'com.github.ctiao:dfm:0.4.1' 134 compile 'com.github.ctiao:dfm:0.4.1'
131 compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' 135 compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
132 -  
133 - compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {  
134 - transitive = true;  
135 - }  
136 - 136 + compile 'com.android.support.constraint:constraint-layout:1.0.2'
  137 + testCompile 'org.testng:testng:6.9.6'
  138 + testCompile 'junit:junit:4.12'
  139 + annotationProcessor 'com.jakewharton:butterknife-compiler:8.2.1'
137 } 140 }
app/src/main/java/com/cnlive/goldenline/ui/activity/RegisterActivity.java
@@ -3,49 +3,17 @@ package com.cnlive.goldenline.ui.activity; @@ -3,49 +3,17 @@ package com.cnlive.goldenline.ui.activity;
3 import android.app.ProgressDialog; 3 import android.app.ProgressDialog;
4 import android.content.Context; 4 import android.content.Context;
5 import android.content.Intent; 5 import android.content.Intent;
  6 +import android.databinding.DataBindingUtil;
6 import android.os.Bundle; 7 import android.os.Bundle;
7 import android.os.CountDownTimer; 8 import android.os.CountDownTimer;
8 import android.support.annotation.NonNull; 9 import android.support.annotation.NonNull;
9 -import android.text.Editable;  
10 -import android.text.TextUtils;  
11 -import android.text.TextWatcher;  
12 -import android.view.View;  
13 -import android.widget.Button;  
14 -import android.widget.EditText;  
15 -import android.widget.ImageButton;  
16 10
17 import com.cnlive.goldenline.R; 11 import com.cnlive.goldenline.R;
18 -import com.cnlive.goldenline.api.UserAPI;  
19 -import com.cnlive.goldenline.application.GoldenLineApplication;  
20 -import com.cnlive.goldenline.model.User;  
21 -import com.cnlive.goldenline.model.mine.SyncUserRequestBean; 12 +import com.cnlive.goldenline.databinding.ActivityRegisterBinding;
22 import com.cnlive.goldenline.ui.base.BaseActivity; 13 import com.cnlive.goldenline.ui.base.BaseActivity;
23 -import com.cnlive.goldenline.ui.base.GoldenlineCall;  
24 -import com.cnlive.goldenline.util.ChannelUtil;  
25 -import com.cnlive.goldenline.util.RestAdapterUtils;  
26 -import com.cnlive.goldenline.util.SPUtils;  
27 -import com.cnlive.goldenline.util.ShareSdkUtil;  
28 -import com.cnlive.goldenline.util.StringUtils;  
29 -import com.cnlive.goldenline.util.SystemTools;  
30 -import com.cnlive.goldenline.util.ToastUtil;  
31 import com.cnlive.goldenline.util.UserService; 14 import com.cnlive.goldenline.util.UserService;
32 -import com.cnlive.libs.user.IUserService;  
33 -import com.cnlive.libs.user.UserUtil; 15 +import com.cnlive.goldenline.viewmodel.LoginViewModel;
34 import com.cnlive.libs.user.model.DataEntity; 16 import com.cnlive.libs.user.model.DataEntity;
35 -import com.cnlive.libs.user.model.UserData;  
36 -  
37 -import java.util.HashMap;  
38 -import java.util.Locale;  
39 -  
40 -import butterknife.BindView;  
41 -import cn.sharesdk.framework.Platform;  
42 -import cn.sharesdk.framework.PlatformActionListener;  
43 -import cn.sharesdk.sina.weibo.SinaWeibo;  
44 -import cn.sharesdk.tencent.qq.QQ;  
45 -import cn.sharesdk.wechat.friends.Wechat;  
46 -import retrofit.Callback;  
47 -import retrofit.RetrofitError;  
48 -import retrofit.client.Response;  
49 17
50 /** 18 /**
51 * Description: 登录页面 19 * Description: 登录页面
@@ -55,27 +23,13 @@ import retrofit.client.Response; @@ -55,27 +23,13 @@ import retrofit.client.Response;
55 public class RegisterActivity extends BaseActivity { 23 public class RegisterActivity extends BaseActivity {
56 24
57 25
  26 + private LoginViewModel loginViewModel;
  27 +
58 public static void start(@NonNull Context context) { 28 public static void start(@NonNull Context context) {
59 Intent starter = new Intent(context, RegisterActivity.class); 29 Intent starter = new Intent(context, RegisterActivity.class);
60 context.startActivity(starter); 30 context.startActivity(starter);
61 } 31 }
62 32
63 - @BindView(R.id.imabutton_colse)  
64 - protected ImageButton imabutton_colse;  
65 - @BindView(R.id.imabutton_wx)  
66 - protected ImageButton imabutton_wx;  
67 - @BindView(R.id.imabutton_wb)  
68 - protected ImageButton imabutton_wb;  
69 - @BindView(R.id.imabutton_qq)  
70 - protected ImageButton imabutton_qq;  
71 - @BindView(R.id.button_sendcode)  
72 - protected Button button_sendcode;  
73 - @BindView(R.id.button_login)  
74 - protected Button button_login;  
75 - @BindView(R.id.et_phone)  
76 - protected EditText et_phone;  
77 - @BindView(R.id.et_code)  
78 - protected EditText et_code;  
79 /** 33 /**
80 * 当前时间 34 * 当前时间
81 */ 35 */
@@ -97,335 +51,31 @@ public class RegisterActivity extends BaseActivity { @@ -97,335 +51,31 @@ public class RegisterActivity extends BaseActivity {
97 @Override 51 @Override
98 protected void onCreate(Bundle savedInstanceState) { 52 protected void onCreate(Bundle savedInstanceState) {
99 super.onCreate(savedInstanceState); 53 super.onCreate(savedInstanceState);
100 - setContentView(R.layout.activity_register);  
101 - mUserService = new UserService(this);  
102 - initData(); 54 + ActivityRegisterBinding activityRegisterBinding= DataBindingUtil.setContentView(this,R.layout.activity_register);
  55 + loginViewModel=new LoginViewModel(activityRegisterBinding,RegisterActivity.this);
  56 + activityRegisterBinding.setLoginViewModel(loginViewModel);
  57 +// setContentView(R.layout.activity_register);
  58 +// mUserService = new UserService(this);
  59 +
  60 +// initData();
103 } 61 }
104 62
105 @Override 63 @Override
106 public void onResume() { 64 public void onResume() {
107 super.onResume(); 65 super.onResume();
108 - et_phone.addTextChangedListener(new TextWatcher() {  
109 - @Override  
110 - public void beforeTextChanged(CharSequence s, int start, int count, int after) {  
111 -  
112 - }  
113 -  
114 - @Override  
115 - public void onTextChanged(CharSequence s, int start, int before, int count) {  
116 -  
117 - }  
118 -  
119 - @Override  
120 - public void afterTextChanged(Editable s) {  
121 - formatPhone(s);  
122 - }  
123 - });  
124 - et_code.addTextChangedListener(new TextWatcher() {  
125 - @Override  
126 - public void beforeTextChanged(CharSequence s, int start, int count, int after) {  
127 -  
128 - }  
129 -  
130 - @Override  
131 - public void onTextChanged(CharSequence s, int start, int before, int count) {  
132 -  
133 - }  
134 -  
135 - @Override  
136 - public void afterTextChanged(Editable s) {  
137 - formatCode(s);  
138 - }  
139 - });  
140 - }  
141 -  
142 - /**  
143 - * 处理验证码  
144 - *  
145 - * @param code  
146 - */  
147 - private void formatCode(Editable code) {  
148 - if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString()) && code.length() == 6) {  
149 - button_login.setBackgroundResource(R.drawable.login_canuse);  
150 - button_login.setEnabled(true);  
151 - } else {  
152 - button_login.setBackgroundResource(R.drawable.login_nouse);  
153 - button_login.setEnabled(false);  
154 - }  
155 } 66 }
156 67
157 - /**  
158 - * 处理手机号  
159 - */  
160 - private void formatPhone(Editable phone) {  
161 - this.phone = phone.toString();  
162 - if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString())) {  
163 - button_sendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);  
164 - button_sendcode.setTextColor(getResources().getColor(R.color.color_ff6633));  
165 - button_sendcode.setEnabled(true);  
166 - } else {  
167 - button_sendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);  
168 - button_sendcode.setTextColor(getResources().getColor(R.color.color_959595));  
169 - button_sendcode.setEnabled(false);  
170 - }  
171 - }  
172 68
173 - /**  
174 - * 初始化数据  
175 - */  
176 - private void initData() {  
177 - imabutton_colse.setOnClickListener(this);  
178 - imabutton_wx.setOnClickListener(this);  
179 - imabutton_wb.setOnClickListener(this);  
180 - imabutton_qq.setOnClickListener(this);  
181 - button_sendcode.setOnClickListener(this);  
182 - button_login.setOnClickListener(this);  
183 - }  
184 69
185 - @Override  
186 - public void onClick(View v) {  
187 - super.onClick(v);  
188 - switch (v.getId()) {  
189 - case R.id.imabutton_colse://关闭  
190 - this.finish();  
191 - break;  
192 - case R.id.imabutton_wx://微信登录  
193 - getOtherInfo("1", Wechat.NAME);  
194 - showLogin();  
195 - break;  
196 - case R.id.imabutton_wb://微博登录  
197 - getOtherInfo("2", SinaWeibo.NAME);  
198 - showLogin();  
199 - break;  
200 - case R.id.imabutton_qq://qq登录  
201 - getOtherInfo("3", QQ.NAME);  
202 - showLogin();  
203 - break;  
204 - case R.id.button_sendcode://发送验证码  
205 - UserUtil.sendMessage(IUserService.QUICK_LOGIN, et_phone.getText().toString(), new MobileCall());  
206 - break;  
207 - case R.id.button_login://登录  
208 - showLogin();  
209 - UserUtil.quickLogin(String.valueOf(et_phone.getText()), String.valueOf(et_code.getText()), ChannelUtil.getChannelFromApk(this), userDataCall);  
210 - break;  
211 70
212 - default:  
213 - break;  
214 - }  
215 - }  
216 -  
217 - /**  
218 - * 显示等待框  
219 - */  
220 - private void showLogin() {  
221 - progressDialog = ProgressDialog.show(this, "登录中...", "请稍候...", true, false);  
222 - progressDialog.setCancelable(true);// 设置是否可以通过点击Back键取消  
223 - progressDialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条  
224 - }  
225 -  
226 - /**  
227 - * 发送验证码sdk  
228 - */  
229 - class MobileCall extends GoldenlineCall {  
230 - @Override  
231 - protected void dowork(int what, String extra, Object obj) {  
232 - switch (what) {  
233 - case IUserService.SUCCESS:  
234 - ToastUtil.showToast("验证码已发送");  
235 - startTimer();  
236 - break;  
237 - default:  
238 - ToastUtil.showToast("验证码发送失败");  
239 - updateSendButtonText(true);  
240 - break;  
241 - }  
242 -  
243 - }  
244 -  
245 - /**  
246 - * 开始计数器  
247 - */  
248 - private void startTimer() {  
249 - countDownTimer = new CountDownTimer(COUNTDOWN_TIME * 1000, 990) {  
250 - @Override  
251 - public void onTick(long leftTimeInMilliseconds) {  
252 - long seconds = leftTimeInMilliseconds / 1000;  
253 - count = (int) (seconds % 60);  
254 - updateSendButtonText(false);  
255 - }  
256 -  
257 - @Override  
258 - public void onFinish() {  
259 - updateSendButtonText(true);  
260 - }  
261 -  
262 - };  
263 - countDownTimer.start();  
264 - }  
265 -  
266 - /**  
267 - * 更新按钮的状态  
268 - *  
269 - * @param showNormal  
270 - */  
271 - private void updateSendButtonText(boolean showNormal) {  
272 - if (showNormal) {  
273 - button_sendcode.setText(getResources().getString(R.string.logoin_getcode));  
274 - button_sendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);  
275 - button_sendcode.setTextColor(getResources().getColor(R.color.color_ff6633));  
276 - button_sendcode.setEnabled(true);  
277 - } else {  
278 - String s = String.format(Locale.CHINESE, getString(R.string.format_verify_countdown), count);  
279 - button_sendcode.setText(s);  
280 - button_sendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);  
281 - button_sendcode.setTextColor(getResources().getColor(R.color.color_959595));  
282 - button_sendcode.setEnabled(false);  
283 - }  
284 - }  
285 - }  
286 -  
287 - /**  
288 - * 登陆完成后调用此方法同步用户其他信息  
289 - */  
290 - public void doNetWork(final DataEntity data) {  
291 - final UserAPI userApi = RestAdapterUtils.getRestAPI(UserAPI.class);  
292 - SyncUserRequestBean request = new SyncUserRequestBean(this);  
293 - request.setEmail(data.getEmail());  
294 - request.setExtInfo(data.getExtInfo());  
295 - request.setFaceUrl(data.getFaceUrl());  
296 - request.setGender(data.getGender().equals("m") ? 0 : (data.getGender().equals("f") ? 1 : 2));  
297 - request.sethUid(data.gethUid());  
298 - request.setLocation(data.getLocation());  
299 - request.setMobile(data.getMobile());  
300 - request.setNickName(data.getNickName());  
301 - request.setUid(data.getUid());  
302 - userApi.syncUserById(request, new Callback<User>() {  
303 - @Override  
304 - public void success(User user, Response response) {  
305 - progressDialog.dismiss();  
306 - if (null != user && user.getErrorCode().equals("0")) {  
307 - mUserService.setUserInfo(user, "");  
308 - SPUtils.put(RegisterActivity.this, "isSubscribeSuccess", true);  
309 - //登录成功关闭页面  
310 - finish();  
311 - }else{  
312 - ToastUtil.showToast(getString(R.string.login_error));  
313 - }  
314 - }  
315 -  
316 - @Override  
317 - public void failure(RetrofitError error) {  
318 - ToastUtil.showToast(getString(R.string.login_error));  
319 - progressDialog.dismiss();  
320 - }  
321 - });  
322 - }  
323 -  
324 - public void getOtherInfo(final String tag, String s) {  
325 - ShareSdkUtil.loginThirdPlatform(RegisterActivity.this, s, new PlatformActionListener() {  
326 - @Override  
327 - public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {//授权成功  
328 -  
329 - progressDialog.dismiss();  
330 -  
331 - if (null != hashMap && hashMap.size() > 0) {  
332 - if ("1" == tag) {  
333 - //微信登录  
334 - String uid = (String) hashMap.get("unionid");  
335 - String nick = platform.getDb().getUserName();  
336 - String location = (String) hashMap.get("city");  
337 - String avatar = (String) hashMap.get("headimgurl");  
338 - //为了红包提现,把uid传为openid  
339 - String openid = (String) hashMap.get("openid");  
340 - String userSex = "n";  
341 - int sex = (int) hashMap.get("sex");  
342 - if (sex == 1) {  
343 - userSex = "m";  
344 - } else if (sex == 2) {  
345 - userSex = "f";  
346 - }  
347 - UserUtil.thirdPartyLogin(3, uid, nick, userSex, location, avatar,  
348 - ChannelUtil.getChannelFromApk(RegisterActivity.this), userDataCall);  
349 - }else if ("2" == tag) {  
350 - //微博登录  
351 - String uid = platform.getDb().getUserId();  
352 - String nick = (String) hashMap.get("name");  
353 - String location = (String) hashMap.get("location");  
354 - String userSex = (String) hashMap.get("gender");  
355 - String avatar = (String) hashMap.get("profile_image_url");  
356 - UserUtil.thirdPartyLogin(1, uid, nick, userSex, location, avatar,  
357 - ChannelUtil.getChannelFromApk(RegisterActivity.this), userDataCall);  
358 - } else if("3" == tag){  
359 - //QQ登录  
360 - String uid = platform.getDb().getUserId();  
361 - String nick = (String) hashMap.get("nickname");  
362 - String location = (String) hashMap.get("city");  
363 - String avatar = hashMap.get("figureurl_qq_2").toString();  
364 - String userSex = "n";  
365 - String sex = (String) hashMap.get("gender");  
366 - if (sex.equals("男")) {  
367 - userSex = "m";  
368 - } else if (sex.equals("女")) {  
369 - userSex = "f";  
370 - }  
371 - UserUtil.thirdPartyLogin(2, uid, nick, userSex, location, avatar,  
372 - ChannelUtil.getChannelFromApk(RegisterActivity.this), userDataCall);  
373 - }  
374 - }  
375 - }  
376 -  
377 - @Override  
378 - public void onError(Platform platform, int i, Throwable throwable) {//授权失败  
379 - progressDialog.dismiss();  
380 - }  
381 -  
382 - @Override  
383 - public void onCancel(Platform platform, int i) {//取消  
384 - SystemTools.show_msg(getBaseContext(), "已取消");  
385 - progressDialog.dismiss();  
386 - }  
387 - });  
388 - }  
389 -  
390 - private GoldenlineCall userDataCall = new GoldenlineCall() {  
391 - @Override  
392 - protected void dowork(int what, String extra, Object obj) {  
393 - UserData userData = (UserData) obj;  
394 - DataEntity data = userData.getData();  
395 - GoldenLineApplication.mEdit.clear();  
396 - GoldenLineApplication.mEdit.putBoolean("isQuckLogin", true);  
397 - GoldenLineApplication.mEdit.putString("uid", data.getUid());  
398 - GoldenLineApplication.mEdit.putString("hUid", data.gethUid());  
399 - GoldenLineApplication.mEdit.apply();  
400 - if (null != data) {  
401 - //手机号为空必须要进行绑定,这是正在上演的逻辑  
402 - if(TextUtils.isEmpty(data.getMobile())){  
403 - Intent starter = new Intent(RegisterActivity.this, UpdatePhoneActivity.class);  
404 - starter.putExtra("title","绑定手机号");  
405 - starter.putExtra("uid",data.getUid());  
406 - starter.putExtra("data",data);  
407 - startActivityForResult(starter,101);  
408 - }else{  
409 - doNetWork(data);  
410 - }  
411 - }  
412 - }  
413 -  
414 - @Override  
415 - public void onState(int what, String extra, Object obj) {  
416 - super.onState(what, extra, obj);  
417 - if (what != IUserService.SUCCESS) {  
418 - progressDialog.dismiss();  
419 - }  
420 - }  
421 - };  
422 71
423 @Override 72 @Override
424 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 73 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
425 super.onActivityResult(requestCode, resultCode, data); 74 super.onActivityResult(requestCode, resultCode, data);
426 if(resultCode == RESULT_OK){ 75 if(resultCode == RESULT_OK){
427 DataEntity dataEntity = (DataEntity) (data.getSerializableExtra("data")); 76 DataEntity dataEntity = (DataEntity) (data.getSerializableExtra("data"));
428 - doNetWork(dataEntity); 77 +
  78 + loginViewModel. doNetWork(dataEntity);
429 } 79 }
430 } 80 }
431 } 81 }
app/src/main/java/com/cnlive/goldenline/viewmodel/LoginViewModel.java 0 → 100644
  1 +package com.cnlive.goldenline.viewmodel;
  2 +
  3 +import android.app.Activity;
  4 +import android.app.ProgressDialog;
  5 +import android.content.Context;
  6 +import android.content.Intent;
  7 +import android.databinding.BaseObservable;
  8 +import android.os.CountDownTimer;
  9 +import android.text.Editable;
  10 +import android.text.TextUtils;
  11 +import android.util.Log;
  12 +import android.view.View;
  13 +
  14 +import com.cnlive.goldenline.R;
  15 +import com.cnlive.goldenline.api.UserAPI;
  16 +import com.cnlive.goldenline.application.GoldenLineApplication;
  17 +import com.cnlive.goldenline.databinding.ActivityRegisterBinding;
  18 +import com.cnlive.goldenline.model.User;
  19 +import com.cnlive.goldenline.model.mine.SyncUserRequestBean;
  20 +import com.cnlive.goldenline.ui.activity.UpdatePhoneActivity;
  21 +import com.cnlive.goldenline.ui.base.GoldenlineCall;
  22 +import com.cnlive.goldenline.util.ChannelUtil;
  23 +import com.cnlive.goldenline.util.RestAdapterUtils;
  24 +import com.cnlive.goldenline.util.SPUtils;
  25 +import com.cnlive.goldenline.util.ShareSdkUtil;
  26 +import com.cnlive.goldenline.util.StringUtils;
  27 +import com.cnlive.goldenline.util.SystemTools;
  28 +import com.cnlive.goldenline.util.ToastUtil;
  29 +import com.cnlive.goldenline.util.UserService;
  30 +import com.cnlive.libs.user.IUserService;
  31 +import com.cnlive.libs.user.UserUtil;
  32 +import com.cnlive.libs.user.model.DataEntity;
  33 +import com.cnlive.libs.user.model.UserData;
  34 +
  35 +import java.util.HashMap;
  36 +import java.util.Locale;
  37 +
  38 +import cn.sharesdk.framework.Platform;
  39 +import cn.sharesdk.framework.PlatformActionListener;
  40 +import cn.sharesdk.sina.weibo.SinaWeibo;
  41 +import cn.sharesdk.tencent.qq.QQ;
  42 +import cn.sharesdk.wechat.friends.Wechat;
  43 +import retrofit.Callback;
  44 +import retrofit.RetrofitError;
  45 +import retrofit.client.Response;
  46 +
  47 +/**
  48 + * Created by ZJL on 2017/5/10.
  49 + */
  50 +
  51 +public class LoginViewModel extends BaseObservable{
  52 + /**
  53 + * 当前时间
  54 + */
  55 + private int count = COUNTDOWN_TIME;
  56 + /**
  57 + * 验证码计算时间
  58 + */
  59 + private final static int COUNTDOWN_TIME = 60;
  60 +
  61 + /**
  62 + * 倒数计数器
  63 + */
  64 + private CountDownTimer countDownTimer;
  65 +
  66 + private String mPhone;
  67 + private ActivityRegisterBinding activityRegisterBinding;
  68 +
  69 + private String phone = "";
  70 + private ProgressDialog progressDialog;
  71 + private UserService mUserService;
  72 + private Context context;
  73 +
  74 + public LoginViewModel(ActivityRegisterBinding activityRegisterBinding, Context context){
  75 + this.activityRegisterBinding=activityRegisterBinding;
  76 + this.context=context;
  77 + mUserService = new UserService(context);
  78 + }
  79 + public String getMPhone() {
  80 + return mPhone;
  81 + }
  82 +
  83 + public void setMPhone(String mPhone) {
  84 + this.mPhone = mPhone;
  85 + }
  86 +
  87 + /**
  88 + * 处理验证码
  89 + *
  90 + * @param code
  91 + */
  92 + public void formatCode(Editable code) {
  93 + if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString()) && code.length() == 6) {
  94 + activityRegisterBinding.buttonLogin.setBackgroundResource(R.drawable.login_canuse);
  95 + activityRegisterBinding.buttonLogin.setEnabled(true);
  96 + } else {
  97 + activityRegisterBinding.buttonLogin.setBackgroundResource(R.drawable.login_nouse);
  98 + activityRegisterBinding.buttonLogin.setEnabled(false);
  99 + }
  100 + }
  101 + public void phoneChanged(Editable phone) {
  102 + Log.i("name","titleChanged");
  103 + this.phone = phone.toString();
  104 + if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString())) {
  105 + activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);
  106 + activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_ff6633));
  107 + activityRegisterBinding.buttonSendcode.setEnabled(true);
  108 + } else {
  109 + activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);
  110 + activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_959595));
  111 + activityRegisterBinding.buttonSendcode.setEnabled(false);
  112 + }
  113 + }
  114 + public void sendSMS(View view){
  115 + UserUtil.sendMessage(IUserService.QUICK_LOGIN, activityRegisterBinding.etPhone.getText().toString(), new MobileCall());
  116 +
  117 + }
  118 + public void toLogin(View view){
  119 + showLogin();
  120 + UserUtil.quickLogin(String.valueOf(activityRegisterBinding.etPhone.getText()), String.valueOf(activityRegisterBinding.etCode.getText()), ChannelUtil.getChannelFromApk(context), userDataCall);
  121 + }
  122 + public void weixinLogin(View view){
  123 + getOtherInfo("1", Wechat.NAME);
  124 + showLogin();
  125 + }
  126 + public void weiboLogin(View view){
  127 + getOtherInfo("2", SinaWeibo.NAME);
  128 + showLogin();
  129 + }
  130 + public void qqLogin(View view){
  131 + getOtherInfo("3", QQ.NAME);
  132 + showLogin();
  133 + }
  134 + public void closeAct(View view){
  135 + ( (Activity)context).finish();
  136 + }
  137 + /**
  138 + * 发送验证码sdk
  139 + */
  140 + class MobileCall extends GoldenlineCall {
  141 + @Override
  142 + protected void dowork(int what, String extra, Object obj) {
  143 + switch (what) {
  144 + case IUserService.SUCCESS:
  145 + ToastUtil.showToast("验证码已发送");
  146 + startTimer();
  147 + break;
  148 + default:
  149 + ToastUtil.showToast("验证码发送失败");
  150 + updateSendButtonText(true);
  151 + break;
  152 + }
  153 +
  154 + }
  155 +
  156 + /**
  157 + * 开始计数器
  158 + */
  159 + private void startTimer() {
  160 + countDownTimer = new CountDownTimer(COUNTDOWN_TIME * 1000, 990) {
  161 + @Override
  162 + public void onTick(long leftTimeInMilliseconds) {
  163 + long seconds = leftTimeInMilliseconds / 1000;
  164 + count = (int) (seconds % 60);
  165 + updateSendButtonText(false);
  166 + }
  167 +
  168 + @Override
  169 + public void onFinish() {
  170 + updateSendButtonText(true);
  171 + }
  172 +
  173 + };
  174 + countDownTimer.start();
  175 + }
  176 +
  177 + /**
  178 + * 更新按钮的状态
  179 + *
  180 + * @param showNormal
  181 + */
  182 + private void updateSendButtonText(boolean showNormal) {
  183 + if (showNormal) {
  184 + activityRegisterBinding.buttonSendcode.setText(GoldenLineApplication.getInstance().getResources().getString(R.string.logoin_getcode));
  185 + activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);
  186 + activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_ff6633));
  187 + activityRegisterBinding.buttonSendcode.setEnabled(true);
  188 + } else {
  189 + String s = String.format(Locale.CHINESE, GoldenLineApplication.getInstance().getString(R.string.format_verify_countdown), count);
  190 + activityRegisterBinding.buttonSendcode.setText(s);
  191 + activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);
  192 + activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_959595));
  193 + activityRegisterBinding.buttonSendcode.setEnabled(false);
  194 + }
  195 + }
  196 + }
  197 + /**
  198 + * 显示等待框
  199 + */
  200 + private void showLogin() {
  201 + progressDialog = ProgressDialog.show(context, "登录中...", "请稍候...", true, false);
  202 + progressDialog.setCancelable(true);// 设置是否可以通过点击Back键取消
  203 + progressDialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
  204 + }
  205 + private GoldenlineCall userDataCall = new GoldenlineCall() {
  206 + @Override
  207 + protected void dowork(int what, String extra, Object obj) {
  208 + UserData userData = (UserData) obj;
  209 + DataEntity data = userData.getData();
  210 + GoldenLineApplication.mEdit.clear();
  211 + GoldenLineApplication.mEdit.putBoolean("isQuckLogin", true);
  212 + GoldenLineApplication.mEdit.putString("uid", data.getUid());
  213 + GoldenLineApplication.mEdit.putString("hUid", data.gethUid());
  214 + GoldenLineApplication.mEdit.apply();
  215 + if (null != data) {
  216 + //手机号为空必须要进行绑定,这是正在上演的逻辑
  217 + if(TextUtils.isEmpty(data.getMobile())){
  218 + Intent starter = new Intent(context, UpdatePhoneActivity.class);
  219 + starter.putExtra("title","绑定手机号");
  220 + starter.putExtra("uid",data.getUid());
  221 + starter.putExtra("data",data);
  222 + ( (Activity)context).startActivityForResult(starter,101);
  223 + }else{
  224 + doNetWork(data);
  225 + }
  226 + }
  227 + }
  228 +
  229 + @Override
  230 + public void onState(int what, String extra, Object obj) {
  231 + super.onState(what, extra, obj);
  232 + if (what != IUserService.SUCCESS) {
  233 + progressDialog.dismiss();
  234 + }
  235 + }
  236 + };
  237 + /**
  238 + * 登陆完成后调用此方法同步用户其他信息
  239 + */
  240 + public void doNetWork(final DataEntity data) {
  241 + final UserAPI userApi = RestAdapterUtils.getRestAPI(UserAPI.class);
  242 + SyncUserRequestBean request = new SyncUserRequestBean(context);
  243 + request.setEmail(data.getEmail());
  244 + request.setExtInfo(data.getExtInfo());
  245 + request.setFaceUrl(data.getFaceUrl());
  246 + request.setGender(data.getGender().equals("m") ? 0 : (data.getGender().equals("f") ? 1 : 2));
  247 + request.sethUid(data.gethUid());
  248 + request.setLocation(data.getLocation());
  249 + request.setMobile(data.getMobile());
  250 + request.setNickName(data.getNickName());
  251 + request.setUid(data.getUid());
  252 + userApi.syncUserById(request, new Callback<User>() {
  253 + @Override
  254 + public void success(User user, Response response) {
  255 + progressDialog.dismiss();
  256 + if (null != user && user.getErrorCode().equals("0")) {
  257 + mUserService.setUserInfo(user, "");
  258 + SPUtils.put(context, "isSubscribeSuccess", true);
  259 + //登录成功关闭页面
  260 + ( (Activity)context).finish();
  261 + }else{
  262 + ToastUtil.showToast(GoldenLineApplication.getInstance().getString(R.string.login_error));
  263 + }
  264 + }
  265 +
  266 + @Override
  267 + public void failure(RetrofitError error) {
  268 + ToastUtil.showToast(GoldenLineApplication.getInstance().getString(R.string.login_error));
  269 + progressDialog.dismiss();
  270 + }
  271 + });
  272 + }
  273 + public void getOtherInfo(final String tag, String s) {
  274 + ShareSdkUtil.loginThirdPlatform(context, s, new PlatformActionListener() {
  275 + @Override
  276 + public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {//授权成功
  277 +
  278 + progressDialog.dismiss();
  279 +
  280 + if (null != hashMap && hashMap.size() > 0) {
  281 + if ("1" == tag) {
  282 + //微信登录
  283 + String uid = (String) hashMap.get("unionid");
  284 + String nick = platform.getDb().getUserName();
  285 + String location = (String) hashMap.get("city");
  286 + String avatar = (String) hashMap.get("headimgurl");
  287 + //为了红包提现,把uid传为openid
  288 + String openid = (String) hashMap.get("openid");
  289 + String userSex = "n";
  290 + int sex = (int) hashMap.get("sex");
  291 + if (sex == 1) {
  292 + userSex = "m";
  293 + } else if (sex == 2) {
  294 + userSex = "f";
  295 + }
  296 + UserUtil.thirdPartyLogin(3, uid, nick, userSex, location, avatar,
  297 + ChannelUtil.getChannelFromApk(context), userDataCall);
  298 + }else if ("2" == tag) {
  299 + //微博登录
  300 + String uid = platform.getDb().getUserId();
  301 + String nick = (String) hashMap.get("name");
  302 + String location = (String) hashMap.get("location");
  303 + String userSex = (String) hashMap.get("gender");
  304 + String avatar = (String) hashMap.get("profile_image_url");
  305 + UserUtil.thirdPartyLogin(1, uid, nick, userSex, location, avatar,
  306 + ChannelUtil.getChannelFromApk(context), userDataCall);
  307 + } else if("3" == tag){
  308 + //QQ登录
  309 + String uid = platform.getDb().getUserId();
  310 + String nick = (String) hashMap.get("nickname");
  311 + String location = (String) hashMap.get("city");
  312 + String avatar = hashMap.get("figureurl_qq_2").toString();
  313 + String userSex = "n";
  314 + String sex = (String) hashMap.get("gender");
  315 + if (sex.equals("男")) {
  316 + userSex = "m";
  317 + } else if (sex.equals("女")) {
  318 + userSex = "f";
  319 + }
  320 + UserUtil.thirdPartyLogin(2, uid, nick, userSex, location, avatar,
  321 + ChannelUtil.getChannelFromApk(context), userDataCall);
  322 + }
  323 + }
  324 + }
  325 +
  326 + @Override
  327 + public void onError(Platform platform, int i, Throwable throwable) {//授权失败
  328 + progressDialog.dismiss();
  329 + }
  330 +
  331 + @Override
  332 + public void onCancel(Platform platform, int i) {//取消
  333 + SystemTools.show_msg(GoldenLineApplication.getInstance().getBaseContext(), "已取消");
  334 + progressDialog.dismiss();
  335 + }
  336 + });
  337 + }
  338 +}
app/src/main/res/layout/activity_register.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
3 - android:layout_width="match_parent"  
4 - android:layout_height="match_parent"  
5 - android:background="@color/white"  
6 - android:orientation="vertical">  
7 -  
8 - <RelativeLayout  
9 - android:layout_width="match_parent"  
10 - android:layout_height="45dp"  
11 - android:background="@null">  
12 -  
13 - <ImageButton  
14 - android:id="@+id/imabutton_colse"  
15 - android:layout_width="wrap_content"  
16 - android:layout_height="wrap_content"  
17 - android:layout_alignParentRight="true"  
18 - android:layout_centerVertical="true"  
19 - android:layout_marginRight="22dp"  
20 - android:background="@mipmap/register_close" />  
21 - </RelativeLayout>  
22 - 2 +<layout xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <data>
  4 + <variable
  5 + name="loginViewModel"
  6 + type="com.cnlive.goldenline.viewmodel.LoginViewModel"/>
  7 + </data>
23 <LinearLayout 8 <LinearLayout
24 android:layout_width="match_parent" 9 android:layout_width="match_parent"
25 - android:layout_height="wrap_content"  
26 - android:layout_marginLeft="38dp"  
27 - android:layout_marginRight="38dp" 10 + android:layout_height="match_parent"
  11 + android:background="@color/white"
28 android:orientation="vertical"> 12 android:orientation="vertical">
29 13
30 <RelativeLayout 14 <RelativeLayout
31 android:layout_width="match_parent" 15 android:layout_width="match_parent"
32 - android:layout_height="wrap_content"  
33 - android:layout_gravity="center_horizontal"  
34 - android:layout_marginTop="80dp"  
35 - android:gravity="center">  
36 - 16 + android:layout_height="45dp"
  17 + android:background="@null">
37 18
38 -  
39 - <EditText  
40 - android:id="@+id/et_phone"  
41 - android:layout_width="match_parent"  
42 - android:layout_height="35dp"  
43 - android:layout_alignParentStart="true"  
44 - android:layout_alignParentTop="true"  
45 - android:layout_toLeftOf="@+id/button_sendcode"  
46 - android:digits="0123456789"  
47 - android:hint="@string/logoin_phone"  
48 - android:inputType="phone"  
49 - android:maxLength="11"  
50 - android:background="@color/white"  
51 - android:singleLine="true"  
52 - android:textColor="@color/color_333"  
53 - android:textColorHint="@color/color_c7c7cd"  
54 - android:textSize="14sp" />  
55 -  
56 - <Button  
57 - android:id="@+id/button_sendcode" 19 + <ImageButton
  20 + android:onClick="@{loginViewModel::closeAct}"
  21 + android:id="@+id/imabutton_colse"
58 android:layout_width="wrap_content" 22 android:layout_width="wrap_content"
59 android:layout_height="wrap_content" 23 android:layout_height="wrap_content"
60 - android:layout_above="@+id/view"  
61 - android:layout_marginRight="8dp"  
62 - android:textSize="11sp"  
63 - android:text="获取验证码"  
64 - android:gravity="center"  
65 - android:enabled="false"  
66 - android:textColor="@color/color_959595"  
67 - android:layout_alignParentEnd="true"  
68 - android:background="@mipmap/verificationcode_nouse" />  
69 -  
70 - <View  
71 - android:id="@+id/view"  
72 - android:layout_width="match_parent"  
73 - android:layout_height="1dp"  
74 - android:layout_below="@id/et_phone"  
75 - android:layout_marginTop="15dp"  
76 - android:background="@color/color_ededed" /> 24 + android:layout_alignParentRight="true"
  25 + android:layout_centerVertical="true"
  26 + android:layout_marginRight="22dp"
  27 + android:background="@mipmap/register_close" />
77 </RelativeLayout> 28 </RelativeLayout>
78 29
79 - <RelativeLayout 30 + <LinearLayout
80 android:layout_width="match_parent" 31 android:layout_width="match_parent"
81 android:layout_height="wrap_content" 32 android:layout_height="wrap_content"
82 - android:layout_gravity="center_horizontal"  
83 - android:layout_marginTop="20dp"  
84 - android:gravity="center">  
85 - 33 + android:layout_marginLeft="38dp"
  34 + android:layout_marginRight="38dp"
  35 + android:orientation="vertical">
86 36
87 - <View 37 + <RelativeLayout
88 android:layout_width="match_parent" 38 android:layout_width="match_parent"
89 - android:layout_height="1dp"  
90 - android:layout_below="@+id/et_code"  
91 - android:layout_marginTop="15dp"  
92 - android:background="@color/color_ededed" />  
93 -  
94 - <EditText  
95 - android:id="@+id/et_code" 39 + android:layout_height="wrap_content"
  40 + android:layout_gravity="center_horizontal"
  41 + android:layout_marginTop="80dp"
  42 + android:gravity="center">
  43 +
  44 +
  45 +
  46 + <EditText
  47 + android:afterTextChanged="@{loginViewModel::phoneChanged}"
  48 + android:id="@+id/et_phone"
  49 + android:layout_width="match_parent"
  50 + android:layout_height="35dp"
  51 + android:layout_alignParentStart="true"
  52 + android:layout_alignParentTop="true"
  53 + android:layout_toLeftOf="@+id/button_sendcode"
  54 + android:digits="0123456789"
  55 + android:hint="@string/logoin_phone"
  56 + android:inputType="phone"
  57 + android:maxLength="11"
  58 + android:background="@color/white"
  59 + android:singleLine="true"
  60 + android:textColor="@color/color_333"
  61 + android:textColorHint="@color/color_c7c7cd"
  62 + android:textSize="14sp" />
  63 +
  64 + <Button
  65 + android:onClick="@{loginViewModel::sendSMS}"
  66 + android:id="@+id/button_sendcode"
  67 + android:layout_width="wrap_content"
  68 + android:layout_height="wrap_content"
  69 + android:layout_above="@+id/view"
  70 + android:layout_marginRight="8dp"
  71 + android:textSize="11sp"
  72 + android:text="获取验证码"
  73 + android:gravity="center"
  74 + android:enabled="false"
  75 + android:textColor="@color/color_959595"
  76 + android:layout_alignParentEnd="true"
  77 + android:background="@mipmap/verificationcode_nouse" />
  78 +
  79 + <View
  80 + android:id="@+id/view"
  81 + android:layout_width="match_parent"
  82 + android:layout_height="1dp"
  83 + android:layout_below="@id/et_phone"
  84 + android:layout_marginTop="15dp"
  85 + android:background="@color/color_ededed" />
  86 + </RelativeLayout>
  87 +
  88 + <RelativeLayout
96 android:layout_width="match_parent" 89 android:layout_width="match_parent"
97 android:layout_height="wrap_content" 90 android:layout_height="wrap_content"
98 - android:layout_alignParentStart="true"  
99 - android:layout_alignParentTop="true"  
100 - android:digits="0123456789"  
101 - android:hint="@string/logoin_code"  
102 - android:inputType="number"  
103 - android:maxLength="6"  
104 - android:background="@color/white"  
105 - android:singleLine="true"  
106 - android:textColor="@color/color_333"  
107 - android:textColorHint="@color/color_c7c7cd"  
108 - android:textSize="14sp" /> 91 + android:layout_gravity="center_horizontal"
  92 + android:layout_marginTop="20dp"
  93 + android:gravity="center">
109 94
110 - </RelativeLayout>  
111 95
112 - <Button  
113 - android:id="@+id/button_login"  
114 - android:layout_width="wrap_content"  
115 - android:layout_height="wrap_content"  
116 - android:layout_gravity="center_horizontal"  
117 - android:enabled="false"  
118 - android:layout_marginTop="40dp"  
119 - android:background="@drawable/login_nouse" />  
120 - </LinearLayout> 96 + <View
  97 + android:layout_width="match_parent"
  98 + android:layout_height="1dp"
  99 + android:layout_below="@+id/et_code"
  100 + android:layout_marginTop="15dp"
  101 + android:background="@color/color_ededed" />
121 102
122 - <RelativeLayout  
123 - android:layout_width="match_parent"  
124 - android:layout_height="wrap_content"  
125 - android:layout_gravity="bottom"  
126 - android:layout_weight="1"> 103 + <EditText
  104 + android:afterTextChanged="@{loginViewModel::formatCode}"
  105 + android:id="@+id/et_code"
  106 + android:layout_width="match_parent"
  107 + android:layout_height="wrap_content"
  108 + android:layout_alignParentStart="true"
  109 + android:layout_alignParentTop="true"
  110 + android:digits="0123456789"
  111 + android:hint="@string/logoin_code"
  112 + android:inputType="number"
  113 + android:maxLength="6"
  114 + android:background="@color/white"
  115 + android:singleLine="true"
  116 + android:textColor="@color/color_333"
  117 + android:textColorHint="@color/color_c7c7cd"
  118 + android:textSize="14sp" />
  119 +
  120 + </RelativeLayout>
  121 +
  122 + <Button
  123 + android:onClick="@{loginViewModel::toLogin}"
  124 + android:id="@+id/button_login"
  125 + android:layout_width="wrap_content"
  126 + android:layout_height="wrap_content"
  127 + android:layout_gravity="center_horizontal"
  128 + android:enabled="false"
  129 + android:layout_marginTop="40dp"
  130 + android:background="@drawable/login_nouse" />
  131 + </LinearLayout>
127 132
128 <RelativeLayout 133 <RelativeLayout
129 android:layout_width="match_parent" 134 android:layout_width="match_parent"
130 - android:layout_height="95dp"  
131 - android:layout_marginBottom="20dp"  
132 - android:layout_alignParentBottom="true">  
133 -  
134 - <TextView  
135 - android:id="@+id/text"  
136 - android:layout_width="match_parent"  
137 - android:layout_height="wrap_content"  
138 - android:gravity="center"  
139 - android:text="使用其他账号登录"  
140 - android:textColor="@color/color_a6a6a6"  
141 - android:textSize="13sp" /> 135 + android:layout_height="wrap_content"
  136 + android:layout_gravity="bottom"
  137 + android:layout_weight="1">
142 138
143 - <LinearLayout 139 + <RelativeLayout
144 android:layout_width="match_parent" 140 android:layout_width="match_parent"
145 - android:layout_height="match_parent"  
146 - android:layout_below="@id/text"  
147 - android:layout_marginTop="20dp"  
148 - android:orientation="horizontal"> 141 + android:layout_height="95dp"
  142 + android:layout_marginBottom="20dp"
  143 + android:layout_alignParentBottom="true">
149 144
150 - <RelativeLayout  
151 - android:layout_width="wrap_content" 145 + <TextView
  146 + android:id="@+id/text"
  147 + android:layout_width="match_parent"
152 android:layout_height="wrap_content" 148 android:layout_height="wrap_content"
153 - android:layout_weight="1">  
154 -  
155 - <ImageButton  
156 - android:id="@+id/imabutton_wx" 149 + android:gravity="center"
  150 + android:text="使用其他账号登录"
  151 + android:textColor="@color/color_a6a6a6"
  152 + android:textSize="13sp" />
  153 +
  154 + <LinearLayout
  155 + android:layout_width="match_parent"
  156 + android:layout_height="match_parent"
  157 + android:layout_below="@id/text"
  158 + android:layout_marginTop="20dp"
  159 + android:orientation="horizontal">
  160 +
  161 + <RelativeLayout
157 android:layout_width="wrap_content" 162 android:layout_width="wrap_content"
158 android:layout_height="wrap_content" 163 android:layout_height="wrap_content"
159 - android:layout_centerInParent="true"  
160 - android:background="@mipmap/login_wx" />  
161 - </RelativeLayout>  
162 -  
163 - <RelativeLayout  
164 - android:layout_width="wrap_content"  
165 - android:layout_height="wrap_content"  
166 - android:layout_weight="1">  
167 -  
168 - <ImageButton  
169 - android:id="@+id/imabutton_wb" 164 + android:layout_weight="1">
  165 +
  166 + <ImageButton
  167 + android:onClick="@{loginViewModel::weixinLogin}"
  168 + android:id="@+id/imabutton_wx"
  169 + android:layout_width="wrap_content"
  170 + android:layout_height="wrap_content"
  171 + android:layout_centerInParent="true"
  172 + android:background="@mipmap/login_wx" />
  173 + </RelativeLayout>
  174 +
  175 + <RelativeLayout
170 android:layout_width="wrap_content" 176 android:layout_width="wrap_content"
171 android:layout_height="wrap_content" 177 android:layout_height="wrap_content"
172 - android:layout_centerInParent="true"  
173 - android:background="@mipmap/login_wb" />  
174 - </RelativeLayout>  
175 -  
176 - <RelativeLayout  
177 - android:layout_width="wrap_content"  
178 - android:layout_height="wrap_content"  
179 - android:layout_weight="1">  
180 -  
181 - <ImageButton  
182 - android:id="@+id/imabutton_qq" 178 + android:layout_weight="1">
  179 +
  180 + <ImageButton
  181 + android:onClick="@{loginViewModel::weiboLogin}"
  182 + android:id="@+id/imabutton_wb"
  183 + android:layout_width="wrap_content"
  184 + android:layout_height="wrap_content"
  185 + android:layout_centerInParent="true"
  186 + android:background="@mipmap/login_wb" />
  187 + </RelativeLayout>
  188 +
  189 + <RelativeLayout
  190 + android:onClick="@{loginViewModel::qqLogin}"
183 android:layout_width="wrap_content" 191 android:layout_width="wrap_content"
184 android:layout_height="wrap_content" 192 android:layout_height="wrap_content"
185 - android:layout_centerInParent="true"  
186 - android:background="@mipmap/login_qq" />  
187 - </RelativeLayout>  
188 - </LinearLayout>  
189 - </RelativeLayout> 193 + android:layout_weight="1">
  194 +
  195 + <ImageButton
  196 + android:id="@+id/imabutton_qq"
  197 + android:layout_width="wrap_content"
  198 + android:layout_height="wrap_content"
  199 + android:layout_centerInParent="true"
  200 + android:background="@mipmap/login_qq" />
  201 + </RelativeLayout>
  202 + </LinearLayout>
  203 + </RelativeLayout>
190 204
191 - </RelativeLayout>  
192 -</LinearLayout> 205 + </RelativeLayout>
  206 + </LinearLayout>
  207 +</layout>