Files
midi-android/moduleUtil/src/main/java/com/xscm/moduleutil/activity/BaseMvpActivity.java
2025-09-26 01:13:02 +08:00

303 lines
11 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.xscm.moduleutil.activity;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.databinding.ViewDataBinding;
import com.blankj.utilcode.util.LogUtils;
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;
import com.xscm.moduleutil.base.CommonAppContext;
import com.xscm.moduleutil.base.RoomManager;
import com.xscm.moduleutil.bean.UserBean;
import com.xscm.moduleutil.bean.UserInfo;
import com.xscm.moduleutil.dialog.ConfirmDialog;
import com.xscm.moduleutil.event.UnreadCountEvent;
import com.xscm.moduleutil.http.RetrofitClient;
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
IView<Activity> {
protected P MvpPre;
protected abstract P bindPresenter();
@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) {
MvpPre.detachView();
}
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 点击登录的时候调用
TUILogin.login(getBaseContext(), CommonAppContext.getInstance().getCurrentEnvironment().getSdkAppId(), "u" + userBean.getUser_id(), userBean.getTencent_im(), new TUICallback() {
@Override
public void onError(final int code, final String desc) {
LogUtils.e("@@@1", code, "描述:", desc);
}
@Override
public void onSuccess() {
LogUtils.e("@@@", "成功");
V2TIMManager.getConversationManager().getTotalUnreadMessageCount(new V2TIMValueCallback<Long>() {
@Override
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);
}
@Override
public void onError(int code, String desc) {
// 错误处理
}
});
//initLocation();
}
});
V2TIMManager.getInstance().addIMSDKListener(imSdkListener);
}
private final V2TIMSDKListener imSdkListener = new V2TIMSDKListener() {
@Override
public void onConnecting() {
}
@Override
public void onConnectSuccess() {//重连成功
if (CommonAppContext.getInstance().playId!=null){
RetrofitClient.getInstance().roomUserReconnect(CommonAppContext.getInstance().playId);
}
}
@Override
public void onConnectFailed(int code, String error) {
}
@Override
public void onKickedOffline() {
// queren1();
}
@Override
public void onUserSigExpired() {
}
@Override
public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
}
};
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);
}
},
v -> {
// 点击“取消”按钮时什么都不做
}, false, 0).show();
}
@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());
}
}
return resources;
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void userInfoEvent(UserInfo event) {
// V2TIMUserFullInfo userFullInfo = new V2TIMUserFullInfo();
// userFullInfo.setNickname(event.getNickname());
// userFullInfo.setFaceUrl(event.getAvatar());
// userFullInfo.setAllowType(event.getSex());
// V2TIMManager.getInstance().setSelfInfo(userFullInfo, new V2TIMCallback() {
// @Override
// public void onSuccess() {
// LogUtils.e("@@@", "成功");
// }
//
// @Override
// public void onError(int code, String desc) {
// LogUtils.e("@@@", "描述"+desc);
// }
// });
}
/**
* 显示全局飘屏消息(支持任意位置飘过)
*
*/
// @Subscribe(threadMode = ThreadMode.MAIN)
// public void showPiaoPingMessage(MqttBean mqttBean) {
// WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
// if (windowManager == null) return;
//
// int screenWidth = getResources().getDisplayMetrics().widthPixels;
// int screenHeight = getResources().getDisplayMetrics().heightPixels;
//
// WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
// WindowManager.LayoutParams.MATCH_PARENT,
// WindowManager.LayoutParams.WRAP_CONTENT,
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
// WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY :
// WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
// WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
// WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
// WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
// PixelFormat.TRANSLUCENT);
//
// // 设置 Gravity 为左上角
// layoutParams.gravity = Gravity.TOP | Gravity.START;
//
// // Y 轴随机位置
//// layoutParams.y = (int) ((Math.random() * (screenHeight - 200)));
//
// // 初始 X 设为负值,确保 View 在屏幕左侧外
// layoutParams.x = -screenWidth;
//
// View piaoPingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
// TextView textView = piaoPingView.findViewById(R.id.tv_name);
// TextView textView2 = piaoPingView.findViewById(R.id.tv_to_name);
// textView2.setText("送给"+mqttBean.getList().getToUserName());
// textView.setText(mqttBean.getList().getFromUserName());
// ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), piaoPingView.findViewById(R.id.iv_piaoping));
// TextView tv_time = piaoPingView.findViewById(R.id.tv_num);
// tv_time.setText(mqttBean.getList().getNumber());
// windowManager.addView(piaoPingView, layoutParams);
//
// piaoPingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
// @Override
// public void onGlobalLayout() {
// piaoPingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
//
// // 设置锚点为左上角,避免偏移干扰
// piaoPingView.setPivotX(0);
// piaoPingView.setPivotY(0);
//
// // 启动动画:从左外滑入 -> 右外滑出
// ObjectAnimator animator = ObjectAnimator.ofFloat(
// piaoPingView,
// "translationX",
// 0f, // 初始偏移为 0此时 View 在左侧外)
// screenWidth // 向右移动整个屏幕宽度
// );
// animator.setDuration(2000); // 整个动画的时长为2秒
//
// // 强制 GPU 渲染
// piaoPingView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
//
// // 延迟显示2秒后开始滑出屏幕的动画
// piaoPingView.postDelayed(new Runnable() {
// @Override
// public void run() {
// animator.start();
// }
// }, 3000);
//
// animator.addListener(new AnimatorListenerAdapter() {
// @Override
// public void onAnimationEnd(Animator animation) {
// windowManager.removeView(piaoPingView);
// }
// });
// }
// });
// }
}