diff --git a/app/src/main/java/com/gh/common/util/LibaoUtils.java b/app/src/main/java/com/gh/common/util/LibaoUtils.java index 58126b6538..2e9078a953 100644 --- a/app/src/main/java/com/gh/common/util/LibaoUtils.java +++ b/app/src/main/java/com/gh/common/util/LibaoUtils.java @@ -21,6 +21,7 @@ import com.gh.gamecenter.db.info.LibaoInfo; import com.gh.gamecenter.entity.LibaoEntity; import com.gh.gamecenter.entity.LibaoStatusEntity; import com.gh.gamecenter.eventbus.EBReuse; +import com.gh.gamecenter.geetest.GeetestUtils; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -40,7 +41,7 @@ import rx.schedulers.Schedulers; /** * Created by khy on 2016/12/16. - * + * 礼包工具类, 包括联网操作和领取按钮状态 */ public class LibaoUtils { @@ -79,7 +80,6 @@ public class LibaoUtils { public void onResponse(List response) { LibaoDao libaoDao = new LibaoDao(context); for (LibaoEntity libaoEntity : response) { - Utils.log("============cunhaoxiang" + libaoEntity.getPackageName() + "==" + libaoEntity.getName()); LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity); libaoInfo.setActive(libaoEntity.isActive()); libaoDao.add(libaoInfo); @@ -98,12 +98,16 @@ public class LibaoUtils { } private static void postLibaoLing(final Context context, final String libaoId, final boolean isCheck, - final PostLibaoListener listener) { + final PostLibaoListener listener, final String captchaCode) { TokenUtils.getToken(context, isCheck) .flatMap(new Func1>() { @Override public Observable call(String token) { - return RetrofitManager.getLibao().postLibaoLing(token, libaoId); + if (!TextUtils.isEmpty(captchaCode)) { + return RetrofitManager.getLibao().postLibaoLing(token, captchaCode, libaoId); + } else { + return RetrofitManager.getLibao().postLibaoLing(token, libaoId); + } } }).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -116,8 +120,12 @@ public class LibaoUtils { @Override public void onFailure(HttpException e) { if (e != null && e.code() == 401) { - postLibaoLing(context, libaoId, false, listener); + postLibaoLing(context, libaoId, false, listener, captchaCode); return; + } else if (e.code() == 410) { // 该接口已废弃 + Utils.toast(context, "领取失败,请安装最新版本的光环助手"); + } else if (e.code() == 412) { + //TODO 需要验证码 } listener.postFailed(e); } @@ -143,7 +151,7 @@ public class LibaoUtils { @Override public void onFailure(HttpException e) { if (e != null && e.code() == 401) { - postLibaoLing(context, libaoId, false, listener); + postLibaoTao(context, libaoId, false, listener); return; } listener.postFailed(e); @@ -170,7 +178,7 @@ public class LibaoUtils { @Override public void onFailure(HttpException e) { if (e != null && e.code() == 401) { - postLibaoLing(context, code, false, listener); + deleteLibaoCode(context, code, false, listener); return; } listener.postFailed(e); @@ -260,6 +268,7 @@ public class LibaoUtils { libaoBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + // 领取限制 if ("领取".equals(libaoBtn.getText().toString()) || "淘号".equals(libaoBtn.getText().toString())) { if (isInstallRequired && !isAppInstalled(libaoBtn.getContext(), libaoEntity.getPackageName())) { String platform; @@ -271,8 +280,9 @@ public class LibaoUtils { } DialogUtils.showWarningDialog(libaoBtn.getContext(), "条件不符", - "请先安装《" + libaoEntity.getGame().getName() + "》 " - + platform, "关闭", "立即安装" + Html.fromHtml("请先"+ "" + + "安装《" + libaoEntity.getGame().getName() + "》 " + + platform + ""), "关闭", "立即安装" , new DialogUtils.ConfiremListener() { @Override public void onConfirem() { @@ -293,97 +303,7 @@ public class LibaoUtils { libaoBtn.getContext().startActivity(intent); break; case "领取": - postLibaoLing(libaoBtn.getContext(), libaoEntity.getId(), true, new PostLibaoListener() { - @Override - public void postSucced(Object response) { - - JSONObject responseBody = (JSONObject) response; - Utils.log("postLibaoLing=====" + responseBody); - String libaoCode = null; - try { - libaoCode = responseBody.getString("code"); - } catch (JSONException e) { - e.printStackTrace(); - } - - if (TextUtils.isEmpty(libaoCode)) { - Utils.toast(libaoBtn.getContext(), "领取异常"); - return; - } - libaoEntity.setAvailable(libaoEntity.getAvailable() - 1); - - LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity); -// libaoInfo.setTime(String.valueOf(new Date().getTime())); - libaoInfo.setCode(libaoCode); - libaoDao.add(libaoInfo); - - EventBus.getDefault().post(new EBReuse("libaoChanged")); - - libaoEntity.setStatus("linged"); - adapter.initLibaoDao(); - adapter.notifyDataSetChanged(); - - final String finalLibaoCode = libaoCode; - DialogUtils.showWarningDialog(libaoBtn.getContext(), "领取成功", "礼包码:" + libaoCode + - "\n请尽快使用,礼包码将于60分钟后进入淘号池" - , "关闭", " 复制礼包码" - , new DialogUtils.ConfiremListener() { - @Override - public void onConfirem() { - copyLink(finalLibaoCode, libaoBtn.getContext()); - if (isInstallRequired) { - libaoBtn.postDelayed(new Runnable() { - @Override - public void run() { - lunningAppDialog(libaoBtn.getContext() - , Html.fromHtml("礼包码:" - + "" + finalLibaoCode + "" - + " 复制成功" +"
请尽快进入游戏兑换"), libaoEntity); - } - }, 300); - } - } - }, null); - } - - @Override - public void postFailed(Throwable error) { - Utils.log("-----" + error.toString()); - - if (error instanceof HttpException) { - HttpException exception = (HttpException) error; - if (exception.code() == 403) { - try { - JSONObject errorJson = new JSONObject(exception.response().errorBody().string()); - String detail = errorJson.getString("detail"); - - if ("coming".equals(detail)) { - Utils.toast(libaoBtn.getContext(), "礼包领取时间未开始"); - } else if ("finish".equals(detail)) { - Utils.toast(libaoBtn.getContext(), "礼包领取时间已结束"); - } else if ("fetched".equals(detail)) { - Utils.toast(libaoBtn.getContext(), "你已领过这个礼包了"); - getCunHaoXiang(libaoBtn.getContext(), true); - libaoBtn.setText("复制"); - libaoBtn.setBackgroundResource(R.drawable.textview_blue_style); - } else if ("try tao".equals(detail) || "used up".equals(detail)) { - DialogUtils.showHintDialog(libaoBtn.getContext(), "礼包已领光" - , "手速不够快,礼包已经被抢光了,十分抱歉", "知道了"); - } else if ("maintaining".equals(detail)) { - Utils.toast(libaoBtn.getContext(), "网络状态异常,请稍后再试"); - } else { - Utils.toast(libaoBtn.getContext(), "操作失败"); - } - } catch (Exception ex) { - ex.printStackTrace(); - Utils.toast(libaoBtn.getContext(),"礼包处理异常"); - } - return; - } - } - Utils.toast(libaoBtn.getContext(), "网络异常"); - } - }); + libaoLing(libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, null); break; case "淘号": @@ -419,8 +339,9 @@ public class LibaoUtils { adapter.notifyDataSetChanged(); final String finalLibaoCode = libaoCode; - DialogUtils.showWarningDialog(libaoBtn.getContext(), "淘号成功", "礼包码:" + libaoCode + - "\n淘号礼包不保证可用,请尽快进入游戏尝试兑换" + DialogUtils.showWarningDialog(libaoBtn.getContext(), "淘号成功",Html.fromHtml("礼包码:" + + "" + libaoCode + "" + + "
淘号礼包不保证可用,请尽快进入游戏尝试兑换") , "关闭", " 复制礼包码" , new DialogUtils.ConfiremListener() { @Override @@ -480,7 +401,7 @@ public class LibaoUtils { return; } } - Utils.toast(libaoBtn.getContext(), "网络异常"); + Utils.toast(libaoBtn.getContext(), "发生异常"); } }); break; @@ -489,6 +410,117 @@ public class LibaoUtils { }); } + private static void libaoLing(final TextView libaoBtn, final LibaoEntity libaoEntity, final LibaoDetailAdapter adapter, + final boolean isInstallRequired, final LibaoDao libaoDao, String captchaCode) { + + postLibaoLing(libaoBtn.getContext(), libaoEntity.getId(), true, new PostLibaoListener() { + @Override + public void postSucced(Object response) { + + JSONObject responseBody = (JSONObject) response; + Utils.log("postLibaoLing=====" + responseBody); + String libaoCode = null; + try { + libaoCode = responseBody.getString("code"); + } catch (JSONException e) { + e.printStackTrace(); + } + + if (TextUtils.isEmpty(libaoCode)) { + Utils.toast(libaoBtn.getContext(), "领取异常"); + return; + } + libaoEntity.setAvailable(libaoEntity.getAvailable() - 1); + + LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity); + libaoInfo.setCode(libaoCode); + libaoDao.add(libaoInfo); + + EventBus.getDefault().post(new EBReuse("libaoChanged")); + + libaoEntity.setStatus("linged"); + adapter.initLibaoDao(); + adapter.notifyDataSetChanged(); + + final String finalLibaoCode = libaoCode; + DialogUtils.showWarningDialog(libaoBtn.getContext(), "领取成功", Html.fromHtml("礼包码:" + + "" + libaoCode + "" + + "
请尽快使用,礼包码将于60分钟后进入淘号池") + , "关闭", " 复制礼包码" + , new DialogUtils.ConfiremListener() { + @Override + public void onConfirem() { + copyLink(finalLibaoCode, libaoBtn.getContext()); + if (isInstallRequired) { + libaoBtn.postDelayed(new Runnable() { + @Override + public void run() { + lunningAppDialog(libaoBtn.getContext() + , Html.fromHtml("礼包码:" + + "" + finalLibaoCode + "" + + " 复制成功" +"
请尽快进入游戏兑换"), libaoEntity); + } + }, 300); + } + } + }, null); + } + + @Override + public void postFailed(Throwable error) { + Utils.log("-----" + error.toString()); + + if (error instanceof HttpException) { + HttpException exception = (HttpException) error; + if (exception.code() == 403) { + try { + Utils.log("----403" + exception.response().errorBody().string()); + JSONObject errorJson = new JSONObject(exception.response().errorBody().string()); + String detail = errorJson.getString("detail"); + + if ("coming".equals(detail)) { + Utils.toast(libaoBtn.getContext(), "礼包领取时间未开始"); + } else if ("finish".equals(detail)) { + Utils.toast(libaoBtn.getContext(), "礼包领取时间已结束"); + } else if ("fetched".equals(detail)) { + Utils.toast(libaoBtn.getContext(), "你已领过这个礼包了"); + getCunHaoXiang(libaoBtn.getContext(), true); + libaoBtn.setText("复制"); + libaoBtn.setBackgroundResource(R.drawable.textview_blue_style); + + } else if ("try tao".equals(detail) || "used up".equals(detail)) { + DialogUtils.showHintDialog(libaoBtn.getContext(), "礼包已领光" + , "手速不够快,礼包已经被抢光了,十分抱歉", "知道了"); + libaoEntity.setStatus("used_up"); + initLibaoBtn(libaoBtn, libaoEntity, libaoDao, isInstallRequired, adapter); + + } else if ("maintaining".equals(detail)) { + Utils.toast(libaoBtn.getContext(), "网络状态异常,请稍后再试"); + } else { + Utils.toast(libaoBtn.getContext(), "操作失败"); + } + } catch (Exception ex) { + ex.printStackTrace(); + Utils.toast(libaoBtn.getContext(),"礼包处理异常"); + } + return; + } else if (exception.code() == 412) { + // 需要验证 + GeetestUtils.getInstance(libaoBtn.getContext()) + .showDialog(new GeetestUtils.GeetestListener() { + @Override + public void succed(String response) { + libaoLing(libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, response); + } + }); + return; + } + } + Utils.toast(libaoBtn.getContext(), "发生异常"); + } + }, captchaCode); + } + public static boolean isAppInstalled(Context context, String packageName) { final android.content.pm.PackageManager packageManager = context.getPackageManager(); List pinfo = packageManager.getInstalledPackages(0); diff --git a/app/src/main/java/com/gh/common/util/NotificationUtils.java b/app/src/main/java/com/gh/common/util/NotificationUtils.java index 33e9a6b2d3..41a4fc3598 100644 --- a/app/src/main/java/com/gh/common/util/NotificationUtils.java +++ b/app/src/main/java/com/gh/common/util/NotificationUtils.java @@ -27,13 +27,13 @@ public class NotificationUtils { String text; String title; if (downloadEntity.isPluggable()) { - text = "下载完成,点击继续插件化"; - title = downloadEntity.getName() + "-" + title = "下载完成,点击继续插件化"; + text = downloadEntity.getName() + " - " + PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform()); } else { if (downloadEntity.isPlugin()) { text = downloadEntity.getName() - + PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform()); + + " - " + PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform()); } else { text = downloadEntity.getName(); } diff --git a/app/src/main/java/com/gh/download/DownloadManager.java b/app/src/main/java/com/gh/download/DownloadManager.java index 266a5aa031..09a49426c3 100644 --- a/app/src/main/java/com/gh/download/DownloadManager.java +++ b/app/src/main/java/com/gh/download/DownloadManager.java @@ -221,7 +221,7 @@ public class DownloadManager { String location) { // 安装指引 - if (android.os.Build.BRAND.equals("Huawei") || "Oppo".equals(android.os.Build.BRAND)) { + if (android.os.Build.MANUFACTURER.equalsIgnoreCase("Huawei") || "Oppo".equalsIgnoreCase(android.os.Build.MANUFACTURER)) { SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); final SharedPreferences.Editor edit = sp.edit(); if (sp.getBoolean("InstallHint" + PackageUtils.getVersionName(context), true)) { diff --git a/app/src/main/java/com/gh/gamecenter/WebActivity.java b/app/src/main/java/com/gh/gamecenter/WebActivity.java index d0ccad5837..f9b5ed3187 100644 --- a/app/src/main/java/com/gh/gamecenter/WebActivity.java +++ b/app/src/main/java/com/gh/gamecenter/WebActivity.java @@ -150,7 +150,7 @@ public class WebActivity extends BaseActivity { super.onNext(response); if (response.size() > 0 && response.get(0).getNum() > 0) { commentNum = response.get(0).getNum(); - webComment.setText("查看评论 (" + response.get(0).getNum() + ")"); + webComment.setText("查看评论(" + response.get(0).getNum() + ")"); } } }); @@ -170,7 +170,7 @@ public class WebActivity extends BaseActivity { super.onActivityResult(requestCode, resultCode, data); // 刷新评论数 if (resultCode == 1001 && progressBar.getVisibility() == View.VISIBLE && newsId != null) { - webComment.setText("查看评论 (" + data.getExtras().getInt("commentNum") + ")"); + webComment.setText("查看评论(" + data.getExtras().getInt("commentNum") + ")"); } } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java index 0c857f07f3..e67e1b2ccf 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java @@ -221,7 +221,7 @@ public class LibaoDetailAdapter extends RecyclerView.Adapter" + libaoInfo.getCode() + "" + " 复制成功" + + msg = Html.fromHtml("礼包码:" + "" + libaoInfo.getCode() + "" + " 复制成功" + "
请尽快进入游戏兑换"); } else { msg = Html.fromHtml("礼包码:" +"" + libaoInfo.getCode() + "" + " 复制成功" + @@ -236,7 +236,7 @@ public class LibaoDetailAdapter extends RecyclerView.Adapter" +libaoInfo.getCode()+ ""); + libaoCode = Html.fromHtml("已领取:" + "" +libaoInfo.getCode()+ ""); if (count == 0) { content = Html.fromHtml("剩余:" + count + "%"); } else { diff --git a/app/src/main/java/com/gh/gamecenter/game/GameFragment.java b/app/src/main/java/com/gh/gamecenter/game/GameFragment.java index 14311b4892..5a8c5514a8 100644 --- a/app/src/main/java/com/gh/gamecenter/game/GameFragment.java +++ b/app/src/main/java/com/gh/gamecenter/game/GameFragment.java @@ -228,6 +228,7 @@ public class GameFragment extends HomeFragment implements SwipeRefreshLayout.OnR adapter.notifyItemRangeRemoved(1, 2); // adapter.notifyItemChanged(1); // 如果position是1为图片时 需要刷新卡片高度 } else { + adapter.initPlugin(); adapter.initItemCount(); adapter.notifyItemRemoved(location); adapter.notifyItemChanged(1); diff --git a/app/src/main/java/com/gh/gamecenter/game/GameFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/game/GameFragmentAdapter.java index 0af583f5ee..81e70bd913 100644 --- a/app/src/main/java/com/gh/gamecenter/game/GameFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/game/GameFragmentAdapter.java @@ -36,6 +36,7 @@ import com.gh.common.util.RandomUtils; import com.gh.common.util.Utils; import com.gh.common.view.AutoScrollViewPager; import com.gh.common.view.CardLinearLayout; +import com.gh.common.view.CardRelativeLayout; import com.gh.download.DownloadManager; import com.gh.gamecenter.LibaoActivity; import com.gh.gamecenter.NewsDetailActivity; @@ -336,7 +337,7 @@ public class GameFragmentAdapter extends RecyclerView.Adapter mJsInterfaceMap = new HashMap(); + private String mJsStringCache = null; + private Context mContext; + private Timer domainTimer; + private Timer ipTimer; + + private String mParamsString; + + public boolean debug = false; + + public interface GtWebViewListener { + //通知native验证已准备完毕 + void gtCallReady(Boolean status); // true准备完成/false未准备完成 + //通知javascript发生严重错误 + void gtError(); + } + + private GtWebViewListener gtListener; + + public void setGtWebViewListener(GtWebViewListener listener) { + gtListener = listener; + } + + public GTWebView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(context); + } + + public GTWebView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public GTWebView(Context context) { + super(context); + init(context); + } + + private void init(Context context) { + mContext = context; + + WebSettings webSettings = this.getSettings(); + webSettings.setJavaScriptEnabled(true); + webSettings.setLoadWithOverviewMode(true); + webSettings.setDomStorageEnabled(true); + webSettings.setDatabaseEnabled(true); +// webSettings.setSupportZoom(true); + webSettings.setUseWideViewPort(true); + this.setOverScrollMode(View.OVER_SCROLL_NEVER); + this.setHorizontalScrollBarEnabled(false); + this.setVerticalScrollBarEnabled(false); + this.onResume(); + + // 添加默认的Client + super.setWebChromeClient(new WebChromeClientEx()); + super.setWebViewClient(new WebViewClientEx()); + + // 删除掉Android默认注册的JS接口 + removeSearchBoxImpl(); + } + + @Override + public void loadUrl(String url) { + domainTimer = new Timer(); + TimerTask timerTask = new TimerTask() { + @Override + public void run() { + ((Activity)mContext).runOnUiThread(new Runnable() { + @Override + public void run() { + if (getProgress() < 100) { + stopLoading(); + new PingTask().execute(); + + domainTimer.cancel(); + domainTimer.purge(); + } + } + }); + } + }; + domainTimer.schedule(timerTask, 5000); + + super.loadUrl(url); + } + + public void loadIPUrl(String aIP, String paramsString) { + String mobile_ip_request_url = "http://" + aIP +"/static/appweb/app-index.html" + paramsString; + Utils.log("验证模块url: " + mobile_ip_request_url); + final Map additionalHttpHeaders = new HashMap(); + additionalHttpHeaders.put("Host", baseDomain); + loadUrl(mobile_ip_request_url, additionalHttpHeaders); +// Log.i(ACTIVITY_TAG, "webview did load ip url"); + ipTimer = new Timer(); + TimerTask timerTask1 = new TimerTask() { + @Override + public void run() { + ((Activity)mContext).runOnUiThread(new Runnable() { + @Override + public void run() { + if (getProgress() < 100) { + stopLoading(); + if (gtListener != null) { + gtListener.gtCallReady(false); + } + ipTimer.cancel(); + ipTimer.purge(); + } + } + }); + } + }; + ipTimer.schedule(timerTask1, 10000); + } + + @Override + public void addJavascriptInterface(Object obj, String interfaceName) { + if (TextUtils.isEmpty(interfaceName)) { + return; + } + + // 如果在4.2以上,直接调用基类的方法来注册 + if (hasJellyBeanMR1()) { + super.addJavascriptInterface(obj, interfaceName); + } else { + mJsInterfaceMap.put(interfaceName, obj); + } + } + + @Override + public void removeJavascriptInterface(String interfaceName) { + if (hasJellyBeanMR1()) { + super.removeJavascriptInterface(interfaceName); + } else { + mJsInterfaceMap.remove(interfaceName); + mJsStringCache = null; + injectJavascriptInterfaces(); + } + } + + private boolean removeSearchBoxImpl() { + if (hasHoneycomb() && !hasJellyBeanMR1()) { + super.removeJavascriptInterface("searchBoxJavaBridge_"); + return true; + } + + return false; + } + + private void injectJavascriptInterfaces() { + if (!TextUtils.isEmpty(mJsStringCache)) { + loadJavascriptInterfaces(); + return; + } + + String jsString = genJavascriptInterfacesString(); + mJsStringCache = jsString; + loadJavascriptInterfaces(); + } + + private void injectJavascriptInterfaces(WebView webView) { + if (webView instanceof GTWebView) { + injectJavascriptInterfaces(); + } + } + + private void loadJavascriptInterfaces() { + this.loadUrl(mJsStringCache); + } + + private String genJavascriptInterfacesString() { + if (mJsInterfaceMap.size() == 0) { + mJsStringCache = null; + return null; + } + + /* + * 要注入的JS的格式,其中XXX为注入的对象的方法名,例如注入的对象中有一个方法A,那么这个XXX就是A + * 如果这个对象中有多个方法,则会注册多个window.XXX_js_interface_name块,我们是用反射的方法遍历 + * 注入对象中的所有带有@JavaScripterInterface标注的方法 + * + * javascript:(function JsAddJavascriptInterface_(){ + * if(typeof(window.XXX_js_interface_name)!='undefined'){ + * console.log('window.XXX_js_interface_name is exist!!'); + * }else{ + * window.XXX_js_interface_name={ + * XXX:function(arg0,arg1){ + * return prompt('MyApp:'+JSON.stringify({obj:'XXX_js_interface_name',func:'XXX_',args:[arg0,arg1]})); + * }, + * }; + * } + * })() + */ + + Iterator> iterator = mJsInterfaceMap.entrySet().iterator(); + // Head + StringBuilder script = new StringBuilder(); + script.append("javascript:(function JsAddJavascriptInterface_(){"); + + // Add methods + try { + while (iterator.hasNext()) { + Entry entry = iterator.next(); + String interfaceName = entry.getKey(); + Object obj = entry.getValue(); + + createJsMethod(interfaceName, obj, script); + } + } catch (Exception e) { + e.printStackTrace(); + } + + // End + script.append("})()"); + + return script.toString(); + } + + private void createJsMethod(String interfaceName, Object obj, StringBuilder script) { + if (TextUtils.isEmpty(interfaceName) || (null == obj) || (null == script)) { + return; + } + + Class objClass = obj.getClass(); + + script.append("if(typeof(window.").append(interfaceName).append(")!='undefined'){"); + if (DEBUG) { + script.append(" console.log('window." + interfaceName + "_js_interface_name is exist!!');"); + } + + script.append("}else {"); + script.append(" window.").append(interfaceName).append("={"); + + // Add methods + Method[] methods = objClass.getMethods(); + for (Method method : methods) { + String methodName = method.getName(); + // 过滤掉Object类的方法,包括getClass()方法,因为在Js中就是通过getClass()方法来得到Runtime实例 + if (filterMethods(methodName)) { + continue; + } + + script.append(" ").append(methodName).append(":function("); + // 添加方法的参数 + int argCount = method.getParameterTypes().length; + if (argCount > 0) { + int maxCount = argCount - 1; + for (int i = 0; i < maxCount; ++i) { + script.append(VAR_ARG_PREFIX).append(i).append(","); + } + script.append(VAR_ARG_PREFIX).append(argCount - 1); + } + + script.append(") {"); + + // Add implementation + if (method.getReturnType() != void.class) { + script.append(" return ").append("prompt('").append(MSG_PROMPT_HEADER).append("'+"); + } else { + script.append(" prompt('").append(MSG_PROMPT_HEADER).append("'+"); + } + + // Begin JSON + script.append("JSON.stringify({"); + script.append(KEY_INTERFACE_NAME).append(":'").append(interfaceName).append("',"); + script.append(KEY_FUNCTION_NAME).append(":'").append(methodName).append("',"); + script.append(KEY_ARG_ARRAY).append(":["); + // 添加参数到JSON串中 + if (argCount > 0) { + int max = argCount - 1; + for (int i = 0; i < max; i++) { + script.append(VAR_ARG_PREFIX).append(i).append(","); + } + script.append(VAR_ARG_PREFIX).append(max); + } + + // End JSON + script.append("]})"); + // End prompt + script.append(");"); + // End function + script.append(" }, "); + } + + // End of obj + script.append(" };"); + // End of if or else + script.append("}"); + } + + private boolean handleJsInterface(WebView view, String url, String message, String defaultValue, + JsPromptResult result) { + String prefix = MSG_PROMPT_HEADER; + if (!message.startsWith(prefix)) { + return false; + } + + String jsonStr = message.substring(prefix.length()); + try { + JSONObject jsonObj = new JSONObject(jsonStr); + String interfaceName = jsonObj.getString(KEY_INTERFACE_NAME); + String methodName = jsonObj.getString(KEY_FUNCTION_NAME); + JSONArray argsArray = jsonObj.getJSONArray(KEY_ARG_ARRAY); + Object[] args = null; + if (null != argsArray) { + int count = argsArray.length(); + if (count > 0) { + args = new Object[count]; + + for (int i = 0; i < count; ++i) { + args[i] = argsArray.get(i); + } + } + } + + if (invokeJSInterfaceMethod(result, interfaceName, methodName, args)) { + return true; + } + } catch (Exception e) { + e.printStackTrace(); + } + + result.cancel(); + return false; + } + + private boolean invokeJSInterfaceMethod(JsPromptResult result, + String interfaceName, String methodName, Object[] args) { + + boolean succeed = false; + final Object obj = mJsInterfaceMap.get(interfaceName); + if (null == obj) { + result.cancel(); + return false; + } + + Class[] parameterTypes = null; + int count = 0; + if (args != null) { + count = args.length; + } + + if (count > 0) { + parameterTypes = new Class[count]; + for (int i = 0; i < count; ++i) { + parameterTypes[i] = getClassFromJsonObject(args[i]); + } + } + + try { + Method method = obj.getClass().getMethod(methodName, parameterTypes); + Object returnObj = method.invoke(obj, args); // 执行接口调用 + boolean isVoid = returnObj == null || returnObj.getClass() == void.class; + String returnValue = isVoid ? "" : returnObj.toString(); + result.confirm(returnValue); // 通过prompt返回调用结果 + succeed = true; + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + result.cancel(); + return succeed; + } + + private Class getClassFromJsonObject(Object obj) { + Class cls = obj.getClass(); + + // js对象只支持int boolean string三种类型 + if (cls == Integer.class) { + cls = Integer.TYPE; + } else if (cls == Boolean.class) { + cls = Boolean.TYPE; + } else { + cls = String.class; + } + + return cls; + } + + private boolean filterMethods(String methodName) { + for (String method : mFilterMethods) { + if (method.equals(methodName)) { + return true; + } + } + + return false; + } + + private boolean hasHoneycomb() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; + } + + private boolean hasJellyBeanMR1() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; + } + + private class WebChromeClientEx extends WebChromeClient { + @Override + public final void onProgressChanged(WebView view, int newProgress) { + injectJavascriptInterfaces(view); + super.onProgressChanged(view, newProgress); + } + + @Override + public final boolean onJsPrompt(WebView view, String url, String message, + String defaultValue, JsPromptResult result) { + if (view instanceof GTWebView) { + if (handleJsInterface(view, url, message, defaultValue, result)) { + return true; + } + } + + return super.onJsPrompt(view, url, message, defaultValue, result); + } + + @Override + public final void onReceivedTitle(WebView view, String title) { + injectJavascriptInterfaces(view); + } + } + + private class WebViewClientEx extends WebViewClient { + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + // TODO Auto-generated method stub + + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + mContext.startActivity(intent); + + return true; + } + +// @Override +// public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { +// // TODO Auto-generated method stub +// if (gtListener != null) { +// gtListener.gtCallReady(false); +// } +// super.onReceivedError(view, request, error); +// } + + @Override + public void onReceivedError(WebView view, int errorCode, + String description, String failingUrl) { + // TODO Auto-generated method stub + if (gtListener != null) { + gtListener.gtCallReady(false); + } + super.onReceivedError(view, errorCode, description, failingUrl); + } + +// @TargetApi(23) +// @Override +// public void onReceivedHttpError( +// WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { +// // +// if (gtListener != null) { +// gtListener.gtCallReady(false); +// } +// super.onReceivedHttpError(view, request, errorResponse); +// } + + @Override + public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { + //handler.cancel(); 默认的处理方式,WebView变成空白页 + //handler.process();接受证书 + //handleMessage(Message msg); 其他处理 + if (gtListener != null) { + gtListener.gtError(); + } + } + + @Override + public void onLoadResource(WebView view, String url) { + injectJavascriptInterfaces(view); + super.onLoadResource(view, url); + } + + @Override + public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) { + injectJavascriptInterfaces(view); + super.doUpdateVisitedHistory(view, url, isReload); + } + + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + // TODO Auto-generated method stub +// Log.i(ACTIVITY_TAG, "webview did start"); + injectJavascriptInterfaces(view); + super.onPageStarted(view, url, favicon); + } + + @Override + public void onPageFinished(WebView view, String url) { + if (debug) { + //当验证无法访问, 可能展示PROXY ERROR + if (gtListener != null) { + gtListener.gtCallReady(false); + } + } + // TODO Auto-generated method stub +// Log.i(ACTIVITY_TAG, "webview did finish"); + injectJavascriptInterfaces(view); + super.onPageFinished(view, url); + } + } + + private class PingTask extends AsyncTask { + + @Override + protected String doInBackground(String... params) { + //"115.28.113.153" + for (int i = 0; i < staticIPList.length; i++) { + String ip = ping(staticIPList[i], 0); + if (null != ip) { + return ip; + } + } + return null; + } + + @Override + protected void onPostExecute(String result) { + if (null != result) { + loadIPUrl(result, mParamsString); + } + else { + if (gtListener != null) { + gtListener.gtCallReady(false); + } + } + } + + private String ping(String host, int port) { + if (port == 0) port = 80; + + Socket connect = new Socket(); + try { + connect.connect(new InetSocketAddress(host, port), 2 * 1000); +// Log.i(ACTIVITY_TAG, "Ping " + host); + if (connect.isConnected()) { + return host; + } + else { + return null; + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + connect.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + } +} diff --git a/app/src/main/java/com/gh/gamecenter/geetest/GeetestUtils.java b/app/src/main/java/com/gh/gamecenter/geetest/GeetestUtils.java new file mode 100644 index 0000000000..e2f63057cc --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/geetest/GeetestUtils.java @@ -0,0 +1,215 @@ +package com.gh.gamecenter.geetest; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.widget.Toast; + +import com.gh.common.util.TokenUtils; +import com.gh.common.util.Utils; +import com.gh.gamecenter.retrofit.JSONObjectResponse; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import org.json.JSONObject; + +import okhttp3.ResponseBody; +import retrofit2.adapter.rxjava.HttpException; +import rx.Observable; +import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Func1; +import rx.schedulers.Schedulers; + +/** + * Created by khy on 2017/1/12. + */ +public class GeetestUtils { + private static Context context; + private static GeetestUtils singleton; + + private ProgressDialog progressDialog; + + private GeetestListener geetestListener; + + public Boolean isOperating; + + public static GeetestUtils getInstance(Context currentContext) { + context = currentContext; + if (singleton == null) { + synchronized (GeetestUtils.class) { + if (singleton == null) { + singleton = new GeetestUtils(); + return singleton; + } + } + } + return singleton; + } + + + public void showDialog(GeetestListener listener) { + this.geetestListener = listener; + checkServer(true,singleton); + + if (!((Activity) context).isFinishing()) { + progressDialog = ProgressDialog.show(context, null, "Loading", true, true); + progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { +// toastMsg("user cancel progress dialog"); + //TODO 用户主动退出验证 + } + }); + } + } + + public void checkServer(boolean isCheck, final GeetestUtils geetestUtils) { + isOperating = true; + + TokenUtils.getToken(context, isCheck) + .flatMap(new Func1>() { + @Override + public Observable call(String token) { + return RetrofitManager.getLibao().getCaptchaData(token); + } + }).subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new JSONObjectResponse(){ + @Override + public void onResponse(JSONObject info) { + super.onResponse(info); + isOperating = false; + try { + if (info.toString().length() > 0) { + + Utils.log("验证模块返回:" + info.toString()); + + JSONObject config = info; + + if (config.getInt("success") == 1) { + geetestUtils.openGtTest(context, config); + } else { + // TODO 从API_1获得极验服务宕机或不可用通知, 使用备用验证或静态验证 + if (progressDialog.isShowing()) { + progressDialog.dismiss(); + } + toastMsg("从服务器不接受的验证"); + } + } + + } catch (Exception e) { + if (progressDialog.isShowing()) { + progressDialog.dismiss(); + } + toastMsg("从API接收到无效的JSON参数"); + e.printStackTrace(); + } + } + + @Override + public void onFailure(HttpException e) { + super.onFailure(e); + if (e != null && e.code() == 401) { + checkServer(false, geetestUtils); + } else { + if (progressDialog.isShowing()) { + progressDialog.dismiss(); + } + toastMsg("服务器返回错误/网络错误"); + isOperating = false; + } + } + }); + } + + + public void openGtTest(Context ctx, JSONObject params) { + + GtDialog dialog = new GtDialog(ctx, params); + + // 启用debug可以在webview上看到验证过程的一些数据 +// dialog.setDebug(true); + + dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + //TODO 用户取消验证 +// toastMsg("user close the geetest."); + } + }); + + dialog.setGtListener(new GtDialog.GtListener() { + + @Override + public void gtResult(boolean success, String result) { + + if (success) { + geetestListener.succed(result); +// toastMsg("client captcha succeed:" + result); + Utils.log("client captcha succeed:" + result); + } else { + //TODO 验证失败 +// toastMsg("client captcha failed:" + result); + Utils.log("client captcha failed:" + result); + } + } + + @Override + public void gtCallClose() { + +// toastMsg("close geetest windows"); + } + + @Override + public void gtCallReady(Boolean status) { + + progressDialog.dismiss(); + + if (status) { + //TODO 验证加载完成 +// toastMsg("geetest finish load"); + } else { + //TODO 验证加载超时,未准备完成 +// toastMsg("there's a network jam"); + toastMsg("验证加载超时,请重新尝试"); + } + } + + @Override + public void gtError() { + progressDialog.dismiss(); + //TODO 验证加载出现异常 +// toastMsg("Fatal Error Did Occur."); + } + + }); + + } + + private void toastMsg(final String msg) { + + ((Activity)context).runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); + } + }); + + } + + private void toastLongTimeMsg(final String msg) { + + ((Activity)context).runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); + } + }); + + } + + public interface GeetestListener { + void succed(String response); + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/geetest/GtDialog.java b/app/src/main/java/com/gh/gamecenter/geetest/GtDialog.java new file mode 100644 index 0000000000..b07efc9a75 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/geetest/GtDialog.java @@ -0,0 +1,330 @@ +package com.gh.gamecenter.geetest; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.telephony.TelephonyManager; +import android.view.Gravity; +import android.view.ViewGroup.LayoutParams; +import android.view.Window; +import android.webkit.JavascriptInterface; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.gh.common.util.Utils; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Iterator; + +/** + * 验证对话框 + * + * @author dreamzsm@gmail.com + * + */ +public class GtDialog extends Dialog { + + private String baseURL = "https://static.geetest.com/static/appweb/app-index.html"; +// private String baseURL = "http://192.168.1.158:8721"; + + protected static final String ACTIVITY_TAG="GtDialog"; + private TelephonyManager tm; + private Context mContext; + + private String mParamsString; + private String product = "embed"; + private String language = "zh-cn"; + private String mTitle = ""; + private Boolean debug = false; + + private Dialog mDialog = this; + private int mWidth; + private int mHeight; + private int mTimeout = 10000;//默认10000ms + private GTWebView webView; + + public Boolean isShowing = false; + + public void setBaseURL(String url) { + this.baseURL = url; + } + + public void setDebug(Boolean debug) { + this.debug = debug; + } + + public void setProduct(String product) { + this.product = product; + } + + //支持"zh-cn","zh-hk","zh-tw","ko-kr","ja-jp","en-us".默认"zh-cn". + public void setLanguage(String lang) { + this.language = lang; + } + + //验证标题, 默认无标题, 不宜过长. + public void setGTTitle(String title) { this.mTitle = title;} + + public void setTimeout(int timeout) { + this.mTimeout = timeout; + } + + @Override + public void onDetachedFromWindow() { + + super.onDetachedFromWindow(); + } + + public void stopLoading() { + webView.stopLoading(); + } + + public GtDialog (Context context, JSONObject params) { + super(context); + mContext = context; + tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); + mParamsString = unwrappingParameters(params); + init(context); + } + + private void init(Context context) { + + webView = new GTWebView(context); + + webView.setGtWebViewListener(new GTWebView.GtWebViewListener() { + @Override + public void gtCallReady(Boolean status) { + if (gtListener != null) { + gtListener.gtCallReady(status); + } + } + + @Override + public void gtError() { + if (gtListener != null) { + gtError(); + } + } + }); + + webView.addJavascriptInterface(new JSInterface(), "JSInterface"); + + String pathUrl = getPathUrl(mParamsString); + String gt_mobile_req_url = baseURL + pathUrl; + Utils.log("验证模块拼接后的url: " + gt_mobile_req_url); + webView.loadUrl(gt_mobile_req_url); + + webView.buildLayer(); + } + + + + private String unwrappingParameters(JSONObject params) { + Iterator iter = params.keys(); + String paramString = ""; + while (iter.hasNext()) { + String key = iter.next(); + try { + if (iter.hasNext()) { + String comp = key + "=" + params.getString(key) + "&"; + paramString = paramString + comp; + } + else { + String comp = key + "=" + params.getString(key); + paramString = paramString + comp; + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + return paramString; + } + + private String getPathUrl(String paramsString) { + + mWidth = getDeviceWidth(); + mHeight = getDeviceHeight(); + float scale = getDeviceScale(); + + return "?" + paramsString +// + "&challenge=" + this.challenge +// + "&success=" + (this.success ? 1 : 0) + + "&imei=" + tm.getDeviceId() + + "&mType=" + Build.MODEL + + "&osType=" + "android" + + "&osVerInt=" + Build.VERSION.RELEASE + + "&gsdkVerCode=" + "2.16.12.15.1" + + "&title=" + this.mTitle //验证标题,不宜过长 + + "&lang=" + this.language //支持"zh-cn","zh-hk","zh-tw","ko-kr","ja-jp","en-us".默认"zh-cn" + + "&debug=" + this.debug + + "&width=" + (int)(mWidth / scale + 1.5f);//1.5f: fix blank on the webview + } + + private float getDeviceScale() { + return getContext().getResources().getDisplayMetrics().density; + } + + private int getDeviceWidth() { + int height = DimenTool.getHeightPx(getContext()); + int width = DimenTool.getWidthPx(getContext()); + float scale = getDeviceScale(); + + final int WIDTH = 290; + + if (height < width) { + width = height * 3 / 4; + } + width = width * 4 / 5; + if ((int)(width / scale + 0.5f) < WIDTH) { + width = (int)((WIDTH - 0.5f) * scale); + } + return width; + } + + private int getDeviceHeight() { + int height = DimenTool.getHeightPx(getContext()); + int width = DimenTool.getWidthPx(getContext()); + float scale = getContext().getResources().getDisplayMetrics().density; + + final int HEIGHT = 500; + + return (int)(HEIGHT * scale); + } + + public interface GtListener { + //通知native验证已准备完毕 + void gtCallReady(Boolean status); // true准备完成/false未准备完成 + //通知native关闭验证 + void gtCallClose(); + //通知javascript发生严重错误 + void gtError(); + //通知native验证结果,并准备二次验证 + void gtResult(boolean success, String result); + } + + private GtListener gtListener; + + public void setGtListener(GtListener listener) { + gtListener = listener; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + RelativeLayout contentView = new RelativeLayout(getContext()); + + contentView.addView(webView); + TextView textView = new TextView(getContext()); + textView.setBackgroundColor(Color.WHITE); + textView.setGravity(Gravity.CENTER); + textView.setText("完成验证,领取礼包"); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(getDeviceWidth(), (int)((float)getDeviceWidth()/7.5)); + params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + contentView.addView(textView, params); + + setContentView(contentView); + + final LayoutParams layoutParams = webView.getLayoutParams(); + + layoutParams.width = mWidth; + layoutParams.height = LayoutParams.WRAP_CONTENT; + webView.setLayoutParams(layoutParams); + + + LayoutParams contentViewParams = contentView.getLayoutParams(); + contentViewParams.height = (int) ((float)getDeviceWidth() * 0.97); + contentViewParams.width = getDeviceWidth(); + contentView.setLayoutParams(contentViewParams); + } + + @Override + public void show() { + isShowing = true; + super.show(); + } + + @Override + public void dismiss() { + isShowing = false; + webView.stopLoading(); + webView.removeJavascriptInterface("JSInterface"); + webView.removeAllViews(); + webView.destroy(); + super.dismiss(); + } + + public class JSInterface { + + @JavascriptInterface + public void gtCallBack(String code, String result, String message) { + final int fCode; + final String fResult = result; + final String fMessage = message; + try { + fCode = Integer.parseInt(code); + ((Activity)mContext).runOnUiThread(new Runnable() { + @Override + public void run() { + + if (fCode == 1) { + dismiss(); + + if (gtListener != null) { + gtListener.gtResult(true, fResult); + } + + } else { + if (gtListener != null) { + gtListener.gtResult(false, fResult); + } + } + } + }); + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @JavascriptInterface + public void gtCloseWindow() { + dismiss(); + if (gtListener != null) { + gtListener.gtCallClose(); + } + } + + @JavascriptInterface + public void gtReady() { + + ((Activity)mContext).runOnUiThread(new Runnable() { + + @Override + public void run() { + mDialog.show(); + } + }); + + if (gtListener != null) { + gtListener.gtCallReady(true); + } + } + + @JavascriptInterface + public void gtError() { + if (gtListener != null) { + gtListener.gtError(); + } + } + + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java b/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java index 8a1bcb3818..54723fb7e5 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao1Fragment.java @@ -156,9 +156,9 @@ public class Libao1Fragment extends BaseFragment implements SwipeRefreshLayout.O } else { if (mNormalAdapter != null && !isRefresh) { adapter = mNormalAdapter; - adapter.setSearchKey(mSearckKey); +// adapter.setSearchKey(mSearckKey); } else { - adapter = new Libao1FragmentAdapter(Libao1Fragment.this, mIsSearch, mSearckKey); + adapter = new Libao1FragmentAdapter(Libao1Fragment.this, mIsSearch, null); mNormalAdapter = adapter; adapter.addLibaoList(false, 0); } diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java index fca486dbdb..5fcb80af6a 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java @@ -116,7 +116,7 @@ public class Libao3FragmentAdapter extends RecyclerView.Adapter" +libaoEntity.getCode()+ ""); + content = Html.fromHtml("已领取:" + "" +libaoEntity.getCode()+ ""); } else { content = Html.fromHtml("已淘号:" + "" +libaoEntity.getCode()+ ""); } @@ -130,7 +130,7 @@ public class Libao3FragmentAdapter extends RecyclerView.Adapter" + libaoEntity.getCode() + "" + " 复制成功" + + msg = Html.fromHtml("礼包码:" + "" + libaoEntity.getCode() + "" + " 复制成功" + "
请尽快进入游戏兑换"); } else { msg = Html.fromHtml("礼包码:" +"" + libaoEntity.getCode() + "" + " 复制成功" + diff --git a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java index 994301d228..3ae2914378 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java @@ -567,7 +567,12 @@ public class News1FragmentAdapter extends RecyclerView.Adapter postLibaoLing(@Header("TOKEN") String token, @Path("libao_id") String libaoId); // 领取礼包 + @POST("libao/{libao_id}/ling") + Observable postLibaoLing(@Header("TOKEN") String token, @Header("CODE") String captchaCode, + @Path("libao_id") String libaoId); // 领取礼包 带验证数据 + @POST("libao/{libao_id}/tao") Observable postLibaoTao(@Header("TOKEN") String token, @Path("libao_id") String libaoId); // 礼包 淘号 @DELETE("libao/code/{code}") Observable deleteLibaoCode(@Header("TOKEN") String token, @Path("code") String code); //删除存号箱的礼包 + @POST("libao/captcha") + Observable getCaptchaData(@Header("TOKEN") String token); //获取验证码数据 + } diff --git a/app/src/main/java/com/gh/gamecenter/statistics/AppStaticService.java b/app/src/main/java/com/gh/gamecenter/statistics/AppStaticService.java index 545bcf5c86..5327b36e42 100644 --- a/app/src/main/java/com/gh/gamecenter/statistics/AppStaticService.java +++ b/app/src/main/java/com/gh/gamecenter/statistics/AppStaticService.java @@ -112,7 +112,9 @@ public class AppStaticService extends Service { } private void writeToStorage() { - StatisticsUtils.saveRunTime( mPrePackageName, mRunTime, runTimeDao); + if (mRunTime != 0) { + StatisticsUtils.saveRunTime( mPrePackageName, mRunTime, runTimeDao); + } mRunTime = 0; mPrePackageName = mNextPackageName; } diff --git a/app/src/main/res/layout/game_test_item.xml b/app/src/main/res/layout/game_test_item.xml index d44ba9eeb6..63d9d1d1c6 100644 --- a/app/src/main/res/layout/game_test_item.xml +++ b/app/src/main/res/layout/game_test_item.xml @@ -146,10 +146,10 @@ android:layout_height="wrap_content" android:layout_marginRight="5dp" android:background="@drawable/border_white_bg" - android:paddingBottom="2dp" - android:paddingLeft="4dp" - android:paddingRight="4dp" - android:paddingTop="2dp" + android:paddingBottom="1dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" + android:paddingTop="1dp" android:singleLine="true" android:text="null" android:textColor="#ff9601" @@ -161,10 +161,10 @@ android:layout_height="wrap_content" android:layout_marginRight="5dp" android:background="@drawable/textview_green_up" - android:paddingBottom="2dp" - android:paddingLeft="4dp" - android:paddingRight="4dp" - android:paddingTop="2dp" + android:paddingBottom="1dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" + android:paddingTop="1dp" android:singleLine="true" android:text="null" android:textColor="@android:color/white" diff --git a/app/src/main/res/layout/libao_item.xml b/app/src/main/res/layout/libao_item.xml index c191fca089..004e80c25c 100644 --- a/app/src/main/res/layout/libao_item.xml +++ b/app/src/main/res/layout/libao_item.xml @@ -1,6 +1,7 @@