2020-08-03 09:11:54 +08:00
|
|
|
package com.sl.house_property;
|
|
|
|
|
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
2021-03-04 21:36:39 +08:00
|
|
|
import android.util.Log;
|
2020-08-03 09:11:54 +08:00
|
|
|
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;
|
2021-03-04 21:36:39 +08:00
|
|
|
import com.google.gson.reflect.TypeToken;
|
2020-08-03 09:11:54 +08:00
|
|
|
import com.sl.house_property.databinding.ActivityLoginBinding;
|
|
|
|
|
|
2021-03-04 21:36:39 +08:00
|
|
|
import java.lang.reflect.Type;
|
|
|
|
|
import java.util.ArrayList;
|
2020-08-03 09:11:54 +08:00
|
|
|
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;
|
2021-03-04 21:36:39 +08:00
|
|
|
import utils.SPUtils;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
|
|
|
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());
|
2021-03-04 21:36:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
if (user != null) {
|
|
|
|
|
map.put("userid", user.getUserid());
|
|
|
|
|
} else {
|
|
|
|
|
map.put("userid", 0 + "");
|
2020-08-03 09:11:54 +08:00
|
|
|
}
|
2021-03-04 21:36:39 +08:00
|
|
|
map.put("app", "Cas");
|
|
|
|
|
map.put("class", "MyHouseList");
|
|
|
|
|
//map.put("home_id", "GetHomeByPid");
|
|
|
|
|
map.put("sign", Md5.md5("Cas" + "MyHouseList" + Md5.secret));
|
|
|
|
|
getpammar(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-03 09:11:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, new Action1<Throwable>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void call(Throwable throwable) {
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
setToast( getString(R.string.getdatafailure));
|
|
|
|
|
throwable.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addSubscription(subscription);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 21:36:39 +08:00
|
|
|
|
|
|
|
|
private void getpammar(String myurl, Map<String, String> map, String msg, final int requstecode) {
|
|
|
|
|
// progressDialog.setMessage(msg);
|
|
|
|
|
// progressDialog.setCancelable(false);
|
|
|
|
|
// progressDialog.show();
|
|
|
|
|
mGankLoader = new Loader();
|
|
|
|
|
Subscription subscription = mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void call(Resultcode resultcode) {
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
|
|
|
|
|
if (!(resultcode.status == 0)) {
|
|
|
|
|
setToast(resultcode.msg);
|
|
|
|
|
}
|
|
|
|
|
if (resultcode.status == 0) {
|
|
|
|
|
if (requstecode == 0) {
|
|
|
|
|
Gson gs = new Gson();
|
|
|
|
|
ArrayList<LinkedTreeMap> adta = (ArrayList<LinkedTreeMap>) resultcode.data;
|
|
|
|
|
String s = gs.toJson(adta);
|
|
|
|
|
//final ArrayList<MyHomequEntity> list = null;
|
|
|
|
|
Type type = new TypeToken<ArrayList<MyHouseEntity>>() {
|
|
|
|
|
}.getType();
|
|
|
|
|
final ArrayList<MyHouseEntity> list = new Gson().fromJson(s, type);
|
|
|
|
|
if(list.size()==0){
|
|
|
|
|
SPUtils.setSP(LoginActivity.this, DoConfig.FANGCHAN_DATA, "0");
|
|
|
|
|
Log.e("fuzhi","0");
|
|
|
|
|
}else {
|
|
|
|
|
SPUtils.setSP(LoginActivity.this, DoConfig.FANGCHAN_DATA, "1");
|
|
|
|
|
Log.e("fuzhi","1");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (!Config.getInstance(LoginActivity.this).getBoolean("MainTabActivity", false)) {
|
|
|
|
|
Intent intent = new Intent(LoginActivity.this, MainTabActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, new Action1<Throwable>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void call(Throwable throwable) {
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
setToast(getString(R.string.getdatafailure));
|
|
|
|
|
throwable.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addSubscription(subscription);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-03 09:11:54 +08:00
|
|
|
}
|