Commit 53555810 authored by 小费同学阿's avatar 小费同学阿 💬

基础搭建

功能开发
1:bug 修复 客商端修复登录超时问题
parent 8f555d20
package com.xx.merchanthbh.ui.home;
import static me.goldze.mvvmhabit.utils.Utils.Interceptor_TOKEN;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -19,6 +21,8 @@ import androidx.lifecycle.Observer;
import com.xx.merchanthbh.BR;
import com.xx.merchanthbh.R;
import com.xx.merchanthbh.data.http.requst.HomeRequest;
import com.xx.merchanthbh.data.http.requst.LogOffRequest;
import com.xx.merchanthbh.data.staticdata.StaticData;
import com.xx.merchanthbh.databinding.ActivityHomeBinding;
import com.xx.merchanthbh.ui.home.HomeFragment;
......@@ -26,6 +30,7 @@ import com.tbruyelle.rxpermissions3.RxPermissions;
import com.xx.merchanthbh.ui.home.HomeViewModel;
import com.xx.merchanthbh.ui.huanbohai.HuanBoHaiFragment;
import com.xx.merchanthbh.ui.login.LoginActivity;
import com.xx.merchanthbh.ui.logoff.LogOffViewModel;
import com.xx.merchanthbh.ui.mine.MineFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.xx.xxviewlibrary.base.AppManager;
......@@ -89,10 +94,13 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding, HomeViewMode
// 从SharedPreferences中获取用户名和密码
String username = sharedPreferences.getString("username", null);
String password = sharedPreferences.getString("password", null);
String token = sharedPreferences.getString("token", null);
// 检查是否成功获取到用户名和密码
if (username != null && password != null) {
Log.v("刚开始获取的账号:", username);
Log.v("刚开始获取的密码:", password);
Log.v("刚开始获取的token:", token);
Interceptor_TOKEN = token;
viewModel.getLogin(username,password);
}else {
......@@ -115,7 +123,7 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding, HomeViewMode
}
@Override
public int initVariableId() {
return BR.hmViewModel;
return BR.homeViewModel;
}
@Override
public void onStart() {
......@@ -185,4 +193,10 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding, HomeViewMode
super.onStop();
}
@Override
public HomeViewModel initViewModel() {
HomeRequest lm = new HomeRequest();
return new HomeViewModel(getApplication(), lm);
}
}
\ No newline at end of file
......@@ -302,7 +302,7 @@ public class HomeViewModel extends BaseViewModel<HomeRequest> {
public void getLogin(String username,String password){
model.login(username, password)
model.login(username, password)
.compose(RxUtils.schedulersTransformer()) //线程调度
// .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
.doOnSubscribe(HomeViewModel.this)
......
......@@ -439,9 +439,7 @@ public class LoginViewModel extends BaseViewModel<LoginRequest> {
StaticData.personType = 1;
}
LocalData.saveMerchant(resultBean.getMerchant());
Intent intent = new Intent(getContext(), HomeActivity.class);
intent.putExtra("logFlag", "1"); // 把字符串"1"作为额外信息传递
startActivity(intent.getClass());
startActivity(HomeActivity.class);
}
// finish();
......
......@@ -4,6 +4,7 @@ import android.Manifest;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
......@@ -127,9 +128,23 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
showCommTextDialog(new RefuseDialogBean("是否确定退出?", "确定", "取消"), new CommTextDialog.onAcceptCallBack() {
@Override
public void acceptBack() {
// 获取SharedPreferences实例
SharedPreferences sharedPreferences = getApplication().getSharedPreferences("AppNamePreferences", Context.MODE_PRIVATE);
// 获取SharedPreferences.Editor实例
SharedPreferences.Editor editor = sharedPreferences.edit();
// 清除username和password
editor.remove("username");
editor.remove("password");
editor.remove("token");
// 提交更改
editor.apply();
startActivity(LoginActivity.class); // 跳转到登录页面
finish();
// startActivity(LoginActivity.class); // 跳转到登录页面
AppManager.getAppManager().finishAllActivityExThis(LoginActivity.class);
// AppManager.getAppManager().finishAllActivityExThis(LoginActivity.class);
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment