From 239c27390bf96802a1f82dcc46c9099d13e52afb Mon Sep 17 00:00:00 2001 From: huangjian Date: Thu, 14 Apr 2022 17:11:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E6=92=AD=E7=B2=89=E4=B8=9D=E5=9B=A2?= =?UTF-8?q?=E5=BC=80=E9=80=9A=E7=B2=89=E4=B8=9D=E5=9B=A2UI=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/layout/activity_fans_team_join.xml | 4 +- .../manager/IMNetEaseManager.java | 4 +- .../xchat_android_core/manager/RoomEvent.java | 2 + .../praise/IPraiseModel.java | 2 + .../praise/PraiseModel.java | 34 +++++++++---- .../room/anotherroompk/SingleRoomPKModel.kt | 49 +++++++++---------- 6 files changed, 56 insertions(+), 39 deletions(-) diff --git a/app/src/main/res/layout/activity_fans_team_join.xml b/app/src/main/res/layout/activity_fans_team_join.xml index 8ec9a56a1..0c55000c4 100644 --- a/app/src/main/res/layout/activity_fans_team_join.xml +++ b/app/src/main/res/layout/activity_fans_team_join.xml @@ -234,8 +234,8 @@ isPraised(long uid, long isLikeUid); + boolean isPraised(long isLikeUid); + } diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/praise/PraiseModel.java b/core/src/main/java/com/yizhuan/xchat_android_core/praise/PraiseModel.java index b312545fb..a6f78e2eb 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/praise/PraiseModel.java +++ b/core/src/main/java/com/yizhuan/xchat_android_core/praise/PraiseModel.java @@ -1,6 +1,8 @@ package com.yizhuan.xchat_android_core.praise; import android.annotation.SuppressLint; +import android.util.LongSparseArray; +import android.util.SparseArray; import com.netease.nimlib.sdk.chatroom.ChatRoomMessageBuilder; import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage; @@ -23,6 +25,8 @@ import com.yizhuan.xchat_android_library.net.rxnet.RxNet; import org.greenrobot.eventbus.EventBus; +import java.util.HashMap; + import io.reactivex.Single; import io.reactivex.SingleSource; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -38,20 +42,17 @@ import retrofit2.http.Query; */ public class PraiseModel extends BaseModel implements IPraiseModel { + private final LongSparseArray praiseCache = new LongSparseArray<>(); private Api api = RxNet.create(Api.class); - private static final class Helper { - public static final PraiseModel INSTANCE = new PraiseModel(); + private PraiseModel() { + } public static PraiseModel get() { return Helper.INSTANCE; } - private PraiseModel() { - - } - /** * 1点赞,2取消 */ @@ -67,8 +68,8 @@ public class PraiseModel extends BaseModel implements IPraiseModel { @Override public SingleSource apply(ServiceResult stringServiceResult) throws Exception { if (stringServiceResult.isSuccess()) { - return Single.just(isPraise ? "点赞成功":"取消点赞成功"); - }else { + return Single.just(isPraise ? "点赞成功" : "取消点赞成功"); + } else { return Single.error(new Throwable(stringServiceResult.getMessage())); } } @@ -82,6 +83,8 @@ public class PraiseModel extends BaseModel implements IPraiseModel { if (roomInfo != null && roomInfo.getUid() == likedUid && isPraise) { PraiseModel.this.sendAttentionRoomTipMsg(likedUid); } + + praiseCache.put(likedUid, isPraise); UserModel.get().updateCurrentUserInfo().subscribe(); EventBus.getDefault().post(new PraiseEvent(isPraise, likedUid)); } @@ -94,10 +97,11 @@ public class PraiseModel extends BaseModel implements IPraiseModel { /** * 收藏房间成功 + * * @param targetUid */ @SuppressLint("CheckResult") - public void setFollowRoomSuccessRoomTip(long targetUid){ + public void setFollowRoomSuccessRoomTip(long targetUid) { UserModel.get().getUserInfo(targetUid).subscribe(new Consumer() { @Override public void accept(UserInfo userInfo) throws Exception { @@ -148,7 +152,7 @@ public class PraiseModel extends BaseModel implements IPraiseModel { public SingleSource apply(ServiceResult stringServiceResult) throws Exception { if (stringServiceResult.isSuccess()) { return Single.just("成功"); - }else { + } else { return Single.error(new Throwable(stringServiceResult.getMessage())); } } @@ -189,11 +193,17 @@ public class PraiseModel extends BaseModel implements IPraiseModel { @Override public void accept(Boolean aBoolean) throws Exception { EventBus.getDefault().post(new IsLikedEvent(aBoolean, isLikeUid)); + praiseCache.put(isLikeUid, aBoolean); } }); } + @Override + public boolean isPraised(long isLikeUid) { + return praiseCache.get(isLikeUid,false); + } + @SuppressLint("CheckResult") private void sendAttentionRoomTipMsg(long targetUid) { //如果关注的人不是房主,不显示公屏提示。 @@ -288,4 +298,8 @@ public class PraiseModel extends BaseModel implements IPraiseModel { @Query("isLikeUid") String isLikeUid); } + + private static final class Helper { + public static final PraiseModel INSTANCE = new PraiseModel(); + } } diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/room/anotherroompk/SingleRoomPKModel.kt b/core/src/main/java/com/yizhuan/xchat_android_core/room/anotherroompk/SingleRoomPKModel.kt index 47280dc51..0dbdac98c 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/room/anotherroompk/SingleRoomPKModel.kt +++ b/core/src/main/java/com/yizhuan/xchat_android_core/room/anotherroompk/SingleRoomPKModel.kt @@ -2,6 +2,7 @@ package com.yizhuan.xchat_android_core.room.anotherroompk import com.yizhuan.xchat_android_core.bean.response.ServiceResult import com.yizhuan.xchat_android_core.im.custom.bean.RoomPkBean +import com.yizhuan.xchat_android_core.manager.AvRoomDataManager import com.yizhuan.xchat_android_core.utils.net.RxHelper import com.yizhuan.xchat_android_library.net.rxnet.RxNet import io.reactivex.Single @@ -78,20 +79,6 @@ object SingleRoomPKModel { .compose(RxHelper.handleBeanData()) } - /** - * 跨房pk/牌照房搜索 - * - * @param roomUid roomUid - * - * @return - */ - fun getRoomPKData( - roomUid: Long - ): Single { - return api.getRoomPKData(roomUid) - .compose(RxHelper.handleSchAndExce()) - .compose(RxHelper.handleBeanData()) - } /** * 结束跨房PK @@ -108,6 +95,17 @@ object SingleRoomPKModel { .compose(RxHelper.handleStringData()) } + /** + * 获取个播PK规则说明 + * + * @return + */ + fun getSingleRoomPkRule(): Single { + return api.getSingleRoomPkRule(AvRoomDataManager.get().roomUid) + .compose(RxHelper.handleSchAndExce()) + .compose(RxHelper.handleStringData()) + } + private interface Api { /** * 发起挑战 @@ -152,17 +150,6 @@ object SingleRoomPKModel { @Query("pageSize") pageSize: Int ): Single>> - /** - * - * 获取PK数据 - * - * @return - */ - @FormUrlEncoded - @POST("/crossroompkround/getCrossPkData") - fun getRoomPKData( - @Field("roomUid") roomUid: Long? - ): Single> /** * @@ -176,7 +163,17 @@ object SingleRoomPKModel { @Field("roundId") roundId: String? ): Single> - + /** + *获取个播PK规则说明 + * + * + * @return + */ + @FormUrlEncoded + @POST("/crossroompkround/getSingleRoomPkRule") + fun getSingleRoomPkRule( + @Field("roomUid") roomUid: Long? + ): Single> } } \ No newline at end of file