feat:完成房间榜流水展示
This commit is contained in:
@@ -12,6 +12,7 @@ import com.chwl.app.avroom.dialog.RoomTeamPKResultDialog;
|
||||
import com.chwl.app.avroom.dialog.RoomTeamPkDialog;
|
||||
import com.chwl.app.avroom.headline.RoomHeadlineWidget;
|
||||
import com.chwl.app.avroom.online.RoomOnlineWidget;
|
||||
import com.chwl.app.avroom.rank.RoomRankNumberWidget;
|
||||
import com.chwl.app.music.widget.MusicPlayerView;
|
||||
import com.chwl.app.ui.webview.DialogWebViewActivity;
|
||||
import com.chwl.core.room.pk.event.PKDataUpdateEvent;
|
||||
@@ -135,6 +136,7 @@ public class HomePartyRoomFragment extends BaseRoomFragment<IHomePartyView, Home
|
||||
super.initWidget();
|
||||
registerWidget(RoomOnlineWidget.class.getSimpleName(), gameBinding.onlineWidget);
|
||||
registerWidget(RoomHeadlineWidget.class.getSimpleName(), gameBinding.headlineWidget);
|
||||
registerWidget(RoomRankNumberWidget.class.getSimpleName(), gameBinding.rankNumberWidget);
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
|
@@ -0,0 +1,92 @@
|
||||
package com.chwl.app.avroom.rank
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import com.chwl.core.support.room.FrameLayoutRoomWidget
|
||||
import com.chwl.core.support.room.RoomWidget
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.databinding.RoomRankNumberWidgetBinding
|
||||
import com.chwl.app.ui.webview.DialogWebViewActivity
|
||||
import com.chwl.core.UriProvider
|
||||
import com.chwl.core.im.custom.bean.RoomSerialValueChangedAttachment
|
||||
import com.chwl.core.manager.AvRoomDataManager
|
||||
import com.chwl.core.manager.IMNetEaseManager
|
||||
import com.chwl.core.manager.RoomEvent
|
||||
import com.chwl.core.support.room.RoomContext
|
||||
import com.chwl.core.support.room.RoomView
|
||||
import com.chwl.library.utils.FormatUtils
|
||||
import com.example.lib_utils.ktx.singleClick
|
||||
|
||||
/**
|
||||
* 房间榜单入口
|
||||
*/
|
||||
class RoomRankNumberWidget : FrameLayoutRoomWidget, RoomWidget {
|
||||
|
||||
private val binding: RoomRankNumberWidgetBinding =
|
||||
DataBindingUtil.inflate(
|
||||
LayoutInflater.from(
|
||||
context
|
||||
), R.layout.room_rank_number_widget, this, true
|
||||
)
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet?,
|
||||
defStyleAttr: Int,
|
||||
defStyleRes: Int
|
||||
) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||
|
||||
init {
|
||||
this.singleClick {
|
||||
DialogWebViewActivity.start(context, UriProvider.getRoomRanking())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInitialize(roomView: RoomView, roomContext: RoomContext) {
|
||||
super.onInitialize(roomView, roomContext)
|
||||
refreshData()
|
||||
registerMemberChangedListener()
|
||||
}
|
||||
|
||||
override fun onUnbindContext() {
|
||||
super.onUnbindContext()
|
||||
updateView(null)
|
||||
}
|
||||
|
||||
private fun registerMemberChangedListener() {
|
||||
getCompositeDisposable().add(IMNetEaseManager.get().chatRoomEventObservable.subscribe {
|
||||
when (it.event) {
|
||||
RoomEvent.SERIAL_VALUE_CHANGED -> {
|
||||
val attachment =
|
||||
it.chatRoomMessage.attachment as? RoomSerialValueChangedAttachment
|
||||
attachment?.serialValue?.let {
|
||||
updateView(attachment.serialValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun refreshData() {
|
||||
val value = AvRoomDataManager.get().serialValue
|
||||
updateView(value)
|
||||
}
|
||||
|
||||
private fun updateView(value: Double?) {
|
||||
if (value == null || value <= 0) {
|
||||
binding.tvNumber.text = "0"
|
||||
} else {
|
||||
binding.tvNumber.text = FormatUtils.formatToShortKMHalfUp(value)
|
||||
}
|
||||
}
|
||||
}
|
@@ -101,32 +101,11 @@
|
||||
android:textSize="@dimen/dp_10" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_marginEnd="@dimen/dp_5"
|
||||
android:id="@+id/layout_room_rank"
|
||||
<com.chwl.app.avroom.rank.RoomRankNumberWidget
|
||||
android:id="@+id/rank_number_widget"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_16"
|
||||
android:background="@drawable/room_bg_hour_rank"
|
||||
android:gravity="center_vertical"
|
||||
android:onClick="@{click}"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="@dimen/dp_14"
|
||||
android:layout_height="@dimen/dp_14"
|
||||
android:layout_marginStart="@dimen/dp_3"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/room_ic_rank" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:layout_marginEnd="@dimen/dp_3"
|
||||
android:text="@string/room_rank"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/dp_10" />
|
||||
</LinearLayout>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/dp_5" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_music"
|
||||
|
31
app/src/main/res/layout/room_rank_number_widget.xml
Normal file
31
app/src/main/res/layout/room_rank_number_widget.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/layout_room_rank"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_16"
|
||||
android:background="@drawable/room_bg_hour_rank"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="@dimen/dp_14"
|
||||
android:layout_height="@dimen/dp_14"
|
||||
android:layout_marginStart="@dimen/dp_3"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/room_ic_rank" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/dp_2"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="@dimen/dp_5"
|
||||
android:text="0"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/dp_10" />
|
||||
</LinearLayout>
|
||||
</layout>
|
@@ -727,6 +727,13 @@ public class CustomAttachParser implements MsgAttachmentParser {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CustomAttachment.CUSTOM_MSG_ROOM_SERIAL_VALUE_CHANGED:
|
||||
switch (second) {
|
||||
case CustomAttachment.CUSTOM_MSG_ROOM_SERIAL_VALUE_CHANGED_SUB:
|
||||
attachment = new RoomSerialValueChangedAttachment(first, second);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LogUtils.e(ResUtil.getString(R.string.custom_bean_customattachparser_01) + first + " second=" + second);
|
||||
break;
|
||||
|
@@ -527,6 +527,13 @@ public class CustomAttachment implements MsgAttachment {
|
||||
public static final int CUSTOM_MSG_FAMILY_CREATE = 1107;
|
||||
public static final int CUSTOM_MSG_FAMILY_DISMISS = 1108;
|
||||
|
||||
|
||||
/**
|
||||
* 房间总流水
|
||||
*/
|
||||
public static final int CUSTOM_MSG_ROOM_SERIAL_VALUE_CHANGED = 111;
|
||||
public static final int CUSTOM_MSG_ROOM_SERIAL_VALUE_CHANGED_SUB = 1110;
|
||||
|
||||
/**
|
||||
* 自定义消息附件的类型,根据该字段区分不同的自定义消息
|
||||
*/
|
||||
|
@@ -0,0 +1,22 @@
|
||||
package com.chwl.core.im.custom.bean
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.alibaba.fastjson.JSONObject
|
||||
import com.chwl.core.bean.game.GameRoomInfo
|
||||
import com.chwl.library.utils.json.JsonUtils
|
||||
import com.google.gson.Gson
|
||||
|
||||
@Keep
|
||||
class RoomSerialValueChangedAttachment : CustomAttachment {
|
||||
|
||||
var serialValue: Double? = null
|
||||
|
||||
constructor() : super()
|
||||
constructor(first: Int, second: Int) : super(first, second)
|
||||
|
||||
override fun parseData(data: JSONObject?) {
|
||||
if (data?.contains("serialValue") == true) {
|
||||
serialValue = data.getDoubleValue("serialValue")
|
||||
}
|
||||
}
|
||||
}
|
@@ -231,6 +231,9 @@ public final class AvRoomDataManager {
|
||||
@Getter
|
||||
private boolean hasRoomAlbum;
|
||||
|
||||
@Getter
|
||||
private double serialValue;
|
||||
|
||||
private List<Integer> unlockedRoomAlbumPhotos = new ArrayList<>();
|
||||
|
||||
private AvRoomDataManager() {
|
||||
@@ -295,6 +298,7 @@ public final class AvRoomDataManager {
|
||||
pkBeginTime = roomInfo.getPkBeginTime();
|
||||
redEnvelopeType = roomInfo.getRedEnvelopeType();
|
||||
hasRoomAlbum = roomInfo.isHasRoomAlbum();
|
||||
serialValue = roomInfo.getSerialValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1488,6 +1488,11 @@ public final class IMNetEaseManager {
|
||||
noticeRoomEvent(msg, RoomEvent.TEMPLATE_NOTIFY);
|
||||
}
|
||||
break;
|
||||
case CUSTOM_MSG_ROOM_SERIAL_VALUE_CHANGED:
|
||||
if (second == CUSTOM_MSG_ROOM_SERIAL_VALUE_CHANGED_SUB) {
|
||||
noticeRoomEvent(msg, RoomEvent.SERIAL_VALUE_CHANGED);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -268,6 +268,9 @@ public class RoomEvent {
|
||||
//PK创建
|
||||
public static final int PK_CREATE = 111;
|
||||
|
||||
//房间流水
|
||||
public static final int SERIAL_VALUE_CHANGED = 112;
|
||||
|
||||
private int event = NONE;
|
||||
private int micPosition = Integer.MIN_VALUE;
|
||||
private int posState = -1;
|
||||
|
@@ -154,6 +154,8 @@ public class RoomInfo implements Parcelable,Serializable {
|
||||
private boolean showPkBeginTime;
|
||||
private long pkBeginTime;
|
||||
|
||||
// 总流水
|
||||
private double serialValue;
|
||||
|
||||
protected RoomInfo(Parcel in) {
|
||||
uid = in.readLong();
|
||||
@@ -216,6 +218,7 @@ public class RoomInfo implements Parcelable,Serializable {
|
||||
mgName = in.readString();
|
||||
mgMicNum = in.readInt();
|
||||
clearScreenTime = in.readLong();
|
||||
serialValue = in.readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -280,6 +283,7 @@ public class RoomInfo implements Parcelable,Serializable {
|
||||
dest.writeString(mgName);
|
||||
dest.writeInt(mgMicNum);
|
||||
dest.writeLong(clearScreenTime);
|
||||
dest.writeDouble(serialValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.chwl.library.utils;
|
||||
|
||||
|
||||
import com.chwl.library.R;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -165,4 +166,40 @@ public class FormatUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatToShortKMHalfUp(double num) {
|
||||
return formatToShortKM(num, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
public static String formatToShortKMDown(double num) {
|
||||
return formatToShortKM(num, RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把过长的金额类数字,转换成两位小数带K,M 缩写
|
||||
*
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static String formatToShortKM(double num, RoundingMode roundingMode) {
|
||||
try {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.#");
|
||||
decimalFormat.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.ENGLISH));
|
||||
decimalFormat.setRoundingMode(roundingMode);
|
||||
double K = Math.pow(10.0f, 3);
|
||||
double M = Math.pow(10.0f, 6);
|
||||
double resK = num / K;
|
||||
if (resK < 1) {
|
||||
return decimalFormat.format(num);
|
||||
} else {
|
||||
double resM = num / M;
|
||||
if (resM < 1) {
|
||||
return decimalFormat.format(resK) + "K";
|
||||
} else {
|
||||
return decimalFormat.format(resM) + "M";
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return String.valueOf(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user