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

基础搭建

功能开发
1:bug 修复 客商端修复登录超时问题
parent dc766b52
...@@ -49,11 +49,6 @@ ...@@ -49,11 +49,6 @@
android:name=".ui.login.LoginActivity" android:name=".ui.login.LoginActivity"
android:exported="true" android:exported="true"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".ui.merchantenter.MerchantEnterActivity" android:name=".ui.merchantenter.MerchantEnterActivity"
...@@ -63,7 +58,14 @@ ...@@ -63,7 +58,14 @@
<activity <activity
android:name=".ui.home.HomeActivity" android:name=".ui.home.HomeActivity"
android:exported="true" android:exported="true"
android:screenOrientation="portrait"/> android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 忘记密码页面--> <!-- 忘记密码页面-->
<activity <activity
android:name=".ui.pwd.ForgetPwdActivity" android:name=".ui.pwd.ForgetPwdActivity"
......
...@@ -3,6 +3,7 @@ package com.xx.merchanthbh.data.http.requst; ...@@ -3,6 +3,7 @@ package com.xx.merchanthbh.data.http.requst;
import com.xx.merchanthbh.data.http.BaseRespons; import com.xx.merchanthbh.data.http.BaseRespons;
import com.xx.merchanthbh.data.http.respons.HomeStatisticalBean; import com.xx.merchanthbh.data.http.respons.HomeStatisticalBean;
import com.xx.merchanthbh.data.http.respons.MessageBean; import com.xx.merchanthbh.data.http.respons.MessageBean;
import com.xx.merchanthbh.data.http.respons.UserInfoBean;
import com.xx.xxviewlibrary.model.VersionBean; import com.xx.xxviewlibrary.model.VersionBean;
import com.xx.xxviewlibrary.model.VersionBody; import com.xx.xxviewlibrary.model.VersionBody;
...@@ -10,7 +11,65 @@ import io.reactivex.rxjava3.core.Observable; ...@@ -10,7 +11,65 @@ import io.reactivex.rxjava3.core.Observable;
import me.goldze.mvvmhabit.http.ApiParams; import me.goldze.mvvmhabit.http.ApiParams;
import me.goldze.mvvmhabit.http.BasePageResponse; import me.goldze.mvvmhabit.http.BasePageResponse;
import me.goldze.mvvmhabit.http.BaseResponse; import me.goldze.mvvmhabit.http.BaseResponse;
import okhttp3.RequestBody;
public class HomeRequest extends BaseRespons { public class HomeRequest extends BaseRespons {
/**
* 登录
*/
public Observable<BaseResponse<String>> login(String user,String pwd) {
return getApiService().Login(
new ApiParams<LoginRequestBody>().setParams(
new LoginRequestBody(user,pwd,"02")
)
);
}
/**
* 登陆入参
* userType : 10 系统用户,01 企业用户,02商户用户,13消费者用户
*/
public class LoginRequestBody{
String phone;
String password;
String userType;
public LoginRequestBody(String phone, String password, String userType) {
this.phone = phone;
this.password = password;
this.userType = userType;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
}
/**
* 获取用户信息
*/
public Observable<BaseResponse<UserInfoBean>> getUserInfo() {
return getApiService().getUserInfo();
}
/** /**
* 获取订单信息 * 获取订单信息
*/ */
......
package com.xx.merchanthbh.ui.home; package com.xx.merchanthbh.ui.home;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -8,6 +10,7 @@ import android.os.Environment; ...@@ -8,6 +10,7 @@ import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.widget.Toast; import android.widget.Toast;
...@@ -70,6 +73,7 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding, HomeViewMode ...@@ -70,6 +73,7 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding, HomeViewMode
@Override @Override
public void initData() { public void initData() {
super.initData(); super.initData();
// 初始化底部导航栏 // 初始化底部导航栏
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view); BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
bottomNavigationView.setOnNavigationItemSelectedListener(navItemSelectedListener); bottomNavigationView.setOnNavigationItemSelectedListener(navItemSelectedListener);
...@@ -86,6 +90,36 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding, HomeViewMode ...@@ -86,6 +90,36 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding, HomeViewMode
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
// 获取Intent对象
Intent intent = getIntent();
// 从Intent中获取传递的额外信息
if (intent != null) {
String logFlag = intent.getStringExtra("logFlag");
if (logFlag != null) {
Log.v("首页按钮登录","");
}else {
Log.v("直接登录首页","");
// 获取SharedPreferences实例
SharedPreferences sharedPreferences = getSharedPreferences("AppNamePreferences", Context.MODE_PRIVATE);
// 从SharedPreferences中获取用户名和密码
String username = sharedPreferences.getString("username", null);
String password = sharedPreferences.getString("password", null);
// 检查是否成功获取到用户名和密码
if (username != null && password != null) {
Log.v("刚开始获取的账号:", username);
Log.v("刚开始获取的密码:", password);
viewModel.getLogin(username,password);
}else {
Log.v("账号密码为空跳转登录页","");
startActivity(LoginActivity.class);
finish();
}
}
}
} }
......
package com.xx.merchanthbh.ui.home; package com.xx.merchanthbh.ui.home;
import static me.goldze.mvvmhabit.utils.Utils.Interceptor_TOKEN;
import static me.goldze.mvvmhabit.utils.Utils.getContext;
import android.Manifest; import android.Manifest;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -40,6 +44,8 @@ import com.xx.merchanthbh.ui.order.OrderActivity; ...@@ -40,6 +44,8 @@ import com.xx.merchanthbh.ui.order.OrderActivity;
import com.xx.merchanthbh.ui.ordercreate.OrderCreateActivity; import com.xx.merchanthbh.ui.ordercreate.OrderCreateActivity;
import com.xx.merchanthbh.ui.point.StorePointsActivity; import com.xx.merchanthbh.ui.point.StorePointsActivity;
import com.xx.merchanthbh.ui.productmanager.ProductManagerActivity; import com.xx.merchanthbh.ui.productmanager.ProductManagerActivity;
import com.xx.merchanthbh.ui.pwd.PwdActivity;
import com.xx.merchanthbh.ui.pwd.SetPwdActivity;
import com.xx.merchanthbh.ui.recruitment.RecruitmentActivity; import com.xx.merchanthbh.ui.recruitment.RecruitmentActivity;
import com.xx.merchanthbh.ui.share.ShareActivity; import com.xx.merchanthbh.ui.share.ShareActivity;
import com.xx.xxviewlibrary.comm.CommTextDialog; import com.xx.xxviewlibrary.comm.CommTextDialog;
...@@ -89,6 +95,10 @@ public class HomeViewModel extends BaseViewModel<HomeRequest> { ...@@ -89,6 +95,10 @@ public class HomeViewModel extends BaseViewModel<HomeRequest> {
super(application); super(application);
} }
public HomeViewModel(@NonNull Application application, HomeRequest model) {
super(application, model);
}
/*设置消息初始状态是0*/ /*设置消息初始状态是0*/
public String flag = "0"; public String flag = "0";
public Integer page = 1; public Integer page = 1;
...@@ -286,11 +296,150 @@ public class HomeViewModel extends BaseViewModel<HomeRequest> { ...@@ -286,11 +296,150 @@ public class HomeViewModel extends BaseViewModel<HomeRequest> {
context.startActivity(intent); context.startActivity(intent);
} }
public void getLogin(String username,String password){
model.login(username, password)
.compose(RxUtils.schedulersTransformer()) //线程调度
// .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
.doOnSubscribe(HomeViewModel.this)
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) throws Exception {
showDialog("正在请求...");
}
}).subscribe(new ApiDisposableObserver<String>() {
@Override
public void onSuccess(String resultBean) {
//是指token
Interceptor_TOKEN = "Bearer " + resultBean;
SharedPreferences sharedPreferences = getContext().getSharedPreferences("AppNamePreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.putString("token", Interceptor_TOKEN);
editor.apply();
getuserInfo();
// startActivity(HomeActivity.class);
}
@Override
public void onError(String Error) {
dismissDialog();
}
});
}
public HomeViewModel(@NonNull Application application, HomeRequest model) { /**
super(application, model); * 获取用户信息
*/
public void getuserInfo() {
model.getUserInfo()
.compose(RxUtils.schedulersTransformer()) //线程调度
// .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
.doOnSubscribe(HomeViewModel.this)
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) throws Exception {
}
}).subscribe(new ApiDisposableObserver<UserInfoBean>() {
@Override
public void onSuccess(UserInfoBean resultBean) {
Log.v("昵称昵称啊", resultBean.getUser().getNickName());
//将用户信息存储到本地
LocalData.saveUser(resultBean.getUser());
/*在登录的时候就给staticData的消息标志位设置成未读*/
StaticData.flag = 0;
dismissDialog();
if (resultBean.getMerchant() == null) {
Bundle bundle = new Bundle();
bundle.putInt("pageStep", R.id.registerMaterialFragment);
startActivity(MerchantEnterActivity.class, bundle);
} else if (resultBean.getMerchant().getAuditStatus().equals("0")) {
Bundle bundle = new Bundle();
bundle.putInt("pageStep", R.id.merchantWaitFragment);
startActivity(MerchantEnterActivity.class, bundle);
} else if (resultBean.getMerchant().getAuditStatus().equals("2")) {
LocalData.saveMerchant(resultBean.getMerchant());
Bundle bundle = new Bundle();
bundle.putInt("pageStep", R.id.registerMaterialFragment);
startActivity(MerchantEnterActivity.class, bundle);
} else if (resultBean.getNeedChangeInitPassword()) {
startActivity(SetPwdActivity.class);
} else if (resultBean.getNeedChangeTimeLongPassword()) {
/*执行超期弹窗方法*/
ShowOverDueDialog();
} else {
LocalData.saveMerchant(resultBean.getMerchant());
// 判断是否是店长
if (resultBean.getUser().getUserId() == resultBean.getMerchant().getUserId()) {
StaticData.personType = 0;
} else {
StaticData.personType = 1;
}
LocalData.saveMerchant(resultBean.getMerchant());
// startActivity(HomeActivity.class);
}
// finish();
}
@Override
public void onError(String Error) {
dismissDialog();
}
});
} }
/**
* 密码超期显示
*/
public void ShowOverDueDialog() {
showCommTextDialog(new RefuseDialogBean("您的密码使用时间过长,请修改密码后重新登录", "修改密码", "取消", "温馨提示"), new CommTextDialog.onAcceptCallBack() {
@Override
public void refuseBack() {
/*跳转到首页(首先获取用户信息)*/
model.getUserInfo()
.compose(RxUtils.schedulersTransformer()) //线程调度
// .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换, 这里可以换成自己的ExceptionHandle
.doOnSubscribe(HomeViewModel.this)
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) throws Exception {
}
}).subscribe(new ApiDisposableObserver<UserInfoBean>() {
@Override
public void onSuccess(UserInfoBean resultBean) {
//将用户信息存储到本地
LocalData.saveUser(resultBean.getUser());
/*在登录的时候就给staticData的消息标志位设置成未读*/
StaticData.flag = 0;
dismissDialog();
LocalData.saveMerchant(resultBean.getMerchant());
// startActivity(HomeActivity.class);
}
@Override
public void onError(String Error) {
dismissDialog();
}
});
}
@Override
public void acceptBack() {
/*跳转到修改密码页面*/
startActivity(PwdActivity.class);
}
});
}
//跳转添加商品 //跳转添加商品
public BindingCommand goAddProduct = new BindingCommand(new BindingAction() { public BindingCommand goAddProduct = new BindingCommand(new BindingAction() {
@Override @Override
......
...@@ -7,6 +7,7 @@ import android.Manifest; ...@@ -7,6 +7,7 @@ import android.Manifest;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -364,6 +365,12 @@ public class LoginViewModel extends BaseViewModel<LoginRequest> { ...@@ -364,6 +365,12 @@ public class LoginViewModel extends BaseViewModel<LoginRequest> {
public void onSuccess(String resultBean) { public void onSuccess(String resultBean) {
//是指token //是指token
Interceptor_TOKEN = "Bearer " + resultBean; Interceptor_TOKEN = "Bearer " + resultBean;
SharedPreferences sharedPreferences = getContext().getSharedPreferences("AppNamePreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("username", userName.get());
editor.putString("password", password.get());
editor.putString("token", Interceptor_TOKEN);
editor.apply();
getuserInfo(); getuserInfo();
// startActivity(HomeActivity.class); // startActivity(HomeActivity.class);
} }
...@@ -432,7 +439,9 @@ public class LoginViewModel extends BaseViewModel<LoginRequest> { ...@@ -432,7 +439,9 @@ public class LoginViewModel extends BaseViewModel<LoginRequest> {
StaticData.personType = 1; StaticData.personType = 1;
} }
LocalData.saveMerchant(resultBean.getMerchant()); LocalData.saveMerchant(resultBean.getMerchant());
startActivity(HomeActivity.class); Intent intent = new Intent(getContext(), HomeActivity.class);
intent.putExtra("logFlag", "1"); // 把字符串"1"作为额外信息传递
startActivity(intent.getClass());
} }
// finish(); // finish();
......
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