1、处理viewholder
2、处理adapter 3、
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -215,7 +214,7 @@ public class LibaoUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void initLibaoBtn(final Activity activity, final TextView libaoBtn, final LibaoEntity libaoEntity, final LibaoDao libaoDao,
|
||||
public static void initLibaoBtn(final Context context, final TextView libaoBtn, final LibaoEntity libaoEntity, final LibaoDao libaoDao,
|
||||
final boolean isInstallRequired, final LibaoDetailAdapter adapter, final String entrance) {
|
||||
|
||||
libaoBtn.setTextColor(Color.WHITE);
|
||||
@ -257,8 +256,7 @@ public class LibaoUtils {
|
||||
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")};
|
||||
int[] colors2 = new int[]{Color.WHITE, Color.parseColor("#ffb13c")};
|
||||
ColorStateList sl2 = new ColorStateList(states2, colors2);
|
||||
libaoBtn.setText("已淘号");
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
|
||||
@ -278,16 +276,16 @@ public class LibaoUtils {
|
||||
public void onClick(View v) {
|
||||
// 领取限制
|
||||
if ("领取".equals(libaoBtn.getText().toString()) || "淘号".equals(libaoBtn.getText().toString())) {
|
||||
if (isInstallRequired && !isAppInstalled(libaoBtn.getContext(), libaoEntity.getPackageName())) {
|
||||
if (isInstallRequired && !isAppInstalled(context, libaoEntity.getPackageName())) {
|
||||
String platform;
|
||||
if (TextUtils.isEmpty(libaoEntity.getPlatform())) {
|
||||
platform = "";
|
||||
} else {
|
||||
platform = PlatformUtils.getInstance(libaoBtn.getContext())
|
||||
platform = PlatformUtils.getInstance(context)
|
||||
.getPlatformName(libaoEntity.getPlatform()) + "版";
|
||||
}
|
||||
|
||||
DialogUtils.showWarningDialog(libaoBtn.getContext(), "条件不符",
|
||||
DialogUtils.showWarningDialog(context, "条件不符",
|
||||
Html.fromHtml("请先" + "<font color=\"#06D0A8\">"
|
||||
+ "安装《" + libaoEntity.getGame().getName() + "》 "
|
||||
+ platform + "</font>"), "关闭", "立即安装"
|
||||
@ -303,17 +301,17 @@ public class LibaoUtils {
|
||||
|
||||
switch (libaoBtn.getText().toString()) {
|
||||
case "未开始":
|
||||
Utils.toast(libaoBtn.getContext(), "还没到开始领取时间");
|
||||
Utils.toast(context, "还没到开始领取时间");
|
||||
break;
|
||||
case "查看":
|
||||
Intent intent = LibaoDetailActivity.getLibaoDetailIntent(libaoEntity, libaoBtn, entrance);
|
||||
libaoBtn.getContext().startActivity(intent);
|
||||
Intent intent = LibaoDetailActivity.getIntent(context, libaoEntity, entrance);
|
||||
context.startActivity(intent);
|
||||
break;
|
||||
case "领取":
|
||||
libaoLing(activity, libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, null, entrance);
|
||||
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, null, entrance);
|
||||
break;
|
||||
case "淘号":
|
||||
postLibaoTao(libaoBtn.getContext(), libaoEntity.getId(), true, new PostLibaoListener() {
|
||||
postLibaoTao(context, libaoEntity.getId(), true, new PostLibaoListener() {
|
||||
@Override
|
||||
public void postSucced(Object response) {
|
||||
|
||||
@ -330,11 +328,11 @@ public class LibaoUtils {
|
||||
try {
|
||||
String detail = responseBody.getString("detail");
|
||||
if ("maintaining".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "网络状态异常,请稍后再试");
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
} else if ("fail to compete".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "淘号失败,稍后重试");
|
||||
Utils.toast(context, "淘号失败,稍后重试");
|
||||
} else {
|
||||
Utils.toast(libaoBtn.getContext(), "淘号异常");
|
||||
Utils.toast(context, "淘号异常");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -342,13 +340,13 @@ public class LibaoUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
Utils.toast(libaoBtn.getContext(), "淘号成功");
|
||||
Utils.toast(context, "淘号成功");
|
||||
|
||||
libaoEntity.setStatus("taoed");
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setCode(libaoCode);
|
||||
libaoInfo.setTime(Utils.getTime(libaoBtn.getContext()));
|
||||
libaoInfo.setTime(Utils.getTime(context));
|
||||
libaoDao.add(libaoInfo);
|
||||
|
||||
EventBus.getDefault().post(new EBReuse("libaoChanged"));
|
||||
@ -357,20 +355,20 @@ public class LibaoUtils {
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
final String finalLibaoCode = libaoCode;
|
||||
DialogUtils.showWarningDialog(libaoBtn.getContext(), "淘号成功", Html.fromHtml("礼包码:"
|
||||
DialogUtils.showWarningDialog(context, "淘号成功", Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#ffb13c\">" + libaoCode + "</font>" +
|
||||
"<br/>淘号礼包不保证可用,请尽快进入游戏尝试兑换")
|
||||
, "关闭", " 复制礼包码"
|
||||
, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
copyLink(finalLibaoCode, libaoBtn.getContext());
|
||||
copyLink(finalLibaoCode, context);
|
||||
|
||||
if (isInstallRequired) {
|
||||
libaoBtn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lunningAppDialog(libaoBtn.getContext()
|
||||
lunningAppDialog(context
|
||||
, Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#ffb13c\">" + finalLibaoCode + "</font>"
|
||||
+ " 复制成功"
|
||||
@ -392,14 +390,14 @@ public class LibaoUtils {
|
||||
try {
|
||||
JSONObject errorJson = new JSONObject(exception.response().errorBody().string());
|
||||
String detail = errorJson.getString("detail");
|
||||
Utils.toast(libaoBtn.getContext(), "返回::" + detail);
|
||||
Utils.toast(context, "返回::" + detail);
|
||||
if ("coming".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "礼包领取时间未开始");
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
} else if ("finish".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "礼包领取时间已结束");
|
||||
Utils.toast(context, "礼包领取时间已结束");
|
||||
} else if ("fetched".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "你已领过这个礼包了");
|
||||
getCunHaoXiang(libaoBtn.getContext(), true);
|
||||
Utils.toast(context, "你已领过这个礼包了");
|
||||
getCunHaoXiang(context, true);
|
||||
|
||||
int[][] states2 = new int[2][];
|
||||
states2[0] = new int[]{android.R.attr.state_pressed};
|
||||
@ -412,23 +410,23 @@ public class LibaoUtils {
|
||||
libaoBtn.setTextColor(sl2);
|
||||
libaoEntity.setStatus("taoed");
|
||||
} else if ("try tao".equals(detail) || "used up".equals(detail)) {
|
||||
DialogUtils.showHintDialog(libaoBtn.getContext(), "礼包已领光"
|
||||
DialogUtils.showHintDialog(context, "礼包已领光"
|
||||
, "手速不够快,礼包已经被抢光了,十分抱歉", "知道了");
|
||||
} else if ("maintaining".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "网络状态异常,请稍后再试");
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
} else if ("fail to compete".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "淘号失败,稍后重试");
|
||||
Utils.toast(context, "淘号失败,稍后重试");
|
||||
} else {
|
||||
Utils.toast(libaoBtn.getContext(), "操作失败");
|
||||
Utils.toast(context, "操作失败");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Utils.toast(libaoBtn.getContext(), "礼包处理异常" + ex.toString());
|
||||
Utils.toast(context, "礼包处理异常" + ex.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
Utils.toast(libaoBtn.getContext(), "发生异常");
|
||||
Utils.toast(context, "发生异常");
|
||||
}
|
||||
});
|
||||
break;
|
||||
@ -437,10 +435,14 @@ public class LibaoUtils {
|
||||
});
|
||||
}
|
||||
|
||||
private static void libaoLing(final Activity activity, final TextView libaoBtn, final LibaoEntity libaoEntity, final LibaoDetailAdapter adapter,
|
||||
private static void libaoLing(final Context context, final TextView libaoBtn, final LibaoEntity libaoEntity, final LibaoDetailAdapter adapter,
|
||||
final boolean isInstallRequired, final LibaoDao libaoDao, String captchaCode, final String entrance) {
|
||||
|
||||
postLibaoLing(libaoBtn.getContext(), libaoEntity.getId(), true, new PostLibaoListener() {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e("LIBAO", "context? " + context + libaoBtn.getContext());
|
||||
}
|
||||
|
||||
postLibaoLing(context, libaoEntity.getId(), true, new PostLibaoListener() {
|
||||
@Override
|
||||
public void postSucced(Object response) {
|
||||
|
||||
@ -454,7 +456,7 @@ public class LibaoUtils {
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(libaoCode)) {
|
||||
Utils.toast(libaoBtn.getContext(), "领取异常");
|
||||
Utils.toast(context, "领取异常");
|
||||
return;
|
||||
}
|
||||
libaoEntity.setAvailable(libaoEntity.getAvailable() - 1);
|
||||
@ -462,7 +464,7 @@ public class LibaoUtils {
|
||||
libaoEntity.setStatus("linged");
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setTime(Utils.getTime(libaoBtn.getContext()));
|
||||
libaoInfo.setTime(Utils.getTime(context));
|
||||
libaoInfo.setCode(libaoCode);
|
||||
libaoDao.add(libaoInfo);
|
||||
|
||||
@ -472,19 +474,19 @@ public class LibaoUtils {
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
final String finalLibaoCode = libaoCode;
|
||||
DialogUtils.showWarningDialog(libaoBtn.getContext(), "领取成功", Html.fromHtml("礼包码:"
|
||||
DialogUtils.showWarningDialog(context, "领取成功", Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#00B7FA\">" + libaoCode + "</font>" +
|
||||
"<br/>请尽快使用,礼包码将于60分钟后进入淘号池")
|
||||
, "关闭", " 复制礼包码"
|
||||
, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
copyLink(finalLibaoCode, libaoBtn.getContext());
|
||||
copyLink(finalLibaoCode, context);
|
||||
if (isInstallRequired) {
|
||||
libaoBtn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lunningAppDialog(libaoBtn.getContext()
|
||||
lunningAppDialog(context
|
||||
, Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#00B7FA\">" + finalLibaoCode + "</font>"
|
||||
+ " 复制成功" + "<br/>请尽快进入游戏兑换"), libaoEntity);
|
||||
@ -508,11 +510,11 @@ public class LibaoUtils {
|
||||
String detail = errorJson.getString("detail");
|
||||
|
||||
if ("coming".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "礼包领取时间未开始");
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
} else if ("finish".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "礼包领取时间已结束");
|
||||
Utils.toast(context, "礼包领取时间已结束");
|
||||
} else if ("fetched".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "你已领过这个礼包了");
|
||||
Utils.toast(context, "你已领过这个礼包了");
|
||||
int countdown = 0;
|
||||
if (errorJson.toString().contains("countdown")) {
|
||||
countdown = errorJson.getInt("countdown");
|
||||
@ -520,7 +522,7 @@ public class LibaoUtils {
|
||||
if (countdown > 0 && countdown < 60 * 10) {
|
||||
EventBus.getDefault().post(new EBUISwitch(REFRESH_LIBAO_TIME, countdown));
|
||||
} else {
|
||||
getCunHaoXiang(libaoBtn.getContext(), true);
|
||||
getCunHaoXiang(context, true);
|
||||
}
|
||||
|
||||
int[][] states = new int[2][];
|
||||
@ -535,38 +537,33 @@ public class LibaoUtils {
|
||||
|
||||
libaoEntity.setStatus("linged");
|
||||
} else if ("try tao".equals(detail) || "used up".equals(detail)) {
|
||||
DialogUtils.showHintDialog(libaoBtn.getContext(), "礼包已领光"
|
||||
DialogUtils.showHintDialog(context, "礼包已领光"
|
||||
, "手速不够快,礼包已经被抢光了,十分抱歉", "知道了");
|
||||
libaoEntity.setStatus("used_up");
|
||||
initLibaoBtn(activity, libaoBtn, libaoEntity, libaoDao, isInstallRequired, adapter, entrance);
|
||||
initLibaoBtn(context, libaoBtn, libaoEntity, libaoDao, isInstallRequired, adapter, entrance);
|
||||
|
||||
} else if ("maintaining".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "网络状态异常,请稍后再试");
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
} else {
|
||||
Utils.toast(libaoBtn.getContext(), "操作失败");
|
||||
Utils.toast(context, "操作失败");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Utils.toast(libaoBtn.getContext(), "礼包处理异常");
|
||||
Utils.toast(context, "礼包处理异常");
|
||||
}
|
||||
return;
|
||||
} else if (exception.code() == 412) {
|
||||
// 需要验证
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e("LIBAO", "context? " + libaoBtn.getContext() + activity);
|
||||
}
|
||||
|
||||
GeetestUtils.getInstance().showDialog(activity, new GeetestListener() {
|
||||
GeetestUtils.getInstance().showDialog(context, new GeetestListener() {
|
||||
@Override
|
||||
public void onVerified(String captcha) {
|
||||
libaoLing(activity, libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, captcha, entrance);
|
||||
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, captcha, entrance);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
Utils.toast(libaoBtn.getContext(), "发生异常");
|
||||
Utils.toast(context, "发生异常");
|
||||
}
|
||||
}, captchaCode);
|
||||
}
|
||||
@ -612,8 +609,8 @@ public class LibaoUtils {
|
||||
|
||||
|
||||
// 合并List<LibaoStatusEntity> 和 List<LibaoEntity> 并检查重复领取的礼包
|
||||
public static void initLiBaoEntity(LibaoDao libaoDao, List<LibaoStatusEntity> statusList
|
||||
, List<LibaoEntity> mLibaoList, Context mContext) {
|
||||
public static void initLiBaoEntity(LibaoDao libaoDao, List<LibaoStatusEntity> statusList,
|
||||
List<LibaoEntity> libaoEntities, Context mContext) {
|
||||
|
||||
for (LibaoInfo libaoInfo : libaoDao.getAll()) {
|
||||
for (LibaoStatusEntity libaoStatusEntity : statusList) {
|
||||
@ -635,7 +632,7 @@ public class LibaoUtils {
|
||||
}
|
||||
}
|
||||
|
||||
for (LibaoEntity libaoEntity : mLibaoList) {
|
||||
for (LibaoEntity libaoEntity : libaoEntities) {
|
||||
for (LibaoStatusEntity libaoStatusEntity : statusList) {
|
||||
if (libaoEntity.getId().equals(libaoStatusEntity.getId())) {
|
||||
libaoEntity.setAvailable(libaoStatusEntity.getAvailable());
|
||||
|
||||
Reference in New Issue
Block a user