Files
HouseProperty/app/src/main/java/com/sl/house_property/LoginActivity.java
2026-01-08 17:50:27 +08:00

351 lines
14 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.sl.house_property;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.cutil.RegexUtils;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
import com.google.gson.reflect.TypeToken;
import com.sl.house_property.databinding.ActivityLoginBinding;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import cn.jpush.android.api.JPushInterface;
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.DateUtils;
import utils.DateUtilss;
import utils.Md5;
import utils.SPUtils;
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);
//获取当前日期
String gettimetwo = DateUtilss.gettimetwo();
Log.e("当前日期", gettimetwo);
// if(gettimetwo.equals("2021年04月02日")||gettimetwo.equals("2021年04月03日")||gettimetwo.equals("2021年04月04日")||gettimetwo.equals("2021年04月05日")||gettimetwo.equals("2021年04月06日")){
// mDataBinding.rlzhuce.setVisibility(View.GONE);
// mDataBinding.lyfuwu.setVisibility(View.VISIBLE);
// mDataBinding.lyyinsi.setVisibility(View.VISIBLE);
// }else {
// mDataBinding.rlzhuce.setVisibility(View.GONE);
// mDataBinding.lyfuwu.setVisibility(View.VISIBLE);
// mDataBinding.lyyinsi.setVisibility(View.VISIBLE);
// }
String str="我已阅读并同意《隐私政策》和《用户协议》";
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(str);
// 只设置《隐私政策》和《用户协议》为可点击链接
int start = str.indexOf("");
ssb.setSpan(new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
//隐私政策
WebActivitytwo.runActivity(LoginActivity.this, "", "https://wy.dou1.net/articlemobile/index/detail?article_id=19");
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(getResources().getColor(R.color.red));
ds.setUnderlineText(false);
}
}, start, start + 6, 0);
int end = str.lastIndexOf("");
ssb.setSpan(new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
//用户协议
WebActivitytwo.runActivity(LoginActivity.this, "", "https://wy.dou1.net/articlemobile/index/detail?article_id=1");
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(getResources().getColor(R.color.red));
ds.setUnderlineText(false);
}
}, end, end + 6, 0);
// 先设置文本和链接
mDataBinding.tvYs.setMovementMethod(LinkMovementMethod.getInstance());
mDataBinding.tvYs.setText(ssb,TextView.BufferType.SPANNABLE);
// 设置整个TextView可点击来切换选中状态
// 注意LinkMovementMethod会优先处理链接点击点击非链接区域才会触发此监听器
mDataBinding.tvYs.setClickable(true);
mDataBinding.tvYs.setFocusable(true);
mDataBinding.tvYs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleAgreementCheck();
}
});
}
@Override
public void onClick(View view) {
int gotoregisterId = R.id.gotoregister;
int forgetpawId = R.id.forgetpaw;
int logintextId = R.id.logintext;
if (view.getId() == gotoregisterId) {
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
} else if (view.getId() == forgetpawId) {
Intent intent2 = new Intent(LoginActivity.this, ForgetPwdActivity.class);
startActivity(intent2);
} else if (view.getId() == logintextId) {
if (!mDataBinding.tvYs.isSelected()) {
setToast("请先阅读并勾选同意用户协议和隐私政策");
return;
}
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;
}
// if (!mDataBinding.agreewhitemeg.isChecked()) {
// setToast("请先同意注册协议");
//
// return;
// }
// if (!mDataBinding.agreewhitemegy.isChecked()) {
// setToast("请先同意隐私政策");
//
// 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());
}
}
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;
}
int logintextId2 = R.id.logintext;
if (getcode1 == logintextId2) {
Gson gs = new Gson();
LinkedTreeMap adta = (LinkedTreeMap) resultcode.data;
String s = gs.toJson(adta);
RegisterUser user = gs.fromJson(s, RegisterUser.class);//把JSON字符串转为对象
JPushInterface.setAlias(getApplicationContext(), 0, user.getUserid());
Config.getInstance(LoginActivity.this).putUser(user);
Config.getInstance(LoginActivity.this).put("username", mDataBinding.phone.getText().toString().trim());
Map<String, String> map = new HashMap<>();
if (user != null) {
map.put("userid", user.getUserid());
} else {
map.put("userid", 0 + "");
}
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);
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
progressDialog.dismiss();
setToast(getString(R.string.getdatafailure));
throwable.printStackTrace();
}
});
addSubscription(subscription);
}
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) {
SPUtils.cleanAllSP(LoginActivity.this);
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);
}
/**
* 用户协议
*
* @param v v
*/
public void agreementEvent(View v) {
// Intent intent = new Intent(this, RegisterAgreementActivity.class);
// startActivity(intent);
WebActivitytwo.runActivity(this, "", "https://wy.dou1.net/articlemobile/index/detail?article_id=1");
}
/**
* 隐私政策
*
* @param v v
*/
public void yinagreementEvent(View v) {
WebActivitytwo.runActivity(this, "", "https://wy.dou1.net/articlemobile/index/detail?article_id=19");
}
/**
* 切换协议选中状态
*/
private void toggleAgreementCheck() {
if (mDataBinding.tvYs.isSelected()) {
mDataBinding.tvYs.setSelected(false);
Drawable drawable = getResources().getDrawable(R.mipmap.icon_publish_selected2);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
mDataBinding.tvYs.setCompoundDrawables(drawable, null, null, null);
} else {
mDataBinding.tvYs.setSelected(true);
Drawable drawable = getResources().getDrawable(R.mipmap.icon_publish_selected);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
mDataBinding.tvYs.setCompoundDrawables(drawable, null, null, null);
}
}
}