| | |
| | | import android.view.View; |
| | | import android.widget.Button; |
| | | import android.widget.EditText; |
| | | import android.widget.ImageView; |
| | | import android.widget.TextView; |
| | | |
| | | import com.lzy.okgo.cache.CacheMode; |
| | | import com.moral.andbrickslib.utils.FastJsonTools; |
| | | import com.moral.andbrickslib.utils.NetworkUtil; |
| | | import com.moral.andbrickslib.utils.StatusBarUtil; |
| | | import com.moral.yunfushao.MainActivity; |
| | | import com.moral.yunfushao.MainApp; |
| | |
| | | import com.moral.yunfushao.httputils.HttpCallBack; |
| | | import com.moral.yunfushao.httputils.HttpUtils; |
| | | import com.moral.yunfushao.model.User; |
| | | import com.moral.yunfushao.utils.SharedPreferencesUtil; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | |
| | | public class LoginActivity extends BaseActivity { |
| | | private Button bt_sure; |
| | | private TextView tv_forget,tv_register; |
| | | private ImageView weixinlogin; |
| | | private TextView tv_forget, tv_register; |
| | | private EditText et_phone, et_pwd; |
| | | |
| | | @Override |
| | | protected void getBundleExtras(Bundle extras) { |
| | | |
| | |
| | | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | StatusBarUtil.translucentStatusBar(LoginActivity.this); |
| | | |
| | | int type = SharedPreferencesUtil.getUtil(this).getLoginInfo().getLogin_type(); |
| | | |
| | | if (!NetworkUtil.isAvailable(this)) { |
| | | return; |
| | | } |
| | | switch (type) { |
| | | case 1: |
| | | //手机登陆 |
| | | goHome(); |
| | | break; |
| | | case 2: |
| | | //微信登陆 |
| | | sendReq(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void goHome() { |
| | | if (!TextUtils.isEmpty(MainApp.userId)) { |
| | | Intent intent = new Intent(this, MainActivity.class); |
| | | startActivity(intent); |
| | | } else { |
| | | Intent intent = new Intent(this, LoginActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | finish(); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | protected int getLayoutId() { |
| | |
| | | tv_register = findView(R.id.tv_register); |
| | | et_phone = findView(R.id.et_phone); |
| | | et_pwd = findView(R.id.et_pwd); |
| | | et_phone.setText("15950198162"); |
| | | et_pwd.setText("888888"); |
| | | weixinlogin = findView(R.id.weixinlogin); |
| | | } |
| | | |
| | | @Override |
| | |
| | | bt_sure.setOnClickListener(this); |
| | | tv_forget.setOnClickListener(this); |
| | | tv_register.setOnClickListener(this); |
| | | weixinlogin.setOnClickListener(this); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | protected void processClick(View view) { |
| | | switch (view.getId()){ |
| | | switch (view.getId()) { |
| | | case R.id.bt_sure: |
| | | String userphone = et_phone.getText().toString().trim(); |
| | | String password = et_pwd.getText().toString().trim(); |
| | |
| | | mToatUtils.showSingletonToast("请输入密码"); |
| | | return; |
| | | } |
| | | login(userphone,password); |
| | | login(userphone, password); |
| | | break; |
| | | case R.id.tv_forget: |
| | | Intent intent = new Intent(LoginActivity.this,ForgetPasswordActivity.class); |
| | | Intent intent = new Intent(LoginActivity.this, ForgetPasswordActivity.class); |
| | | startActivity(intent); |
| | | break; |
| | | case R.id.tv_register: |
| | | Intent intentRgister = new Intent(LoginActivity.this,RegisterActivity.class); |
| | | Intent intentRgister = new Intent(LoginActivity.this, RegisterActivity.class); |
| | | startActivity(intentRgister); |
| | | break; |
| | | case R.id.weixinlogin: |
| | | weixinlogin(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void weixinlogin() { |
| | | sendReq(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | private void login(String tel, final String pwd) { |
| | | String url = API.LOGIN; |
| | | final String url = API.LOGIN; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("username", tel); |
| | | params.put("phone", tel); |
| | | params.put("password", pwd); |
| | | HttpUtils.doPost(url, params, CacheMode.DEFAULT, true, new HttpCallBack() { |
| | | @Override |
| | |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | User user = FastJsonTools.getJson(res,User.class); |
| | | if(user!=null){ |
| | | User user = FastJsonTools.getJson(res, User.class); |
| | | if (user != null) { |
| | | MainApp.theApp.sharedPreferencesUtil.saveLoginInfo(user); |
| | | // MainApp.theApp.userId = user.get_id(); |
| | | Intent intent = new Intent(getApplicationContext(), MainActivity.class); |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putBoolean("islogin",true); |
| | | intent.putExtras(bundle); |
| | | startActivity(intent); |
| | | finish(); |
| | | user.setLogin_type(1); |
| | | MainApp.theApp.userId = user.get_id(); |
| | | jumpMain(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void onFail(int errno,String s) { |
| | | public void onFail(int errno, String s) { |
| | | mToatUtils.showSingletonToast(s); |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | protected void onStop() { |
| | | super.onStop(); |
| | | finish(); |
| | | } |
| | | |
| | | private void jumpMain() { |
| | | Intent intent = new Intent(getApplicationContext(), MainActivity.class); |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putBoolean("islogin", true); |
| | | intent.putExtras(bundle); |
| | | startActivity(intent); |
| | | finish(); |
| | | } |
| | | } |