sdf
This commit is contained in:
158
app/src/main/java/com/sl/house_property/LoginActivity.java
Normal file
158
app/src/main/java/com/sl/house_property/LoginActivity.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package com.sl.house_property;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cutil.RegexUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import com.sl.house_property.databinding.ActivityLoginBinding;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import entity.RegisterUser;
|
||||
import my_loader.Loader;
|
||||
import my_loader.Resultcode;
|
||||
import tools.Config;
|
||||
import http.ApiConfig;
|
||||
import rx.Subscription;
|
||||
import rx.functions.Action1;
|
||||
import utils.Md5;
|
||||
|
||||
public class LoginActivity extends BaseActivity<ActivityLoginBinding> implements View.OnClickListener {
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
private Loader mGankLoader;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_login;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setAbr(getString(R.string.me_login), new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
}, 0, null, 0, null, 0, null, "");
|
||||
|
||||
progressDialog = new ProgressDialog(LoginActivity.this);
|
||||
String username = Config.getInstance(LoginActivity.this).getString("username", "15129217176");
|
||||
// mDataBinding.phone.setText(username);
|
||||
// mDataBinding.phone.setSelection(username.length());
|
||||
mDataBinding.logintext.setOnClickListener(this);
|
||||
mDataBinding.forgetpaw.setOnClickListener(this);
|
||||
mDataBinding.gotoregister.setOnClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.gotoregister:
|
||||
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.forgetpaw:
|
||||
Intent intent2 = new Intent(LoginActivity.this, ForgetPwdActivity.class);
|
||||
startActivity(intent2);
|
||||
break;
|
||||
case R.id.logintext:
|
||||
String phone = mDataBinding.phone.getText().toString().trim();
|
||||
String password = mDataBinding.pwd.getText().toString().trim();
|
||||
if (phone.length() <1) {
|
||||
setToast("请输入手机号码");
|
||||
return;
|
||||
}
|
||||
if (phone.length() != 11) {
|
||||
setToast("请输入有效的手机号");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!RegexUtils.isMobileExact(phone)) {
|
||||
setToast(getString(R.string.me_account_or_password_error_tip));
|
||||
return;
|
||||
}
|
||||
if (password.equals("")) {
|
||||
setToast(getString(R.string.me_input_password_tip));
|
||||
return;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("phone", phone);
|
||||
map.put("password", password);
|
||||
map.put("sign", Md5.md5("Cas" + "Login" + Md5.secret));
|
||||
map.put("app", "Cas");
|
||||
map.put("class", "Login");
|
||||
getGankList(ApiConfig.BASE_URL, map, getResources().getString(R.string.logining), view.getId());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void getGankList(final String myurl, Map<String, String> map, String string, final int getcode1) {
|
||||
progressDialog.setMessage(string);
|
||||
|
||||
//map.put("")
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
mDataBinding.getRoot().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressDialog.dismiss();
|
||||
//setToast(1, getString(R.string.timeout));
|
||||
}
|
||||
}, 13000);
|
||||
mGankLoader = new Loader();
|
||||
/* Map<String,String> map=new HashMap<String,String>();
|
||||
map.put("phone");*/
|
||||
Subscription subscription = mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
progressDialog.dismiss();
|
||||
//setToast(0,resultcode.status);
|
||||
if ((!(resultcode.status == 0))) {
|
||||
setToast(resultcode.msg);
|
||||
return;
|
||||
}
|
||||
switch (getcode1) {
|
||||
|
||||
case R.id.logintext:
|
||||
Gson gs = new Gson();
|
||||
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
RegisterUser user = gs.fromJson(s, RegisterUser.class);//把JSON字符串转为对象
|
||||
Config.getInstance(LoginActivity.this).putUser(user);
|
||||
Config.getInstance(LoginActivity.this).put("username", mDataBinding.phone.getText().toString().trim());
|
||||
if (!Config.getInstance(LoginActivity.this).getBoolean("MainTabActivity", false)) {
|
||||
Intent intent = new Intent(LoginActivity.this, MainTabActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
setToast( getString(R.string.getdatafailure));
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
addSubscription(subscription);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user