281 lines
10 KiB
Java
281 lines
10 KiB
Java
package com.xscm.moduleutil.activity;
|
||
|
||
import android.Manifest;
|
||
import android.app.Activity;
|
||
import android.content.Context;
|
||
import android.content.pm.PackageManager;
|
||
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.bean.UserBean;
|
||
import com.xscm.moduleutil.bean.UserInfo;
|
||
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>, LocationProvider.LocationCallback {
|
||
|
||
protected P MvpPre;
|
||
|
||
protected abstract P bindPresenter();
|
||
|
||
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 点击登录的时候调用
|
||
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("@@@", "成功");
|
||
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() {
|
||
}
|
||
|
||
@Override
|
||
public void onUserSigExpired() {
|
||
}
|
||
|
||
@Override
|
||
public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
|
||
}
|
||
};
|
||
|
||
private SystemLocationProvider locationProvider;
|
||
|
||
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);
|
||
}
|
||
|
||
@Override
|
||
public void onLocationReceived(double latitude, double longitude, String city) {
|
||
LogUtils.e("当前位置:" + city);
|
||
city1 = city;
|
||
EventBus.getDefault().post(city1);
|
||
}
|
||
|
||
@Override
|
||
public void onFailed(String errorMessage) {
|
||
LogUtils.e("定位失败");
|
||
}
|
||
|
||
@Override
|
||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||
|
||
if (requestCode == 1001) {
|
||
if (locationProvider == null) {
|
||
locationProvider = new SystemLocationProvider();
|
||
}
|
||
locationProvider.getLastKnownLocation(this, this);
|
||
}
|
||
|
||
}
|
||
|
||
@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);
|
||
// }
|
||
// });
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
}
|