From cc6f055ce06f18ba62b94630f6e54aae01dfa422 Mon Sep 17 00:00:00 2001 From: oujunhui <313127320@qq.com> Date: Mon, 6 Jul 2020 18:38:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7gradle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android_crop_lib/build.gradle | 6 ++ app/accompany/release/output.json | 1 - app/build.gradle | 3 + .../yizhuan/erban/bindadapter/RvAdapter.java | 25 ++---- .../res/layout/activity_recyclerview_bind.xml | 2 - build.gradle | 4 +- core/build.gradle | 7 ++ .../xchat_android_core/community/UserVo.kt | 26 ++++++ .../im/custom/bean/CustomAttachParser.java | 20 +++++ .../im/custom/bean/CustomAttachment.java | 13 ++- .../im/custom/bean/RedPackageAttachment.java | 33 ++++++++ .../bean/RedPackageRoomMsgAttachment.java | 33 ++++++++ .../redpackage/RedEnvelopeGiftItemVO.kt | 9 ++ .../redpackage/RedEnvelopeItemVO.kt | 11 +++ .../redpackage/RedEnvelopeRoomMsg.kt | 40 +++++++++ .../redpackage/RedEnvelopeState.kt | 23 ++++++ .../redpackage/RedEnvelopeVO.kt | 23 ++++++ .../redpackage/RedPackageInfo.kt | 18 ++++ .../redpackage/RedPackageModel.kt | 82 +++++++++++++++++++ .../redpackage/RedPackageNotifyInfo.kt | 41 ++++++++++ .../redpackage/RedPackageType.kt | 6 ++ .../utils/CurrentTimeUtils.java | 15 ++++ .../utils/StringExtension.kt | 24 ++++++ .../utils/net/RxExtension.kt | 80 ++++++++++++++++++ gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 6 ++ nim_uikit/build.gradle | 7 ++ 28 files changed, 537 insertions(+), 25 deletions(-) delete mode 100644 app/accompany/release/output.json create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/community/UserVo.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageAttachment.java create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageRoomMsgAttachment.java create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeGiftItemVO.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeItemVO.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeRoomMsg.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeState.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeVO.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageInfo.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageModel.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageNotifyInfo.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageType.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/utils/CurrentTimeUtils.java create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/utils/StringExtension.kt create mode 100644 core/src/main/java/com/yizhuan/xchat_android_core/utils/net/RxExtension.kt diff --git a/android_crop_lib/build.gradle b/android_crop_lib/build.gradle index d62065705..bac08935a 100644 --- a/android_crop_lib/build.gradle +++ b/android_crop_lib/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { compileSdkVersion 29 @@ -24,5 +25,10 @@ android { dependencies { api 'androidx.annotation:annotation:1.1.0' api 'androidx.legacy:legacy-support-v4:1.0.0' + implementation "androidx.core:core-ktx:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/app/accompany/release/output.json b/app/accompany/release/output.json deleted file mode 100644 index f89997f5c..000000000 --- a/app/accompany/release/output.json +++ /dev/null @@ -1 +0,0 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":100,"versionName":"1.0.0","enabled":true,"outputFile":"accompany_release_v1.0.0-05152110.apk","fullName":"accompanyRelease","baseName":"accompany-release"},"path":"accompany_release_v1.0.0-05152110.apk","properties":{}}] \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 26ced13aa..08160600b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,6 +2,9 @@ apply plugin: 'com.android.application' // android res guard 资源混淆脚本 apply from: 'and_res_guard.gradle' +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 diff --git a/app/src/main/java/com/yizhuan/erban/bindadapter/RvAdapter.java b/app/src/main/java/com/yizhuan/erban/bindadapter/RvAdapter.java index 89af91718..67a3a9d4d 100644 --- a/app/src/main/java/com/yizhuan/erban/bindadapter/RvAdapter.java +++ b/app/src/main/java/com/yizhuan/erban/bindadapter/RvAdapter.java @@ -15,37 +15,30 @@ import java.util.List; public class RvAdapter { /** * 实现adapter加载更多的一些处理与rv的映射 + * * @param recyclerView - * @param date rv的数据 - * @param newData 每次加载回的数控 + * @param date rv的数据 + * @param newData 每次加载回的数控 * @param isLode * @param throwable * @param pageSize * @param */ - @BindingAdapter(value = {"date", "newData", "isLode", "error", "pageSize", "loadMoreListener"}, requireAll = false) - public static void bindRvData(RecyclerView recyclerView, List date, List newData, boolean isLode, - Throwable throwable, int pageSize, BaseQuickAdapter.RequestLoadMoreListener loadMoreListener) { + @BindingAdapter(value = {"date", "newData", "isLode", "error", "pageSize"}, requireAll = false) + public static void bindRvData(RecyclerView recyclerView, List date, List newData, boolean isLode, Throwable throwable, int pageSize) { BaseAdapter adapter = (BaseAdapter) recyclerView.getAdapter(); - if (loadMoreListener != null) { - adapter.setOnLoadMoreListener(loadMoreListener, recyclerView); - } adapter.setNewData(date); - if (throwable!=null){ + if (throwable != null) { adapter.loadMoreFail(); return; } - if ( newData==null || newData.size() @@ -37,7 +36,6 @@ isLode="@{viewmodel.isLode}" newData="@{viewmodel.loadData}" pageSize="@{viewmodel.pageSize}" - loadMoreListener="@{viewmodel.loadMoreListener}" android:layout_width="match_parent" android:layout_height="match_parent"> diff --git a/build.gradle b/build.gradle index 00bdd0c38..21d5eceba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.61' println "\n\n\n" println '当前选择版本 Version Name:'+ version_name @@ -13,11 +14,12 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.6.2' //realm 数据库插件 classpath "io.realm:realm-gradle-plugin:5.3.0" // android 资源混淆插件 classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.15' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/core/build.gradle b/core/build.gradle index 37e2fa1f9..a9bfc15d9 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'realm-android' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 @@ -123,4 +125,9 @@ dependencies { api project(':nim_uikit') api project(':library') api project(':agora-ktv-kit-release') + implementation "androidx.core:core-ktx:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/community/UserVo.kt b/core/src/main/java/com/yizhuan/xchat_android_core/community/UserVo.kt new file mode 100644 index 000000000..678b53f49 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/community/UserVo.kt @@ -0,0 +1,26 @@ +package com.yizhuan.xchat_android_core.community + +import com.yizhuan.xchat_android_core.decoration.headwear.bean.HeadWearInfo +import com.yizhuan.xchat_android_core.utils.CurrentTimeUtils +import java.io.Serializable + + +data class UserVo( + var erbanNo: Long = 0, + var uid: Long = 0, + var birth: Long = 0, + var nick: String? = null, + var gender: Int = 0, + var avatar: String? = null, + var isHasRegPacket: Boolean = false, + var userHeadwear: HeadWearInfo? = null +) : Serializable { + var age : Int = 0 + get() { + if (field != 0) return field + val current = CurrentTimeUtils.getCurrentTime() + var age = current - birth + age = age / 1000 / 60 / 60 / 24 / 365 + return if (age >= 0) age.toInt() else 0 + } +} \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java index e82396f4d..7b4f31777 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java @@ -67,6 +67,7 @@ import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUS import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_MODULE_HALL; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUBLIC_CHAT_HALL; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_QUEUING_MIC; +import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_ROOM_GIFT_VALUE; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHARE_FAMILY; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHARE_MINI_WORLD; @@ -82,6 +83,11 @@ import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUS import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_AIT_ME; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_FULL_SCREEN; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_GIFT; +import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND; +import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_GIFT; +import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_DIAMOND; +import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_GIFT; +import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_MSG; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_TYPE_RECEIVE_LUCKY_MONEY; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_TYPE_SEND_ADD_BLACK; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_TYPE_SEND_KICK_ROOM; @@ -405,6 +411,20 @@ public class CustomAttachParser implements MsgAttachmentParser { } break; + case CUSTOM_MSG_RED_PACKAGE: + switch (second) { + case CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_GIFT: + case CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_DIAMOND: + case CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_GIFT: + case CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND: + attachment = new RedPackageAttachment(second); + break; + case CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_MSG: + attachment = new RedPackageRoomMsgAttachment(second); + break; + } + break; + case CUSTOM_MSG_LEAVE_MODE: if (second == CUSTOM_MSG_LEAVE_MODE_NOTICE) { attachment = new LeaveModeAttachment(); diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java index 6491cbe93..57fbf40d0 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java @@ -288,7 +288,6 @@ public class CustomAttachment implements MsgAttachment { public static final int CUSTOM_MSG_ROOM_FOLLOW_2 = 467;//在房间的公屏上关注房主,第二个 public static final int CUSTOM_MSG_ROOM_FOLLOW_SUCCESS = 468;//在房间的关注房主,第二个 - //全服广播 public static final int CUSTOM_MSG_HEADER_ALL_SERVICE_PUSH = 49; public static final int CUSTOM_MSG_SUB_TYPE_PUSH_APP_TO_UPDATE = 491;//推送App更新消息 @@ -339,9 +338,17 @@ public class CustomAttachment implements MsgAttachment { public static final int CUSTOM_MSG_HEADER_TYPE_COMMON_SYS_NOTICATION = 58; public static final int CUSTOM_MSG_SUB_TYPE_FIRST_RECHARGE_SUCCESS = 581; //首充成功 - //收藏房间 + //收藏房间消息 public static final int CUSTOM_MSG_HEADER_TYPE_FOLLOW_ROOM = 59; - public static final int CUSTOM_MSG_SUB_TYPE_FOLLOW_ROOM_SUCCESS = 591; //首充成功 + public static final int CUSTOM_MSG_SUB_TYPE_FOLLOW_ROOM_SUCCESS = 591; + + //红包消息 + public static final int CUSTOM_MSG_RED_PACKAGE = 60; + public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_GIFT = 601; + public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_DIAMOND = 602; + public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_GIFT = 603; + public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND = 604; + public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_MSG = 605; public CustomAttachment() { diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageAttachment.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageAttachment.java new file mode 100644 index 000000000..30a701dfb --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageAttachment.java @@ -0,0 +1,33 @@ +package com.yizhuan.xchat_android_core.im.custom.bean; + +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.yinyuan.xchat_android_core.redpackage.RedPackageNotifyInfo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Created by MadisonRong on 17/06/2018. + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class RedPackageAttachment extends CustomAttachment { + + private RedPackageNotifyInfo redPackageNotifyInfo; + + public RedPackageAttachment(int second) { + super(CUSTOM_MSG_RED_PACKAGE, second); + } + + @Override + protected void parseData(JSONObject data) { + redPackageNotifyInfo = new Gson().fromJson(data.toJSONString(), RedPackageNotifyInfo.class); + } + + @Override + protected JSONObject packData() { + String jsonStr = new Gson().toJson(redPackageNotifyInfo); + return JSONObject.parseObject(jsonStr); + } +} diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageRoomMsgAttachment.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageRoomMsgAttachment.java new file mode 100644 index 000000000..da13fb0d7 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RedPackageRoomMsgAttachment.java @@ -0,0 +1,33 @@ +package com.yizhuan.xchat_android_core.im.custom.bean; + +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.yinyuan.xchat_android_core.redpackage.RedEnvelopeRoomMsg; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Created by MadisonRong on 17/06/2018. + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class RedPackageRoomMsgAttachment extends CustomAttachment { + + private RedEnvelopeRoomMsg redEnvelopeRoomMsg; + + public RedPackageRoomMsgAttachment(int second) { + super(CUSTOM_MSG_RED_PACKAGE, second); + } + + @Override + protected void parseData(JSONObject data) { + redEnvelopeRoomMsg = new Gson().fromJson(data.toJSONString(), RedEnvelopeRoomMsg.class); + } + + @Override + protected JSONObject packData() { + String jsonStr = new Gson().toJson(redEnvelopeRoomMsg); + return JSONObject.parseObject(jsonStr); + } +} diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeGiftItemVO.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeGiftItemVO.kt new file mode 100644 index 000000000..f5dbb8d9e --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeGiftItemVO.kt @@ -0,0 +1,9 @@ +package com.yinyuan.xchat_android_core.redpackage + +import com.yizhuan.xchat_android_core.gift.bean.GiftInfo + + +data class RedEnvelopeGiftItemVO( + var giftNum: Int = 0, + var giftVo: GiftInfo? = null +) \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeItemVO.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeItemVO.kt new file mode 100644 index 000000000..31b7e5940 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeItemVO.kt @@ -0,0 +1,11 @@ +package com.yinyuan.xchat_android_core.redpackage + +import com.yizhuan.xchat_android_core.community.UserVo + + +class RedEnvelopeItemVO( + var amount: String, + var createTime: Long = 0, + var redEnvelopeGiftItemVOs: List? = null, + var userVO: UserVo +) \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeRoomMsg.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeRoomMsg.kt new file mode 100644 index 000000000..e119b7d83 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeRoomMsg.kt @@ -0,0 +1,40 @@ +package com.yinyuan.xchat_android_core.redpackage + +import java.io.Serializable + +/** + * 开红包发送公屏信息 + */ +data class RedEnvelopeRoomMsg( + + /** + * 开红包者 uid + */ + var openRedEnvelopeId: String = "", + + /** + * 开红包者昵称 + */ + var openRedEnvelopeUserNick: String = "", + + /** + * 红包类型 + */ + var redEnvelopeType: Int = 0, + + /** + * 红包金额 + */ + var amount: Double = 0.0, + + /** + * 红包主人 uid + */ + var redEnvelopeMasterId: Long = 0, + + /** + * 红包主人昵称 + */ + var redEnvelopeMasterNick: String = "" + +) : Serializable \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeState.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeState.kt new file mode 100644 index 000000000..4f26b08c0 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeState.kt @@ -0,0 +1,23 @@ +package com.yinyuan.xchat_android_core.redpackage + +/** + * 红包状态 + */ +interface RedEnvelopeState { + companion object { + /** + * ING(1, “开抢中”) + * TIME_OUT(2, “过时”) + * REMAIN_ZERO(3, “抢光了”) + * SUCCESS(4, “抢到了”) + * WILL(5, “将要开始”) + * TIME_OUT_BACK(6, “超时已退还”) + */ + const val ING = 1 + const val TIME_OUT = 2 + const val REMAIN_ZERO = 3 + const val SUCCESS = 4 + const val WILL = 5 + const val TIME_OUT_BACK = 6 + } +} \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeVO.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeVO.kt new file mode 100644 index 000000000..4b4b97b75 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedEnvelopeVO.kt @@ -0,0 +1,23 @@ +package com.yinyuan.xchat_android_core.redpackage + +import com.yizhuan.xchat_android_core.community.UserVo + + +data class RedEnvelopeVO( + var beginTime: Long = 0, + var createTime: Long = 0, + var endTime: Long = 0, + var id: String, + var message: String, + var redEnvelopeAmount: Double = 0.0, + var roomUId: Long = 0, + /** + * 红包类型 1:房间水晶红包 2:全服水晶红包 3:房间礼物红包 4:全服礼物红包 + */ + var type: Int = 0, + var updateTime: Long = 0, + var userId: Long = 0, + var totalNum: String = "", + var pickNum: String = "", + var userVO: UserVo? = null +) \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageInfo.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageInfo.kt new file mode 100644 index 000000000..611fa9023 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageInfo.kt @@ -0,0 +1,18 @@ +package com.yinyuan.xchat_android_core.redpackage + + +data class RedPackageInfo( + var redEnvelopeItemVOs: List? = null, + var redEnvelopeVO: RedEnvelopeVO? = null, + + /** + * ING(1, “开抢中”) + * TIME_OUT(2, “过时”) + * REMAIN_ZERO(3, “抢光了”) + * SUCCESS(4, “抢到了”) + * WILL(5, “将要开始”) + * TIME_OUT_BACK(6, “超时已退还”) + */ + var redEnvelopeState: Int = 0 + +) \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageModel.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageModel.kt new file mode 100644 index 000000000..ae4b152fe --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageModel.kt @@ -0,0 +1,82 @@ +package com.yinyuan.xchat_android_core.redpackage + + + +import com.yizhuan.xchat_android_core.bean.response.ServiceResult +import com.yizhuan.xchat_android_core.utils.net.handleBeanData +import com.yizhuan.xchat_android_core.utils.net.handleStringData +import com.yizhuan.xchat_android_core.utils.net.io2main +import com.yizhuan.xchat_android_library.net.rxnet.RxNet +import io.reactivex.Observable +import io.reactivex.Single +import retrofit2.http.* + +object RedPackageModel { + + + private val api: Api + + init { + api = RxNet.create(Api::class.java) + } + + fun sendRedPackage(goldNum: String, message: String, num: String, roomUId: String, type: Int, password: String): Single { + return api.sendRedPackage(goldNum, message, num, roomUId, type, password) + .io2main() + .handleStringData() + } + + + fun openRedPackage(redEnvelopeId: String): Single { + return api.openRedPackage(redEnvelopeId) + .io2main() + .handleBeanData() + } + + fun getRedPackage(uid: Long): Observable { + return api.getRedPackage(uid) + .io2main() + .handleBeanData() + .toObservable() + .flatMap { Observable.fromIterable(it) } + .map { RedPackageNotifyInfo(it.id, it.type, it.message, it.userVO?.avatar?:"", it.userVO?.nick?:"", it.roomUId, "") } + } + + private interface Api { + + /** + * 发红包 + * + * @return + */ + @FormUrlEncoded + @POST("/red-envelope") + fun sendRedPackage(@Field("goldNum") goldNum: String, + @Field("message") message: String, + @Field("num") num: String, + @Field("roomUId") roomUId: String, + @Field("type") type: Int, + @Field("password") password: String): Single> + + /** + * 开红包 + * + * @return + */ + @FormUrlEncoded + @POST("/red-envelope/open") + fun openRedPackage(@Field("redEnvelopeId") redEnvelopeId: String): Single> + + + /** + * 当前可以领取的红包 + * + * @return + */ + @GET("/room/red-envelop") + fun getRedPackage(@Query("uid") uid: Long): Single>> + } + + +} + diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageNotifyInfo.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageNotifyInfo.kt new file mode 100644 index 000000000..b5a679f91 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageNotifyInfo.kt @@ -0,0 +1,41 @@ +package com.yinyuan.xchat_android_core.redpackage + +import java.io.Serializable + +data class RedPackageNotifyInfo( + + /** + * 红包 id + */ + var redEnvelopeId: String = "", + + /** + * 红包类型 + */ + var redEnvelopeType: Int = 0, + + /** + * 红包消息 + */ + var redEnvelopeMessage: String = "", + + /** + * 红包发送者头像 + */ + var sendUserAvatar: String = "", + + /** + * 红包发送者昵称 + */ + var sendUserNick: String = "", + /** + * 房间uid + */ + var roomUid: Long = 0, + + /** + * 房间名称 + */ + var roomTitle: String = "" + +) : Serializable \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageType.kt b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageType.kt new file mode 100644 index 000000000..c014c678b --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/redpackage/RedPackageType.kt @@ -0,0 +1,6 @@ +package com.yinyuan.xchat_android_core.redpackage + +const val ROOM_DIAMOND = 1 +const val ROOM_GIFT = 3 +const val ALL_DIAMOND = 2 +const val ALL_GIFT = 4 diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/utils/CurrentTimeUtils.java b/core/src/main/java/com/yizhuan/xchat_android_core/utils/CurrentTimeUtils.java new file mode 100644 index 000000000..d13a2414e --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/utils/CurrentTimeUtils.java @@ -0,0 +1,15 @@ +package com.yizhuan.xchat_android_core.utils; + +public class CurrentTimeUtils { + + private static long offsetTime; + + public static void initTime(long currentTime) { + if (currentTime == 0) return; + offsetTime = System.currentTimeMillis() - currentTime; + } + + public static long getCurrentTime() { + return System.currentTimeMillis() - offsetTime; + } +} diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/utils/StringExtension.kt b/core/src/main/java/com/yizhuan/xchat_android_core/utils/StringExtension.kt new file mode 100644 index 000000000..6181d1d2e --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/utils/StringExtension.kt @@ -0,0 +1,24 @@ +package com.yizhuan.xchat_android_core.utils + +import com.yizhuan.xchat_android_library.utils.SingleToastUtil + + +fun String?.subAndReplaceDot(maxLength: Int = 6): String { + if (this == null) return "" + return if (this.length > maxLength) this.substring(0, maxLength) + "..." else this +} + +fun String?.toIntOrDef(def: Int = 0): Int { + return this?.toIntOrNull() ?: def +} + +fun String?.toDoubleOrDef(def: Double = 0.0): Double { + return this?.toDoubleOrNull() ?: def +} + +fun String?.toast() { + SingleToastUtil.showToast(this) +} + +inline fun String?.ifNullOrEmpty(defaultValue: () -> String): String = + if (this.isNullOrEmpty()) defaultValue() else this \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/utils/net/RxExtension.kt b/core/src/main/java/com/yizhuan/xchat_android_core/utils/net/RxExtension.kt new file mode 100644 index 000000000..7ef93873b --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/utils/net/RxExtension.kt @@ -0,0 +1,80 @@ +package com.yizhuan.xchat_android_core.utils.net + + +import com.yizhuan.xchat_android_core.bean.response.ServiceResult +import com.yizhuan.xchat_android_core.utils.ifNullOrEmpty +import io.reactivex.Single +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.schedulers.Schedulers +import java.io.IOException + +/** + * 这里简单对接口脱掉外层,不适合成功情况下没有data字段的接口使用 + * + * @param + * @return + */ + +fun Single>.handleBeanData(): Single { + return this.handleException() + .flatMap { + if (it.isSuccess) { + if (it.data != null) { + return@flatMap Single.just(it.data) + } else { + return@flatMap Single.error(Throwable("成功情况下接口返回data字段可以为空,不适合使用此方法脱掉外层。")) + } + } else { + return@flatMap Single.error(Throwable(it.message.ifNullOrEmpty { "未知错误" })) + } + } + + +} + +/** + * data是String的接口服务器返回的data可能是空的,写个String专用的,主要是进行了判空处理... + * + * @return + */ +fun Single>.handleStringData(): Single { + return this.handleException() + .flatMap { + if (it.isSuccess) { + return@flatMap Single.just(it.data.ifNullOrEmpty { "成功" }) + } else { + return@flatMap Single.error(Throwable(it.message.ifNullOrEmpty { "未知错误" })) + } + } + +} + +/** + * 统一IOException处理,请求接口报IOException基本是网络不正常导致的 + * + * @param + * @return + */ + +fun Single.handleException(): Single { + return this.onErrorResumeNext { + if (it is IOException) { + return@onErrorResumeNext Single.error(Throwable("网络异常,请检查您的网络再试...")) + } + Single.error(it) + } + +} + +/** + * 接口线程调度 + * + * @param + * @return + */ +fun Single.io2main(): Single { + return this.subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + +} + diff --git a/gradle.properties b/gradle.properties index 4f695f9c1..a61190b1b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ org.gradle.daemon=true # org.gradle.parallel=true android.enableD8=true android.injected.testOnly=false - +android.useNewApkCreator=false android.useAndroidX=true android.enableJetifier=true with_jenkins=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 69ed8a555..1a71ae044 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip diff --git a/library/build.gradle b/library/build.gradle index 120b68132..50b96b4c4 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { compileSdkVersion 29 @@ -85,5 +86,10 @@ dependencies { api "com.qiniu:qiniu-android-sdk:${qiniu}" api "org.greenrobot:eventbus:${eventbusVersion}" + implementation "androidx.core:core-ktx:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } +repositories { + mavenCentral() +} diff --git a/nim_uikit/build.gradle b/nim_uikit/build.gradle index 741d7c37f..41928ef6f 100644 --- a/nim_uikit/build.gradle +++ b/nim_uikit/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 @@ -67,5 +69,10 @@ dependencies { annotationProcessor "com.github.bumptech.glide:compiler:${glideVersion}" implementation project(':library') + implementation "androidx.core:core-ktx:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } +repositories { + mavenCentral() +}