1:修改交友房

2:修改拍卖房
3:修改飘屏(没有修改成功)
This commit is contained in:
2025-09-24 00:30:40 +08:00
parent 1c54f0c072
commit 5f573e607d
43 changed files with 1172 additions and 307 deletions

View File

@@ -2,6 +2,8 @@ package com.xscm.moduleutil.activity;
import static androidx.core.content.ContextCompat.getSystemService;
import static com.xscm.moduleutil.base.CommonAppContext.postDelayed;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
@@ -23,7 +25,9 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
@@ -53,6 +57,8 @@ import com.xscm.moduleutil.utils.ColorManager;
import com.xscm.moduleutil.utils.DisplayUtil;
import com.xscm.moduleutil.utils.ImageUtils;
import com.xscm.moduleutil.utils.SpUtil;
import com.xscm.moduleutil.utils.SystemUtils;
import com.xscm.moduleutil.widget.QXGiftDriftView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -98,7 +104,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
ActivityUtils.finishAllActivities();
}
QXGiftDriftView qxGiftDriftView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -141,7 +147,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
EventBus.getDefault().register(this);
}
}
// 在Activity中
@@ -414,10 +419,10 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
synchronized (mqttQueueLock) {
mqttMessageQueue.addAll(mqttBean.getList());
if (!isMqttPlaying) {
isMqttPlaying = true;
// if (!isMqttPlaying) {
// isMqttPlaying = true;
processNextMqttMessage();
}
// }
}
}else {
mqttMessageQueue.clear();
@@ -472,6 +477,11 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
ViewGroup decorView1;
private void showFloatingMessage(MqttBean.ListBean mqttBean) {
// QXGiftDriftView.getInstance( this).addGiftModel(mqttBean);
try {
// 清理之前的视图(如果存在)
if (currentMqttView != null && currentMqttView.getParent() != null) {
@@ -569,35 +579,92 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
view.setTranslationX(screenWidth);
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
// ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", getScreenWidth(), (getScreenWidth() - view.getMeasuredWidth()) / 2f);
animator1.setDuration(1500);
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
animator1.start();
TranslateAnimation enterAnim = new TranslateAnimation(
Animation.ABSOLUTE, screenWidth,
Animation.ABSOLUTE, (screenWidth - SystemUtils.getWidth(316)) / 2,
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0
);
enterAnim.setDuration(1500);
enterAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
view.postDelayed(() -> {
try {
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
// ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", (getScreenWidth() - view.getMeasuredWidth()) / 2f, -view.getMeasuredWidth());
animator2.setDuration(1500);
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
animator2.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
onAnimationEnd.run();
}
@Override
public void onAnimationEnd(Animation animation) {
// 停留后退出
postDelayed(() -> {
TranslateAnimation exitAnim = new TranslateAnimation(
Animation.ABSOLUTE, (screenWidth - SystemUtils.getWidth(316)) / 2,
Animation.ABSOLUTE, -screenWidth,
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0
);
exitAnim.setDuration(2000);
exitAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationCancel(Animator animation) {
onAnimationEnd.run();
}
});
animator2.start();
} catch (Exception e) {
LogUtils.e("MQTT动画执行失败", e);
onAnimationEnd.run();
@Override
public void onAnimationEnd(Animation animation) {
// 移除视图并处理下一个
// ViewGroup rootView = (ViewGroup) getParent();
// if (rootView != null) {
// rootView.removeView(QXGiftDriftView.this);
// }
//
// if (!dataArray.isEmpty()) {
// dataArray.remove(0);
// }
// isPlaying = false;
//
// if (!dataArray.isEmpty()) {
// giftAction();
// }
onAnimationEnd.run();
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
view.startAnimation(exitAnim);
}, 3000); // 停留1秒
}
}, 3000);
@Override
public void onAnimationRepeat(Animation animation) {}
});
view.startAnimation(enterAnim);
// ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
// animator1.setDuration(1500);
// animator1.setInterpolator(new DecelerateInterpolator(1f));
// animator1.start();
// view.postDelayed(() -> {
// try {
// ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
// animator2.setDuration(3000);
// animator2.setInterpolator(new DecelerateInterpolator(2.0f));
// animator2.addListener(new AnimatorListenerAdapter() {
// @Override
// public void onAnimationEnd(Animator animation) {
// onAnimationEnd.run();
// }
//
// @Override
// public void onAnimationCancel(Animator animation) {
// onAnimationEnd.run();
// }
// });
// animator2.start();
// } catch (Exception e) {
// LogUtils.e("MQTT动画执行失败", e);
// onAnimationEnd.run();
// }
// }, 3000);
} catch (Exception e) {
LogUtils.e("MQTT动画启动失败", e);
onAnimationEnd.run();

View File

@@ -4,6 +4,8 @@ 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;
@@ -21,8 +23,11 @@ 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;
@@ -96,6 +101,25 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
@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();
}
});
@@ -121,6 +145,8 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
@Override
public void onKickedOffline() {
// queren1();
}
@Override
@@ -132,6 +158,32 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
}
};
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();
}
private SystemLocationProvider locationProvider;
private void initLocation() {
@@ -178,6 +230,20 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
}
@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();

View File

@@ -17,6 +17,7 @@ import android.os.Handler;
import android.os.PowerManager;
import android.provider.Settings;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.webkit.WebView;
import androidx.annotation.NonNull;
@@ -71,6 +72,7 @@ import java.security.MessageDigest;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
/**
@@ -92,6 +94,8 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
public boolean isPlaying;
public String playId;
public String lable_id;
public boolean isMicPlace;
public String playCover;
public boolean showSelf;//盲盒是否能送自己
public String playName;
@@ -114,27 +118,13 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
private int activityCount = 0;
private Long masageCount;
private int announcement_read_count;
public int getAnnouncement_read_count() {
return announcement_read_count;
}
public void setAnnouncement_read_count(int announcement_read_count) {
this.announcement_read_count = announcement_read_count;
}
public Long getMasageCount() {
return masageCount;
}
public void setMasageCount(Long masageCount) {
this.masageCount = masageCount;
}
private AppStateListener appStateListener;
private boolean isListeningUnreadCount = false;
@Setter
@Getter
public UnreadCountEvent unreadCountEvent;
@Override
public void onCreate() {
super.onCreate();
@@ -148,7 +138,26 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
registerActivityLifecycleCallbacks(this);
appStateListener = AppStateManager.getInstance();
startListeningUnreadMessageCount();
// 全局设置字体不缩放
adjustFontScale(getResources().getConfiguration());
}
public void adjustFontScale(Configuration configuration) {
if (configuration.fontScale != 1.0f) {
configuration.fontScale = 1.0f;
DisplayMetrics metrics = getResources().getDisplayMetrics();
getResources().updateConfiguration(configuration, metrics);
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// 配置变化时重新应用字体设置
adjustFontScale(newConfig);
}
// 在适当的位置如onCreate或onResume添加实时监听
protected void startListeningUnreadMessageCount() {
if (!isListeningUnreadCount) {
@@ -181,7 +190,6 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
V2TIMManager.getConversationManager().getTotalUnreadMessageCount(new V2TIMValueCallback<Long>() {
@Override
public void onSuccess(Long aLong) {
CommonAppContext.getInstance().setMasageCount(aLong != null ? aLong : 0L);
// 通知未读数变化
notifyUnreadCountChanged(aLong != null ? aLong : 0L);
}
@@ -189,7 +197,6 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
@Override
public void onError(int code, String desc) {
// 错误处理
CommonAppContext.getInstance().setMasageCount(0L);
notifyUnreadCountChanged(0L);
}
});
@@ -197,10 +204,14 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
// 通知未读数变化的方法可以发送广播或EventBus事件
private void notifyUnreadCountChanged(long unreadCount) {
UnreadCountEvent event =unreadCountEvent;
if (event==null){
event=new UnreadCountEvent();
}
event.setALong(unreadCount);
// 使用EventBus通知
EventBus.getDefault().post(new UnreadCountEvent(unreadCount,0));
CommonAppContext.getInstance().setUnreadCountEvent(event);
EventBus.getDefault().post(event);
}
/**
* 优化内存设置
@@ -359,6 +370,7 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
// 每次启动应用时重置状态
SpUtil.getInstance().setBooleanValue("youth_model_shown", false);
startInitSdk();
}
}
// piaoPingManager = PiaoPingManager.getInstance(this);

View File

@@ -43,7 +43,8 @@ public class RoomManager {
// 缓存有效期5分钟
private static final long CACHE_DURATION = 5 * 60 * 1000;
private RoomManager() {}
private RoomManager() {
}
public static synchronized RoomManager getInstance() {
if (instance == null) {
@@ -54,8 +55,9 @@ public class RoomManager {
/**
* 进入房间 - 自动获取房间数据
*
* @param context 上下文
* @param roomId 房间ID
* @param roomId 房间ID
*/
public void enterRoom(Context context, String roomId) {
enterRoom(context, roomId, null, null);
@@ -63,8 +65,9 @@ public class RoomManager {
/**
* 进入房间 - 使用密码
* @param context 上下文
* @param roomId 房间ID
*
* @param context 上下文
* @param roomId 房间ID
* @param password 房间密码
*/
public void enterRoom(Context context, String roomId, String password) {
@@ -73,9 +76,10 @@ public class RoomManager {
/**
* 进入房间 - 使用缓存数据
* @param context 上下文
* @param roomId 房间ID
* @param password 房间密码
*
* @param context 上下文
* @param roomId 房间ID
* @param password 房间密码
* @param cachedData 缓存的房间数据
*/
public void enterRoom(Context context, String roomId, String password, RoomInfoResp cachedData) {
@@ -98,8 +102,9 @@ public class RoomManager {
/**
* 获取房间数据并进入房间
* @param context 上下文
* @param roomId 房间ID
*
* @param context 上下文
* @param roomId 房间ID
* @param password 房间密码
*/
public void fetchRoomDataAndEnter(Context context, String roomId, String password) {
@@ -110,10 +115,17 @@ public class RoomManager {
// RoomInfoResp roomInfo = getCachedRoomData(roomId);
// 检查是否是当前房间且用户在线
// boolean isCurrentRoom = isCurrentRoom(roomId);
if (CommonAppContext.getInstance().playId==null){
if (CommonAppContext.getInstance().playId == null) {
fetchAndJoinRoom(context, roomId, password);
}else {
} else {
if (!CommonAppContext.getInstance().playId.equals(roomId)) {
exitRoom(CommonAppContext.getInstance().playId);
} else if (CommonAppContext.getInstance().lable_id.equals("6")) {
upInfo(context, roomId, password, true, null, true);
return;
}
isUserOnline(context, roomId, password, null);
}
// try {
@@ -166,12 +178,12 @@ public class RoomManager {
// navigateToRoom(context, roomId, password, null);
}
private void upInfo(Context context, String roomId, String password,boolean isOnline, RoomInfoResp roomInfo,boolean isCurrentRoom){
private void upInfo(Context context, String roomId, String password, boolean isOnline, RoomInfoResp roomInfo, boolean isCurrentRoom) {
if (isOnline){
navigateToRoom(context, roomId, password, roomInfo,isOnline);
}else {
if (isOnline) {
navigateToRoom(context, roomId, password, roomInfo, isOnline);
} else {
// CommonAppContext.getInstance().isShow = false;
// CommonAppContext.getInstance().isPlaying = false;
// EventBus.getDefault().post(new RoomOutEvent());
@@ -184,7 +196,6 @@ public class RoomManager {
}
// if (isCurrentRoom&& isOnline) {
// if (roomInfo != null) {
// navigateToRoom(context, roomId, password, roomInfo);
@@ -214,7 +225,7 @@ public class RoomManager {
// cacheRoomData(roomId, roomInfo);
// navigateToRoom(context, roomId, password, roomInfo);
return;
return;
// }
// 其他情况,获取新的房间数据并加入房间
@@ -223,8 +234,9 @@ public class RoomManager {
/**
* 获取新的房间数据并加入房间
* @param context 上下文
* @param roomId 房间ID
*
* @param context 上下文
* @param roomId 房间ID
* @param password 房间密码
*/
private void fetchAndJoinRoom(Context context, String roomId, String password) {
@@ -236,7 +248,7 @@ public class RoomManager {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
navigateToRoom(context, roomId, password, null,false);
navigateToRoom(context, roomId, password, null, false);
// RetrofitClient.getInstance().roomGetIn(roomId, password, new BaseObserver<RoomInfoResp>() {
//
@@ -270,6 +282,7 @@ public class RoomManager {
/**
* 检查是否是当前房间
*
* @param roomId 房间ID
* @return true表示是当前房间false表示不是
*/
@@ -279,24 +292,26 @@ public class RoomManager {
// 目前返回false需要根据实际需求实现具体逻辑
RoomInfoResp roomInfo = getCachedRoomData(roomId);
if (roomInfo != null){
if (roomInfo.getRoom_info().getRoom_id().equals(roomId)){
if (roomInfo != null) {
if (roomInfo.getRoom_info().getRoom_id().equals(roomId)) {
return true;
}else {
} else {
return false;
}
}
return false;
}
/**
* 跳转到房间页面
* @param context 上下文
* @param roomId 房间ID
*
* @param context 上下文
* @param roomId 房间ID
* @param password 房间密码
* @param roomInfo 房间信息
*/
private void navigateToRoom(Context context, String roomId, String password, RoomInfoResp roomInfo,boolean isOnline) {
private void navigateToRoom(Context context, String roomId, String password, RoomInfoResp roomInfo, boolean isOnline) {
try {
// 构建跳转参数
Bundle bundle = new Bundle();
@@ -325,7 +340,8 @@ public class RoomManager {
/**
* 缓存房间数据
* @param roomId 房间ID
*
* @param roomId 房间ID
* @param roomInfo 房间信息
*/
public void cacheRoomData(String roomId, RoomInfoResp roomInfo) {
@@ -342,6 +358,7 @@ public class RoomManager {
/**
* 获取缓存的房间数据
*
* @param roomId 房间ID
* @return 房间信息如果缓存无效则返回null
*/
@@ -365,12 +382,14 @@ public class RoomManager {
return roomDataCache.get(roomId);
}
/**
* 检查用户是否在线
*
* @param roomId 房间ID
* @return true表示用户在线false表示不在线
*/
private boolean isUserOnline(Context context, String roomId,String password,RoomInfoResp roomInfo) {
private boolean isUserOnline(Context context, String roomId, String password, RoomInfoResp roomInfo) {
// 这里应该实现检查用户是否在线的逻辑
// 可以通过检查Agora是否还在房间中或者通过服务端接口查询用户状态等方式实现
// 目前返回false需要根据实际需求实现具体逻辑
@@ -420,10 +439,12 @@ public class RoomManager {
}
}
});
return isOnline[0];
return isOnline[0];
}
/**
* 清除指定房间的缓存数据
*
* @param roomId 房间ID
*/
public void clearRoomCache(String roomId) {
@@ -443,6 +464,7 @@ public class RoomManager {
/**
* 退出房间
*
* @param roomId 房间ID
*/
public void exitRoom(String roomId) {
@@ -452,11 +474,24 @@ public class RoomManager {
// 可以在这里添加其他退出房间的逻辑
// 例如:通知服务器用户已退出、清理房间相关资源等
RetrofitClient.getInstance().quitRoom(roomId, SpUtil.getUserId() + "", new BaseObserver<String>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(String s) {
}
});
Logger.d(TAG, "退出房间: " + roomId);
}
/**
* 批量退出房间
*
* @param roomIds 房间ID列表
*/
public void exitRooms(String... roomIds) {
@@ -469,6 +504,7 @@ public class RoomManager {
/**
* 获取房间缓存状态
*
* @param roomId 房间ID
* @return 缓存状态信息
*/

View File

@@ -34,7 +34,7 @@ public class RoomPitBean implements Serializable {
private int is_lock;//0未锁麦 1锁麦
private int is_mute;//0未禁麦 1禁麦
private int count_down;//麦位倒计时
private String user_id;//麦位上用户id
private String user_id="";//麦位上用户id
private String nickname;//麦位上用户昵称
private String avatar;//用户头像
private String sex;//性别

View File

@@ -58,7 +58,7 @@ public class WebViewDialog extends BaseDialog<WebViewDialogBinding> {
android.util.DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
// 设置高度为屏幕高度的80%
android.view.WindowManager.LayoutParams params = getWindow().getAttributes();
params.height = (int) (displayMetrics.heightPixels * 0.7);
params.height = (int) (displayMetrics.heightPixels * 0.9);
params.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
getWindow().setAttributes(params);
}
@@ -102,6 +102,32 @@ public class WebViewDialog extends BaseDialog<WebViewDialogBinding> {
public void initData1() {
// WebSettings webSettings = mBinding.webView.getSettings();
// webSettings.setUseWideViewPort(true);
// webSettings.setLoadWithOverviewMode(true);
// webSettings.setJavaScriptEnabled(true);
// webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
// //增加JSBridge
// mBinding.webView.addJavascriptInterface(new WebAppInterface(getContext()), "Android");
//// mBinding.webView.addJavascriptInterface(new WebViewBridgeConfig(title), WebViewBridgeConfig.NAME);
// webSettings.setBuiltInZoomControls(false);
// webSettings.setSupportZoom(false);
// webSettings.setDomStorageEnabled(true);
// webSettings.setBlockNetworkImage(false);//解决图片不显示
// // 启用 WebView 内容的滚动
// mBinding.webView.setVerticalScrollBarEnabled(true);
// mBinding.webView.setScrollbarFadingEnabled(true);
// webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
// webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
// mBinding.webView.setHorizontalScrollBarEnabled(false);//水平不显示
// mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示
// mBinding.webView.setWebViewClient(new WebViewClient());
// mBinding.webView.setBackgroundColor(Color.TRANSPARENT);
// mBinding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
//
// mBinding.webView.requestFocus();
// mBinding.webView.loadUrl(mUrl);
WebSettings webSettings = mBinding.webView.getSettings();
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
@@ -116,12 +142,16 @@ public class WebViewDialog extends BaseDialog<WebViewDialogBinding> {
webSettings.setBlockNetworkImage(false);//解决图片不显示
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
// 启用 WebView 内容的滚动,但隐藏滚动条
mBinding.webView.setHorizontalScrollBarEnabled(false);//水平不显示
mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示
mBinding.webView.setVerticalScrollBarEnabled(false); //垂直不显示滚动条
mBinding.webView.setWebViewClient(new WebViewClient());
mBinding.webView.setBackgroundColor(Color.TRANSPARENT);
mBinding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
// 确保内容可以滚动
webSettings.setDomStorageEnabled(true);
mBinding.webView.requestFocus();
mBinding.webView.loadUrl(mUrl);
}

View File

@@ -11,8 +11,16 @@ public class UnreadCountEvent {
private long aLong;
private long bLong;
public UnreadCountEvent(long aLong, long bLong) {
this.aLong = aLong;
this.bLong = bLong;
}
// public UnreadCountEvent(long aLong, long bLong) {
// this.aLong = aLong;
// this.bLong = bLong;
// }
//
// public UnreadCountEvent() {
// }
// public UnreadCountEvent(long aLong) {
// this.aLong = aLong;
// }
}

View File

@@ -91,7 +91,7 @@ public interface ApiServer {
@FormUrlEncoded
@POST(Constants.LOGIN)
Observable<BaseModel<List<UserBean>>> login(@Field("user_login") String user_login, @Field("sms_code") String sms_code);
Call<BaseModel<List<UserBean>>> login(@Field("user_login") String user_login, @Field("sms_code") String sms_code);
@FormUrlEncoded //手机换绑
@POST(Constants.MODIFY_MOBILE)

View File

@@ -53,9 +53,11 @@ public abstract class BaseObserver<T> implements Observer<T> {
} else if (e instanceof APIException) {
APIException apiException = (APIException) e;
if (apiException.getCode() == 301) {
EventBus.getDefault().post(new LogOutEvent());
try {
com.blankj.utilcode.util.ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
ToastUtils.show(extractChinese(apiException.getMessage()));
// com.blankj.utilcode.util.ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
EventBus.getDefault().post(new LogOutEvent());
CommonAppContext.getInstance().clearLoginInfo();
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);

View File

@@ -2,8 +2,13 @@ package com.xscm.moduleutil.http;
import com.blankj.utilcode.util.ToastUtils;
import com.xscm.moduleutil.base.CommonAppContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
@@ -23,17 +28,44 @@ public class DefaultTransformer<T> implements ObservableTransformer<BaseModel<T>
return upstream
.map(response -> {
if (response.isTokenExpired()) {
// 触发登出事件EventBus
com.blankj.utilcode.util.ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
CommonAppContext.getInstance().clearLoginInfo();
throw new APIException(-1, "登录已过期");
if (response.getCode()==301){
CommonAppContext.getInstance().clearLoginInfo();
ToastUtils.showShort(response.getMsg());
}else {
// 触发登出事件EventBus
// com.blankj.utilcode.util.ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
CommonAppContext.getInstance().clearLoginInfo();
}
throw new APIException(response.getCode(), response.getMsg());
}
if (!response.isSuccess()) {
throw new APIException(response.getCode(), response.getMsg());
}
return response.getData();
// 确保不会返回null值
T data = response.getData();
if (data == null) {
return getDefaultValue();
// 根据类型返回默认值
// if (data instanceof String) {
// data = (T) "";
// } else if (data instanceof List) {
// data = (T) new ArrayList<>();
// } else if (data instanceof Integer) {
// data = (T) Integer.valueOf(0);
// } else if (data instanceof Long) {
// data = (T) Long.valueOf(0L);
// } else if (data instanceof Double) {
// data = (T) Double.valueOf(0.0);
// } else if (data instanceof Float) {
// data = (T) Float.valueOf(0.0f);
// } else if (data instanceof Boolean) {
// data = (T) Boolean.FALSE;
// } else {
// data= ;
// }
}
return data;
})
.onErrorResumeNext(throwable -> {
// 可以在这里统一处理异常
@@ -45,4 +77,14 @@ public class DefaultTransformer<T> implements ObservableTransformer<BaseModel<T>
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
@SuppressWarnings("unchecked")
private T getDefaultValue() {
try {
// 尝试返回合理类型的默认值
return (T) new Object();
} catch (Exception e) {
return null;
}
}
}

View File

@@ -3,6 +3,7 @@ package com.xscm.moduleutil.http;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.xscm.moduleutil.utils.GsonUtils;
@@ -25,21 +26,76 @@ public class ResponseBodyConverter<T> implements Converter<ResponseBody, T> {
@Override
public T convert(@NonNull ResponseBody value) throws IOException {
String json = value.string();
BaseModel obj = GsonUtils.GsonToBean(json, BaseModel.class);
if (obj.getCode() != 1) {
String info = obj.getMsg();
if ("当前余额不足".equals(info)) {
value.close();
return adapter.fromJson(json);
} else {
if(!info.contains("更新失败")) {
try {
BaseModel obj = GsonUtils.GsonToBean(json, BaseModel.class);
if (obj.getCode() != 1) {
String info = obj.getMsg();
if ("当前余额不足".equals(info)) {
value.close();
return parseDataSafely(json);
} else {
if (!info.contains("更新失败")) {
// ToastUtils.showShort(info);
}
}
// throw new APIException(obj.getCode(), info);
}
}
value.close();
return parseDataSafely(json);
} catch (Exception e) {
// 处理解析异常,避免崩溃
value.close();
try {
// 尝试返回默认值
return createDefaultInstance();
} catch (Exception ex) {
return null;
}
}
}
/**
* 安全地解析数据,处理各种可能的返回类型
*/
private T parseDataSafely(String json) {
try {
return adapter.fromJson(json);
} catch (IOException | JsonParseException e) {
// 当解析失败时,尝试其他方式处理
try {
// 尝试返回默认值
return createDefaultInstance();
} catch (Exception ex) {
return null;
}
}
value.close();
return adapter.fromJson(json);
}
/**
* 创建默认实例以避免null返回
*/
@SuppressWarnings("unused")
private T createDefaultInstance() {
try {
// 对于基本类型和常见集合类型,返回默认值
Class<?> rawType = adapter.getClass();
if (rawType.isAssignableFrom(String.class)) {
return (T) "";
} else if (rawType.isAssignableFrom(Boolean.class) || rawType.isAssignableFrom(boolean.class)) {
return (T) Boolean.FALSE;
} else if (rawType.isAssignableFrom(Integer.class) || rawType.isAssignableFrom(int.class)) {
return (T) Integer.valueOf(0);
} else if (rawType.isAssignableFrom(Long.class) || rawType.isAssignableFrom(long.class)) {
return (T) Long.valueOf(0L);
} else if (rawType.isAssignableFrom(Double.class) || rawType.isAssignableFrom(double.class)) {
return (T) Double.valueOf(0.0);
} else if (rawType.isAssignableFrom(Float.class) || rawType.isAssignableFrom(float.class)) {
return (T) Float.valueOf(0.0f);
} else {
// 对于其他类型返回null而不是抛出异常
return null;
}
} catch (Exception e) {
return null;
}
}
}

View File

@@ -287,7 +287,30 @@ public class RetrofitClient {
}
public void login(String mobile, String password, BaseObserver<List<UserBean>> observer) {
sApiServer.login(mobile, password).compose(new DefaultTransformer<>()).subscribe(observer);
sApiServer.login(mobile, password).enqueue(new Callback<BaseModel<List<UserBean>>>() {
@Override
public void onResponse(Call<BaseModel<List<UserBean>>> call, Response<BaseModel<List<UserBean>>> response) {
if (response.code() == 200){
BaseModel<List<UserBean>> listBaseModel=response.body();
if (listBaseModel!=null){
int code=listBaseModel.getCode();
if (code==1){
observer.onNext(listBaseModel.getData());
}else if (code==301){
ToastUtils.showShort(listBaseModel.getMsg());
}else {
ToastUtils.showShort(listBaseModel.getMsg());
}
}
}
}
@Override
public void onFailure(Call<BaseModel<List<UserBean>>> call, Throwable t) {
t.printStackTrace();
}
});
}
public void userLogin(String mobile, String password, BaseObserver<List<UserBean>> observer) {
@@ -316,14 +339,18 @@ public class RetrofitClient {
if (code == 1) {
observer.onNext(string.getData());
} else if (code == 301) {
try {
ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
CommonAppContext.getInstance().clearLoginInfo();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
// try {
ToastUtils.showShort(string.getMsg());
// ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
// CommonAppContext.getInstance().clearLoginInfo();
// } catch (ClassNotFoundException e) {
// throw new RuntimeException(e);
// }
}else {
ToastUtils.showShort(string.getMsg());
}
}
}
}
@@ -833,7 +860,12 @@ public class RetrofitClient {
public void onResponse(Call<BaseModel<List<UserBean>>> call, Response<BaseModel<List<UserBean>>> response) {
if (response.code() == 200) {
BaseModel<List<UserBean>> baseModel = response.body();
observer.onNext(baseModel.getData());
if (baseModel.getCode()==1) {
observer.onNext(baseModel.getData());
}else if (baseModel.getCode()==301){
ToastUtils.showShort(baseModel.getMsg());
observer.onNext(null);
}
}
}
@@ -2048,14 +2080,16 @@ public class RetrofitClient {
@Override
public void onFailure(Call<BaseModel<String>> call, Throwable t) {
ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
// ToastUtils.showShort("提示当前账号已在别的地方登陆,如果不是本人操作请修改密码");
if (t.toString().contains("登录失效")) {
try {
CommonAppContext.getInstance().clearLoginInfo();
ToastUtils.showShort(t.toString());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
ToastUtils.showShort(t.toString());
}
});
}

View File

@@ -9,6 +9,7 @@ import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.xscm.moduleutil.base.CommonAppContext;
import com.xscm.moduleutil.bean.HeadlineBean;
import com.xscm.moduleutil.bean.RoomMessageEvent;
import com.xscm.moduleutil.bean.room.EMMessageInfo;
@@ -512,7 +513,15 @@ public class MessageListenerSingleton {
@Override
public void onTotalUnreadMessageCountChanged(long totalUnreadCount) {
super.onTotalUnreadMessageCountChanged(totalUnreadCount);
EventBus.getDefault().post(new UnreadCountEvent(totalUnreadCount,0));
UnreadCountEvent event = CommonAppContext.getInstance().getUnreadCountEvent();
if (event== null){
event = new UnreadCountEvent();
event.setBLong(0);
}
event.setALong( totalUnreadCount);
CommonAppContext.getInstance().setUnreadCountEvent(event);
EventBus.getDefault().post(event);
}
};
}

View File

@@ -250,7 +250,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
if (!mIvRipple.isAnimating()) {
mIvRipple.startAnimation();
}
// iv_on_line.setVisibility(GONE);
iv_on_line.setVisibility(GONE);
});
}
@@ -270,7 +270,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
if (!mIvRipple.isAnimating()) {
mIvRipple.startAnimation();
}
// iv_on_line.setVisibility(GONE);
iv_on_line.setVisibility(GONE);
});
}

View File

@@ -0,0 +1,273 @@
package com.xscm.moduleutil.widget;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.event.MqttBean;
import java.util.ArrayList;
import java.util.List;
public class QXGiftDriftView extends ViewGroup {
private static QXGiftDriftView instance;
private ImageView bgImageView;
private TextView titleLabel;
private ImageView giftImageView;
private TextView countLabel;
private boolean isPlaying=false;
private boolean isClose;
private List<MqttBean.ListBean> dataArray = new ArrayList<>();
private MqttBean.ListBean model;
private Context context;
private int screenWidth;
public static QXGiftDriftView getInstance(Context context) {
if (instance == null) {
instance = new QXGiftDriftView(context);
}
return instance;
}
private QXGiftDriftView(Context context) {
super(context);
this.context = context;
// 获取屏幕宽度
screenWidth = context.getResources().getDisplayMetrics().widthPixels;
// 初始化视图
initSubviews();
// 从SharedPreferences读取设置
SharedPreferences prefs = context.getSharedPreferences("AppPrefs", Context.MODE_PRIVATE);
isClose = prefs.getBoolean("kIsCloseDrifPop", false);
}
private void initSubviews() {
// 设置视图尺寸
int width = scaleWidth(316);
int height = scaleWidth(50);
setLayoutParams(new LayoutParams(width, height));
// 背景图片
bgImageView = new ImageView(context);
bgImageView.setImageResource(R.mipmap.gift_p_b);
addView(bgImageView);
// 标题标签
titleLabel = new TextView(context);
titleLabel.setTextSize(14);
titleLabel.setTextColor(Color.WHITE);
addView(titleLabel);
// 礼物图片
giftImageView = new ImageView(context);
giftImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
addView(giftImageView);
// 数量标签
countLabel = new TextView(context);
countLabel.setTextSize(14);
countLabel.setTextColor(Color.WHITE);
addView(countLabel);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
// 布局子视图
int width = getWidth();
int height = getHeight();
// 背景图片填满整个视图
bgImageView.layout(0, 0, width, height);
// 标题标签居中偏左
int titleWidth = titleLabel.getMeasuredWidth();
int titleHeight = titleLabel.getMeasuredHeight();
int titleLeft = (width - titleWidth) / 2 - scaleWidth(30);
int titleTop = (height - titleHeight) / 2;
titleLabel.layout(titleLeft, titleTop, titleLeft + titleWidth, titleTop + titleHeight);
// 礼物图片在标题右侧
int giftSize = scaleWidth(20);
int giftLeft = titleLeft + titleWidth + scaleWidth(5);
int giftTop = titleTop + (titleHeight - giftSize) / 2;
giftImageView.layout(giftLeft, giftTop, giftLeft + giftSize, giftTop + giftSize);
// 数量标签在礼物图片右侧
int countWidth = countLabel.getMeasuredWidth();
int countLeft = giftLeft + giftSize;
countLabel.layout(countLeft, titleTop, countLeft + countWidth, titleTop + titleHeight);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = scaleWidth(316);
int height = scaleWidth(50);
setMeasuredDimension(width, height);
// 测量子视图
measureChildren(widthMeasureSpec, heightMeasureSpec);
}
public void addGiftModel(MqttBean.ListBean model) {
if (isClose) {
return;
}
dataArray.add(model);
giftAction();
}
public void addGiftModelList(List<MqttBean.ListBean> list) {
dataArray.addAll(list);
giftAction();
}
private void giftAction() {
if (isPlaying) {
return;
}
if (dataArray.isEmpty()) {
return;
}
isPlaying = true;
model = dataArray.get(0);
// 添加到窗口(这里需要根据实际情况获取根布局)
ViewGroup rootView = (ViewGroup) ((Activity) context).getWindow().getDecorView();
rootView.addView(QXGiftDriftView.getInstance( context));
// 设置初始位置(屏幕右侧外)
setX(screenWidth);
// 进入动画
TranslateAnimation enterAnim = new TranslateAnimation(
Animation.ABSOLUTE, screenWidth,
Animation.ABSOLUTE, (screenWidth - scaleWidth(316)) / 2,
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0
);
enterAnim.setDuration(1500);
enterAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
// 停留后退出
postDelayed(() -> {
TranslateAnimation exitAnim = new TranslateAnimation(
Animation.ABSOLUTE, (screenWidth - scaleWidth(316)) / 2,
Animation.ABSOLUTE, -screenWidth,
Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 0
);
exitAnim.setDuration(2000);
exitAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
// 移除视图并处理下一个
ViewGroup rootView = (ViewGroup) getParent();
if (rootView != null) {
rootView.removeView(QXGiftDriftView.getInstance( context));
}
if (!dataArray.isEmpty()) {
dataArray.remove(0);
}
isPlaying = false;
if (!dataArray.isEmpty()) {
giftAction();
}
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
startAnimation(exitAnim);
}, 1000); // 停留1秒
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
startAnimation(enterAnim);
}
public void setModel(MqttBean.ListBean model) {
this.model = model;
String text = String.format("%s送给%s", model.getFromUserName(), model.getToUserName());
// 这里需要使用SpannableString来实现富文本效果
// 简化处理,直接设置文本
titleLabel.setText(text);
// 加载图片 - 使用图片加载库如Glide
// Glide.with(context).load(model.getGiftPicture()).into(giftImageView);
countLabel.setText(String.format("X%s", model.getNumber()));
}
public void drifPopIsClose(boolean isClose) {
this.isClose = isClose;
setVisibility(isClose ? View.GONE : View.VISIBLE);
SharedPreferences prefs = context.getSharedPreferences("AppPrefs", Context.MODE_PRIVATE);
prefs.edit().putBoolean("kIsCloseDrifPop", isClose).apply();
if (isClose) {
ViewGroup rootView = (ViewGroup) getParent();
if (rootView != null) {
rootView.removeView(this);
}
dataArray.clear();
isPlaying = false;
}
}
private int scaleWidth(int width) {
// 根据屏幕密度进行缩放
float density = context.getResources().getDisplayMetrics().density;
return (int) (width * density);
}
// QXGiftScrollModel 类(需要单独定义)
public static class QXGiftScrollModel {
private String fromUserName;
private String toUserName;
private String giftPicture;
private String number;
// getters and setters
public String getFromUserName() { return fromUserName; }
public void setFromUserName(String fromUserName) { this.fromUserName = fromUserName; }
public String getToUserName() { return toUserName; }
public void setToUserName(String toUserName) { this.toUserName = toUserName; }
public String getGiftPicture() { return giftPicture; }
public void setGiftPicture(String giftPicture) { this.giftPicture = giftPicture; }
public String getNumber() { return number; }
public void setNumber(String number) { this.number = number; }
}
}

View File

@@ -64,6 +64,7 @@ public class RoomFriendshipWheatView extends BaseWheatView {
public void onClick(View v) {
if (mOnZhulClickListener != null && pitBean != null) {
mOnZhulClickListener.onZhulClick(RoomFriendshipWheatView.this, pitBean);
}
}
});

View File

@@ -52,7 +52,7 @@
<LinearLayout
android:id="@+id/line"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_14"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_name"
android:layout_marginStart="@dimen/dp_2"
android:layout_marginTop="@dimen/dp_5"

View File

@@ -23,6 +23,8 @@
android:layout_width="match_parent"
android:layout_height="@dimen/dp_600"
android:background="@color/transparent"
android:layout_marginStart="@dimen/dp_25"
android:layout_marginEnd="@dimen/dp_25"
android:hardwareAccelerated="true"
app:layout_constraintTop_toBottomOf="@+id/im_gz"
app:layout_constraintStart_toStartOf="parent"