2025-10-20 10:16:44 +08:00
|
|
|
package com.xscm.moduleutil.activity;
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.pm.PackageManager;
|
2025-10-24 17:52:11 +08:00
|
|
|
import android.content.res.Configuration;
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.view.View;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
import androidx.databinding.ViewDataBinding;
|
|
|
|
|
|
|
|
|
|
import com.blankj.utilcode.util.LogUtils;
|
2025-10-24 17:52:11 +08:00
|
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
|
|
|
import com.tencent.imsdk.v2.V2TIMConversationListener;
|
|
|
|
|
import com.tencent.imsdk.v2.V2TIMConversationManager;
|
|
|
|
|
import com.tencent.imsdk.v2.V2TIMSDKListener;
|
|
|
|
|
import com.tencent.imsdk.v2.V2TIMValueCallback;
|
|
|
|
|
import com.tencent.qcloud.tuicore.TUIConfig;
|
|
|
|
|
import com.tencent.qcloud.tuicore.TUIConstants;
|
|
|
|
|
import com.tencent.qcloud.tuicore.TUICore;
|
|
|
|
|
import com.tencent.qcloud.tuicore.interfaces.TUILoginListener;
|
2025-10-20 10:16:44 +08:00
|
|
|
import com.xscm.moduleutil.base.CommonAppContext;
|
2025-10-24 17:52:11 +08:00
|
|
|
import com.xscm.moduleutil.base.RoomManager;
|
2025-10-20 10:16:44 +08:00
|
|
|
import com.xscm.moduleutil.bean.UserBean;
|
|
|
|
|
import com.xscm.moduleutil.bean.UserInfo;
|
2025-10-24 17:52:11 +08:00
|
|
|
import com.xscm.moduleutil.dialog.ConfirmDialog;
|
|
|
|
|
import com.xscm.moduleutil.event.UnreadCountEvent;
|
|
|
|
|
import com.xscm.moduleutil.http.RetrofitClient;
|
2025-10-20 10:16:44 +08:00
|
|
|
import com.xscm.moduleutil.utils.LanguageUtil;
|
|
|
|
|
import com.xscm.moduleutil.utils.location.LocationProvider;
|
|
|
|
|
import com.xscm.moduleutil.utils.location.SystemLocationProvider;
|
|
|
|
|
import com.tencent.imsdk.v2.V2TIMCallback;
|
|
|
|
|
import com.tencent.imsdk.v2.V2TIMManager;
|
|
|
|
|
import com.tencent.imsdk.v2.V2TIMUserFullInfo;
|
|
|
|
|
import com.tencent.qcloud.tuicore.TUILogin;
|
|
|
|
|
import com.tencent.qcloud.tuicore.interfaces.TUICallback;
|
|
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
|
|
|
|
|
public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewDataBinding> extends BaseAppCompatActivity<VDB> implements
|
2025-10-24 17:52:11 +08:00
|
|
|
IView<Activity> {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
protected P MvpPre;
|
|
|
|
|
|
|
|
|
|
protected abstract P bindPresenter();
|
2025-10-24 17:52:11 +08:00
|
|
|
|
2025-10-25 18:07:21 +08:00
|
|
|
@Override
|
|
|
|
|
protected void doDone() {
|
|
|
|
|
super.doDone();
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void initView() {
|
|
|
|
|
MvpPre = bindPresenter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showLoadings() {
|
|
|
|
|
// showLoading("加载中");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void showLoadings(String content) {
|
|
|
|
|
// showLoading(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void disLoadings() {
|
|
|
|
|
// disLoading();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
if (MvpPre != null) {
|
2025-10-25 18:07:21 +08:00
|
|
|
try {
|
|
|
|
|
MvpPre.detachView();
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Activity getSelfActivity() {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void attachBaseContext(Context newBase) {
|
|
|
|
|
super.attachBaseContext(LanguageUtil.attachBaseContext(newBase));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
|
public void logOutEvent(UserBean userBean) {
|
|
|
|
|
// 在用户 UI 点击登录的时候调用
|
2025-10-24 17:52:11 +08:00
|
|
|
TUILogin.login(getBaseContext(), CommonAppContext.getInstance().getCurrentEnvironment().getSdkAppId(), "u" + userBean.getUser_id(), userBean.getTencent_im(), new TUICallback() {
|
2025-10-20 10:16:44 +08:00
|
|
|
@Override
|
|
|
|
|
public void onError(final int code, final String desc) {
|
2025-10-24 17:52:11 +08:00
|
|
|
LogUtils.e("@@@1", code, "描述:", desc);
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
@Override
|
|
|
|
|
public void onSuccess() {
|
2025-10-24 17:52:11 +08:00
|
|
|
LogUtils.e("@@@", "成功");
|
|
|
|
|
V2TIMManager.getConversationManager().getTotalUnreadMessageCount(new V2TIMValueCallback<Long>() {
|
2025-10-20 10:16:44 +08:00
|
|
|
@Override
|
2025-10-24 17:52:11 +08:00
|
|
|
public void onSuccess(Long aLong) {
|
|
|
|
|
// 通知未读数变化
|
|
|
|
|
UnreadCountEvent event =CommonAppContext.getInstance().unreadCountEvent;
|
|
|
|
|
if (event==null){
|
|
|
|
|
event=new UnreadCountEvent();
|
|
|
|
|
}
|
|
|
|
|
event.setALong(aLong);
|
|
|
|
|
// 使用EventBus通知
|
|
|
|
|
CommonAppContext.getInstance().setUnreadCountEvent(event);
|
|
|
|
|
EventBus.getDefault().post(event);
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(int code, String desc) {
|
2025-10-24 17:52:11 +08:00
|
|
|
// 错误处理
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
});
|
2025-10-24 17:52:11 +08:00
|
|
|
//initLocation();
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
});
|
2025-10-24 17:52:11 +08:00
|
|
|
// V2TIMManager.getInstance().addIMSDKListener(imSdkListener);
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
|
|
|
|
|
private final V2TIMSDKListener imSdkListener = new V2TIMSDKListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onConnecting() {
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
@Override
|
|
|
|
|
public void onConnectSuccess() {//重连成功
|
|
|
|
|
if (CommonAppContext.getInstance().playId!=null){
|
|
|
|
|
LogUtils.e("@@@", "重连成功");
|
|
|
|
|
LogUtils.e("@@@", ""+CommonAppContext.getInstance().playId);
|
|
|
|
|
RetrofitClient.getInstance().roomUserReconnect(CommonAppContext.getInstance().playId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
@Override
|
2025-10-24 17:52:11 +08:00
|
|
|
public void onConnectFailed(int code, String error) {
|
|
|
|
|
LogUtils.e("@@@", "断开连接");
|
|
|
|
|
CommonAppContext.getInstance().onConnectFailed=true;
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-10-24 17:52:11 +08:00
|
|
|
public void onKickedOffline() {
|
|
|
|
|
// queren1();
|
|
|
|
|
if (CommonAppContext.getInstance().playId!=null){
|
|
|
|
|
ToastUtils.showShort("您的账号已被挤下线");
|
|
|
|
|
try {
|
|
|
|
|
CommonAppContext.getInstance().clearLoginInfo();
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
@Override
|
|
|
|
|
public void onUserSigExpired() {
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
@Override
|
|
|
|
|
public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private void queren1() {
|
|
|
|
|
// 创建并显示确认对话框
|
|
|
|
|
new ConfirmDialog(this,
|
|
|
|
|
"温馨提示",
|
|
|
|
|
"您的账号已在别处登录,请确认密码是否已经泄露",
|
|
|
|
|
"知道了",
|
|
|
|
|
"",
|
|
|
|
|
v -> {
|
|
|
|
|
// 点击“确认”按钮时执行删除操作
|
|
|
|
|
|
|
|
|
|
if (CommonAppContext.getInstance().playId!=null){
|
|
|
|
|
RoomManager.getInstance().exitRoom(CommonAppContext.getInstance().playId);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
CommonAppContext.getInstance().clearLoginInfo();
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
},
|
|
|
|
|
v -> {
|
|
|
|
|
// 点击“取消”按钮时什么都不做
|
|
|
|
|
|
|
|
|
|
}, false, 0).show();
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-10-24 17:52:11 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Resources getResources() {
|
|
|
|
|
Resources resources = super.getResources();
|
|
|
|
|
if (resources != null) {
|
|
|
|
|
Configuration configuration = resources.getConfiguration();
|
|
|
|
|
if (configuration != null) {
|
|
|
|
|
// 设置字体缩放比例不随系统变化
|
|
|
|
|
configuration.fontScale = 1.0f; // 1.0f表示默认大小
|
|
|
|
|
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
}
|
|
|
|
|
return resources;
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|
2025-10-24 17:52:11 +08:00
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
}
|