1:修改K歌房
2:修改房间展示每日任务 3:修改页面跳转 4:遗留问题在进入首页的时候出现首页刷新
@@ -221,6 +221,8 @@ dependencies {
|
||||
// 腾讯cos云储存
|
||||
api 'com.qcloud.cos:cos-android:5.9.+'
|
||||
|
||||
api project(':Loadinglibrary')
|
||||
|
||||
// room数据库
|
||||
// def room_version = "2.5.0"
|
||||
// implementation "androidx.room:room-runtime:$room_version"
|
||||
|
||||
@@ -1157,7 +1157,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
// 使用缓存数据进入房间
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), xlhBean.getRoom_id(), "");
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), xlhBean.getRoom_id(), "",null);
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
@@ -1166,7 +1166,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
// 使用缓存数据进入房间
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), redBean.getRoom_id(), "");
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), redBean.getRoom_id(), "",null);
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ public class WebViewActivity extends BaseAppCompatActivity<ActivityWebViewBindin
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), room_id,"");
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), room_id,"",null);
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class OfficialNoticeActivity extends BaseMvpActivity<NewsPresenter, Activ
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (item.getRoom_id()>0){
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), item.getRoom_id()+"","");
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getApplicationContext(), item.getRoom_id()+"","",null);
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("roomId", item.getRoom_id() + "").navigation();
|
||||
}else if (item.getRoom_id() == 0 && item.getUrl() != null && !item.getUrl().isEmpty()){
|
||||
Intent intent = new Intent(OfficialNoticeActivity.this, WebViewActivity.class);
|
||||
|
||||
@@ -459,7 +459,7 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
|
||||
SpUtil.getInstance().setBooleanValue("youth_model_shown", false);
|
||||
startInitSdk();
|
||||
// 初始化(通常在Application或Activity的onCreate中)
|
||||
CosUploadManager.getInstance().init(this);
|
||||
CosUploadManager.getInstance(CommonAppContext.getInstance());
|
||||
// 启动IM连接服务
|
||||
// IMServiceManager.getInstance().startIMService(this);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 房间管理器
|
||||
@@ -102,10 +103,10 @@ public class RoomManager {
|
||||
|
||||
if (roomInfo != null) {
|
||||
// 使用缓存数据直接进入房间
|
||||
navigateToRoom(context, roomId, password, roomInfo, false);
|
||||
navigateToRoom(context, roomId, password, roomInfo, false,null);
|
||||
} else {
|
||||
// 获取房间数据后进入房间
|
||||
fetchRoomDataAndEnter(context, roomId, password);
|
||||
fetchRoomDataAndEnter(context, roomId, password,null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,19 +117,20 @@ public class RoomManager {
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
*/
|
||||
public void fetchRoomDataAndEnter(Context context, String roomId, String password) {
|
||||
public void fetchRoomDataAndEnter(Context context, String roomId, String password,String taskId) {
|
||||
// 显示加载提示
|
||||
// 这里可以根据需要添加加载对话框
|
||||
if (CommonAppContext.getInstance().isRoomJoininj){
|
||||
return;
|
||||
}
|
||||
|
||||
CommonAppContext.getInstance().isRoomJoininj=true;
|
||||
// 检查是否有有效的缓存数据
|
||||
RoomInfoResp roomInfo = getCachedRoomData(roomId);
|
||||
// 检查是否是当前房间且用户在线
|
||||
// boolean isCurrentRoom = isCurrentRoom(roomId);
|
||||
if (CommonAppContext.getInstance().playId == null) {
|
||||
fetchAndJoinRoom(context, roomId, password);
|
||||
fetchAndJoinRoom(context, roomId, password,taskId);
|
||||
} else {
|
||||
if (!CommonAppContext.getInstance().playId.equals(roomId)) {
|
||||
MessageListenerSingleton.getInstance().joinGroup(roomId);
|
||||
@@ -137,11 +139,13 @@ public class RoomManager {
|
||||
CommonAppContext.getInstance().isPlaying = false;
|
||||
CommonAppContext.getInstance().isRoomJoininj=false;
|
||||
EventBus.getDefault().post(new RoomOutEvent());
|
||||
// fetchAndJoinRoom(context, roomId, password);
|
||||
// return;
|
||||
} else if (CommonAppContext.getInstance().lable_id.equals("6")) {
|
||||
upInfo(context, roomId, password, true, roomInfo, true);
|
||||
upInfo(context, roomId, password, true, roomInfo, true,taskId);
|
||||
return;
|
||||
}
|
||||
isUserOnline(context, roomId, password, roomInfo);
|
||||
isUserOnline(context, roomId, password, roomInfo,taskId);
|
||||
|
||||
}
|
||||
|
||||
@@ -195,58 +199,26 @@ 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,String taskId) {
|
||||
|
||||
|
||||
if (isOnline) {
|
||||
navigateToRoom(context, roomId, password, roomInfo, isOnline);
|
||||
RetrofitClient.getInstance().postRoomInfo(roomId, new BaseObserver<RoomInfoResp>() {
|
||||
|
||||
@Override
|
||||
public void onSubscribe(@NotNull Disposable disposable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NotNull RoomInfoResp roomInfoResp) {
|
||||
navigateToRoom(context, roomId, password, roomInfoResp, false,taskId);
|
||||
}
|
||||
});
|
||||
// navigateToRoom(context, roomId, password, roomInfo, isOnline);
|
||||
} else {
|
||||
// CommonAppContext.getInstance().isShow = false;
|
||||
// CommonAppContext.getInstance().isPlaying = false;
|
||||
// EventBus.getDefault().post(new RoomOutEvent());
|
||||
// try {
|
||||
// Thread.sleep(300);
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
fetchAndJoinRoom(context, roomId, password);
|
||||
fetchAndJoinRoom(context, roomId, password,taskId);
|
||||
}
|
||||
|
||||
|
||||
// if (isCurrentRoom&& isOnline) {
|
||||
// if (roomInfo != null) {
|
||||
// navigateToRoom(context, roomId, password, roomInfo);
|
||||
// } else {
|
||||
// // 即使在线,如果没有缓存数据,也需要获取数据
|
||||
// fetchAndJoinRoom(context, roomId, password);
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
// 如果有缓存数据且用户在线,使用缓存数据进入房间
|
||||
// if (roomInfo != null && isOnline) {
|
||||
// RetrofitClient.getInstance().postRoomInfo(roomId, new BaseObserver<RoomInfoResp>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onSubscribe(Disposable d) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(RoomInfoResp roomInfoResp) {
|
||||
//// cacheRoomData(roomId, roomInfo);
|
||||
// navigateToRoom(context, roomId, password, roomInfoResp);
|
||||
// }
|
||||
// });
|
||||
|
||||
// cacheRoomData(roomId, roomInfo);
|
||||
// navigateToRoom(context, roomId, password, roomInfo);
|
||||
return;
|
||||
// }
|
||||
|
||||
// 其他情况,获取新的房间数据并加入房间
|
||||
// fetchAndJoinRoom(context, roomId, password);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +228,7 @@ public class RoomManager {
|
||||
* @param roomId 房间ID
|
||||
* @param password 房间密码
|
||||
*/
|
||||
private void fetchAndJoinRoom(Context context, String roomId, String password) {
|
||||
private void fetchAndJoinRoom(Context context, String roomId, String password,String taskId) {
|
||||
// 获取房间数据
|
||||
|
||||
// 等待一段时间确保退出完成
|
||||
@@ -266,7 +238,6 @@ public class RoomManager {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
// navigateToRoom(context, roomId, password, null, false);
|
||||
LogUtils.dTag("RoomActivity", "fetchAndJoinRoom:"+roomId.toString());
|
||||
RetrofitClient.getInstance().roomGetIn(roomId, password, new BaseObserver<RoomInfoResp>() {
|
||||
|
||||
@Override
|
||||
@@ -292,7 +263,12 @@ public class RoomManager {
|
||||
AgoraManager.getInstance(context)
|
||||
.joinRoom(token, roomId, uid, enableMic, enableJs);
|
||||
cacheRoomData(roomId, resp);
|
||||
navigateToRoom(context, roomId, password, resp, false);
|
||||
navigateToRoom(context, roomId, password, resp, false,taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -328,8 +304,7 @@ public class RoomManager {
|
||||
* @param password 房间密码
|
||||
* @param roomInfo 房间信息
|
||||
*/
|
||||
private void navigateToRoom(Context context, String roomId, String password, RoomInfoResp roomInfo, boolean isOnline) {
|
||||
LogUtils.dTag("RoomActivity", "navigateToRoom"+roomInfo.toString());
|
||||
private void navigateToRoom(Context context, String roomId, String password, RoomInfoResp roomInfo, boolean isOnline,String taskId) {
|
||||
|
||||
try {
|
||||
// 构建跳转参数
|
||||
@@ -340,28 +315,23 @@ public class RoomManager {
|
||||
if (!TextUtils.isEmpty(password)) {
|
||||
bundle.putString("password", password);
|
||||
}
|
||||
if (taskId != null){
|
||||
bundle.putString("taskId", taskId);
|
||||
}
|
||||
|
||||
if (roomInfo == null){
|
||||
LogUtils.dTag("RoomActivity", "navigateToRoom:房间信息获取存在问题");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isOnline){
|
||||
ARouter.getInstance()
|
||||
.build(ARouteConstants.ROOM_DETAILS)
|
||||
|
||||
.navigation(context);
|
||||
}else {
|
||||
// 使用ARouter跳转到房间页面
|
||||
ARouter.getInstance()
|
||||
.build(ARouteConstants.ROOM_DETAILS)
|
||||
|
||||
.with(bundle)
|
||||
.navigation(context);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "跳转房间页面失败: " + e.getMessage());
|
||||
}finally {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +386,7 @@ public class RoomManager {
|
||||
* @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,String taskId) {
|
||||
// 这里应该实现检查用户是否在线的逻辑
|
||||
// 可以通过检查Agora是否还在房间中,或者通过服务端接口查询用户状态等方式实现
|
||||
// 目前返回false,需要根据实际需求实现具体逻辑
|
||||
@@ -426,6 +396,9 @@ public class RoomManager {
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
final boolean[] isOnline = {false};
|
||||
RetrofitClient.getInstance().getRoomOnline(roomId, "1", "50", new BaseObserver<RoomOnline>() {
|
||||
@Override
|
||||
@@ -453,7 +426,8 @@ public class RoomManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true);
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
|
||||
} else {
|
||||
isOnline[0] = false;
|
||||
}
|
||||
@@ -462,11 +436,11 @@ public class RoomManager {
|
||||
e.printStackTrace();
|
||||
isOnline[0] = false;
|
||||
// 即使出现异常也继续执行
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true);
|
||||
upInfo(context, roomId, password, isOnline[0], roomInfo, true, taskId);
|
||||
}
|
||||
}
|
||||
});
|
||||
return isOnline[0];
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.xscm.moduleutil.R;
|
||||
|
||||
/**
|
||||
* com.xscm.moduleutil.dialog
|
||||
* qx
|
||||
* 2025/10/27
|
||||
*/
|
||||
public class LoadingDialog extends Dialog {
|
||||
|
||||
|
||||
public LoadingDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// 设置布局(这里假设你有一个R.layout.loading_dialog布局文件)
|
||||
setContentView(R.layout.loading_dialog);
|
||||
|
||||
// 设置不可取消
|
||||
setCancelable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示加载对话框
|
||||
*/
|
||||
public void showLoading() {
|
||||
if (!isShowing()) {
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏加载对话框
|
||||
*/
|
||||
public void hideLoading() {
|
||||
if (isShowing()) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public class RoomAuctionWebViewDialog extends BaseDialog<DialogRoomAuctionWebvie
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"");
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"",null);
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class WebViewDialog extends BaseDialog<WebViewDialogBinding> {
|
||||
|
||||
@JavascriptInterface
|
||||
public void jumpRoomPage(String room_id) {
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"");
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(getContext(), room_id,"",null);
|
||||
|
||||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("form", "首页").withString("roomId", room_id).navigation();
|
||||
}
|
||||
|
||||
@@ -1938,6 +1938,7 @@ public class RetrofitClient {
|
||||
public void onFailure(Call<BaseModel<RoomInfoResp>> call, Throwable t) {
|
||||
MessageListenerSingleton.getInstance().quitGroup(roomId);
|
||||
CommonAppContext.getInstance().isRoomJoininj = false;
|
||||
observer.onError( t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -445,6 +445,7 @@ public class AgoraManager {
|
||||
@Override
|
||||
public void onLyricResult(String requestId, long songCode, String lyricUrl, int reason) {
|
||||
if (lyricUrl != null) {
|
||||
LogUtils.e("roomInfoEvent",lyricUrl);
|
||||
getLyricsInstance(lyricUrl);
|
||||
}
|
||||
}
|
||||
@@ -1449,6 +1450,7 @@ public class AgoraManager {
|
||||
.build();
|
||||
if (StatusUtil.isCompleted(task)) {
|
||||
MusicFileBean musicFileBean = new MusicFileBean();
|
||||
LogUtils.e("roomInfoEvent",convertFileToByteArray(task.getFile()));
|
||||
musicFileBean.setFileData(convertFileToByteArray(task.getFile()));
|
||||
EventBus.getDefault().post(musicFileBean);
|
||||
} else {
|
||||
@@ -1477,6 +1479,7 @@ public class AgoraManager {
|
||||
@Override
|
||||
public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause, @NonNull Listener1Assist.Listener1Model model) {
|
||||
Logger.e("taskEnd", model);
|
||||
LogUtils.e("roomInfoEvent",convertFileToByteArray(task.getFile()));
|
||||
MusicFileBean musicFileBean = new MusicFileBean();
|
||||
musicFileBean.setFileData(convertFileToByteArray(task.getFile()));
|
||||
EventBus.getDefault().post(musicFileBean);
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ARouteConstants {
|
||||
public static final String H5 ="/moduleUtil/WebViewActivity"; //网页
|
||||
// public static final String GIFT_WALL ="/moduleroom/UserGiftWallFragment"; //实名认证
|
||||
public static final String RECHARGE_ACTIVITY ="/modulevocal/RechargeActivity"; //实名认证
|
||||
public static final String DailyTasksActivity ="/modulevocal/DailyTasksActivity"; //每日任务
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.tencent.cos.xml.CosXmlService;
|
||||
import com.tencent.cos.xml.CosXmlServiceConfig;
|
||||
import com.tencent.cos.xml.exception.CosXmlClientException;
|
||||
@@ -31,33 +32,33 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class CosUploadManager {
|
||||
private static volatile CosUploadManager instance;
|
||||
private Context context;
|
||||
private Context mContext;
|
||||
private Handler mainHandler;
|
||||
// 私有构造函数,防止外部实例化
|
||||
private CosUploadManager() {
|
||||
private CosUploadManager(Context context)
|
||||
{
|
||||
mContext = context;
|
||||
mainHandler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
// 双重检查锁定获取单例实例
|
||||
public static CosUploadManager getInstance() {
|
||||
public static CosUploadManager getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
synchronized (CosUploadManager.class) {
|
||||
if (instance == null) {
|
||||
instance = new CosUploadManager();
|
||||
instance = new CosUploadManager(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public void init(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public void upParameters( String objectKey, String localPath, UploadCallback callback) {
|
||||
// 确保已初始化
|
||||
if (context == null) {
|
||||
callback.onFailure(new IllegalStateException("CosUploadManager not initialized with context"));
|
||||
return;
|
||||
}
|
||||
// if (context == null) {
|
||||
// callback.onFailure1(new IllegalStateException("CosUploadManager not initialized with context"));
|
||||
// return;
|
||||
// }
|
||||
RetrofitClient.getInstance().getTempKey(new BaseObserver<TempKeyBean>() {
|
||||
@Override
|
||||
public void onSubscribe(@NotNull Disposable disposable) {
|
||||
@@ -91,7 +92,7 @@ public class CosUploadManager {
|
||||
.setRegion(region)
|
||||
.isHttps(true) // 使用 HTTPS 请求, 默认为 HTTP 请求
|
||||
.builder();
|
||||
CosXmlService cosXmlService = new CosXmlService(context, serviceConfig);
|
||||
CosXmlService cosXmlService = new CosXmlService(mContext, serviceConfig);
|
||||
|
||||
// 任何 CosXmlRequest 都支持这种方式,例如上传 PutObjectRequest、下载 GetObjectRequest、删除 DeleteObjectRequest 等
|
||||
// 以下用上传进行示例
|
||||
@@ -142,5 +143,7 @@ public class CosUploadManager {
|
||||
public interface UploadCallback {
|
||||
void onSuccess(String url); // 上传成功,返回访问URL
|
||||
void onFailure(Exception e); // 上传失败
|
||||
|
||||
void onFailure1(IllegalStateException e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
package com.xscm.moduleutil.widget;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewAnimationUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import com.blankj.utilcode.util.ScreenUtils;
|
||||
import com.xscm.moduleutil.utils.BarUtils;
|
||||
|
||||
/**
|
||||
* com.xscm.moduleutil.widget
|
||||
* qx
|
||||
* 2025/10/27
|
||||
*/
|
||||
public class DropDayTaskView extends LinearLayout {
|
||||
|
||||
private int rightMargin = 0;
|
||||
private float lastX, lastY;
|
||||
private int screenWidth;
|
||||
private int screenHeight; // 添加屏幕高度变量
|
||||
|
||||
public DropDayTaskView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public DropDayTaskView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public DropDayTaskView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void init() {
|
||||
// 初始化屏幕尺寸
|
||||
screenWidth = ScreenUtils.getScreenWidth();
|
||||
screenHeight = ScreenUtils.getScreenHeight();
|
||||
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//设置初始位置
|
||||
int sh = ScreenUtils.getScreenHeight();
|
||||
int sw = ScreenUtils.getScreenWidth();
|
||||
// setBackgroundResource(R.drawable.bg_home_drop_view);
|
||||
int y = (int) (0.7f * sh) - getHeight();
|
||||
// 确保Y坐标不会超出屏幕范围
|
||||
y = Math.max(0, Math.min(y, sh - getHeight()));
|
||||
int x = sw - getWidth();
|
||||
setTranslationX(x);
|
||||
setTranslationY(y);
|
||||
}
|
||||
});
|
||||
|
||||
updateSize();
|
||||
mStatusBarHeight = BarUtils.getStatusBarHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新屏幕尺寸信息
|
||||
*/
|
||||
protected void updateSize() {
|
||||
ViewGroup viewGroup = (ViewGroup) getParent();
|
||||
if (viewGroup != null) {
|
||||
mScreenWidth = viewGroup.getWidth();
|
||||
mScreenHeight = viewGroup.getHeight();
|
||||
} else {
|
||||
// 如果父视图为空,使用屏幕的实际宽度和高度
|
||||
mScreenWidth = getResources().getDisplayMetrics().widthPixels;
|
||||
mScreenHeight = getResources().getDisplayMetrics().heightPixels;
|
||||
}
|
||||
}
|
||||
|
||||
boolean starDrap = false;
|
||||
float X1;
|
||||
float X2;
|
||||
float Y1;
|
||||
float Y2;
|
||||
// 记录视图初始位置
|
||||
private float originalX;
|
||||
private float originalY;
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
if (starDrap) return true;
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
X1 = event.getRawX();
|
||||
Y1 = event.getRawY();
|
||||
// 记录视图当前位置
|
||||
originalX = getTranslationX();
|
||||
originalY = getTranslationY();
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
X2 = event.getRawX();
|
||||
Y2 = event.getRawY();
|
||||
Action(X1, X2, Y1, Y2);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return starDrap;
|
||||
}
|
||||
|
||||
String TAG = "DropHourlView";
|
||||
|
||||
public boolean Action(float X1, float X2, float Y1, float Y2) {
|
||||
float ComparedX = X2 - X1;//第二次的X坐标的位置减去第一次X坐标的位置,代表X坐标上的变化情况
|
||||
float ComparedY = Y2 - Y1;//同理
|
||||
//当X坐标的变化量的绝对值大于Y坐标的变化量的绝对值,以X坐标的变化情况作为判断依据
|
||||
//上下左右的判断,都在一条直线上,但手指的操作不可能划直线,所有选择变化量大的方向上的量
|
||||
//作为判断依据
|
||||
if (Math.abs(ComparedX) > 30 || Math.abs(ComparedY) > 30) {
|
||||
Log.i(TAG, "Action: 拖动");
|
||||
starDrap = true;
|
||||
// setBackgroundResource(R.drawable.bg_home_drop_view);
|
||||
return true;
|
||||
} else {
|
||||
starDrap = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private float mOriginalRawX;
|
||||
private float mOriginalRawY;
|
||||
private float mOriginalX;
|
||||
private float mOriginalY;
|
||||
protected int mScreenWidth;
|
||||
private int mScreenHeight;
|
||||
private int mStatusBarHeight;
|
||||
|
||||
private void updateViewPosition(MotionEvent event) {
|
||||
// 计算新的Y位置
|
||||
float desY = mOriginalY + event.getRawY() - mOriginalRawY;
|
||||
|
||||
// 限制Y位置不超出屏幕边界
|
||||
if (desY < mStatusBarHeight) {
|
||||
desY = mStatusBarHeight;
|
||||
}
|
||||
if (desY > mScreenHeight - getHeight()) {
|
||||
desY = mScreenHeight - getHeight();
|
||||
}
|
||||
|
||||
// 计算新的X位置
|
||||
float desX = mOriginalX + event.getRawX() - mOriginalRawX;
|
||||
|
||||
// 限制X位置不超出屏幕边界
|
||||
if (desX < 0) {
|
||||
desX = 0;
|
||||
}
|
||||
if (desX > mScreenWidth - getWidth()) {
|
||||
desX = mScreenWidth - getWidth();
|
||||
}
|
||||
|
||||
// 设置视图的新位置
|
||||
setX(desX);
|
||||
setY(desY);
|
||||
}
|
||||
|
||||
private void changeOriginalTouchParams(MotionEvent event) {
|
||||
mOriginalX = getX();//getX()相对于控件X坐标的距离
|
||||
mOriginalY = getY();
|
||||
mOriginalRawX = event.getRawX();//getRawX()指控件在屏幕上的X坐标
|
||||
mOriginalRawY = event.getRawY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event == null) {
|
||||
return false;
|
||||
}
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
changeOriginalTouchParams(event);
|
||||
updateSize(); // 添加这行确保尺寸是最新的
|
||||
// ... 其他现有代码 ...
|
||||
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
|
||||
updateViewPosition(event); // 使用更新后的带边界检查的方法
|
||||
|
||||
// setBackgroundResource(R.drawable.bg_home_drop_view);
|
||||
// 使用屏幕绝对坐标计算新位置
|
||||
// float newX = originalX + (event.getRawX() - X1);
|
||||
// float newY = originalY + (event.getRawY() - Y1);
|
||||
//
|
||||
// // 限制X和Y坐标在屏幕范围内
|
||||
// newX = Math.max(0, Math.min(newX, screenWidth - getWidth()));
|
||||
// newY = Math.max(0, Math.min(newY, screenHeight - getHeight()));
|
||||
//
|
||||
// setTranslationX(newX);
|
||||
// setTranslationY(newY);
|
||||
// X2 = event.getRawX();
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
starDrap = false;
|
||||
int sw = ScreenUtils.getScreenWidth();
|
||||
Log.i(TAG, "onTouchEvent: " + sw + "," + X2);
|
||||
boolean isR = getTranslationX() + getWidth() / 2 >= sw / 2;//贴边方向
|
||||
|
||||
// 获取当前Y坐标
|
||||
float currentY = getTranslationY();
|
||||
|
||||
// 创建X轴和Y轴的动画
|
||||
ObjectAnimator animX = ObjectAnimator.ofFloat(this, "translationX", isR ? sw - getWidth() : 0f).setDuration(200);
|
||||
// Y轴保持当前位置,但确保在屏幕范围内
|
||||
currentY = Math.max(0, Math.min(currentY, screenHeight - getHeight()));
|
||||
ObjectAnimator animY = ObjectAnimator.ofFloat(this, "translationY", currentY).setDuration(200);
|
||||
|
||||
animX.start();
|
||||
animY.start();
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void doRevealAnimation(View mPuppet, boolean flag) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
int[] vLocation = new int[2];
|
||||
getLocationInWindow(vLocation);
|
||||
int centerX = vLocation[0] + getMeasuredWidth() / 2;
|
||||
int centerY = vLocation[1] + getMeasuredHeight() / 2;
|
||||
|
||||
int height = ScreenUtils.getScreenHeight();
|
||||
int width = ScreenUtils.getScreenWidth();
|
||||
int maxRradius = (int) Math.hypot(height, width);
|
||||
Log.e("hei", maxRradius + "");
|
||||
|
||||
if (flag) {
|
||||
mPuppet.setVisibility(VISIBLE);
|
||||
Animator animator = ViewAnimationUtils.createCircularReveal(mPuppet, centerX, centerY, maxRradius, 0);
|
||||
animator.setDuration(600);
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
mPuppet.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
flag = false;
|
||||
} else {
|
||||
Animator animator = ViewAnimationUtils.createCircularReveal(mPuppet, centerX, centerY, 0, maxRradius);
|
||||
animator.setDuration(1000);
|
||||
animator.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mPuppet.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="@dimen/dp_8" />
|
||||
<solid android:color="@color/transparent" />
|
||||
<solid android:color="#4d000000" />
|
||||
</shape>
|
||||
@@ -4,8 +4,8 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#4d000000"/>
|
||||
<corners
|
||||
android:topLeftRadius="8dp"
|
||||
android:topRightRadius="8dp"
|
||||
android:bottomLeftRadius="8dp"
|
||||
android:bottomRightRadius="8dp"/>
|
||||
android:topLeftRadius="12dp"
|
||||
android:topRightRadius="12dp"
|
||||
android:bottomLeftRadius="12dp"
|
||||
android:bottomRightRadius="12dp"/>
|
||||
</shape>
|
||||
@@ -2,12 +2,12 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:left="8dp"
|
||||
android:top="8dp"
|
||||
android:top="2dp"
|
||||
android:right="8dp"
|
||||
android:bottom="8dp">
|
||||
android:bottom="2dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#4d000000" />
|
||||
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp" android:bottomLeftRadius="8dp" android:bottomRightRadius="8dp" />
|
||||
<corners android:topLeftRadius="12dp" android:topRightRadius="12dp" android:bottomLeftRadius="12dp" android:bottomRightRadius="12dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -6,100 +6,31 @@
|
||||
android:id="@+id/bubble1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="@dimen/dp_256"
|
||||
android:maxWidth="@dimen/dp_256"
|
||||
android:padding="@dimen/dp_8"
|
||||
android:background="@drawable/ease_row_pubilc_user_bg"
|
||||
android:layout_marginTop="@dimen/dp_3"
|
||||
android:layout_marginStart="@dimen/dp_8"
|
||||
android:paddingStart="@dimen/dp_8"
|
||||
android:paddingTop="@dimen/dp_2"
|
||||
android:paddingBottom="@dimen/dp_2"
|
||||
android:background="@drawable/ease_row_pubilc_sys_bg"
|
||||
>
|
||||
|
||||
<!-- 网络背景图片 -->
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/network_background"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="0dp"-->
|
||||
<!-- tools:src="@mipmap/a1img_9"-->
|
||||
<!-- app:layout_constraintTop_toTopOf="parent"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"/>-->
|
||||
|
||||
<!-- 用户头像 -->
|
||||
<com.xscm.moduleutil.widget.GifAvatarOvalView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="@dimen/dp_28"
|
||||
android:layout_height="@dimen/dp_28"
|
||||
android:layout_marginEnd="@dimen/dp_3"
|
||||
android:layout_marginTop="@dimen/dp_3"
|
||||
android:layout_marginBottom="@dimen/dp_3"
|
||||
android:layout_marginStart="@dimen/dp_8"
|
||||
app:riv_oval="true"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<!-- 用户名称 -->
|
||||
<TextView
|
||||
android:id="@+id/tv_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#CCA882"
|
||||
android:textSize="@dimen/sp_12"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
tools:text="饶利"
|
||||
app:layout_constraintStart_toEndOf="@+id/avatar"
|
||||
app:layout_constraintTop_toTopOf="@+id/avatar"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<!-- 用户标签容器 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/line"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:layout_marginTop="@dimen/dp_5"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintStart_toEndOf="@+id/avatar"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_name"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<!-- 消息内容 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="left|center_vertical"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:padding="@dimen/dp_3"
|
||||
android:paddingEnd="@dimen/dp_10"
|
||||
app:layout_constraintStart_toEndOf="@+id/avatar"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/line">
|
||||
android:lineHeight="@dimen/dp_20"
|
||||
android:lineSpacingExtra="@dimen/dp_2"
|
||||
android:paddingTop="@dimen/dp_2"
|
||||
android:paddingBottom="@dimen/dp_2"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/sp_12"
|
||||
tools:text="饶利: 潇洒亼◇生2.0:"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:lineHeight="@dimen/dp_20"
|
||||
android:lineSpacingExtra="@dimen/dp_2"
|
||||
android:paddingStart="@dimen/dp_8"
|
||||
android:paddingEnd="@dimen/dp_8"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/sp_14"
|
||||
tools:text="饶利: 潇洒亼◇生2.0:"
|
||||
tools:visibility="gone"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/im_emj"
|
||||
android:layout_width="@dimen/dp_50"
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:paddingStart="@dimen/dp_8"
|
||||
android:paddingEnd="@dimen/dp_8"
|
||||
android:scaleType="fitCenter"
|
||||
tools:src="@mipmap/ic_launcher"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/bubble"
|
||||
android:layout_marginTop="@dimen/dp_3"
|
||||
android:layout_marginBottom="@dimen/dp_3"
|
||||
android:padding="@dimen/dp_8"
|
||||
android:layout_marginStart="@dimen/dp_8"
|
||||
android:paddingStart="@dimen/dp_8"
|
||||
android:paddingTop="@dimen/dp_2"
|
||||
android:paddingBottom="@dimen/dp_2"
|
||||
android:background="@drawable/ease_row_pubilc_sys_bg"
|
||||
>
|
||||
|
||||
@@ -21,11 +22,11 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:paddingTop="@dimen/dp_5"
|
||||
android:paddingBottom="@dimen/dp_5"
|
||||
android:paddingTop="@dimen/dp_2"
|
||||
android:paddingBottom="@dimen/dp_2"
|
||||
android:paddingEnd="@dimen/dp_8"
|
||||
android:text="我是房间公告"
|
||||
android:textSize="@dimen/sp_14"/>
|
||||
android:textSize="@dimen/sp_11"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
20
moduleUtil/src/main/res/layout/loading_dialog.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/transparent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<app.dinus.com.loadingdrawable.LoadingView
|
||||
android:id="@+id/cool_wait_view"
|
||||
android:layout_width="@dimen/dp_100"
|
||||
android:layout_height="@dimen/dp_100"
|
||||
android:visibility="visible"
|
||||
app:loading_renderer="CoolWaitLoadingRenderer"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
BIN
moduleUtil/src/main/res/mipmap-hdpi/day_task.webp
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
moduleUtil/src/main/res/mipmap-hdpi/room_sound_effects.webp
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
moduleUtil/src/main/res/mipmap-xhdpi/day_task.webp
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
moduleUtil/src/main/res/mipmap-xhdpi/room_sound_effects.webp
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
moduleUtil/src/main/res/mipmap-xxhdpi/day_task.webp
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
moduleUtil/src/main/res/mipmap-xxhdpi/room_sound_effects.webp
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 12 KiB |