diff --git a/.idea/gradle.xml b/.idea/gradle.xml index d62586096f..f8e9178805 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -12,7 +12,6 @@ diff --git a/.idea/modules.xml b/.idea/modules.xml index e0afaebcf0..a0d9d43a1b 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -6,7 +6,6 @@ - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index a47c496cc0..ce85a8e55f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,5 +37,4 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile project(':hotfixlib') -} +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/base/AppController.java b/app/src/main/java/com/gh/base/AppController.java index b3432f8a04..cf8a14d571 100644 --- a/app/src/main/java/com/gh/base/AppController.java +++ b/app/src/main/java/com/gh/base/AppController.java @@ -5,6 +5,7 @@ import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.app.Application; import android.content.Context; +import android.content.SharedPreferences; import android.os.Process; import android.support.v4.util.ArrayMap; import android.text.TextUtils; @@ -14,7 +15,9 @@ import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.toolbox.Volley; import com.gh.base.GHPushMessageReceiver.PushHandler; +import com.gh.common.constant.Config; import com.gh.common.util.DexUtils; +import com.gh.common.util.HotFix; import com.gh.common.util.Utils; import com.tendcloud.tenddata.TCAgent; import com.xiaomi.channel.commonutils.logger.LoggerInterface; @@ -25,8 +28,6 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import dodola.hotfixlib.HotFix; - public class AppController extends Application { public static final String TAG = AppController.class.getSimpleName(); @@ -102,9 +103,25 @@ public class AppController extends Application { super.onCreate(); File dexPath = new File(getDir("dex", Context.MODE_PRIVATE), "hackdex_dex.jar"); - DexUtils.prepareDex(this.getApplicationContext(), dexPath, "hackdex_dex.jar"); + DexUtils.prepareAssetsDex(this, dexPath, "hackdex_dex.jar"); HotFix.patch(this, dexPath.getAbsolutePath(), "dodola.hackdex.AntilazyLoad"); + SharedPreferences sp = this.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); + File directory = new File(this.getFilesDir().getAbsolutePath() + File.separator + "hotfix"); + if (directory.exists()) { + File[] files = directory.listFiles(); + for (File file : files) { + Utils.log("dex file = " + file.getName()); + String clazz = sp.getString(file.getName(), null); + if (clazz != null) { + dexPath = new File(getDir("dex", Context.MODE_PRIVATE), file.getName()); + DexUtils.prepareDex(this, dexPath, file); + HotFix.patch(this, dexPath.getAbsolutePath(), clazz); + Utils.log(file.getName() + " patch success"); + } + } + } + TCAgent.LOG_ON = true; TCAgent.init(this); TCAgent.setReportUncaughtExceptions(true); diff --git a/app/src/main/java/com/gh/common/util/DexUtils.java b/app/src/main/java/com/gh/common/util/DexUtils.java index 1e7fda9667..c7abf2a848 100644 --- a/app/src/main/java/com/gh/common/util/DexUtils.java +++ b/app/src/main/java/com/gh/common/util/DexUtils.java @@ -8,6 +8,7 @@ import android.content.Context; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -18,7 +19,7 @@ import java.io.OutputStream; public class DexUtils { private static final int BUF_SIZE = 2048; - public static boolean prepareDex(Context context, File dexInternalStoragePath, String dex_file) { + public static boolean prepareAssetsDex(Context context, File dexInternalStoragePath, String dex_file) { BufferedInputStream bis = null; OutputStream dexWriter = null; @@ -51,4 +52,38 @@ public class DexUtils { return false; } } + + public static boolean prepareDex(Context context, File dexInternalStoragePath, File dex_file) { + BufferedInputStream bis = null; + OutputStream dexWriter = null; + + try { + bis = new BufferedInputStream(new FileInputStream(dex_file)); + dexWriter = new BufferedOutputStream(new FileOutputStream(dexInternalStoragePath)); + byte[] buf = new byte[BUF_SIZE]; + int len; + while ((len = bis.read(buf, 0, BUF_SIZE)) > 0) { + dexWriter.write(buf, 0, len); + } + dexWriter.close(); + bis.close(); + return true; + } catch (IOException e) { + if (dexWriter != null) { + try { + dexWriter.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + if (bis != null) { + try { + bis.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + return false; + } + } } diff --git a/hotfixlib/src/main/java/dodola/hotfixlib/HotFix.java b/app/src/main/java/com/gh/common/util/HotFix.java similarity index 99% rename from hotfixlib/src/main/java/dodola/hotfixlib/HotFix.java rename to app/src/main/java/com/gh/common/util/HotFix.java index 2cf41c9444..1c69aa2839 100644 --- a/hotfixlib/src/main/java/dodola/hotfixlib/HotFix.java +++ b/app/src/main/java/com/gh/common/util/HotFix.java @@ -1,7 +1,7 @@ /* * Copyright (C) 2015 Baidu, Inc. All Rights Reserved. */ -package dodola.hotfixlib; +package com.gh.common.util; import android.annotation.TargetApi; import android.content.Context; diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 4195042a98..4040139caf 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -436,6 +436,60 @@ public class MainActivity extends BaseFragmentActivity implements DataCollectionManager.upsert(MainActivity.this, "user", map); } }, 1000); + + //检查是否存在更新的dex包 +// checkHotfix(); + } + + private void checkHotfix() { + String version = PackageUtils.getVersion(getApplicationContext()); + String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"); + String url = "http://api.ghzhushou.com/v1d45/hotfix?channel=" + TD_CHANNEL_ID + "&version=" + version; + JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url, new Response.Listener() { + @Override + public void onResponse(JSONArray response) { + Utils.log("hotfix = " + response.toString()); + try { + for (int i = 0; i < response.length(); i++) { + JSONObject jsonObject = response.getJSONObject(i); + String clazz = jsonObject.getString("class"); + final String url = jsonObject.getString("url"); + String fileName = url.substring(url.lastIndexOf("/")); + File directory = new File(getFilesDir().getAbsolutePath() + File.separator + "hotfix"); + if (!directory.exists() || !directory.isDirectory()) { + directory.mkdirs(); + } + File file = new File(directory.getAbsolutePath() + File.separator + fileName); + if (file.exists()) { + break; + } + //下载文件 + final String savePath = file.getAbsolutePath(); + new Thread(){ + @Override + public void run() { + try { + FileUtils.downloadFile(url, savePath); + } catch (IOException e) { + e.printStackTrace(); + } + Utils.log(savePath + " download success"); + } + }.start(); + //存储class + sp.edit().putString(file.getName(),clazz).apply(); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Utils.log("hotfix = " + error.toString()); + } + }); + AppController.addToRequestQueue(request, MainActivity.class); } // 获取免责声明 diff --git a/app/src/main/java/com/gh/gamecenter/NewsActivity.java b/app/src/main/java/com/gh/gamecenter/NewsActivity.java index 2ff07143ba..55c632efc4 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsActivity.java @@ -143,7 +143,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { private boolean isSentReport = false; private boolean isDestroy = false; private boolean isShowBottom = false; - private boolean isLoading = true; + // private boolean isLoading = true; private boolean isNetworkError = false; private DismissEntity dismissEntity; @@ -255,55 +255,51 @@ public class NewsActivity extends BaseActivity implements OnClickListener { getWindowManager().getDefaultDisplay().getMetrics(outMetrics); width = outMetrics.widthPixels - DisplayUtils.dip2px(getApplicationContext(), 73); - RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar); +// RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar); - View share = View.inflate(this, R.layout.reuse_ico, null); - share.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (gameEntity == null) { - toast("分享异常,请稍后再试!"); - } else { - String url = "http://news.ghzhushou.com/" + entity.getId() + ".html"; - showShare(url, entity.getTitle(), gameEntity.getIcon(), entrance, "新闻"); - } - } - }); - ((ImageView) share.findViewById(R.id.reuse_iv_ico)) - .setImageResource(R.drawable.essay_share); - RelativeLayout.LayoutParams rparams1 = new RelativeLayout.LayoutParams( - LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - rparams1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - rparams1.addRule(RelativeLayout.CENTER_VERTICAL); - rparams1.rightMargin = DisplayUtils.dip2px(getApplicationContext(), 8); - share.setLayoutParams(rparams1); - reuse_actionbar.addView(share); +// View share = View.inflate(this, R.layout.reuse_ico, null); +// share.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// String url = "http://news.ghzhushou.com/" + entity.getId() + ".html"; +// showShare(url, entity.getTitle(), gameEntity.getIcon(), entrance, "新闻"); +// } +// }); +// ((ImageView) share.findViewById(R.id.reuse_iv_ico)) +// .setImageResource(R.drawable.essay_share); +// RelativeLayout.LayoutParams rparams1 = new RelativeLayout.LayoutParams( +// LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); +// rparams1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); +// rparams1.addRule(RelativeLayout.CENTER_VERTICAL); +// rparams1.rightMargin = DisplayUtils.dip2px(getApplicationContext(), 8); +// share.setLayoutParams(rparams1); +// reuse_actionbar.addView(share); - View comment = View.inflate(this, R.layout.reuse_ico, null); - comment.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (essaydetails_ll_comment.getVisibility() != View.VISIBLE) { - essaydetails_ll_comment.setVisibility(View.VISIBLE); - essaydetails_ll_bottom.setVisibility(View.GONE); - TranslateAnimation animation = new TranslateAnimation(0, 0, - DisplayUtils.dip2px(getApplicationContext(), 48), 0); - animation.setDuration(500); - essaydetails_ll_comment.startAnimation(animation); - } - int moreSize = entity.getMore() == null ? 0 : entity.getMore().size(); - essaydetails_rv_show.smoothScrollToPosition(3 + moreSize); - } - }); - ((ImageView) comment.findViewById(R.id.reuse_iv_ico)) - .setImageResource(R.drawable.essay_comment); - RelativeLayout.LayoutParams rparams2 = new RelativeLayout.LayoutParams( - LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - rparams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - rparams2.addRule(RelativeLayout.CENTER_VERTICAL); - rparams2.rightMargin = DisplayUtils.dip2px(getApplicationContext(), 46); - comment.setLayoutParams(rparams2); - reuse_actionbar.addView(comment); +// View comment = View.inflate(this, R.layout.reuse_ico, null); +// comment.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// if (essaydetails_ll_comment.getVisibility() != View.VISIBLE) { +// essaydetails_ll_comment.setVisibility(View.VISIBLE); +// essaydetails_ll_bottom.setVisibility(View.GONE); +// TranslateAnimation animation = new TranslateAnimation(0, 0, +// DisplayUtils.dip2px(getApplicationContext(), 48), 0); +// animation.setDuration(500); +// essaydetails_ll_comment.startAnimation(animation); +// } +// int moreSize = entity.getMore() == null ? 0 : entity.getMore().size(); +// essaydetails_rv_show.smoothScrollToPosition(3 + moreSize); +// } +// }); +// ((ImageView) comment.findViewById(R.id.reuse_iv_ico)) +// .setImageResource(R.drawable.essay_comment); +// RelativeLayout.LayoutParams rparams2 = new RelativeLayout.LayoutParams( +// LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); +// rparams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); +// rparams2.addRule(RelativeLayout.CENTER_VERTICAL); +// rparams2.rightMargin = DisplayUtils.dip2px(getApplicationContext(), 46); +// comment.setLayoutParams(rparams2); +// reuse_actionbar.addView(comment); entrance = (String) getIntent().getExtras().get("entrance"); newsId = getIntent().getStringExtra("newsId"); @@ -407,41 +403,41 @@ public class NewsActivity extends BaseActivity implements OnClickListener { essaydetails_rv_show.setLayoutManager(linearLayoutManager); adapter = new NewsAdapter(); essaydetails_rv_show.setAdapter(adapter); - essaydetails_rv_show.setOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - if (!isDestroy){ - if (newState == 0) { - int moreSize = entity.getMore() == null ? 0 : entity.getMore().size(); - if (linearLayoutManager.findLastVisibleItemPosition() >= 2 + moreSize) { - if (essaydetails_ll_comment.getVisibility() != View.VISIBLE) { - essaydetails_ll_comment.setVisibility(View.VISIBLE); - essaydetails_ll_bottom.setVisibility(View.GONE); - TranslateAnimation animation = new TranslateAnimation(0, 0, - DisplayUtils.dip2px(getApplicationContext(), 48), 0); - animation.setDuration(500); - essaydetails_ll_comment.startAnimation(animation); - } - } else { - if (essaydetails_ll_bottom.getVisibility() != View.VISIBLE) { - if (isShowBottom) { - essaydetails_ll_comment.setVisibility(View.GONE); - essaydetails_ll_bottom.setVisibility(View.VISIBLE); - TranslateAnimation animation = new TranslateAnimation(0, 0, - DisplayUtils.dip2px(getApplicationContext(), 48), 0); - animation.setDuration(500); - essaydetails_ll_bottom.startAnimation(animation); - } - } - } - if (isLoading && linearLayoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1) { - getComment(commentList.size()); - } - } - } - } - }); +// essaydetails_rv_show.setOnScrollListener(new RecyclerView.OnScrollListener() { +// @Override +// public void onScrollStateChanged(RecyclerView recyclerView, int newState) { +// super.onScrollStateChanged(recyclerView, newState); +// if (!isDestroy){ +// if (newState == 0) { +// int moreSize = entity.getMore() == null ? 0 : entity.getMore().size(); +// if (linearLayoutManager.findLastVisibleItemPosition() >= 2 + moreSize) { +// if (essaydetails_ll_comment.getVisibility() != View.VISIBLE) { +// essaydetails_ll_comment.setVisibility(View.VISIBLE); +// essaydetails_ll_bottom.setVisibility(View.GONE); +// TranslateAnimation animation = new TranslateAnimation(0, 0, +// DisplayUtils.dip2px(getApplicationContext(), 48), 0); +// animation.setDuration(500); +// essaydetails_ll_comment.startAnimation(animation); +// } +// } else { +// if (essaydetails_ll_bottom.getVisibility() != View.VISIBLE) { +// if (isShowBottom) { +// essaydetails_ll_comment.setVisibility(View.GONE); +// essaydetails_ll_bottom.setVisibility(View.VISIBLE); +// TranslateAnimation animation = new TranslateAnimation(0, 0, +// DisplayUtils.dip2px(getApplicationContext(), 48), 0); +// animation.setDuration(500); +// essaydetails_ll_bottom.startAnimation(animation); +// } +// } +// } +// if (isLoading && linearLayoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1) { +// getComment(commentList.size()); +// } +// } +// } +// } +// }); if (newsId != null) { getNewDigest(newsId); @@ -845,6 +841,8 @@ public class NewsActivity extends BaseActivity implements OnClickListener { private void getContent() { JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( Config.HOST + "v1d45/news/" + entity.getId() + "/detail", + // Config.HOST + "newsV1d45/test_news/" + // + System.currentTimeMillis(), new Response.Listener() { @Override @@ -1016,34 +1014,36 @@ public class NewsActivity extends BaseActivity implements OnClickListener { essaydetails_ll_bottom.setVisibility(View.GONE); isShowBottom = false; } else { - for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) { - String packageName = gameEntity.getApk().get(i).getPackageName(); - if (PackageManager.isInstalled(packageName) - || getPackageName().equals(packageName)) { - essaydetails_ll_bottom.setVisibility(View.GONE); - essaydetails_ll_comment.setVisibility(View.VISIBLE); - TranslateAnimation animation = new TranslateAnimation(0, 0, - DisplayUtils.dip2px(getApplicationContext(), 48), 0); - animation.setDuration(500); - essaydetails_ll_comment.startAnimation(animation); - isShowBottom = false; - break; - } else if (i == size - 1) { - isShowBottom = true; - essaydetails_ll_bottom.setVisibility(View.VISIBLE); - TranslateAnimation animation = new TranslateAnimation(0, 0, - DisplayUtils.dip2px(getApplicationContext(), 48), 0); - animation.setDuration(500); - essaydetails_ll_bottom.startAnimation(animation); - } - } + essaydetails_ll_bottom.setVisibility(View.VISIBLE); + isShowBottom = false; +// for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) { +// String packageName = gameEntity.getApk().get(i).getPackageName(); +// if (PackageManager.isInstalled(packageName) +// || getPackageName().equals(packageName)) { +// essaydetails_ll_bottom.setVisibility(View.GONE); +// essaydetails_ll_comment.setVisibility(View.VISIBLE); +// TranslateAnimation animation = new TranslateAnimation(0, 0, +// DisplayUtils.dip2px(getApplicationContext(), 48), 0); +// animation.setDuration(500); +// essaydetails_ll_comment.startAnimation(animation); +// isShowBottom = false; +// break; +// } else if (i == size - 1) { +// isShowBottom = true; +// essaydetails_ll_bottom.setVisibility(View.VISIBLE); +// TranslateAnimation animation = new TranslateAnimation(0, 0, +// DisplayUtils.dip2px(getApplicationContext(), 48), 0); +// animation.setDuration(500); +// essaydetails_ll_bottom.startAnimation(animation); +// } +// } } adapter.notifyItemChanged(0); } private void getNewsFeedback() { JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( - TimestampUtils.addTimestamp("http://comment.ghzhushou.com/v1d45/news/" + TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" + entity.getId() + "/feedback", Constants.COMMENT_CD), new Response.Listener() { @@ -1055,7 +1055,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { entity.setUp(response.getLong("up")); entity.setDown(response.getLong("down")); int moreSize = entity.getMore() == null ? 0 : entity.getMore().size(); - adapter.notifyItemChanged(1 + moreSize); + adapter.notifyItemChanged(1 + moreSize); } catch (JSONException e) { e.printStackTrace(); } @@ -1076,14 +1076,15 @@ public class NewsActivity extends BaseActivity implements OnClickListener { @Override public void run() { JsonObjectExtendedRequest request = new JsonObjectExtendedRequest( - TimestampUtils.addTimestamp("http://comment.ghzhushou.com/v1d45/news/" + TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" + entity.getId() + "/user/feedback", Constants.COMMENT_CD), new Response.Listener() { @Override public void onResponse(JSONObject response) { - Utils.log("getUserFeedback success = " + response.toString()); + Utils.log("getUserFeedback = " + + response.toString()); if (!isDestroy) { try { String action = response.getJSONObject("news").getString("action"); @@ -1110,10 +1111,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { @Override public void onErrorResponse(VolleyError error) { - Utils.log("getUserFeedback error = " + error.toString()); - if (error.networkResponse != null) { - Utils.log("getUserFeedback error = " + new String(error.networkResponse.data)); - } + Utils.log("getUserFeedback = " + error.toString()); } }); String token = TokenUtils.getToken(NewsActivity.this); @@ -1438,13 +1436,15 @@ public class NewsActivity extends BaseActivity implements OnClickListener { view = LayoutInflater.from(parent.getContext()).inflate(R.layout.essaydetails_item_top, parent, false); } else if (viewType == 1) { view = LayoutInflater.from(parent.getContext()).inflate(R.layout.essaydetails_more_news_item, parent, false); - } else if (viewType == 2) { - view = LayoutInflater.from(parent.getContext()).inflate(R.layout.essaydetails_comment_evaluate, parent, false); - } else if (viewType == 3) { - view = LayoutInflater.from(parent.getContext()).inflate(R.layout.essaydetails_comment_item, parent, false); - } else if (viewType == 4) { - view = LayoutInflater.from(parent.getContext()).inflate(R.layout.refresh_footerview, parent, false); - } else { + } +// else if (viewType == 2) { +// view = LayoutInflater.from(parent.getContext()).inflate(R.layout.essaydetails_comment_evaluate, parent, false); +// } else if (viewType == 3) { +// view = LayoutInflater.from(parent.getContext()).inflate(R.layout.essaydetails_comment_item, parent, false); +// } else if (viewType == 4) { +// view = LayoutInflater.from(parent.getContext()).inflate(R.layout.refresh_footerview, parent, false); +// } + else { RelativeLayout relativeLayout = new RelativeLayout(NewsActivity.this); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(getApplicationContext(), 48)); @@ -1518,33 +1518,33 @@ public class NewsActivity extends BaseActivity implements OnClickListener { webSettings.setJavaScriptEnabled(true); holder.essaydetails_wv_content.loadDataWithBaseURL(null, entity.getContent(), "text/html", "utf-8", null); holder.essaydetails_wv_content .setWebViewClient(new WebViewClient() { - @Override - public void onPageFinished(WebView view, - String url) { - view.loadUrl("javascript:(function(){" - + "var imgs = document.getElementsByTagName(\"img\");" - + "for(var i = 0; i < imgs.length - 1; i++) {" - + " window.imagelistener.addImage(imgs[i].src);" - + "}" - + "for(var i = 0; i < imgs.length - 1; i++) {" - + " imgs[i].onclick = function() {" - + " window.imagelistener.openImage(this.src);" - + " }" - + "}" - + "var as = document.getElementsByTagName(\"a\");" - + "for(var i = 0; i < as.length; i++) {" - + " as[i].onclick = function() {" - + " window.imagelistener.skip(this.id, this.type);" - + " }" - + "}" - + "})()"); - super.onPageFinished(view, url); - if (essaydetails_ll_loading != null) { - essaydetails_ll_loading.setVisibility(View.GONE); - essaydetails_rv_show.setVisibility(View.VISIBLE); - } - } - }); + @Override + public void onPageFinished(WebView view, + String url) { + view.loadUrl("javascript:(function(){" + + "var imgs = document.getElementsByTagName(\"img\");" + + "for(var i = 0; i < imgs.length - 1; i++) {" + + " window.imagelistener.addImage(imgs[i].src);" + + "}" + + "for(var i = 0; i < imgs.length - 1; i++) {" + + " imgs[i].onclick = function() {" + + " window.imagelistener.openImage(this.src);" + + " }" + + "}" + + "var as = document.getElementsByTagName(\"a\");" + + "for(var i = 0; i < as.length; i++) {" + + " as[i].onclick = function() {" + + " window.imagelistener.skip(this.id, this.type);" + + " }" + + "}" + + "})()"); + super.onPageFinished(view, url); + if (essaydetails_ll_loading != null) { + essaydetails_ll_loading.setVisibility(View.GONE); + essaydetails_rv_show.setVisibility(View.VISIBLE); + } + } + }); holder.essaydetails_wv_content.setTag("show"); } @@ -1560,254 +1560,255 @@ public class NewsActivity extends BaseActivity implements OnClickListener { holder.news_type.setText(newsEntity.getType()); holder.news_title.setText(newsEntity.getTitle()); holder.news_item_ll.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(NewsActivity.this, - NewsActivity.class); - intent.putExtra("newsId", newsEntity.getId()); - intent.putExtra("entrance", entrance); - startActivity(intent); - } - }); - } else if ((entity.getMore() == null && position == 1) - || (entity.getMore() != null && position == 1 + entity.getMore().size())) { - holder.essaydetails_ll_liked.setBackgroundResource(R.drawable.essay_liked_style); - holder.essaydetails_ll_unliked.setBackgroundResource(R.drawable.essay_unliked_style); - holder.essaydetails_iv_liked.setImageResource(R.drawable.essay_like_style); - ColorStateList colorStateList = getResources().getColorStateList(R.color.essay_text_style); - holder.essaydetails_tv_liked.setTextColor(colorStateList); - holder.essaydetails_iv_unliked.setImageResource(R.drawable.essay_unlike_style); - if (entity.getAction() != null) { - if ("up".equals(entity.getAction())) { - holder.essaydetails_ll_liked.setBackgroundResource(R.drawable.essay_liked_dn); - holder.essaydetails_iv_liked.setImageResource(R.drawable.essay_like_dn); - holder.essaydetails_tv_liked.setTextColor(0xFFFFFFFF); - } else if ("down".equals(entity.getAction())) { - holder.essaydetails_ll_unliked.setBackgroundResource(R.drawable.essay_unliked_dn); - holder.essaydetails_iv_unliked.setImageResource(R.drawable.essay_unlike_dn); + @Override + public void onClick(View v) { + Intent intent = new Intent(NewsActivity.this, + NewsActivity.class); + intent.putExtra("newsId", newsEntity.getId()); + intent.putExtra("entrance", entrance); + startActivity(intent); } - } - holder.essaydetails_tv_liked.setText(entity.getUp() + ""); - holder.essaydetails_tv_unliked.setText(entity.getDown() + ""); - } else if ((entity.getMore() == null && !commentList.isEmpty() - && position >= 2 && position < 2 + commentList.size()) - || (entity.getMore() != null && !commentList.isEmpty() - && position >= 2 + entity.getMore().size() && position < 2 - + entity.getMore().size() + commentList.size())) { - final int index; - if (entity.getMore() != null) { - index = position - 2 - entity.getMore().size(); - } else { - index = position - 2; - } - final CommentEntity commentEntity = commentList.get(index); - - ImageUtils.getInstance(getApplicationContext()).display( - commentEntity.getUser().getIcon(), - holder.comment_item_iv_icon, - R.drawable.default_user_icon); - holder.comment_item_tv_username.setText(commentEntity.getUser().getName()); - holder.comment_item_tv_content.setText(commentEntity.getContent().replaceAll("\n", " ")); - - Boolean b = fullMap.get(commentEntity.getId()); - if (b != null && b) { - holder.comment_item_tv_content.setMaxLines(Integer.MAX_VALUE); - holder.comment_item_ll_full.setVisibility(View.GONE); - } else { - holder.comment_item_tv_content.setMaxLines(4); - holder.comment_item_tv_content.setEllipsize(TruncateAt.END); - if (holder.comment_item_tv_content.getPaint() - .measureText(holder.comment_item_tv_content.getText().toString()) - - 4 * width > 0) { - holder.comment_item_ll_full.setVisibility(View.VISIBLE); - holder.comment_item_ll_full.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - fullMap.put(commentEntity.getId(), true); - if (entity.getMore() == null) { - adapter.notifyItemChanged(index + 2); - essaydetails_rv_show.smoothScrollToPosition(index + 2); - } else { - adapter.notifyItemChanged(index + 2 + entity.getMore().size()); - essaydetails_rv_show.smoothScrollToPosition(index + 2 + entity.getMore().size()); - } - } - }); - } else { - holder.comment_item_ll_full.setVisibility(View.GONE); - } - } - - String date; - long time = System.currentTimeMillis() - - commentEntity.getTime() * 1000; - if (time <= 3600 * 1000) { - // 一小时内 - int minute = (int) (time / 1000 / 60); - if (minute == 0) { - date = "刚刚"; - } else { - date = minute + "分钟之前"; - } - } else if (time <= 86400 * 1000) { - // 今天 - int hour = (int) (time / 1000 / 3600); - if (hour == 0) { - hour = 1; - } - date = hour + "小时之前"; - } else if (time <= 2 * 86400 * 1000) { - // 昨天 - date = "昨天"; - } else { - SimpleDateFormat format = new SimpleDateFormat("MM月dd日", - Locale.getDefault()); - date = format.format(new Date( - commentEntity.getTime() * 1000)); - } - if (entity.getMore() != null) { - holder.comment_item_tv_time.setText((position - 1 - entity.getMore().size()) + "楼\t\t\t\t" + date); - } else { - holder.comment_item_tv_time.setText((position - 1) + "楼\t\t\t\t" + date); - } - - holder.comment_item_tv_like.setText(commentEntity.getFeedback().getUp() + " 赞"); - holder.comment_item_tv_unlike.setText(commentEntity.getFeedback().getDown() + " 踩"); - - holder.comment_item_tv_like.setBackgroundResource(R.drawable.essay_comment_liked_style); - holder.comment_item_tv_unlike.setBackgroundResource(R.drawable.essay_comment_unliked_style); - ColorStateList colorStateList = getResources().getColorStateList(R.color.essay_text_style); - holder.comment_item_tv_like.setTextColor(colorStateList); - if (commentFeedbackMap != null) { - String action = commentFeedbackMap.get(commentEntity.getId()); - if (action != null) { - if ("up".equals(action)) { - holder.comment_item_tv_like.setBackgroundResource(R.drawable.essay_comment_liked_dn); - holder.comment_item_tv_like.setTextColor(0xFFFFFFFF); - } else if ("down".equals(action)) { - holder.comment_item_tv_unlike.setBackgroundResource(R.drawable.essay_comment_unliked_dn); - } - } - } - - holder.comment_item_tv_like.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Message msg = Message.obtain(); - msg.what = Constants.SEND_COMMENT_FEEDBACK; - if (commentFeedbackMap != null) { - String key = commentEntity.getId(); - String action = commentFeedbackMap.get(key); - if (action != null) { - if ("up".equals(action)) { - commentFeedbackMap.remove(key); - commentEntity.getFeedback().setUp(commentEntity.getFeedback().getUp() - 1); - if (entity.getMore() == null) { - adapter.notifyItemChanged(index + 2); - } else { - adapter.notifyItemChanged(index + 2 + entity.getMore().size()); - } - msg.arg1 = 2; - msg.arg2 = index; - msg.obj = "CancelCommentLike=up"; - timeMap.put("CancelCommentLike", System.currentTimeMillis()); - handler.sendMessageDelayed(msg, 1000); - return; - } else { - commentEntity.getFeedback().setDown(commentEntity.getFeedback().getDown() - 1); - msg.obj = "SendCommentLike=down"; - } - } else { - msg.obj = "SendCommentLike"; - } - } else { - commentFeedbackMap = new ArrayMap(); - msg.obj = "SendCommentLike"; - } - commentFeedbackMap.put(commentEntity.getId(), "up"); - commentEntity.getFeedback().setUp(commentEntity.getFeedback().getUp() + 1); - if (entity.getMore() == null) { - adapter.notifyItemChanged(index + 2); - } else { - adapter.notifyItemChanged(index + 2 + entity.getMore().size()); - } - msg.arg1 = 0; - msg.arg2 = index; - timeMap.put("SendCommentLike", System.currentTimeMillis()); - handler.sendMessageDelayed(msg, 1000); - } - }); - holder.comment_item_tv_unlike.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Message msg = Message.obtain(); - msg.what = Constants.SEND_COMMENT_FEEDBACK; - if (commentFeedbackMap != null) { - String key = commentList.get(index).getId(); - String action = commentFeedbackMap.get(key); - if (action != null) { - if ("down".equals(action)) { - commentFeedbackMap.remove(key); - commentList.get(index).getFeedback() - .setDown(commentList.get(index).getFeedback().getDown() - 1); - if (entity.getMore() == null) { - adapter.notifyItemChanged(index + 2); - } else { - adapter.notifyItemChanged(index + 2 + entity.getMore().size()); - } - msg.arg1 = 2; - msg.arg2 = index; - msg.obj = "CancelCommentLike=down"; - timeMap.put("CancelCommentLike", System.currentTimeMillis()); - handler.sendMessageDelayed(msg, 1000); - return; - } else { - commentList.get(index).getFeedback().setUp(commentList.get(index).getFeedback().getUp() - 1); - msg.obj = "SendCommentUnlike=up"; - } - } else { - msg.obj = "SendCommentUnlike"; - } - } else { - commentFeedbackMap = new ArrayMap(); - msg.obj = "SendCommentUnlike"; - } - commentFeedbackMap.put(commentList.get(index).getId(), "down"); - commentList.get(index).getFeedback() - .setDown(commentList.get(index).getFeedback().getDown() + 1); - if (entity.getMore() == null) { - adapter.notifyItemChanged(index + 2); - } else { - adapter.notifyItemChanged(index + 2 + entity.getMore().size()); - } - msg.arg1 = 1; - msg.arg2 = index; - timeMap.put("SendCommentUnlike", System.currentTimeMillis()); - handler.sendMessageDelayed(msg, 1000); - } - }); - } else if (isLoading - && ((entity.getMore() == null && position == 2 + commentList - .size()) || (entity.getMore() != null && position == 2 - + entity.getMore().size() + commentList.size()))) { - if (isNetworkError) { - holder.footerview_progressbar.setVisibility(View.GONE); - holder.footerview_tv_loading.setText("加载失败,点击重试"); - holder.rootView.setClickable(true); - holder.rootView.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - isNetworkError = false; - adapter.notifyItemChanged(adapter.getItemCount() - 1); - getComment(commentList.size()); - } - }); - } else { - holder.footerview_progressbar.setVisibility(View.VISIBLE); - holder.footerview_tv_loading.setText("加载中..."); - holder.rootView.setClickable(false); - } + }); } +// else if ((entity.getMore() == null && position == 1) +// || (entity.getMore() != null && position == 1 + entity.getMore().size())) { +// holder.essaydetails_ll_liked.setBackgroundResource(R.drawable.essay_liked_style); +// holder.essaydetails_ll_unliked.setBackgroundResource(R.drawable.essay_unliked_style); +// holder.essaydetails_iv_liked.setImageResource(R.drawable.essay_like_style); +// ColorStateList colorStateList = getResources().getColorStateList(R.color.essay_text_style); +// holder.essaydetails_tv_liked.setTextColor(colorStateList); +// holder.essaydetails_iv_unliked.setImageResource(R.drawable.essay_unlike_style); +// if (entity.getAction() != null) { +// if ("up".equals(entity.getAction())) { +// holder.essaydetails_ll_liked.setBackgroundResource(R.drawable.essay_liked_dn); +// holder.essaydetails_iv_liked.setImageResource(R.drawable.essay_like_dn); +// holder.essaydetails_tv_liked.setTextColor(0xFFFFFFFF); +// } else if ("down".equals(entity.getAction())) { +// holder.essaydetails_ll_unliked.setBackgroundResource(R.drawable.essay_unliked_dn); +// holder.essaydetails_iv_unliked.setImageResource(R.drawable.essay_unlike_dn); +// } +// } +// holder.essaydetails_tv_liked.setText(entity.getUp() + ""); +// holder.essaydetails_tv_unliked.setText(entity.getDown() + ""); +// } else if ((entity.getMore() == null && !commentList.isEmpty() +// && position >= 2 && position < 2 + commentList.size()) +// || (entity.getMore() != null && !commentList.isEmpty() +// && position >= 2 + entity.getMore().size() && position < 2 +// + entity.getMore().size() + commentList.size())) { +// final int index; +// if (entity.getMore() != null) { +// index = position - 2 - entity.getMore().size(); +// } else { +// index = position - 2; +// } +// final CommentEntity commentEntity = commentList.get(index); +// +// ImageUtils.getInstance(getApplicationContext()).display( +// commentEntity.getUser().getIcon(), +// holder.comment_item_iv_icon, +// R.drawable.default_user_icon); +// holder.comment_item_tv_username.setText(commentEntity.getUser().getName()); +// holder.comment_item_tv_content.setText(commentEntity.getContent().replaceAll("\n", " ")); +// +// Boolean b = fullMap.get(commentEntity.getId()); +// if (b != null && b) { +// holder.comment_item_tv_content.setMaxLines(Integer.MAX_VALUE); +// holder.comment_item_ll_full.setVisibility(View.GONE); +// } else { +// holder.comment_item_tv_content.setMaxLines(4); +// holder.comment_item_tv_content.setEllipsize(TruncateAt.END); +// if (holder.comment_item_tv_content.getPaint() +// .measureText(holder.comment_item_tv_content.getText().toString()) +// - 4 * width > 0) { +// holder.comment_item_ll_full.setVisibility(View.VISIBLE); +// holder.comment_item_ll_full.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// fullMap.put(commentEntity.getId(), true); +// if (entity.getMore() == null) { +// adapter.notifyItemChanged(index + 2); +// essaydetails_rv_show.smoothScrollToPosition(index + 2); +// } else { +// adapter.notifyItemChanged(index + 2 + entity.getMore().size()); +// essaydetails_rv_show.smoothScrollToPosition(index + 2 + entity.getMore().size()); +// } +// } +// }); +// } else { +// holder.comment_item_ll_full.setVisibility(View.GONE); +// } +// } +// +// String date; +// long time = System.currentTimeMillis() +// - commentEntity.getTime() * 1000; +// if (time <= 3600 * 1000) { +// // 一小时内 +// int minute = (int) (time / 1000 / 60); +// if (minute == 0) { +// date = "刚刚"; +// } else { +// date = minute + "分钟之前"; +// } +// } else if (time <= 86400 * 1000) { +// // 今天 +// int hour = (int) (time / 1000 / 3600); +// if (hour == 0) { +// hour = 1; +// } +// date = hour + "小时之前"; +// } else if (time <= 2 * 86400 * 1000) { +// // 昨天 +// date = "昨天"; +// } else { +// SimpleDateFormat format = new SimpleDateFormat("MM月dd日", +// Locale.getDefault()); +// date = format.format(new Date( +// commentEntity.getTime() * 1000)); +// } +// if (entity.getMore() != null) { +// holder.comment_item_tv_time.setText((position - 1 - entity.getMore().size()) + "楼\t\t\t\t" + date); +// } else { +// holder.comment_item_tv_time.setText((position - 1) + "楼\t\t\t\t" + date); +// } +// +// holder.comment_item_tv_like.setText(commentEntity.getFeedback().getUp() + " 赞"); +// holder.comment_item_tv_unlike.setText(commentEntity.getFeedback().getDown() + " 踩"); +// +// holder.comment_item_tv_like.setBackgroundResource(R.drawable.essay_comment_liked_style); +// holder.comment_item_tv_unlike.setBackgroundResource(R.drawable.essay_comment_unliked_style); +// ColorStateList colorStateList = getResources().getColorStateList(R.color.essay_text_style); +// holder.comment_item_tv_like.setTextColor(colorStateList); +// if (commentFeedbackMap != null) { +// String action = commentFeedbackMap.get(commentEntity.getId()); +// if (action != null) { +// if ("up".equals(action)) { +// holder.comment_item_tv_like.setBackgroundResource(R.drawable.essay_comment_liked_dn); +// holder.comment_item_tv_like.setTextColor(0xFFFFFFFF); +// } else if ("down".equals(action)) { +// holder.comment_item_tv_unlike.setBackgroundResource(R.drawable.essay_comment_unliked_dn); +// } +// } +// } +// +// holder.comment_item_tv_like.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// Message msg = Message.obtain(); +// msg.what = Constants.SEND_COMMENT_FEEDBACK; +// if (commentFeedbackMap != null) { +// String key = commentEntity.getId(); +// String action = commentFeedbackMap.get(key); +// if (action != null) { +// if ("up".equals(action)) { +// commentFeedbackMap.remove(key); +// commentEntity.getFeedback().setUp(commentEntity.getFeedback().getUp() - 1); +// if (entity.getMore() == null) { +// adapter.notifyItemChanged(index + 2); +// } else { +// adapter.notifyItemChanged(index + 2 + entity.getMore().size()); +// } +// msg.arg1 = 2; +// msg.arg2 = index; +// msg.obj = "CancelCommentLike=up"; +// timeMap.put("CancelCommentLike", System.currentTimeMillis()); +// handler.sendMessageDelayed(msg, 1000); +// return; +// } else { +// commentEntity.getFeedback().setDown(commentEntity.getFeedback().getDown() - 1); +// msg.obj = "SendCommentLike=down"; +// } +// } else { +// msg.obj = "SendCommentLike"; +// } +// } else { +// commentFeedbackMap = new ArrayMap(); +// msg.obj = "SendCommentLike"; +// } +// commentFeedbackMap.put(commentEntity.getId(), "up"); +// commentEntity.getFeedback().setUp(commentEntity.getFeedback().getUp() + 1); +// if (entity.getMore() == null) { +// adapter.notifyItemChanged(index + 2); +// } else { +// adapter.notifyItemChanged(index + 2 + entity.getMore().size()); +// } +// msg.arg1 = 0; +// msg.arg2 = index; +// timeMap.put("SendCommentLike", System.currentTimeMillis()); +// handler.sendMessageDelayed(msg, 1000); +// } +// }); +// holder.comment_item_tv_unlike.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// Message msg = Message.obtain(); +// msg.what = Constants.SEND_COMMENT_FEEDBACK; +// if (commentFeedbackMap != null) { +// String key = commentList.get(index).getId(); +// String action = commentFeedbackMap.get(key); +// if (action != null) { +// if ("down".equals(action)) { +// commentFeedbackMap.remove(key); +// commentList.get(index).getFeedback() +// .setDown(commentList.get(index).getFeedback().getDown() - 1); +// if (entity.getMore() == null) { +// adapter.notifyItemChanged(index + 2); +// } else { +// adapter.notifyItemChanged(index + 2 + entity.getMore().size()); +// } +// msg.arg1 = 2; +// msg.arg2 = index; +// msg.obj = "CancelCommentLike=down"; +// timeMap.put("CancelCommentLike", System.currentTimeMillis()); +// handler.sendMessageDelayed(msg, 1000); +// return; +// } else { +// commentList.get(index).getFeedback().setUp(commentList.get(index).getFeedback().getUp() - 1); +// msg.obj = "SendCommentUnlike=up"; +// } +// } else { +// msg.obj = "SendCommentUnlike"; +// } +// } else { +// commentFeedbackMap = new ArrayMap(); +// msg.obj = "SendCommentUnlike"; +// } +// commentFeedbackMap.put(commentList.get(index).getId(), "down"); +// commentList.get(index).getFeedback() +// .setDown(commentList.get(index).getFeedback().getDown() + 1); +// if (entity.getMore() == null) { +// adapter.notifyItemChanged(index + 2); +// } else { +// adapter.notifyItemChanged(index + 2 + entity.getMore().size()); +// } +// msg.arg1 = 1; +// msg.arg2 = index; +// timeMap.put("SendCommentUnlike", System.currentTimeMillis()); +// handler.sendMessageDelayed(msg, 1000); +// } +// }); +// } else if (isLoading +// && ((entity.getMore() == null && position == 2 + commentList +// .size()) || (entity.getMore() != null && position == 2 +// + entity.getMore().size() + commentList.size()))) { +// if (isNetworkError) { +// holder.footerview_progressbar.setVisibility(View.GONE); +// holder.footerview_tv_loading.setText("加载失败,点击重试"); +// holder.rootView.setClickable(true); +// holder.rootView.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// isNetworkError = false; +// adapter.notifyItemChanged(adapter.getItemCount() - 1); +// getComment(commentList.size()); +// } +// }); +// } else { +// holder.footerview_progressbar.setVisibility(View.VISIBLE); +// holder.footerview_tv_loading.setText("加载中..."); +// holder.rootView.setClickable(false); +// } +// } } @Override @@ -1815,13 +1816,14 @@ public class NewsActivity extends BaseActivity implements OnClickListener { if (entity == null || entity.getAuthor() == null) { return 0; } - int commentSize = commentList.size(); +// int commentSize = commentList.size(); int moreSize = entity.getMore() == null ? 0 : entity.getMore().size(); - if (isLoading) { - return 4 + moreSize + commentSize; - } else { - return 3 + moreSize + commentSize; - } + return 2 + moreSize; +// if (isLoading) { +// return 4 + moreSize + commentSize; +// } else { +// return 3 + moreSize + commentSize; +// } } @Override @@ -1830,20 +1832,22 @@ public class NewsActivity extends BaseActivity implements OnClickListener { return 0; } else if (entity.getMore() != null && position >= 1 && position < 1 + entity.getMore().size()) { return 1; - } else if ((entity.getMore() == null && position == 1) - || (entity.getMore() != null && position == 1 + entity.getMore().size())) { - return 2; - } else if ((entity.getMore() == null && !commentList.isEmpty() - && position >= 2 && position < 2 + commentList.size()) - || (entity.getMore() != null && !commentList.isEmpty() - && position >= 2 + entity.getMore().size() - && position < 2 + entity.getMore().size() + commentList.size())) { - return 3; - } else if (isLoading - && ((entity.getMore() == null && position == 2 + commentList.size()) - || (entity.getMore() != null && position == 2 + entity.getMore().size() + commentList.size()))) { - return 4; - } else { + } +// else if ((entity.getMore() == null && position == 1) +// || (entity.getMore() != null && position == 1 + entity.getMore().size())) { +// return 2; +// } else if ((entity.getMore() == null && !commentList.isEmpty() +// && position >= 2 && position < 2 + commentList.size()) +// || (entity.getMore() != null && !commentList.isEmpty() +// && position >= 2 + entity.getMore().size() +// && position < 2 + entity.getMore().size() + commentList.size())) { +// return 3; +// } else if (isLoading +// && ((entity.getMore() == null && position == 2 + commentList.size()) +// || (entity.getMore() != null && position == 2 + entity.getMore().size() + commentList.size()))) { +// return 4; +// } + else { return 5; } } @@ -1879,9 +1883,9 @@ public class NewsActivity extends BaseActivity implements OnClickListener { reuse_no_connection.setVisibility(View.GONE); handler.postDelayed(runnable, 1000); } else if (isNetworkError) { - isNetworkError = false; - adapter.notifyItemChanged(adapter.getItemCount() - 1); - getComment(commentList.size()); +// isNetworkError = false; +// adapter.notifyItemChanged(adapter.getItemCount() - 1); +// getComment(commentList.size()); } } } @@ -1929,7 +1933,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { private void getComment(int offset) { JsonArrayExtendedRequest request = new JsonArrayExtendedRequest( TimestampUtils.addTimestamp( - "http://comment.ghzhushou.com/v1d45/news/" + entity.getId() + "/comment?limit=10&offset=" + offset, + Config.HOST + "v1d45/news/" + entity.getId() + "/comment?limit=10&offset=" + offset, Constants.COMMENT_CD), new Response.Listener() { @@ -1950,7 +1954,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { essaydetails_rv_show.smoothScrollToPosition(adapter.getItemCount() - 1); } if (list.size() < 10) { - isLoading = false; +// isLoading = false; adapter.notifyItemRemoved(adapter.getItemCount() - 1); } } @@ -2105,9 +2109,8 @@ public class NewsActivity extends BaseActivity implements OnClickListener { new Thread() { @Override public void run() { - String url = "http://comment.ghzhushou.com/v1d45/news/" + entity.getId() + String url = Config.HOST + "v1d45/news/" + entity.getId() + "/comment?time=" + System.currentTimeMillis(); - Utils.log("url = " + url); Map params = new HashMap(); params.put("content", text.toString()); JSONObject body = new JSONObject(params); @@ -2177,27 +2180,29 @@ public class NewsActivity extends BaseActivity implements OnClickListener { private void modifyNewsCommentVolleyCache(int offset, JSONObject commentData) { File cacheDir = new File(getCacheDir(), DEFAULT_CACHE_DIR); DiskBasedCache cache = new DiskBasedCache(cacheDir); - String key = TimestampUtils.addTimestamp("http://comment.ghzhushou.com/v1d45/news/" + String key = TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" + entity.getId() + "/comment?limit=10&offset=" + offset, Constants.COMMENT_CD); byte[] data = cache.getData(key); if (data != null) { try { - JSONArray jsonArray = new JSONArray(new String(GzipUtils.decompressBytes(data))); + JSONArray jsonArray = new JSONArray(new String( + GzipUtils.decompressBytes(data))); JSONArray newComment = new JSONArray(); newComment.put(commentData); - for (int i = 0, size = jsonArray.length() > 9 ? 9 : jsonArray.length(); i < size; i++) { + for (int i = 0, size = jsonArray.length() > 9 ? 9 : jsonArray + .length(); i < size; i++) { newComment.put(jsonArray.get(i)); } Utils.log(newComment.toString()); - cache.modify(key, GzipUtils.compressBytes(newComment.toString().getBytes())); + cache.modify(key, GzipUtils.compressBytes(newComment.toString() + .getBytes())); if (jsonArray.length() == 10) { - modifyNewsCommentVolleyCache(offset + 10, jsonArray.getJSONObject(9)); + modifyNewsCommentVolleyCache(offset + 10, + jsonArray.getJSONObject(9)); } } catch (JSONException e) { e.printStackTrace(); } - } else { - Utils.log("modifyNewsCommentVolleyCache is null"); } } @@ -2208,22 +2213,22 @@ public class NewsActivity extends BaseActivity implements OnClickListener { if (TextUtils.isEmpty(action)) { return; } - String key = TimestampUtils.addTimestamp("http://comment.ghzhushou.com/v1d45/news/" + String key = TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" + entity.getId() + "/feedback", Constants.COMMENT_CD); File cacheDir = new File(getCacheDir(), DEFAULT_CACHE_DIR); DiskBasedCache cache = new DiskBasedCache(cacheDir); byte[] data = cache.getData(key); if (data != null) { try { - JSONObject jsonObject = new JSONObject(new String(GzipUtils.decompressBytes(data))); + JSONObject jsonObject = new JSONObject(new String( + GzipUtils.decompressBytes(data))); jsonObject.put(action, jsonObject.getInt(action) + value); Utils.log(jsonObject.toString()); - cache.modify(key, GzipUtils.compressBytes(jsonObject.toString().getBytes())); + cache.modify(key, GzipUtils.compressBytes(jsonObject.toString() + .getBytes())); } catch (JSONException e) { e.printStackTrace(); } - } else { - Utils.log("modifyNewsFeedbackVolleyCache is null"); } } @@ -2231,14 +2236,15 @@ public class NewsActivity extends BaseActivity implements OnClickListener { * 修改用户对新闻的反馈的volley缓存 */ private void modifyUserNewsFeedbackVolleyCache(String action) { - String key = TimestampUtils.addTimestamp("http://comment.ghzhushou.com/v1d45/news/" + String key = TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" + entity.getId() + "/user/feedback", Constants.COMMENT_CD); File cacheDir = new File(getCacheDir(), DEFAULT_CACHE_DIR); DiskBasedCache cache = new DiskBasedCache(cacheDir); byte[] data = cache.getData(key); if (data != null) { try { - JSONObject jsonObject = new JSONObject(new String(GzipUtils.decompressBytes(data))); + JSONObject jsonObject = new JSONObject(new String( + GzipUtils.decompressBytes(data))); if (!jsonObject.isNull("news")) { if (action == null) { modifyNewsFeedbackVolleyCache(jsonObject.getJSONObject("news").getString("action"), -1); @@ -2257,12 +2263,11 @@ public class NewsActivity extends BaseActivity implements OnClickListener { } } Utils.log(jsonObject.toString()); - cache.modify(key, GzipUtils.compressBytes(jsonObject.toString().getBytes())); + cache.modify(key, GzipUtils.compressBytes(jsonObject.toString() + .getBytes())); } catch (JSONException e) { e.printStackTrace(); } - } else { - Utils.log("modifyUserNewsFeedbackVolleyCache is null"); } } @@ -2270,14 +2275,15 @@ public class NewsActivity extends BaseActivity implements OnClickListener { * 修改用户对评论的反馈的volley缓存 */ private void modifyUserCommentFeedbackVolleyCache(String id, String action) { - String key = TimestampUtils.addTimestamp("http://comment.ghzhushou.com/v1d45/news/" + String key = TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" + entity.getId() + "/user/feedback", Constants.COMMENT_CD); File cacheDir = new File(getCacheDir(), DEFAULT_CACHE_DIR); DiskBasedCache cache = new DiskBasedCache(cacheDir); byte[] data = cache.getData(key); if (data != null) { try { - JSONObject jsonObject = new JSONObject(new String(GzipUtils.decompressBytes(data))); + JSONObject jsonObject = new JSONObject(new String( + GzipUtils.decompressBytes(data))); JSONArray comment = jsonObject.getJSONArray("comment"); if (comment.length() != 0) { if (action == null) { @@ -2314,12 +2320,11 @@ public class NewsActivity extends BaseActivity implements OnClickListener { } } Utils.log(jsonObject.toString()); - cache.modify(key, GzipUtils.compressBytes(jsonObject.toString().getBytes())); + cache.modify(key, GzipUtils.compressBytes(jsonObject.toString() + .getBytes())); } catch (JSONException e) { e.printStackTrace(); } - } else { - Utils.log("modifyUserCommentFeedbackVolleyCache is null"); } } @@ -2327,7 +2332,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { * 修改评论反馈的volley缓存 */ private void modifyCommentFeedbackVolleyCache(int offset, String id, String action, int value) { - String key = TimestampUtils.addTimestamp("http://comment.ghzhushou.com/v1d45/news/" + String key = TimestampUtils.addTimestamp(Config.HOST + "v1d45/news/" + entity.getId() + "/comment?limit=10&offset=" + offset, Constants.COMMENT_CD); File cacheDir = new File(getCacheDir(), DEFAULT_CACHE_DIR); DiskBasedCache cache = new DiskBasedCache(cacheDir); @@ -2352,8 +2357,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener { } catch (JSONException e) { e.printStackTrace(); } - } else { - Utils.log("modifyCommentFeedbackVolleyCache is null"); } } @@ -2361,7 +2364,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { * 修改新闻的反馈 */ private void modifyNewsFeedback(String news_id, final String newAction, final int oldAction) { - final String url = "http://comment.ghzhushou.com/v1d45/news/" + news_id + "/feedback/" + newAction; + final String url = Config.HOST + "v1d45/news/" + news_id + "/feedback/" + newAction; new Thread() { @Override public void run() { @@ -2377,9 +2380,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener { @Override public void onErrorResponse(VolleyError error) { Utils.log("modifyNewsFeedback = " + error.toString()); - if (error.networkResponse != null) { - Utils.log("modifyNewsFeedback = " + new String(error.networkResponse.data)); - } //TODO 失败回滚 String action = null; if ("up".equals(newAction)) { @@ -2421,7 +2421,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { * 取消对新闻的反馈 */ private void cancelNewsFeedback(String news_id, final int oldAction) { - final String url = "http://comment.ghzhushou.com/v1d45/news/" + news_id + "/feedback"; + final String url = Config.HOST + "v1d45/news/" + news_id + "/feedback"; new Thread() { @Override public void run() { @@ -2463,7 +2463,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { * 修改评论的反馈 */ private void modifyCommentFeedback(String news_id, String comment_id, final String newAction, final String oldAction, final int index) { - final String url = "http://comment.ghzhushou.com/v1d45/news/" + news_id + "/comment/" + comment_id + "/feedback/" + newAction; + final String url = Config.HOST + "v1d45/news/" + news_id + "/comment/" + comment_id + "/feedback/" + newAction; new Thread() { @Override public void run() { @@ -2479,9 +2479,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener { @Override public void onErrorResponse(VolleyError error) { Utils.log("modifyCommentFeedback = " + error.toString()); - if (error.networkResponse != null) { - Utils.log("modifyCommentFeedback = " + new String(error.networkResponse.data)); - } //TODO 失败回滚 String action = null; if ("up".equals(newAction)) { @@ -2527,7 +2524,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { */ private void cancelCommentFeedback(String news_id, String comment_id, final String oldAction, final int index) { - final String url = "http://comment.ghzhushou.com/v1d45/news/" + news_id + "/comment/" + final String url = Config.HOST + "v1d45/news/" + news_id + "/comment/" + comment_id + "/feedback"; new Thread() { @Override @@ -2544,9 +2541,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener { @Override public void onErrorResponse(VolleyError error) { Utils.log("cancelCommentFeedback = " + error.toString()); - if (error.networkResponse != null) { - Utils.log("cancelCommentFeedback = " + new String(error.networkResponse.data)); - } //TODO 失败回滚 if ("up".equals(oldAction)) { commentList.get(index).getFeedback().setUp(commentList.get(index).getFeedback().getUp() + 1); @@ -2660,7 +2654,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener { int seconds = (int) ((end - start) / 1000); - String cost; + String cost = ""; if (seconds < 5) { cost = "小于5秒"; } else if (seconds < 30) { @@ -2712,4 +2706,4 @@ public class NewsActivity extends BaseActivity implements OnClickListener { handler = null; dataWatcher = null; } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java b/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java index bb8708948b..939a7924a0 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java @@ -70,16 +70,13 @@ public class FilterManager { dao.addAll(list); sp.edit().putString("filter_time", today).apply(); } catch (JSONException e) { - e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - Utils.log("getFilterFromServer=" + error.toString()); - } }); AppController.addToRequestQueue(request, FilterManager.class); diff --git a/buildSrc/src/main/groovy/dodola/patch/PatchClass.groovy b/buildSrc/src/main/groovy/dodola/patch/PatchClass.groovy index a3e3aada2b..e53630bffb 100644 --- a/buildSrc/src/main/groovy/dodola/patch/PatchClass.groovy +++ b/buildSrc/src/main/groovy/dodola/patch/PatchClass.groovy @@ -1,6 +1,7 @@ package dodola.patch import javassist.ClassPool +import javassist.CtClass public class PatchClass { /** @@ -10,20 +11,22 @@ public class PatchClass { */ public static void process(String buildDir, String lib) { + println(buildDir) println(lib) + ClassPool classes = ClassPool.getDefault() classes.appendClassPath(buildDir) classes.appendClassPath(lib) //下面的操作比较容易理解,在将需要关联的类的构造方法中插入引用代码 -// CtClass c = classes.getCtClass("dodola.hotfix.BugClass") -// if (c.isFrozen()) { -// c.defrost() -// } -// println("====添加构造方法====") -// def constructor = c.getConstructors()[0]; -// constructor.insertAfter("System.out.println(dodola.hackdex.AntilazyLoad.class);") -// c.writeFile(buildDir) + CtClass c = classes.getCtClass("com.gh.gamecenter.NewsActivity") + if (c.isFrozen()) { + c.defrost() + } + println("====添加构造方法====") + def constructor = c.getConstructors()[0]; + constructor.insertAfter("System.out.println(dodola.hackdex.AntilazyLoad.class);") + c.writeFile(buildDir) } diff --git a/hotfixlib/.gitignore b/hotfixlib/.gitignore deleted file mode 100644 index 796b96d1c4..0000000000 --- a/hotfixlib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/hotfixlib/build.gradle b/hotfixlib/build.gradle deleted file mode 100644 index 124760e80b..0000000000 --- a/hotfixlib/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2015 Baidu, Inc. All Rights Reserved. - */ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 19 - buildToolsVersion "23.0.3" - - defaultConfig { - minSdkVersion 14 - targetSdkVersion 19 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' -} diff --git a/hotfixlib/proguard-rules.pro b/hotfixlib/proguard-rules.pro deleted file mode 100644 index 8e15537806..0000000000 --- a/hotfixlib/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/baidu/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/hotfixlib/src/androidTest/java/dodola/hotfixlib/ApplicationTest.java b/hotfixlib/src/androidTest/java/dodola/hotfixlib/ApplicationTest.java deleted file mode 100644 index f31bbdd505..0000000000 --- a/hotfixlib/src/androidTest/java/dodola/hotfixlib/ApplicationTest.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2015 Baidu, Inc. All Rights Reserved. - */ -package dodola.hotfixlib; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/hotfixlib/src/main/AndroidManifest.xml b/hotfixlib/src/main/AndroidManifest.xml deleted file mode 100644 index 046357423b..0000000000 --- a/hotfixlib/src/main/AndroidManifest.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - diff --git a/hotfixlib/src/main/res/values/strings.xml b/hotfixlib/src/main/res/values/strings.xml deleted file mode 100644 index 60602fba86..0000000000 --- a/hotfixlib/src/main/res/values/strings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - HotFixLib - diff --git a/hotfixlib/src/test/java/dodola/hotfixlib/ExampleUnitTest.java b/hotfixlib/src/test/java/dodola/hotfixlib/ExampleUnitTest.java deleted file mode 100644 index 81420f7ba9..0000000000 --- a/hotfixlib/src/test/java/dodola/hotfixlib/ExampleUnitTest.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2015 Baidu, Inc. All Rights Reserved. - */ -package dodola.hotfixlib; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * To work on unit tests, switch the Test Artifact in the Build Variants view. - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 8094133912..8d4876d9b3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':hackdex', ':buildSrc', ':hotfixlib' +include ':app', ':hackdex', ':buildSrc'