1.PK值格式化样式修改

2.按人数PK公屏增加胜利方战斗值展示
This commit is contained in:
huangjian
2020-12-22 11:26:13 +08:00
parent 2234726c19
commit 61fbc15809
8 changed files with 77 additions and 55 deletions

View File

@@ -83,7 +83,7 @@ public class RecordForPKAdapter extends BaseQuickAdapter<PKRecordInfo, BaseViewH
PKTeamInfo teamBlue = findPKTeam(PKTeamInfo.TEAM_BLUE, item.getTeams());
if (teamRed != null) {
tvRedTeamScore.setText(FormatUtils.formatToShortHalfUp(teamRed.getScore()));
tvRedTeamScore.setText(FormatUtils.formatPKValue(teamRed.getScore()));
for (int i = 0; i < redTeamMemberViews.size(); i++) {
if (i < teamRed.getTeamMembers().size()) {
PKTeamMember pkTeamMember = teamRed.getTeamMembers().get(i);
@@ -96,7 +96,7 @@ public class RecordForPKAdapter extends BaseQuickAdapter<PKRecordInfo, BaseViewH
}
if (teamBlue != null) {
tvBlueTeamScore.setText(FormatUtils.formatToShortHalfUp(teamBlue.getScore()));
tvBlueTeamScore.setText(FormatUtils.formatPKValue(teamBlue.getScore()));
for (int i = 0; i < blueTeamMemberViews.size(); i++) {
if (i < teamBlue.getTeamMembers().size()) {
PKTeamMember pkTeamMember = teamBlue.getTeamMembers().get(i);

View File

@@ -3,9 +3,11 @@ package com.yizhuan.erban.avroom.dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
@@ -26,6 +28,7 @@ import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.room.pk.bean.PKTeamInfo;
import com.yizhuan.xchat_android_core.room.pk.bean.PKTeamMember;
import com.yizhuan.xchat_android_core.room.pk.bean.RoomPkData;
import com.yizhuan.xchat_android_library.utils.FormatUtils;
import java.util.ArrayList;
import java.util.List;
@@ -142,7 +145,7 @@ public class PKResultDialog extends BaseDialog {
llGuardianName.setVisibility(View.GONE);
llGuardianValue.setVisibility(View.GONE);
llResultTie.setVisibility(View.VISIBLE);
tvTieScore.setText(roomPkData.getTeams().get(0).getScore() + "");
tvTieScore.setText(FormatUtils.formatPKValue(roomPkData.getTeams().get(0).getScore()));
refreshBgByStatus();
} else {
pkResult = PK_RESULT_VICTORY;
@@ -268,11 +271,11 @@ public class PKResultDialog extends BaseDialog {
showTeamMembers(teamInfo);
showColorByTeam(teamInfo);
tvScore.setText(teamInfo.getScore() + "");
tvScore.setText(FormatUtils.formatPKValue(teamInfo.getScore()));
if (teamInfo.getProtector() != null && teamInfo.getProtector().getUid() != 0) {
tvGuardianName.setText(teamInfo.getProtector().getNick());
tvGuardianValue.setText(teamInfo.getProtecScore() + "");
tvGuardianValue.setText(FormatUtils.formatPKValue(teamInfo.getProtecScore()));
} else {
tvGuardianName.setText("");
tvGuardianValue.setText("0");

View File

@@ -284,8 +284,8 @@ public class PKScoreBoardDialog extends BaseDialog {
}
long totalScore = redTeam.getScore() + blueTeam.getScore();
if (totalScore > 0) {
tvRedTeamScore.setText(FormatUtils.formatToShortHalfUp(redTeam.getScore()));
tvBlueTeamScore.setText(FormatUtils.formatToShortHalfUp(blueTeam.getScore()));
tvRedTeamScore.setText(FormatUtils.formatPKValue(redTeam.getScore()));
tvBlueTeamScore.setText(FormatUtils.formatPKValue(blueTeam.getScore()));
int percent = (int) ((float) redTeam.getScore() / (float) totalScore * 100.0f);
pbScore.setProgress(percent);
} else {

View File

@@ -1287,9 +1287,9 @@ public class MessageView extends FrameLayout {
case RoomPkData.PK_RESULT_DRAW:
text.append("平局!\n", new ForegroundColorSpan(whiteColor));
if (blueTeam != null && redTeam != null) {
text.append(String.format(Locale.getDefault(), "PK值 %s : %s \n",
FormatUtils.formatToShortHalfUp(blueTeam.getScore()),
FormatUtils.formatToShortHalfUp(redTeam.getScore())),
text.append(String.format(Locale.getDefault(), "PK值 %s : %s",
FormatUtils.formatPKValue(blueTeam.getScore()),
FormatUtils.formatPKValue(redTeam.getScore())),
new ForegroundColorSpan(whiteColor));
UserInfo redProtector = redTeam.getProtector();
@@ -1298,15 +1298,15 @@ public class MessageView extends FrameLayout {
|| blueProtector == null || blueProtector.getUid() == 0) {
break;
}
text.append(String.format(Locale.getDefault(), "蓝队守护者:%s \n", blueProtector.getNick()),
text.append(String.format(Locale.getDefault(), "\n蓝队守护者:%s \n", blueProtector.getNick()),
new ForegroundColorSpan(whiteColor))
.append(String.format(Locale.getDefault(), "蓝队守护值:%s \n",
FormatUtils.formatToShortHalfUp(blueTeam.getProtecScore())),
FormatUtils.formatPKValue(blueTeam.getProtecScore())),
new ForegroundColorSpan(whiteColor))
.append(String.format(Locale.getDefault(), "红队守护者:%s \n", redProtector.getNick()),
new ForegroundColorSpan(whiteColor))
.append(String.format(Locale.getDefault(), "红队守护值:%s \n",
FormatUtils.formatToShortHalfUp(redTeam.getProtecScore())),
.append(String.format(Locale.getDefault(), "红队守护值:%s",
FormatUtils.formatPKValue(redTeam.getProtecScore())),
new ForegroundColorSpan(whiteColor));
}
break;
@@ -1315,19 +1315,23 @@ public class MessageView extends FrameLayout {
text.append("蓝队胜利!\n", new ForegroundColorSpan(whiteColor));
if (blueTeam != null && redTeam != null) {
text.append(String.format(Locale.getDefault(), "PK值 %s : %s \n",
FormatUtils.formatToShortHalfUp(blueTeam.getScore()),
FormatUtils.formatToShortHalfUp(redTeam.getScore())),
FormatUtils.formatPKValue(blueTeam.getScore()),
FormatUtils.formatPKValue(redTeam.getScore())),
new ForegroundColorSpan(whiteColor));
UserInfo blueProtector = blueTeam.getProtector();
if (blueProtector == null) {
break;
text.append(String.format(Locale.getDefault(), "胜利方战斗值:%s",
FormatUtils.formatPKValue(blueTeam.getScore())),
new ForegroundColorSpan(whiteColor));
} else {
text.append(String.format(Locale.getDefault(), "胜方守护者:%s \n", blueProtector.getNick()),
new ForegroundColorSpan(whiteColor))
.append(String.format(Locale.getDefault(), "胜方守护值:%s",
FormatUtils.formatPKValue(blueTeam.getProtecScore())),
new ForegroundColorSpan(whiteColor));
}
text.append(String.format(Locale.getDefault(), "胜方守护者:%s \n", blueProtector.getNick()),
new ForegroundColorSpan(whiteColor))
.append(String.format(Locale.getDefault(), "胜方守护值:%s \n",
FormatUtils.formatToShortHalfUp(blueTeam.getProtecScore())),
new ForegroundColorSpan(whiteColor));
}
break;
@@ -1335,19 +1339,23 @@ public class MessageView extends FrameLayout {
text.append("红队胜利!\n", new ForegroundColorSpan(whiteColor));
if (blueTeam != null && redTeam != null) {
text.append(String.format(Locale.getDefault(), "PK值 %s : %s \n",
FormatUtils.formatToShortHalfUp(redTeam.getScore()),
FormatUtils.formatToShortHalfUp(blueTeam.getScore())),
FormatUtils.formatPKValue(redTeam.getScore()),
FormatUtils.formatPKValue(blueTeam.getScore())),
new ForegroundColorSpan(whiteColor));
UserInfo redProtector = redTeam.getProtector();
if (redProtector == null) {
break;
text.append(String.format(Locale.getDefault(), "胜利方战斗值:%s",
FormatUtils.formatPKValue(redTeam.getScore())),
new ForegroundColorSpan(whiteColor));
} else {
text.append(String.format(Locale.getDefault(), "红队守护者:%s \n", redProtector.getNick()),
new ForegroundColorSpan(whiteColor))
.append(String.format(Locale.getDefault(), "红队守护值:%s",
FormatUtils.formatPKValue(redTeam.getProtecScore())),
new ForegroundColorSpan(whiteColor));
}
text.append(String.format(Locale.getDefault(), "红队守护者:%s \n", redProtector.getNick()),
new ForegroundColorSpan(whiteColor))
.append(String.format(Locale.getDefault(), "红队守护值:%s \n",
FormatUtils.formatToShortHalfUp(redTeam.getProtecScore())),
new ForegroundColorSpan(whiteColor));
}
break;
}

View File

@@ -144,11 +144,11 @@ public class PKBoardView extends RelativeLayout implements View.OnClickListener
PKTeamInfo blueTeamInfo = PkModel.get().findTeamByTeamId(PKTeamInfo.TEAM_BLUE);
if (blueTeamInfo != null) {
tvBlueTeamScore.setText(FormatUtils.formatToShortHalfUp(blueTeamInfo.getScore()));
tvBlueTeamScore.setText(FormatUtils.formatPKValue(blueTeamInfo.getScore()));
}
PKTeamInfo redTeamInfo = PkModel.get().findTeamByTeamId(PKTeamInfo.TEAM_RED);
if (redTeamInfo != null) {
tvRedTeamScore.setText(FormatUtils.formatToShortHalfUp(redTeamInfo.getScore()));
tvRedTeamScore.setText(FormatUtils.formatPKValue(redTeamInfo.getScore()));
}
} else {
tvPkTimer.setText("未开始");
@@ -178,8 +178,8 @@ public class PKBoardView extends RelativeLayout implements View.OnClickListener
llPkScoreBoard.setOnClickListener(null);
if (PkModel.get().getCurPkInfo() != null && PkModel.get().getCurPkInfo().getPkStatus() == RoomPkData.PK_STATUS_BEFORE_PK) {
tvBlueTeamScore.setText("0.00");
tvRedTeamScore.setText("0.00");
tvBlueTeamScore.setText(FormatUtils.formatPKValue(0));
tvRedTeamScore.setText(FormatUtils.formatPKValue(0));
}
}
}
@@ -254,11 +254,11 @@ public class PKBoardView extends RelativeLayout implements View.OnClickListener
if (PkModel.get().getCurPkInfo().getPkStatus() == RoomPkData.PK_STATUS_IN_PK) {
PKTeamInfo blueTeamInfo = PkModel.get().findTeamByTeamId(PKTeamInfo.TEAM_BLUE);
if (blueTeamInfo != null) {
tvBlueTeamScore.setText(FormatUtils.formatToShortHalfUp(blueTeamInfo.getScore()));
tvBlueTeamScore.setText(FormatUtils.formatPKValue(blueTeamInfo.getScore()));
}
PKTeamInfo redTeamInfo = PkModel.get().findTeamByTeamId(PKTeamInfo.TEAM_RED);
if (redTeamInfo != null) {
tvRedTeamScore.setText(FormatUtils.formatToShortHalfUp(redTeamInfo.getScore()));
tvRedTeamScore.setText(FormatUtils.formatPKValue(redTeamInfo.getScore()));
}
if (redTeamInfo != null && blueTeamInfo != null) {
@@ -276,12 +276,12 @@ public class PKBoardView extends RelativeLayout implements View.OnClickListener
if (onActionListener != null) {
onActionListener.onEndPK();
}
tvBlueTeamScore.setText("0.00");
tvRedTeamScore.setText("0.00");
tvBlueTeamScore.setText(FormatUtils.formatPKValue(0));
tvRedTeamScore.setText(FormatUtils.formatPKValue(0));
}
if (PkModel.get().getCurPkInfo().getPkStatus() == RoomPkData.PK_STATUS_TERMINAL_PK_BEFORE_END) {
tvBlueTeamScore.setText("0.00");
tvRedTeamScore.setText("0.00");
tvBlueTeamScore.setText(FormatUtils.formatPKValue(0));
tvRedTeamScore.setText(FormatUtils.formatPKValue(0));
}
}

View File

@@ -47,7 +47,7 @@
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:text="0.00"
android:text="0"
android:textColor="@color/color_FFFFFF"
android:textSize="12dp"
app:layout_constraintStart_toStartOf="@id/pb_score"
@@ -61,7 +61,7 @@
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:text="0.00"
android:text="0"
android:textColor="@color/color_FFFFFF"
android:textSize="12dp"
app:layout_constraintEnd_toEndOf="@id/pb_score"

View File

@@ -80,7 +80,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:text="0.00"
android:text="0"
android:textColor="@color/color_FFFFFF"
android:textSize="12dp"
app:layout_constraintEnd_toEndOf="@id/fl_left"
@@ -164,7 +164,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:text="0.00"
android:text="0"
android:textColor="@color/color_FFFFFF"
android:textSize="12dp"
app:layout_constraintEnd_toEndOf="@id/fl_right"

View File

@@ -34,29 +34,33 @@ public class FormatUtils {
/**
* 把过长的金额类数字,转换成两位小数带万,亿,兆 缩写
* 10000.00 -> 1.00万 丢掉两位小数后面的小数
*
* @param num
* @return
*/
public static String formatToShortDown(double num){
public static String formatToShortDown(double num) {
return formatToShort(num, RoundingMode.DOWN);
}
/**
* 把过长的金额类数字,转换成两位小数带万,亿,兆 缩写
* 10000.00 -> 1.00万 四舍五入两位小数后面的小数
*
* @param num
* @return
*/
public static String formatToShortHalfUp(double num){
public static String formatToShortHalfUp(double num) {
return formatToShort(num, RoundingMode.HALF_UP);
}
/**
* 把过长的金额类数字,转换成两位小数带万,亿,兆 缩写
* 10000.00 -> 1.00万
*
* @param num
* @return
*/
public static String formatToShort(double num, RoundingMode roundingMode){
public static String formatToShort(double num, RoundingMode roundingMode) {
try {
DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
decimalFormat.setRoundingMode(roundingMode);
@@ -64,16 +68,16 @@ public class FormatUtils {
double yi = Math.pow(10.0f, 8);
double zhao = Math.pow(10.0f, 12);
double res = num;
if (Math.abs(num / wan) < 1){
if (Math.abs(num / wan) < 1) {
res = num;
return decimalFormat.format(res);
}else if(Math.abs(num / wan) >= 1 && Math.abs(num / yi) < 1){
} else if (Math.abs(num / wan) >= 1 && Math.abs(num / yi) < 1) {
res = num / wan;
return decimalFormat.format(res) + "";
}else if(Math.abs(num / yi) >= 1 && Math.abs(num /zhao) < 1){
} else if (Math.abs(num / yi) >= 1 && Math.abs(num / zhao) < 1) {
res = num / yi;
return decimalFormat.format(res) + "亿";
}else {
} else {
res = num / zhao;
return decimalFormat.format(res) + "";
}
@@ -85,21 +89,28 @@ public class FormatUtils {
/**
* 将手机号码 显示成带隐私形式
*
* @param phoneNum
* @param beginIndex 开始用* 号替换位置
* @param endIndex 结束用* 号替换位置
* @param endIndex 结束用* 号替换位置
* @return
*/
public static String formatPhoneNumWithPrivacy(String phoneNum, int beginIndex, int endIndex){
public static String formatPhoneNumWithPrivacy(String phoneNum, int beginIndex, int endIndex) {
StringBuffer resSB = new StringBuffer();
for (int i = 0; i < phoneNum.length(); i++) {
if (i >= beginIndex && i < endIndex){
if (i >= beginIndex && i < endIndex) {
resSB.append("*");
}else {
} else {
resSB.append(phoneNum.charAt(i));
}
}
return resSB.toString();
}
//PK值相关格式化方式,统一方法,方便以后更改样式
public static String formatPKValue(long value) {
if (value >= 100000) return (value / 100) / 100f + "";
return String.valueOf(value);
}
}