2025-08-26 19:34: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-09-24 00:30:40 +08:00
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
|
|
import android.content.res.Resources;
|
2025-09-23 14:39:49 +08:00
|
|
|
|
import android.view.View;
|
2025-08-26 19:34: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-09-23 14:39:49 +08:00
|
|
|
|
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-08-26 19:34:44 +08:00
|
|
|
|
import com.xscm.moduleutil.base.CommonAppContext;
|
2025-09-24 00:30:40 +08:00
|
|
|
|
import com.xscm.moduleutil.base.RoomManager;
|
2025-08-26 19:34:44 +08:00
|
|
|
|
import com.xscm.moduleutil.bean.UserBean;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.UserInfo;
|
2025-09-24 00:30:40 +08:00
|
|
|
|
import com.xscm.moduleutil.dialog.ConfirmDialog;
|
|
|
|
|
|
import com.xscm.moduleutil.event.UnreadCountEvent;
|
2025-09-23 14:39:49 +08:00
|
|
|
|
import com.xscm.moduleutil.http.RetrofitClient;
|
2025-08-26 19:34: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-09-23 14:39:49 +08:00
|
|
|
|
IView<Activity>, LocationProvider.LocationCallback {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
protected P MvpPre;
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract P bindPresenter();
|
2025-09-23 14:39:49 +08:00
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
private String city1;
|
|
|
|
|
|
|
|
|
|
|
|
@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 点击登录的时候调用
|
2025-09-23 14:39:49 +08:00
|
|
|
|
TUILogin.login(getBaseContext(), CommonAppContext.getInstance().getCurrentEnvironment().getSdkAppId(), "u" + userBean.getUser_id(), userBean.getTencent_im(), new TUICallback() {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onError(final int code, final String desc) {
|
2025-09-23 14:39:49 +08:00
|
|
|
|
LogUtils.e("@@@1", code, "描述:", desc);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
}
|
2025-09-23 14:39:49 +08:00
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onSuccess() {
|
2025-09-23 14:39:49 +08:00
|
|
|
|
LogUtils.e("@@@", "成功");
|
2025-09-24 00:30:40 +08:00
|
|
|
|
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) {
|
|
|
|
|
|
// 错误处理
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-08-26 19:34:44 +08:00
|
|
|
|
initLocation();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-09-23 14:39:49 +08:00
|
|
|
|
V2TIMManager.getInstance().addIMSDKListener(imSdkListener);
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-23 14:39:49 +08:00
|
|
|
|
|
|
|
|
|
|
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() {
|
2025-09-24 00:30:40 +08:00
|
|
|
|
// queren1();
|
|
|
|
|
|
|
2025-09-23 14:39:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onUserSigExpired() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-24 00:30:40 +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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
v -> {
|
|
|
|
|
|
// 点击“取消”按钮时什么都不做
|
|
|
|
|
|
|
|
|
|
|
|
}, false, 0).show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
private SystemLocationProvider locationProvider;
|
2025-09-23 14:39:49 +08:00
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
private void initLocation() {
|
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
|
|
|
|
// 请求定位权限
|
|
|
|
|
|
ActivityCompat.requestPermissions(
|
|
|
|
|
|
(Activity) this,
|
|
|
|
|
|
new String[]{
|
|
|
|
|
|
android.Manifest.permission.ACCESS_FINE_LOCATION,
|
|
|
|
|
|
Manifest.permission.ACCESS_COARSE_LOCATION
|
|
|
|
|
|
},
|
|
|
|
|
|
1001 // 自定义常量,比如 1001
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
locationProvider = new SystemLocationProvider();
|
|
|
|
|
|
|
|
|
|
|
|
// 请求一次性的位置信息
|
|
|
|
|
|
locationProvider.getLastKnownLocation(this, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-23 14:39:49 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onLocationReceived(double latitude, double longitude, String city) {
|
|
|
|
|
|
LogUtils.e("当前位置:" + city);
|
|
|
|
|
|
city1 = city;
|
|
|
|
|
|
EventBus.getDefault().post(city1);
|
|
|
|
|
|
}
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
2025-09-23 14:39:49 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onFailed(String errorMessage) {
|
|
|
|
|
|
LogUtils.e("定位失败");
|
|
|
|
|
|
}
|
2025-08-26 19:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
|
|
|
|
|
|
|
if (requestCode == 1001) {
|
2025-09-23 14:39:49 +08:00
|
|
|
|
if (locationProvider == null) {
|
2025-08-26 19:34:44 +08:00
|
|
|
|
locationProvider = new SystemLocationProvider();
|
|
|
|
|
|
}
|
|
|
|
|
|
locationProvider.getLastKnownLocation(this, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-24 00:30:40 +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());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return resources;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-26 19:34:44 +08:00
|
|
|
|
@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);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
}
|
2025-09-23 14:39:49 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 显示全局飘屏消息(支持任意位置飘过)
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2025-08-26 19:34:44 +08:00
|
|
|
|
// @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);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
}
|