任务1
This commit is contained in:
@@ -3,16 +3,18 @@ package com.xscm.moduleutil.bean;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/5/27
|
||||
*@description: 礼盒数据
|
||||
* @author qx
|
||||
* @data 2025/5/27
|
||||
* @description: 礼盒数据
|
||||
*/
|
||||
@Data
|
||||
public class GiftBoxBean {
|
||||
private String user_gold;//累计获取的金币
|
||||
private List<GiftBean> gift_box_list;
|
||||
private List<TaskDataBean> tasks;
|
||||
|
||||
@Data
|
||||
public static class GiftBean {
|
||||
// private String giftName; //初级礼盒、高级礼盒
|
||||
@@ -21,10 +23,25 @@ public class GiftBoxBean {
|
||||
// private String giftTypeNumber; //当前的百分比
|
||||
// private String giftTypeStatus; //是否已经可以
|
||||
|
||||
|
||||
/*{
|
||||
"id":2,
|
||||
"name":"高级礼盒",
|
||||
"title":"最高可获得10000金币",
|
||||
"icon":"",
|
||||
"highest_gain":"10000",
|
||||
"meet":"300",
|
||||
"unlock_progress":0,
|
||||
"all_number":"1",
|
||||
"taday_number":0,
|
||||
"taday_number_left":1,
|
||||
"status":0,
|
||||
"status_str":"未解锁"
|
||||
}*/
|
||||
private String id;//礼盒ID
|
||||
private String name;//礼盒名称
|
||||
private String title; //标题
|
||||
private String icon ;//图标
|
||||
private String icon;//图标
|
||||
private String highest_gain;//最高获得金币数
|
||||
private String meet;//满多少金币可抽
|
||||
private String unlock_progress;// //解锁进度
|
||||
@@ -47,18 +64,52 @@ public class GiftBoxBean {
|
||||
|
||||
@Data
|
||||
public static class DailyTasksBean {
|
||||
private int task_id;////任务Id
|
||||
private String task_name;//任务名称
|
||||
private String icon;//图标
|
||||
private int gold_reward; //奖励金币
|
||||
private int target_quantity;//目标完成数量
|
||||
private int task_type;//任务类型 1每日任务 2每日特殊任务 3平台常规任务
|
||||
private int task_status;//任务状态:1完成 2去领取 3已领取
|
||||
private String task_type_str; //任务状态
|
||||
private int processing_type;//跳转状态:
|
||||
private String processing_type_str;//跳转状态
|
||||
private String from_id;
|
||||
private int reward_type;//1:金币 2:钻石
|
||||
|
||||
/* {
|
||||
"task_id":20,
|
||||
"icon":null,
|
||||
"task_name":"每日在房间时长 15 分钟(0/15)",
|
||||
"target_quantity":900,
|
||||
"task_type":2,
|
||||
"jump_type":4,
|
||||
"tasks_bag_id":0,
|
||||
"task_status":1,
|
||||
"task_type_str":"去完成",
|
||||
"jump_type_str":"跳转房间",
|
||||
"from_id":6040,
|
||||
"is_time":1,
|
||||
"processing_type":2,
|
||||
"processing_type_str":"去观看",
|
||||
"reward_str":"25金币,笨笨狗x1,
|
||||
仙女之星头像框,
|
||||
三八大杠"
|
||||
}*/
|
||||
|
||||
private int task_id;////任务Id
|
||||
private String icon;//图标
|
||||
private String task_name;//任务名称
|
||||
private int target_quantity;//目标完成数量
|
||||
private int task_type;//任务类型 1每日任务 2每日特殊任务 3平台常规任务
|
||||
/**
|
||||
* 0 不跳转
|
||||
* 1 跳转实名
|
||||
* 2 跳转我的相册
|
||||
* 3 跳转绑定管理
|
||||
* 4 跳转房间
|
||||
* 5 跳转申请加入公会
|
||||
* 6 跳转充值
|
||||
*/
|
||||
private int jump_type; //跳转类型
|
||||
private int tasks_bag_id; //任务礼盒ID
|
||||
private int task_status;//任务状态:1完成 2去领取 3已领取
|
||||
private String task_type_str; //任务状态
|
||||
private String jump_type_str; //跳转类型提示
|
||||
private String from_id;
|
||||
private int is_time;
|
||||
private int processing_type;//跳转状态:
|
||||
private String processing_type_str;//跳转状态
|
||||
private String reward_str;//1:奖励
|
||||
private String student_id;//徒弟ID
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -111,6 +111,9 @@ public class RoomMessageEvent extends BaseEvent {
|
||||
private String sign_day;//被签约天数
|
||||
private String current_body_value;//被签约身价
|
||||
|
||||
private String status = "";
|
||||
private String from_id = "";
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -80,7 +80,7 @@ public interface ApiServer {
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.dailyTasksReceive)
|
||||
Call<ResponseBody> dailyTasksReceive(@Field("task_id") String task_id);
|
||||
Call<ResponseBody> dailyTasksReceive(@Field("task_id") String task_id,@Field("student_id") String student_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.dailyTasksComplete)
|
||||
@@ -498,6 +498,10 @@ public interface ApiServer {
|
||||
@POST(Constants.JOIN_ROOM)
|
||||
Call<BaseModel<RoomInfoResp>> roomGetIn(@Field("room_id") String roomId, @Field("password") String password);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.TASK_JUMP_ROOM)
|
||||
Call<BaseModel<String>> taskJumpRoomId(@Field("task_id") String taskId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.DELETE_ALBUM_IMAGE)
|
||||
Call<BaseModel<String>> deleteAlbumImage(@Field("id") String id);
|
||||
|
||||
@@ -1058,8 +1058,8 @@ public class RetrofitClient {
|
||||
sApiServer.dailyTasksOpenBox(gift_box_id).compose(new DefaultTransformer<>()).subscribe(observer);
|
||||
}
|
||||
|
||||
public void dailyTasksReceive(String task_id, BaseObserver<String> observer) {
|
||||
sApiServer.dailyTasksReceive(task_id).enqueue(new Callback<ResponseBody>() {
|
||||
public void dailyTasksReceive(String task_id,String student_id, BaseObserver<String> observer) {
|
||||
sApiServer.dailyTasksReceive(task_id,student_id).enqueue(new Callback<ResponseBody>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
||||
@@ -2277,6 +2277,26 @@ public class RetrofitClient {
|
||||
});
|
||||
}
|
||||
|
||||
public void taskJumpRoomId(String taskId, BaseObserver<String> observer) {
|
||||
sApiServer.taskJumpRoomId(taskId).enqueue(new Callback<BaseModel<String>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<BaseModel<String>> call, Response<BaseModel<String>> response) {
|
||||
if (response.code() == 200) {
|
||||
BaseModel<String> stringBaseModel = response.body();
|
||||
if (stringBaseModel.getCode() == 1) {
|
||||
observer.onNext(stringBaseModel.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<BaseModel<String>> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updatePassword(String roomId, String password, BaseObserver<String> observer) {
|
||||
sApiServer.updatePassword(roomId, password).enqueue(new Callback<BaseModel<String>>() {
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.xscm.moduleutil.event.RoomJoinMountModel;
|
||||
import com.xscm.moduleutil.event.UnreadCountEvent;
|
||||
import com.xscm.moduleutil.http.RetrofitClient;
|
||||
import com.xscm.moduleutil.rtc.MusicPlayBean;
|
||||
import com.xscm.moduleutil.utils.CustomMsgCode;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.tencent.imsdk.v2.V2TIMAdvancedMsgListener;
|
||||
import com.tencent.imsdk.v2.V2TIMCallback;
|
||||
@@ -66,6 +67,8 @@ public class MessageListenerSingleton {
|
||||
private final Map<String, List<RoomMessageEvent>> cachedMessages = new ConcurrentHashMap<>();
|
||||
private final Set<String> joinedRooms = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private OnMsgTaskListener onMsgTaskListener;
|
||||
|
||||
// private boolean listenersAdded = false; // 标记监听器是否已添加
|
||||
// 1. 添加新的监听器接口
|
||||
public interface PublicScreenMessageListener {
|
||||
@@ -321,6 +324,10 @@ public class MessageListenerSingleton {
|
||||
if (event.getMsgType() == 130 || event.getMsgType() == 131) {
|
||||
// EventBus.getDefault().post(event);
|
||||
RetrofitClient.getInstance().getCpListener().onReceiveMsg(event);
|
||||
} else if (event.getMsgType() == CustomMsgCode.INSTANCE.getCODE_TASK_APPRENTICE_JOIN_ROOM()) {
|
||||
if (onMsgTaskListener != null) {
|
||||
onMsgTaskListener.onMsgTask(event);
|
||||
}
|
||||
} else {
|
||||
notifyMessageReceived(event);
|
||||
}
|
||||
@@ -400,7 +407,7 @@ public class MessageListenerSingleton {
|
||||
// 使用默认解析
|
||||
event = GsonUtils.fromJson(message, RoomMessageEvent.class);
|
||||
}
|
||||
LogUtils.e("收到群自定义消息:"+mRoomId+"===" + event);
|
||||
LogUtils.e("收到群自定义消息:" + mRoomId + "===" + event);
|
||||
// event = GsonUtils.fromJson(message, RoomMessageEvent.class);
|
||||
} catch (Exception e) {
|
||||
// 处理 JSON 解析过程中可能出现的异常,例如记录日志
|
||||
@@ -608,6 +615,30 @@ public class MessageListenerSingleton {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// TODO: 2025/11/19 添加发送公共方法,messageType:发送的type;message:发送的内容 userId:发送给谁
|
||||
public void sendCustomC2CMessage(int messageType, String userId,RoomMessageEvent.T text) {
|
||||
text.setFromUserInfo(SpUtil.getUserInfo());
|
||||
LogUtils.e("发送消息", "messageType:" + messageType + "\nuserId:" + userId + "\ntext:" + text,toString());
|
||||
RoomMessageEvent roomMessageEvent = new RoomMessageEvent(messageType, mRoomId, text);
|
||||
String json = com.blankj.utilcode.util.GsonUtils.toJson(roomMessageEvent);
|
||||
// 转换为 byte[]
|
||||
byte[] binaryData = json.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
// 创建自定义群消息
|
||||
V2TIMMessage v2TIMMessage = V2TIMManager.getMessageManager().createCustomMessage(binaryData);
|
||||
v2TIMMessage.setExcludedFromUnreadCount(true);
|
||||
v2TIMMessage.setExcludedFromContentModeration(true);
|
||||
// v2TIMMessage.setNeedReadReceipt(true);
|
||||
//
|
||||
// // 发送消息
|
||||
V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, "u" + userId, null, V2TIMMessage.V2TIM_PRIORITY_HIGH,
|
||||
true,
|
||||
null,
|
||||
sendCallback);
|
||||
|
||||
}
|
||||
|
||||
public void sendCustomC2CMessage125(String userId, byte[] binaryData) {
|
||||
// 创建自定义群消息
|
||||
V2TIMMessage v2TIMMessage = V2TIMManager.getMessageManager().createCustomMessage(binaryData);
|
||||
@@ -664,4 +695,13 @@ public class MessageListenerSingleton {
|
||||
public interface OnMessageReceivedListener {
|
||||
void onMessageReceived(RoomMessageEvent message);
|
||||
}
|
||||
|
||||
|
||||
public void setOnMsgTaskListener(OnMsgTaskListener listener) {
|
||||
this.onMsgTaskListener = listener;
|
||||
}
|
||||
|
||||
public interface OnMsgTaskListener {
|
||||
void onMsgTask(RoomMessageEvent message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.xscm.moduleutil.utils
|
||||
|
||||
object CustomMsgCode {
|
||||
val CODE_TASK_APPRENTICE_JOIN_ROOM_TIMER_ID = "132"
|
||||
val CODE_TASK_APPRENTICE_JOIN_ROOM = 132
|
||||
val CODE_TASK_APPRENTICE_JOIN_ROOM_MSG = "您的师傅邀请您进入房间,您是否同意?"
|
||||
val CODE_TASK_APPRENTICE_JOIN_ROOM_MSG_REFUSE = "您的徒弟拒绝了您的邀请。"
|
||||
}
|
||||
@@ -260,6 +260,7 @@ public class Constants {
|
||||
public static final String GET_DECORATE = "/api/Decorate/user_decorate";//装扮详情
|
||||
public static final String SET_USER_DECORATE = "/api/Decorate/set_user_decorate";//用户装扮
|
||||
public static final String JOIN_ROOM = "/api/Room/join_room";//加入房间
|
||||
public static final String TASK_JUMP_ROOM = "/api/Room/task_jump_room";//师徒任务 加入房间
|
||||
|
||||
public static final String UPDATEPASSWORD = "/api/room/setRoomPassword";//更新房间秘密啊
|
||||
public static final String GET_ROOM_ONLINE = "/api/Room/room_online_list";//房间在线列表
|
||||
@@ -360,9 +361,11 @@ public class Constants {
|
||||
public static final String POST_ROOM_RANKING = "/api/Ranking/room_ranking";//房间榜
|
||||
public static final String GUILD_RANKING = "/api/Ranking/guild_ranking";//公会榜
|
||||
public static final String POST_LOVE_RANKING = "/api/Ranking/love_ranking";//真爱榜
|
||||
public static final String GET_TASKS_LIHEN = "/api/Dailytasks/dailyTasksList";//每日任务列表
|
||||
public static final String GET_DAILY_TASK_BOX = "/api/Dailytasks/dailyTasksBoxRecord";//礼盒记录
|
||||
public static final String dailyTasksOpenBox = "/api/Dailytasks/dailyTasksOpenBox";//开启礼盒
|
||||
public static final String GET_TASKS_LIHEN = "/api/Tasks/dailyTasksList";//每日任务列表
|
||||
public static final String GET_DAILY_TASK_BOX = "/api/Tasks/dailyTasksBoxRecord";//礼盒记录
|
||||
public static final String dailyTasksOpenBox = "/api/Tasks/dailyTasksOpenBox";//开启礼盒
|
||||
public static final String dailyTasksReceive = "/api/Tasks/dailyTasksReceive";//领取每日任务奖励
|
||||
public static final String dailyTasksComplete = "/api/Tasks/dailyTasksComplete";//领取每日任务奖励
|
||||
public static final String GET_MY_BAG_DATA = "/api/UserGiftPack/get_gift_pack_income";//背包收入
|
||||
public static final String GET_MY_BAG_OUTCOME = "/api/UserGiftPack/get_gift_pack_outcome";//背包礼物支出列表
|
||||
public static final String GET_GIFT_PACK = "/api/UserGiftPack/get_gift_pack_list";//获取背包礼物列表
|
||||
@@ -386,9 +389,7 @@ public class Constants {
|
||||
public static final String GET_ACTIVITIES_PERMISSION = "/api/Activities/activities_permission";//活动弹框权限
|
||||
public static final String GET_INDEX_RECOMMEND_ROOM = "/api/Index/index_recommend_room";//首页弹窗推荐房间
|
||||
public static final String GET_DAY_DROP_GIFT = "/api/Activities/day_drop_gift";//天降好礼列表接口(弹框)
|
||||
public static final String dailyTasksReceive = "/api/Dailytasks/dailyTasksReceive";//领取每日任务奖励
|
||||
public static final String postRoomSwToken = "/api/Room/update_user_sw_token";//获取用户声网token
|
||||
public static final String dailyTasksComplete = "/api/Dailytasks/dailyTasksComplete";//领取每日任务奖励
|
||||
public static final String POST_CANCEL_USER_DECORATE = "/api/Decorate/cancel_user_decorate";//取消装扮
|
||||
public static final String GET_THEME_DATA = "/api/Theme/get_theme_data";//主题接口
|
||||
public static final String START_FRIEND = "/api/Friend/start_friend";//点击开始按钮 交友房
|
||||
|
||||
@@ -299,6 +299,7 @@
|
||||
<color name="EFF2F8">#EFF2F8</color>
|
||||
<color name="color_5B5B5B">#5B5B5B</color>
|
||||
<color name="color_C7BF62">#C7BF62</color>
|
||||
<color name="color_e3fae4">#FFE3FAE4</color>
|
||||
|
||||
|
||||
<!-- 主题色 -->
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.xscm.modulemain
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.blankj.utilcode.util.ActivityUtils
|
||||
import com.blankj.utilcode.util.AppUtils
|
||||
import com.blankj.utilcode.util.CrashUtils
|
||||
import com.blankj.utilcode.util.LogUtils
|
||||
@@ -12,12 +14,20 @@ import com.scwang.smartrefresh.layout.footer.ClassicsFooter
|
||||
import com.scwang.smartrefresh.layout.header.ClassicsHeader
|
||||
import com.xscm.modulemain.activity.main.activity.MainActivity
|
||||
import com.xscm.modulemain.dialog.InviteDialog
|
||||
import com.xscm.modulemain.manager.RoomManager
|
||||
import com.xscm.modulemain.utils.TimerManager
|
||||
import com.xscm.modulemain.widget.WheatLayoutSingManager
|
||||
import com.xscm.moduleutil.base.CommonAppContext
|
||||
import com.xscm.moduleutil.bean.IndexRecommendRoom
|
||||
import com.xscm.moduleutil.bean.RoomMessageEvent
|
||||
import com.xscm.moduleutil.dialog.ConfirmDialog
|
||||
import com.xscm.moduleutil.http.BaseObserver
|
||||
import com.xscm.moduleutil.http.RetrofitClient
|
||||
import com.xscm.moduleutil.listener.MessageListenerSingleton
|
||||
import com.xscm.moduleutil.utils.CustomMsgCode
|
||||
import io.reactivex.disposables.Disposable
|
||||
import org.json.JSONObject
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
open class Application : CommonAppContext() {
|
||||
@@ -66,7 +76,105 @@ open class Application : CommonAppContext() {
|
||||
initCrashUtils()
|
||||
initSmartRefreshLayout()
|
||||
|
||||
initImMsg()
|
||||
}
|
||||
|
||||
private fun initImMsg() {
|
||||
MessageListenerSingleton.getInstance().setOnMsgTaskListener { event ->
|
||||
when (event.msgType) {
|
||||
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM -> {
|
||||
TimerManager.cancelTimer(CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_TIMER_ID)
|
||||
val json = JSONObject(event.text.text)
|
||||
event.text.status = json.getString("status")
|
||||
event.text.room_id = json.getString("room_id")
|
||||
when (event.text.status) {
|
||||
"1" -> {//1:邀请
|
||||
customDialog(
|
||||
event.text.room_id,
|
||||
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_MSG,
|
||||
5,
|
||||
1,
|
||||
event.text
|
||||
)
|
||||
}
|
||||
|
||||
"2" -> {//2:拒绝
|
||||
customDialog(
|
||||
"",
|
||||
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_MSG_REFUSE,
|
||||
5,
|
||||
3,
|
||||
null,
|
||||
"知道了",
|
||||
""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun customDialog(
|
||||
roomId: String,
|
||||
message: String,
|
||||
downCount: Int,
|
||||
status: Int = 1,
|
||||
event: RoomMessageEvent.T?,
|
||||
confirm: String = "同意",
|
||||
cancel: String = "拒绝",
|
||||
) {
|
||||
// 创建并显示确认对话框
|
||||
ConfirmDialog(
|
||||
ActivityUtils.getTopActivity(),
|
||||
"提示",
|
||||
message,
|
||||
confirm,
|
||||
cancel,
|
||||
{ v: View? ->
|
||||
when (status) {
|
||||
1 -> {
|
||||
if (roomId.equals(CommonAppContext.getInstance().playId))
|
||||
return@ConfirmDialog
|
||||
RoomManager.getInstance()
|
||||
.fetchRoomDataAndEnter(ActivityUtils.getTopActivity(), roomId, "", "")
|
||||
}
|
||||
}
|
||||
},
|
||||
{ v: View? ->
|
||||
when (status) {
|
||||
1 -> {
|
||||
val text = RoomMessageEvent.T()
|
||||
val json = JSONObject()
|
||||
json.put("status", "2")
|
||||
text.text = json.toString()
|
||||
MessageListenerSingleton.getInstance().sendCustomC2CMessage(
|
||||
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM,
|
||||
event?.fromUserInfo?.user_id.toString(),
|
||||
text
|
||||
)
|
||||
}
|
||||
}
|
||||
}, true, downCount
|
||||
).show()
|
||||
}
|
||||
|
||||
fun inviteApprenticeTaskTimer() {
|
||||
TimerManager.scheduleTimer(
|
||||
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_TIMER_ID,
|
||||
15,
|
||||
TimeUnit.SECONDS,
|
||||
onTimeUp = {
|
||||
customDialog(
|
||||
"",
|
||||
CustomMsgCode.CODE_TASK_APPRENTICE_JOIN_ROOM_MSG_REFUSE,
|
||||
5,
|
||||
3,
|
||||
null,
|
||||
"知道了",
|
||||
""
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +190,7 @@ open class Application : CommonAppContext() {
|
||||
override fun onNext(t: IndexRecommendRoom) {
|
||||
LogUtils.e(t)
|
||||
if (!t.room_id.isNullOrEmpty()) {
|
||||
showInviteDialog(activity, t)
|
||||
showInviteDialog(activity, t)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -95,7 +203,7 @@ open class Application : CommonAppContext() {
|
||||
})
|
||||
}
|
||||
|
||||
fun showInviteDialog(activity: Activity?,t: IndexRecommendRoom) {
|
||||
fun showInviteDialog(activity: Activity?, t: IndexRecommendRoom) {
|
||||
if (inviteDialog == null) {
|
||||
inviteDialog = activity?.let { InviteDialog(it, t) }
|
||||
}
|
||||
|
||||
@@ -1142,5 +1142,9 @@ public abstract class BaseMvpActivity<P extends IPresenter, VDB extends ViewData
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void toActivity(Class<?> clazz) {
|
||||
Intent intent = new Intent(this, clazz);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.xscm.modulemain.activity.user.activity;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.xscm.modulemain.Application;
|
||||
import com.xscm.modulemain.R;
|
||||
import com.xscm.modulemain.adapter.TaskBoxAdapter;
|
||||
import com.xscm.modulemain.adapter.TaskDataAdapter;
|
||||
@@ -19,12 +21,18 @@ import com.xscm.modulemain.activity.user.presenter.DailyTasksPresenter;
|
||||
import com.xscm.modulemain.BaseMvpActivity;
|
||||
import com.xscm.modulemain.activity.WebViewActivity;
|
||||
import com.xscm.modulemain.manager.RoomManager;
|
||||
import com.xscm.moduleutil.bean.RoomMessageEvent;
|
||||
import com.xscm.moduleutil.bean.TaskDataBean;
|
||||
import com.xscm.moduleutil.utils.CustomMsgCode;
|
||||
import com.xscm.moduleutil.base.WebUrlConstants;
|
||||
import com.xscm.moduleutil.bean.GiftBoxBean;
|
||||
import com.xscm.moduleutil.bean.GiftName;
|
||||
import com.xscm.moduleutil.bean.TaskItem;
|
||||
import com.xscm.moduleutil.listener.MessageListenerSingleton;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -46,6 +54,8 @@ public class DailyTasksActivity extends BaseMvpActivity<DailyTasksPresenter, Act
|
||||
|
||||
private TaskDataAdapter taskDataAdapter;
|
||||
|
||||
private List<GiftBoxBean.TaskDataBean> taskList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected DailyTasksPresenter bindPresenter() {
|
||||
return new DailyTasksPresenter(this, this);
|
||||
@@ -78,6 +88,27 @@ public class DailyTasksActivity extends BaseMvpActivity<DailyTasksPresenter, Act
|
||||
mBinding.rvTask.setLayoutManager(new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false));
|
||||
mBinding.rvTask.setAdapter(mTaskBoxAdapter);
|
||||
|
||||
mBinding.rvTaskToday.setLayoutManager(new GridLayoutManager(this, 1));
|
||||
mTaskDataAdapter = new TaskSectionAdapter(taskList);
|
||||
mBinding.rvTaskToday.setAdapter(mTaskDataAdapter);
|
||||
|
||||
mTaskDataAdapter.setOnItemClickListener(new TaskSectionAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(GiftBoxBean.TaskDataBean taskItem, GiftBoxBean.TaskDataBean.DailyTasksBean item) {
|
||||
LogUtils.e("taskStatus:" + item.toString() + "\n taskItem:" + taskItem.toString());
|
||||
switch (item.getTask_status()) {
|
||||
case 1://未开始
|
||||
taskStatus1(item);
|
||||
break;
|
||||
case 2://待领取
|
||||
MvpPre.dailyTasksReceive(item.getTask_id() + "",item.getStudent_id());
|
||||
break;
|
||||
case 3://已完成
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mBinding.imGz.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(this, WebViewActivity.class);
|
||||
@@ -103,44 +134,46 @@ public class DailyTasksActivity extends BaseMvpActivity<DailyTasksPresenter, Act
|
||||
mBinding.tvTitle.setText("今日累计充值获得金币:" + (giftBoxBean.getUser_gold() != null ? giftBoxBean.getUser_gold() : "0"));
|
||||
mTaskBoxAdapter.setNewData(giftBoxBean.getGift_box_list());
|
||||
|
||||
mBinding.rvTaskToday.setLayoutManager(new GridLayoutManager(this, 1));
|
||||
|
||||
// List<TaskItem> sections = new ArrayList<>();
|
||||
// // 每日任务
|
||||
// sections.add(new TaskItem("今日任务", giftBoxBean.getTasks().getDaily_tasks()));
|
||||
// // 特殊任务
|
||||
// sections.add(new TaskItem("特殊任务", giftBoxBean.getTasks().getDaily_tasks_special()));//
|
||||
// // 师徒任务
|
||||
// if (giftBoxBean.getTasks().getTeacher_tasks() != null && giftBoxBean.getTasks().getTeacher_tasks().size() > 0) {
|
||||
// sections.add(new TaskItem("师徒任务", giftBoxBean.getTasks().getTeacher_tasks()));
|
||||
// }
|
||||
//
|
||||
// // 平台任务
|
||||
// sections.add(new TaskItem("平台任务", giftBoxBean.getTasks().getUsual_tasks()));
|
||||
mTaskDataAdapter = new TaskSectionAdapter(giftBoxBean.getTasks());
|
||||
mBinding.rvTaskToday.setAdapter(mTaskDataAdapter);
|
||||
mTaskDataAdapter.setOnItemClickListener(new TaskSectionAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(GiftBoxBean.TaskDataBean taskItem, GiftBoxBean.TaskDataBean.DailyTasksBean item) {
|
||||
// if (taskItem.getTitle().equals("今日任务") || taskItem.getTitle().equals("平台任务") || taskItem.getTitle().equals("师徒任务")) {
|
||||
// if (item.getTask_status() == 2) {
|
||||
// MvpPre.dailyTasksReceive(item.getTask_id() + "");
|
||||
// }
|
||||
// } else {
|
||||
// if (item.getTask_status() == 2) {
|
||||
// MvpPre.dailyTasksReceive(item.getTask_id() + "");
|
||||
// } else if (item.getTask_status() == 1) {
|
||||
// mBinding.coolWaitView.setVisibility(View.VISIBLE);
|
||||
// RoomManager.getInstance().fetchRoomDataAndEnter(DailyTasksActivity.this, item.getFrom_id(), "", item.getTask_id() + "");
|
||||
// finish();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
});
|
||||
taskList.clear();
|
||||
|
||||
giftBoxBean.getTasks().stream()
|
||||
.filter(task -> !task.getTask_list().isEmpty())
|
||||
.forEach(taskList::add);
|
||||
|
||||
mTaskDataAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void taskStatus1(GiftBoxBean.TaskDataBean.DailyTasksBean item) {
|
||||
switch (item.getJump_type()) {
|
||||
case 1:
|
||||
toActivity(RealNameActivity.class);
|
||||
break;
|
||||
case 2:
|
||||
toActivity(CreateAlbumActivity.class);
|
||||
break;
|
||||
case 3:
|
||||
toActivity(BindCardActivity.class);
|
||||
break;
|
||||
case 4:
|
||||
mBinding.coolWaitView.setVisibility(View.VISIBLE);
|
||||
MvpPre.taskJumpRoom(item, item.getTask_id() + "");
|
||||
break;
|
||||
case 5:
|
||||
//跳转加入公会
|
||||
Intent intent = new Intent(DailyTasksActivity.this, WebViewActivity.class);
|
||||
intent.putExtra("url", String.format(WebUrlConstants.INSTANCE.getWEB_GUILD_URL(), SpUtil.getToken(), ""));
|
||||
intent.putExtra("title", "公会");
|
||||
startActivity(intent);
|
||||
break;
|
||||
case 6:
|
||||
toActivity(RechargeActivity.class);
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
@@ -160,4 +193,34 @@ public class DailyTasksActivity extends BaseMvpActivity<DailyTasksPresenter, Act
|
||||
ToastUtils.show("任务完成");
|
||||
MvpPre.tasksLihen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskJumpRoom(GiftBoxBean.TaskDataBean.DailyTasksBean item, String roomId) {
|
||||
if (item.getFrom_id().equals("0")) {
|
||||
ToastUtils.show("暂无此类型房间。");
|
||||
mBinding.coolWaitView.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
switch (item.getTask_id()) {
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
RoomMessageEvent.T text = new RoomMessageEvent.T();
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("status", "1");
|
||||
jsonObject.put("room_id", roomId);
|
||||
text.setText(jsonObject.toString());
|
||||
MessageListenerSingleton.getInstance().sendCustomC2CMessage(
|
||||
CustomMsgCode.INSTANCE.getCODE_TASK_APPRENTICE_JOIN_ROOM(),
|
||||
item.getStudent_id(), text);
|
||||
Application.Companion.getInstance().inviteApprenticeTaskTimer();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
RoomManager.getInstance().fetchRoomDataAndEnter(DailyTasksActivity.this, roomId, "", "");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public class DailyTasksConacts {
|
||||
void dailyTasksOpenBox(GiftName giftName);
|
||||
|
||||
void dailyTasksComplete();
|
||||
void taskJumpRoom(GiftBoxBean.TaskDataBean.DailyTasksBean item,String taskId);
|
||||
|
||||
}
|
||||
|
||||
public interface IMePre extends IPresenter {
|
||||
@@ -23,7 +25,9 @@ public class DailyTasksConacts {
|
||||
|
||||
void dailyTasksOpenBox(String gift_box_id);
|
||||
|
||||
void dailyTasksReceive(String task_id);
|
||||
void dailyTasksReceive(String task_id,String student_id);
|
||||
|
||||
void taskJumpRoom(GiftBoxBean.TaskDataBean.DailyTasksBean item,String roomId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.xscm.modulemain.activity.user.conacts.DailyTasksConacts;
|
||||
import com.xscm.moduleutil.bean.GiftBoxBean;
|
||||
import com.xscm.moduleutil.bean.GiftName;
|
||||
import com.xscm.moduleutil.http.BaseObserver;
|
||||
import com.xscm.moduleutil.http.RetrofitClient;
|
||||
import com.xscm.moduleutil.presenter.BasePresenter;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
@@ -18,7 +19,7 @@ public class DailyTasksPresenter extends BasePresenter<DailyTasksConacts.View> i
|
||||
@Override
|
||||
public void tasksLihen() {
|
||||
|
||||
api.tasksLihen(new BaseObserver<GiftBoxBean>() {
|
||||
RetrofitClient.getInstance().tasksLihen(new BaseObserver<GiftBoxBean>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
addDisposable(d);
|
||||
@@ -33,7 +34,7 @@ public class DailyTasksPresenter extends BasePresenter<DailyTasksConacts.View> i
|
||||
|
||||
@Override
|
||||
public void dailyTasksOpenBox(String gift_box_id) {
|
||||
api.dailyTasksOpenBox(gift_box_id, new BaseObserver<GiftName>() {
|
||||
RetrofitClient.getInstance().dailyTasksOpenBox(gift_box_id, new BaseObserver<GiftName>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
addDisposable(d);
|
||||
@@ -47,8 +48,8 @@ public class DailyTasksPresenter extends BasePresenter<DailyTasksConacts.View> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dailyTasksReceive(String task_id) {
|
||||
api.dailyTasksReceive(task_id, new BaseObserver<String>() {
|
||||
public void dailyTasksReceive(String task_id,String student_id) {
|
||||
RetrofitClient.getInstance().dailyTasksReceive(task_id,student_id, new BaseObserver<String>() {
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -63,5 +64,21 @@ public class DailyTasksPresenter extends BasePresenter<DailyTasksConacts.View> i
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void taskJumpRoom(GiftBoxBean.TaskDataBean.DailyTasksBean item,String taskId) {
|
||||
RetrofitClient.getInstance().taskJumpRoomId(taskId, new BaseObserver<String>() {
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String s) {
|
||||
MvpRef.get().taskJumpRoom(item,s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.xscm.modulemain.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
@@ -39,13 +41,15 @@ public class TaskBoxAdapter extends BaseQuickAdapter<GiftBoxBean.GiftBean, BaseV
|
||||
giftName.setText(item.getName());
|
||||
giftTitle.setText(item.getTitle());
|
||||
if (position == 0) {
|
||||
itemView.setBackgroundColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_FCE4ED)); // 红色
|
||||
itemView.setBackgroundResource(R.drawable.shape_8);
|
||||
itemView.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFFCE4ED")));
|
||||
giftName.setTextColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_E24171));
|
||||
setSpannableText(giftTitle, "最高可获得%d金币", Integer.parseInt(item.getHighest_gain()),com.xscm.moduleutil.R.color.color_E24171);
|
||||
ImageUtils.loadSetErrorImg(item.getIcon(), helper.getView(R.id.task_box), com.xscm.moduleutil.R.mipmap.task_cj);
|
||||
} else if (position == 1) {
|
||||
itemView.setBackgroundResource(R.drawable.shape_8);
|
||||
itemView.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFFDE8AE")));
|
||||
ImageUtils.loadSetErrorImg(item.getIcon(), helper.getView(R.id.task_box), com.xscm.moduleutil.R.mipmap.task_gj);
|
||||
itemView.setBackgroundColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_FDE8AE)); // 黄色
|
||||
giftName.setTextColor(mContext.getResources().getColor(com.xscm.moduleutil.R.color.color_F35F07));
|
||||
setSpannableText(giftTitle, "最高可获得%d金币", Integer.parseInt(item.getHighest_gain()),com.xscm.moduleutil.R.color.color_F35F07);
|
||||
|
||||
@@ -73,11 +77,10 @@ public class TaskBoxAdapter extends BaseQuickAdapter<GiftBoxBean.GiftBean, BaseV
|
||||
helper.setText(R.id.iv_unlock, item.getStatus_str());
|
||||
View unlockView = helper.getView(R.id.iv_unlock);
|
||||
if (item.getStatus().equals("0")){
|
||||
// helper.setImageDrawable(R.id.iv_unlock, mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.not_unlocked));
|
||||
unlockView.setClickable(false);
|
||||
unlockView.setEnabled(false);
|
||||
// 可选:改变颜色或透明度来视觉反馈
|
||||
unlockView.setAlpha(0.9f); // 半透明表示不可点击
|
||||
unlockView.setAlpha(0.2f); // 半透明表示不可点击
|
||||
}else if (item.getStatus().equals("1")){
|
||||
unlockView.setClickable(true);
|
||||
unlockView.setEnabled(true);
|
||||
@@ -85,18 +88,10 @@ public class TaskBoxAdapter extends BaseQuickAdapter<GiftBoxBean.GiftBean, BaseV
|
||||
}else if (item.getStatus().equals("2")){
|
||||
unlockView.setClickable(false);
|
||||
unlockView.setEnabled(false);
|
||||
}
|
||||
else {
|
||||
// helper.setImageDrawable(R.id.iv_unlock, mContext.getResources().getDrawable(com.qxcm.moduleutil.R.mipmap.unlocked));
|
||||
|
||||
unlockView.setClickable(false);
|
||||
unlockView.setEnabled(false);
|
||||
// 可选:改变颜色或透明度来视觉反馈
|
||||
unlockView.setAlpha(0.8f); // 半透明表示不可点击
|
||||
unlockView.setAlpha(1.0f); // 恢复正常显示
|
||||
}
|
||||
|
||||
helper.getView(R.id.iv_unlock).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onItemClickListener != null) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TaskDataAdapter extends BaseQuickAdapter<GiftBoxBean.TaskDataBean.D
|
||||
TextView textView1= helper.getView(R.id.task_jb);
|
||||
|
||||
if (item.getTask_status()==1){
|
||||
textView.setText("未完成");
|
||||
textView.setText(item.getTask_type_str());
|
||||
}else if (item.getTask_status()==2){
|
||||
textView.setText("");
|
||||
textView.setBackgroundResource(com.xscm.moduleutil.R.mipmap.task_lq);
|
||||
@@ -52,17 +52,12 @@ public class TaskDataAdapter extends BaseQuickAdapter<GiftBoxBean.TaskDataBean.D
|
||||
// textView.setBackgroundResource(com.xscm.moduleutil.R.mipmap.task_ylq);
|
||||
// }
|
||||
|
||||
if (item.getReward_type()==1){
|
||||
textView1.setText("金币");
|
||||
}else if (item.getReward_type()==2){
|
||||
textView1.setText("钻石");
|
||||
}
|
||||
|
||||
|
||||
ImageUtils.loadHeadCC(item.getIcon(), helper.getView(R.id.task_pic));
|
||||
helper.setText(R.id.task_name, item.getTask_name())
|
||||
.setText(R.id.task_jb_number, "+"+item.getGold_reward());
|
||||
helper.setText(R.id.task_name, item.getTask_name());
|
||||
helper.setText(R.id.task_jb_number, item.getReward_str());
|
||||
helper.getView(R.id.task_type).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (mItemClickLitener!= null){
|
||||
|
||||
@@ -22,6 +22,7 @@ public class TaskSectionAdapter extends RecyclerView.Adapter<TaskSectionAdapter.
|
||||
public TaskSectionAdapter(List<GiftBoxBean.TaskDataBean> sections) {
|
||||
this.sections = sections;
|
||||
}
|
||||
|
||||
// 定义点击事件接口
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(GiftBoxBean.TaskDataBean taskItem, GiftBoxBean.TaskDataBean.DailyTasksBean item);
|
||||
@@ -32,6 +33,7 @@ public class TaskSectionAdapter extends RecyclerView.Adapter<TaskSectionAdapter.
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public SectionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@@ -42,24 +44,17 @@ public class TaskSectionAdapter extends RecyclerView.Adapter<TaskSectionAdapter.
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull SectionViewHolder holder, int position) {
|
||||
GiftBoxBean.TaskDataBean section = sections.get(position);
|
||||
|
||||
holder.title.setText(section.getTask_type_name());
|
||||
|
||||
TaskDataAdapter adapter = new TaskDataAdapter();
|
||||
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.itemView.getContext()));
|
||||
holder.recyclerView.setAdapter(adapter);
|
||||
adapter.setNewData(section.getTask_list());
|
||||
// if (position==2){
|
||||
// holder.view.setVisibility(View.VISIBLE);
|
||||
// }else {
|
||||
// holder.view.setVisibility(View.GONE);
|
||||
// }
|
||||
|
||||
adapter.setItemClickLitener(new TaskDataAdapter.ItemClickLitener() {
|
||||
@Override
|
||||
public void onItemClick(View view, int position, GiftBoxBean.TaskDataBean.DailyTasksBean item) {
|
||||
if (listener!= null) {
|
||||
listener.onItemClick(section,item);
|
||||
}
|
||||
adapter.setItemClickLitener((view, position1, item) -> {
|
||||
if (listener != null) {
|
||||
listener.onItemClick(section, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.xscm.modulemain.utils
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* 单例定时器管理类
|
||||
* 特性:
|
||||
* 1. 单例模式,全局唯一实例
|
||||
* 2. 支持多任务管理(通过taskId区分)
|
||||
* 3. 时间到触发回调,支持取消指定/所有定时器
|
||||
* 4. 线程安全,适配多线程场景
|
||||
*/
|
||||
object TimerManager {
|
||||
// 线程安全的ScheduledExecutorService(核心线程数1,足够处理定时任务)
|
||||
private val scheduler = Executors.newSingleThreadScheduledExecutor()
|
||||
|
||||
// 存储定时任务的Future(用于取消任务),ConcurrentHashMap保证线程安全
|
||||
private val taskMap = ConcurrentHashMap<String, ScheduledFuture<*>>()
|
||||
|
||||
/**
|
||||
* 启动一个定时任务
|
||||
* @param taskId 任务唯一标识(用于后续取消)
|
||||
* @param delay 延迟时间(比如5表示5秒/5分钟,取决于unit)
|
||||
* @param unit 时间单位(TimeUnit.SECONDS/TimeUnit.MILLISECONDS等)
|
||||
* @param onTimeUp 时间到的回调(默认在后台线程执行)
|
||||
*/
|
||||
fun scheduleTimer(
|
||||
taskId: String,
|
||||
delay: Long,
|
||||
unit: TimeUnit,
|
||||
onTimeUp: () -> Unit
|
||||
) {
|
||||
// 先取消同名任务(避免重复创建)
|
||||
if (taskMap.containsKey(taskId)) {
|
||||
cancelTimer(taskId)
|
||||
}
|
||||
|
||||
// 提交定时任务
|
||||
val future = scheduler.schedule({
|
||||
try {
|
||||
onTimeUp.invoke() // 执行回调
|
||||
taskMap.remove(taskId) // 执行完自动移除任务记录
|
||||
} catch (e: Exception) {
|
||||
// 捕获回调异常,避免影响定时器线程
|
||||
println("Timer task $taskId callback error: ${e.message}")
|
||||
}
|
||||
}, delay, unit)
|
||||
|
||||
// 记录任务Future
|
||||
taskMap[taskId] = future
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消指定的定时任务
|
||||
* @param taskId 任务唯一标识
|
||||
* @return 是否取消成功(true=取消成功/任务已执行;false=任务不存在)
|
||||
*/
|
||||
fun cancelTimer(taskId: String): Boolean {
|
||||
val future = taskMap.remove(taskId) ?: return false
|
||||
// mayInterruptIfRunning:是否中断正在执行的任务(这里设为false,避免强制中断)
|
||||
return future.cancel(false)
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消所有定时任务
|
||||
*/
|
||||
fun cancelAllTimers() {
|
||||
taskMap.values.forEach { it.cancel(false) }
|
||||
taskMap.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁定时器(应用退出时调用,释放资源)
|
||||
*/
|
||||
fun destroy() {
|
||||
cancelAllTimers()
|
||||
scheduler.shutdown() // 关闭线程池
|
||||
}
|
||||
}
|
||||
7
MainModule/src/main/res/drawable/shape_8.xml
Normal file
7
MainModule/src/main/res/drawable/shape_8.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners android:radius="@dimen/dp_8"/>
|
||||
<solid android:color="@android:color/white"/>
|
||||
</shape>
|
||||
@@ -11,7 +11,7 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/color_F8E3C8">
|
||||
android:background="@color/color_e3fae4">
|
||||
|
||||
<com.xscm.moduleutil.widget.CustomTopBar
|
||||
android:id="@+id/top_bar"
|
||||
@@ -28,13 +28,18 @@
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rl_top"
|
||||
android:layout_marginBottom="@dimen/dp_12"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_16"
|
||||
android:layout_marginTop="@dimen/dp_9"
|
||||
android:layout_marginEnd="@dimen/dp_16"
|
||||
android:background="@mipmap/task_t"
|
||||
>
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:layout_marginEnd="@dimen/dp_16">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:src="@mipmap/task_t"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
@@ -42,7 +47,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginStart="@dimen/dp_25"
|
||||
android:layout_marginTop="@dimen/dp_23"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:textColor="@color/white"
|
||||
tools:text="今日累计获取金币:20" />
|
||||
|
||||
@@ -53,7 +58,8 @@
|
||||
android:layout_below="@+id/tv_title"
|
||||
android:layout_marginTop="@dimen/dp_8"
|
||||
android:background="@drawable/bg_r16_fff"
|
||||
android:padding="@dimen/dp_16" />
|
||||
android:paddingHorizontal="@dimen/dp_11"
|
||||
android:paddingVertical="@dimen/dp_16" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -62,51 +68,34 @@
|
||||
android:id="@+id/rv_task_today"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/dp_12"
|
||||
android:paddingStart="@dimen/dp_16"
|
||||
android:paddingBottom="@dimen/dp_100"
|
||||
android:paddingEnd="@dimen/dp_16" />
|
||||
|
||||
|
||||
android:paddingEnd="@dimen/dp_16"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="@dimen/dp_100" />
|
||||
|
||||
</LinearLayout>
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:layout_marginTop="@dimen/dp_12"-->
|
||||
<!-- android:orientation="vertical"-->
|
||||
<!-- android:layout_below="@+id/rv_task">-->
|
||||
|
||||
|
||||
<!-- <androidx.recyclerview.widget.RecyclerView-->
|
||||
<!-- android:id="@+id/rv_task_today"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:layout_marginTop="@dimen/dp_12"-->
|
||||
<!-- android:paddingStart="@dimen/dp_16"-->
|
||||
<!-- android:paddingEnd="@dimen/dp_16" />-->
|
||||
<!-- </LinearLayout>-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/im_gz"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_80"
|
||||
android:src="@mipmap/task_gz"
|
||||
android:layout_marginTop="@dimen/dp_65"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/cool_wait_view"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<app.dinus.com.loadingdrawable.LoadingView
|
||||
android:layout_width="@dimen/dp_100"
|
||||
android:layout_height="@dimen/dp_100"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/item"
|
||||
android:layout_marginEnd="@dimen/dp_10"
|
||||
android:layout_marginHorizontal="@dimen/dp_7"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:custom="http://schemas.android.com/tools">
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_16"
|
||||
android:layout_marginTop="@dimen/dp_16"
|
||||
android:layout_marginEnd="@dimen/dp_16"
|
||||
android:layout_marginBottom="@dimen/dp_10">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_marginBottom="@dimen/dp_20">
|
||||
|
||||
<com.xscm.moduleutil.widget.GifAvatarOvalView
|
||||
android:id="@+id/task_pic"
|
||||
@@ -22,12 +20,10 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:layout_marginEnd="@dimen/dp_8"
|
||||
android:text="任务名称"
|
||||
android:layout_marginEnd="@dimen/dp_4"
|
||||
tools:text="任务名称"
|
||||
android:textColor="@color/color_FF333333"
|
||||
android:textSize="@dimen/sp_14"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintEnd_toStartOf="@+id/task_type"
|
||||
app:layout_constraintStart_toEndOf="@id/task_pic"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
@@ -35,9 +31,10 @@
|
||||
<TextView
|
||||
android:id="@+id/task_jb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_21"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:text="金币"
|
||||
android:visibility="gone"
|
||||
android:textColor="@color/color_FF999999"
|
||||
android:textSize="@dimen/sp_14"
|
||||
app:layout_constraintStart_toEndOf="@id/task_pic"
|
||||
@@ -45,12 +42,14 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_jb_number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_21"
|
||||
android:layout_marginStart="@dimen/dp_4"
|
||||
android:text="+10"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="@dimen/dp_4"
|
||||
tools:text="+10"
|
||||
android:gravity="start"
|
||||
android:textColor="#FF8827"
|
||||
android:textSize="@dimen/sp_14"
|
||||
app:layout_constraintEnd_toStartOf="@+id/task_type"
|
||||
app:layout_constraintStart_toEndOf="@id/task_jb"
|
||||
app:layout_constraintTop_toBottomOf="@id/task_name" />
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_12"
|
||||
android:layout_marginBottom="@dimen/dp_12"
|
||||
android:background="@drawable/bg_r16_fff"
|
||||
android:orientation="vertical">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
android:id="@+id/rv_task_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_12"
|
||||
android:layout_marginTop="@dimen/dp_14"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:paddingStart="@dimen/dp_16"
|
||||
android:paddingEnd="@dimen/dp_16" />
|
||||
|
||||
Reference in New Issue
Block a user