java代码抽离颜色代码,修复历史礼包已知bug

This commit is contained in:
kehaoyuan
2017-10-08 14:56:40 +08:00
parent 3201e220a0
commit 1f5e025fea
16 changed files with 59 additions and 362 deletions

View File

@ -1,149 +1,29 @@
package com.gh.common.util;
import android.graphics.Color;
import android.view.View;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.entity.KaiFuServerEntity;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* Created by khy on 2017/3/19.
*/
public class KaiFuUtils {
public static void setKaiFuTimeHint(long curTime, long lastTime, GameEntity entity, boolean isTop) {
SimpleDateFormat format = new SimpleDateFormat("dd", Locale.getDefault());
String curDay = format.format(curTime);
String lastDay = format.format(lastTime);
if (!curDay.equals(lastDay)) {
if (isTop) {
entity.setKaifuTimeHint(curTime);
} else {
entity.setKaifuTimeHint(lastTime);
}
}
}
public static void initKaiFuTimeHintView(TextView view, Long time) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
try {
long today = format.parse(format.format(new Date())).getTime();
if (time >= today && time < today + 86400 * 1000) {
view.setText("↓今天开服");
view.setTextColor(Color.parseColor("#ffb13c"));
} else if (time >= today - 86400 * 1000 && time < today) {
view.setText("↑历史开服");
view.setTextColor(Color.parseColor("#c7c7c7"));
} else if (time > today && time < today + 86400 * 1000 * 2) {
view.setText("↓明天开服");
view.setTextColor(Color.parseColor("#ffb13c"));
} else if (time < today) {
view.setText("↑历史开服");
view.setTextColor(Color.parseColor("#c7c7c7"));
} else if (time > today && time < today + 86400 * 1000 * 3) {
view.setText("↓后天开服");
view.setTextColor(Color.parseColor("#c7c7c7"));
} else {
format.applyPattern("↓M月d日开服");
view.setText(format.format(time));
view.setTextColor(Color.parseColor("#c7c7c7"));
}
} catch (ParseException e) {
e.printStackTrace();
format.applyPattern("M月d日开服");
view.setText(format.format(time));
}
}
public static void setKaiFuTimeHint(TextView top, TextView bottom, List<GameEntity> gameList, int position) {
if (position == 0 || position + 1 >= gameList.size()) return;
GameEntity curGameEntity = gameList.get(position);
GameEntity lastGameEntity = gameList.get(position);
KaiFuServerEntity curServerEntity = curGameEntity.getServerEntity();
KaiFuServerEntity lastServerEntity = lastGameEntity.getServerEntity();
if (curServerEntity == null || lastServerEntity == null) return;
long curTime = curServerEntity.getTime() * 1000;
long lastTime = lastServerEntity.getTime() * 1000;
SimpleDateFormat format = new SimpleDateFormat("dd", Locale.getDefault());
String curDay = format.format(curTime);
String lastDay = format.format(lastTime);
if (!curDay.equals(lastDay)) {
bottom.setVisibility(View.VISIBLE);
} else {
bottom.setVisibility(View.GONE);
}
}
public static void setKaiFuTime(TextView textView, long time) {
time = time * 1000;
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
try {
long today = format.parse(format.format(new Date())).getTime();
if (time >= today && time < today + 86400 * 1000) {
format.applyPattern("HH:mm");
textView.setText(String.format("今天 %s", format.format(time)));
textView.setBackgroundResource(R.drawable.border_white_bg);
textView.setTextColor(Color.parseColor("#ffb13c"));
} else if (time >= today - 86400 * 1000 && time < today) {
format.applyPattern("HH:mm");
textView.setText(String.format("昨天 %s", format.format(time)));
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
textView.setTextColor(Color.parseColor("#c7c7c7"));
} else if (time > today && time < today + 86400 * 1000 * 2) {
format.applyPattern("HH:mm");
textView.setText(String.format("明天 %s", format.format(time)));
textView.setBackgroundResource(R.drawable.border_white_bg);
textView.setTextColor(Color.parseColor("#ffb13c"));
} else if (time >= today - 86400 * 1000 * 2 && time < today) {
format.applyPattern("HH:mm");
textView.setText(String.format("前天 %s", format.format(time)));
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
textView.setTextColor(Color.parseColor("#c7c7c7"));
} else if (time > today && time < today + 86400 * 1000 * 3) {
format.applyPattern("HH:mm");
textView.setText(String.format("后天 %s", format.format(time)));
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
textView.setTextColor(Color.parseColor("#c7c7c7"));
} else {
format.applyPattern("MM-dd HH:mm");
textView.setText(format.format(time));
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
textView.setTextColor(Color.parseColor("#c7c7c7"));
}
} catch (ParseException e) {
e.printStackTrace();
format.applyPattern("yyyy年MM月dd日 HH:mm");
textView.setText(format.format(time));
}
}
public static void setKaiFuType(TextView textView, String type) {
textView.setText(type);
switch (type) {
case "不删档内测":
textView.setBackgroundColor(Color.parseColor("#9a9a9a"));
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.content));
break;
case "删档内测":
textView.setBackgroundColor(Color.parseColor("#9a9a9a"));
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.content));
break;
case "公测":
textView.setBackgroundColor(Color.parseColor("#ffb13c"));
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.tag_yellow));
break;
default:
textView.setBackgroundColor(Color.parseColor("#ffb13c"));
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.tag_yellow));
break;
}
}