大于两个的if分支,使用switch
This commit is contained in:
@ -327,12 +327,16 @@ public class LibaoUtils {
|
||||
if (TextUtils.isEmpty(libaoCode)) {
|
||||
try {
|
||||
String detail = responseBody.getString("detail");
|
||||
if ("maintaining".equals(detail)) {
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
} else if ("fail to compete".equals(detail)) {
|
||||
Utils.toast(context, "淘号失败,稍后重试");
|
||||
} else {
|
||||
Utils.toast(context, "淘号异常");
|
||||
switch (detail) {
|
||||
case "maintaining":
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
break;
|
||||
case "fail to compete":
|
||||
Utils.toast(context, "淘号失败,稍后重试");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "淘号异常");
|
||||
break;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -391,33 +395,43 @@ public class LibaoUtils {
|
||||
JSONObject errorJson = new JSONObject(exception.response().errorBody().string());
|
||||
String detail = errorJson.getString("detail");
|
||||
Utils.toast(context, "返回::" + detail);
|
||||
if ("coming".equals(detail)) {
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
} else if ("finish".equals(detail)) {
|
||||
Utils.toast(context, "礼包领取时间已结束");
|
||||
} else if ("fetched".equals(detail)) {
|
||||
Utils.toast(context, "你已领过这个礼包了");
|
||||
getCunHaoXiang(context, true);
|
||||
switch (detail) {
|
||||
case "coming":
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
break;
|
||||
case "finish":
|
||||
Utils.toast(context, "礼包领取时间已结束");
|
||||
break;
|
||||
case "fetched":
|
||||
Utils.toast(context, "你已领过这个礼包了");
|
||||
getCunHaoXiang(context, true);
|
||||
|
||||
int[][] states2 = new int[2][];
|
||||
states2[0] = new int[]{android.R.attr.state_pressed};
|
||||
states2[1] = new int[]{};
|
||||
int[] colors2 = new int[]{Color.WHITE,
|
||||
Color.parseColor("#ffb13c")};
|
||||
ColorStateList sl2 = new ColorStateList(states2, colors2);
|
||||
libaoBtn.setText("已淘号");
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
|
||||
libaoBtn.setTextColor(sl2);
|
||||
libaoEntity.setStatus("taoed");
|
||||
break;
|
||||
case "try tao":
|
||||
case "used up":
|
||||
DialogUtils.showHintDialog(context, "礼包已领光"
|
||||
, "手速不够快,礼包已经被抢光了,十分抱歉", "知道了");
|
||||
break;
|
||||
case "maintaining":
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
break;
|
||||
case "fail to compete":
|
||||
Utils.toast(context, "淘号失败,稍后重试");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "操作失败");
|
||||
break;
|
||||
|
||||
int[][] states2 = new int[2][];
|
||||
states2[0] = new int[]{android.R.attr.state_pressed};
|
||||
states2[1] = new int[]{};
|
||||
int[] colors2 = new int[]{Color.WHITE,
|
||||
Color.parseColor("#ffb13c")};
|
||||
ColorStateList sl2 = new ColorStateList(states2, colors2);
|
||||
libaoBtn.setText("已淘号");
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
|
||||
libaoBtn.setTextColor(sl2);
|
||||
libaoEntity.setStatus("taoed");
|
||||
} else if ("try tao".equals(detail) || "used up".equals(detail)) {
|
||||
DialogUtils.showHintDialog(context, "礼包已领光"
|
||||
, "手速不够快,礼包已经被抢光了,十分抱歉", "知道了");
|
||||
} else if ("maintaining".equals(detail)) {
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
} else if ("fail to compete".equals(detail)) {
|
||||
Utils.toast(context, "淘号失败,稍后重试");
|
||||
} else {
|
||||
Utils.toast(context, "操作失败");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@ -509,43 +523,50 @@ public class LibaoUtils {
|
||||
JSONObject errorJson = new JSONObject(string);
|
||||
String detail = errorJson.getString("detail");
|
||||
|
||||
if ("coming".equals(detail)) {
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
} else if ("finish".equals(detail)) {
|
||||
Utils.toast(context, "礼包领取时间已结束");
|
||||
} else if ("fetched".equals(detail)) {
|
||||
Utils.toast(context, "你已领过这个礼包了");
|
||||
int countdown = 0;
|
||||
if (errorJson.toString().contains("countdown")) {
|
||||
countdown = errorJson.getInt("countdown");
|
||||
}
|
||||
if (countdown > 0 && countdown < 60 * 10) {
|
||||
EventBus.getDefault().post(new EBUISwitch(REFRESH_LIBAO_TIME, countdown));
|
||||
} else {
|
||||
getCunHaoXiang(context, true);
|
||||
}
|
||||
switch (detail) {
|
||||
case "coming":
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
break;
|
||||
case "finish":
|
||||
Utils.toast(context, "礼包领取时间已结束");
|
||||
break;
|
||||
case "fetched":
|
||||
Utils.toast(context, "你已领过这个礼包了");
|
||||
int countdown = 0;
|
||||
if (errorJson.toString().contains("countdown")) {
|
||||
countdown = errorJson.getInt("countdown");
|
||||
}
|
||||
if (countdown > 0 && countdown < 60 * 10) {
|
||||
EventBus.getDefault().post(new EBUISwitch(REFRESH_LIBAO_TIME, countdown));
|
||||
} else {
|
||||
getCunHaoXiang(context, true);
|
||||
}
|
||||
|
||||
int[][] states = new int[2][];
|
||||
states[0] = new int[]{android.R.attr.state_pressed};
|
||||
states[1] = new int[]{};
|
||||
int[] colors = new int[]{Color.WHITE,
|
||||
Color.parseColor("#06D0A8")};
|
||||
ColorStateList sl = new ColorStateList(states, colors);
|
||||
libaoBtn.setText("已领取");
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
|
||||
libaoBtn.setTextColor(sl);
|
||||
int[][] states = new int[2][];
|
||||
states[0] = new int[]{android.R.attr.state_pressed};
|
||||
states[1] = new int[]{};
|
||||
int[] colors = new int[]{Color.WHITE,
|
||||
Color.parseColor("#06D0A8")};
|
||||
ColorStateList sl = new ColorStateList(states, colors);
|
||||
libaoBtn.setText("已领取");
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
|
||||
libaoBtn.setTextColor(sl);
|
||||
|
||||
libaoEntity.setStatus("linged");
|
||||
} else if ("try tao".equals(detail) || "used up".equals(detail)) {
|
||||
DialogUtils.showHintDialog(context, "礼包已领光"
|
||||
, "手速不够快,礼包已经被抢光了,十分抱歉", "知道了");
|
||||
libaoEntity.setStatus("used_up");
|
||||
initLibaoBtn(context, libaoBtn, libaoEntity, libaoDao, isInstallRequired, adapter, entrance);
|
||||
|
||||
} else if ("maintaining".equals(detail)) {
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
} else {
|
||||
Utils.toast(context, "操作失败");
|
||||
libaoEntity.setStatus("linged");
|
||||
break;
|
||||
case "try tao":
|
||||
case "used up":
|
||||
DialogUtils.showHintDialog(context, "礼包已领光"
|
||||
, "手速不够快,礼包已经被抢光了,十分抱歉", "知道了");
|
||||
libaoEntity.setStatus("used_up");
|
||||
initLibaoBtn(context, libaoBtn, libaoEntity, libaoDao, isInstallRequired, adapter, entrance);
|
||||
break;
|
||||
case "maintaining":
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "操作失败");
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user