diff --git a/.idea/misc.xml b/.idea/misc.xml
index 45bb483c5e..1a3eaffb45 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index d994b4fb22..4fcd16904e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'
task('processWithJavassist') << {
- String classPath = file('build/intermediates/classes/debug')//项目编译class所在目录
+ String classPath = file('build/intermediates/classes/release')//项目编译class所在目录
dodola.patch.PatchClass.process(classPath, project(':hackdex').buildDir
.absolutePath + '/intermediates/classes/debug')//第二个参数是hackdex的class所在目录
}
diff --git a/app/src/main/java/com/gh/gamecenter/NewsActivity.java b/app/src/main/java/com/gh/gamecenter/NewsActivity.java
index f59829130a..dbefeb4524 100644
--- a/app/src/main/java/com/gh/gamecenter/NewsActivity.java
+++ b/app/src/main/java/com/gh/gamecenter/NewsActivity.java
@@ -118,14 +118,11 @@ import de.greenrobot.event.EventBus;
*/
public class NewsActivity extends BaseActivity implements OnClickListener {
- private static final String DEFAULT_CACHE_DIR = "volley";
-
private LinearLayout essaydetails_ll_loading, essaydetails_ll_bottom,
- reuse_no_connection, essaydetails_ll_comment;
+ reuse_no_connection;
private NewsDetailsEntity entity;
private TextView actionbar_tv_title, essaydetails_tv_download,
- essaydetails_tv_per, essaydetails_tv_comment_content,
- essaydetails_tv_comment_send;
+ essaydetails_tv_per;
private ImageView essaydetails_iv_share;
private ProgressBar essaydetails_progressbar;
private GameEntity gameEntity;
@@ -138,24 +135,15 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
private String newsId;
private long start = 0L;
- private int width;
private boolean isSentReport = false;
private boolean isDestroy = false;
private boolean isShowBottom = false;
- // private boolean isLoading = true;
- private boolean isNetworkError = false;
private DismissEntity dismissEntity;
private ArrayMap lastTimeMap;
private ArrayMap statusMap;
- private ArrayMap timeMap;
- private ArrayList commentList;
- private ArrayMap commentFeedbackMap;
- private ArrayMap fullMap;
-
- private PopupWindow popupWindow;
private ConcernManager concernManager;
@@ -175,43 +163,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
DownloadManager.getInstance(NewsActivity.this).pause(
url);
}
- } else if (msg.what == Constants.SEND_NEWS_FEEDBACK) {
- String key = (String) msg.obj;
- if (System.currentTimeMillis() - timeMap.get(key) >= 1000) {
- if (msg.arg1 == 0) {
- modifyUserNewsFeedbackVolleyCache("up");
- modifyNewsFeedback(entity.getId(), "up", msg.arg2);
- } else if (msg.arg1 == 1) {
- modifyUserNewsFeedbackVolleyCache("down");
- modifyNewsFeedback(entity.getId(), "down", msg.arg2);
- } else if (msg.arg1 == 2) {
- modifyUserNewsFeedbackVolleyCache(null);
- cancelNewsFeedback(entity.getId(), msg.arg2);
- }
- }
- } else if (msg.what == Constants.SEND_COMMENT_FEEDBACK) {
- String key = (String) msg.obj;
- String oldAction = null;
- if (key.contains("=")){
- int i = key.indexOf("=");
- oldAction = key.substring(i + 1);
- key = key.substring(0, i);
- }
- if (System.currentTimeMillis() - timeMap.get(key) >= 1000) {
- int index = msg.arg2;
- CommentEntity commentEntity = commentList.get(index);
- final String id = commentEntity.getId();
- if (msg.arg1 == 0) {
- modifyUserCommentFeedbackVolleyCache(id, "up");
- modifyCommentFeedback(entity.getId(), id, "up", oldAction, index);
- } else if (msg.arg1 == 1) {
- modifyUserCommentFeedbackVolleyCache(id, "down");
- modifyCommentFeedback(entity.getId(), id, "down", oldAction, index);
- } else if (msg.arg1 == 2) {
- modifyUserCommentFeedbackVolleyCache(id, null);
- cancelCommentFeedback(entity.getId(), id, oldAction, index);
- }
- }
}
}
}
@@ -253,53 +204,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
- width = outMetrics.widthPixels - DisplayUtils.dip2px(getApplicationContext(), 73);
-
-// 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) {
-// 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);
entrance = (String) getIntent().getExtras().get("entrance");
newsId = getIntent().getStringExtra("newsId");
@@ -308,13 +212,8 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
actionbar_tv_title.setText(entity.getType());
}
- commentList = new ArrayList();
-
lastTimeMap = new ArrayMap();
statusMap = new ArrayMap();
- fullMap = new ArrayMap();
-
- timeMap = new ArrayMap();
WebView essaydetails_webView = (WebView) findViewById(R.id.essaydetails_webView);
if (NetworkUtils.isWifiConnected(this)) {
@@ -340,104 +239,11 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
essaydetails_tv_per.setOnClickListener(this);
- essaydetails_tv_comment_content.setOnClickListener(this);
- essaydetails_tv_comment_content
- .addTextChangedListener(new TextWatcher() {
-
- @Override
- public void onTextChanged(CharSequence s, int start,
- int before, int count) {
-
- if (s.length() > 0) {
- essaydetails_tv_comment_content
- .setBackgroundResource(R.drawable.essaydetails_comment_dn);
- essaydetails_tv_comment_send.setClickable(true);
- essaydetails_tv_comment_send
- .setTextColor(0xffffffff);
- essaydetails_tv_comment_send
- .setBackgroundResource(R.drawable.textview_blue_style);
- } else {
- essaydetails_tv_comment_content
- .setBackgroundResource(R.drawable.essaydetails_comment_up);
- essaydetails_tv_comment_send.setClickable(false);
- essaydetails_tv_comment_send
- .setTextColor(0xff999999);
- essaydetails_tv_comment_send
- .setBackgroundResource(R.drawable.textview_again_up);
- }
- int line = essaydetails_tv_comment_content
- .getLineCount();
- if (line != 0) {
- LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) essaydetails_tv_comment_content
- .getLayoutParams();
- if (line == 1) {
- lparams.height = DisplayUtils.dip2px(
- getApplicationContext(), 34);
- } else {
- lparams.height = DisplayUtils.dip2px(
- getApplicationContext(), 20)
- + (line > 3 ? 3 : line)
- * DisplayUtils.dip2px(
- getApplicationContext(), 12);
- }
- essaydetails_tv_comment_content
- .setLayoutParams(lparams);
- }
- }
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
- }
-
- @Override
- public void afterTextChanged(Editable s) {
-
- }
- });
- essaydetails_tv_comment_send.setOnClickListener(this);
- essaydetails_tv_comment_send.setClickable(false);
-
essaydetails_rv_show.setHasFixedSize(true);
linearLayoutManager = new LinearLayoutManager(this);
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());
-// }
-// }
-// }
-// }
-// });
if (newsId != null) {
getNewDigest(newsId);
@@ -819,11 +625,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
essaydetails_ll_bottom.setVisibility(View.VISIBLE);
reuse_no_connection.setVisibility(View.GONE);
handler.postDelayed(runnable, 1000);
- } else if (v == essaydetails_tv_comment_content) {
- showCommentDialog(v, essaydetails_tv_comment_content.getText(),
- essaydetails_tv_comment_content.getLineCount());
- } else if (v == essaydetails_tv_comment_send) {
- sendComment(essaydetails_tv_comment_content.getText());
}
}
@@ -841,8 +642,6 @@ 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
@@ -868,12 +667,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
// 获取游戏数据
getGameDetails();
-
- // 获取文章反馈数据
- getNewsFeedback();
-
- // 获取用户反馈数据
- getUserFeedback();
}
}
@@ -1016,111 +809,10 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
} else {
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(Config.HOST + "v1d45/news/"
- + entity.getId() + "/feedback", Constants.COMMENT_CD),
- new Response.Listener() {
-
- @Override
- public void onResponse(JSONObject response) {
- Utils.log("getNewsFeedback = " + response.toString());
- if (!isDestroy) {
- try {
- entity.setUp(response.getLong("up"));
- entity.setDown(response.getLong("down"));
- int moreSize = entity.getMore() == null ? 0 : entity.getMore().size();
- adapter.notifyItemChanged(1 + moreSize);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
-
- }
- });
- AppController.addToRequestQueue(request, NewsActivity.class);
- }
-
- private void getUserFeedback() {
- new Thread() {
- @Override
- public void run() {
- JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
- 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 = "
- + response.toString());
- if (!isDestroy) {
- try {
- String action = response.getJSONObject("news").getString("action");
- if (!TextUtils.isEmpty(action)) {
- entity.setAction(action);
- }
- JSONArray comment = response.getJSONArray("comment");
- if (comment.length() != 0) {
- commentFeedbackMap = new ArrayMap();
- for (int i = 0; i < comment.length(); i++) {
- JSONObject jsonObject = comment.getJSONObject(i);
- commentFeedbackMap.put(
- jsonObject.getString("id"),
- jsonObject.getString("action"));
- }
- }
- adapter.notifyItemRangeChanged(1, adapter.getItemCount() - 1);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
- Utils.log("getUserFeedback = " + error.toString());
- }
- });
- String token = TokenUtils.getToken(NewsActivity.this);
- request.addHeader("Auth", token);
- AppController.addToRequestQueue(request, NewsActivity.class);
- }
- }.start();
- }
-
private void showSuccessDialog() {
final Dialog dialog = new Dialog(this);
View view = View.inflate(this, R.layout.gamedetails_attention_dialog,
@@ -1256,20 +948,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
private LinearLayout news_item_ll;
private TextView news_type, news_title;
- private LinearLayout essaydetails_ll_liked, essaydetails_ll_unliked;
- private ImageView essaydetails_iv_liked, essaydetails_iv_unliked;
- private TextView essaydetails_tv_liked, essaydetails_tv_unliked;
-
- private BezelImageView comment_item_iv_icon;
- private LinearLayout comment_item_ll_full;
- private TextView comment_item_tv_username, comment_item_tv_time,
- comment_item_tv_content, comment_item_tv_like,
- comment_item_tv_unlike;
-
- private ProgressBar footerview_progressbar;
- private TextView footerview_tv_loading;
- private View rootView;
-
public NewsViewHolder(View view, int viewType) {
super(view);
if (viewType == 0) {
@@ -1290,105 +968,12 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
news_type = (TextView) view.findViewById(R.id.news_type);
news_title = (TextView) view.findViewById(R.id.news_title);
news_item_ll = (LinearLayout) view.findViewById(R.id.news_item_ll);
- } else if (viewType == 2) {
- essaydetails_ll_liked = (LinearLayout) view.findViewById(R.id.essaydetails_ll_liked);
- essaydetails_ll_liked.setOnClickListener(this);
- essaydetails_ll_unliked = (LinearLayout) view.findViewById(R.id.essaydetails_ll_unliked);
- essaydetails_ll_unliked.setOnClickListener(this);
- essaydetails_iv_liked = (ImageView) view.findViewById(R.id.essaydetails_iv_liked);
- essaydetails_iv_unliked = (ImageView) view.findViewById(R.id.essaydetails_iv_unliked);
- essaydetails_tv_liked = (TextView) view.findViewById(R.id.essaydetails_tv_liked);
- essaydetails_tv_unliked = (TextView) view.findViewById(R.id.essaydetails_tv_unliked);
- } else if (viewType == 3) {
- comment_item_iv_icon = (BezelImageView) view.findViewById(R.id.comment_item_iv_icon);
- comment_item_ll_full = (LinearLayout) view.findViewById(R.id.comment_item_ll_full);
- comment_item_tv_username = (TextView) view.findViewById(R.id.comment_item_tv_username);
- comment_item_tv_content = (TextView) view.findViewById(R.id.comment_item_tv_content);
- comment_item_tv_time = (TextView) view.findViewById(R.id.comment_item_tv_time);
- comment_item_tv_like = (TextView) view.findViewById(R.id.comment_item_tv_like);
- comment_item_tv_unlike = (TextView) view.findViewById(R.id.comment_item_tv_unlike);
- } else if (viewType == 4) {
- footerview_progressbar = (ProgressBar) view.findViewById(R.id.footerview_progressbar);
- footerview_tv_loading = (TextView) view.findViewById(R.id.footerview_tv_loading);
- rootView = view;
}
}
@Override
public void onClick(View v) {
- if (v == essaydetails_ll_liked) {
- Message msg = Message.obtain();
- msg.what = Constants.SEND_NEWS_FEEDBACK;
- if (entity.getAction() != null) {
- if ("up".equals(entity.getAction())) {
- entity.setAction(null);
- entity.setUp(entity.getUp() - 1);
- if (entity.getMore() == null) {
- adapter.notifyItemChanged(1);
- } else {
- adapter.notifyItemChanged(1 + entity.getMore().size());
- }
- msg.arg1 = 2;
- msg.arg2 = 1;
- msg.obj = "CancelNewsLike";
- timeMap.put("CancelNewsLike", System.currentTimeMillis());
- handler.sendMessageDelayed(msg, 1000);
- return;
- } else if ("down".equals(entity.getAction())) {
- entity.setDown(entity.getDown() - 1);
- msg.arg2 = 2;
- }
- } else {
- msg.arg2 = 0;
- }
- entity.setAction("up");
- entity.setUp(entity.getUp() + 1);
- if (entity.getMore() == null) {
- adapter.notifyItemChanged(1);
- } else {
- adapter.notifyItemChanged(1 + entity.getMore().size());
- }
- msg.arg1 = 0;
- msg.obj = "SendNewsLike";
- timeMap.put("SendNewsLike", System.currentTimeMillis());
- handler.sendMessageDelayed(msg, 1000);
- } else if (v == essaydetails_ll_unliked) {
- Message msg = Message.obtain();
- msg.what = Constants.SEND_NEWS_FEEDBACK;
- if (entity.getAction() != null) {
- if ("down".equals(entity.getAction())) {
- entity.setAction(null);
- entity.setDown(entity.getDown() - 1);
- if (entity.getMore() == null) {
- adapter.notifyItemChanged(1);
- } else {
- adapter.notifyItemChanged(1 + entity.getMore().size());
- }
- msg.arg1 = 2;
- msg.arg2 = 2;
- msg.obj = "CancelNewsLike";
- timeMap.put("CancelNewsLike", System.currentTimeMillis());
- handler.sendMessageDelayed(msg, 1000);
- return;
- } else if ("up".equals(entity.getAction())) {
- entity.setUp(entity.getUp() - 1);
- msg.arg2 = 1;
- }
- } else {
- msg.arg2 = 0;
- }
- entity.setAction("down");
- entity.setDown(entity.getDown() + 1);
- if (entity.getMore() == null) {
- adapter.notifyItemChanged(1);
- } else {
- adapter.notifyItemChanged(1 + entity.getMore().size());
- }
- msg.arg1 = 1;
- msg.obj = "SendNewsUnlike";
- timeMap.put("SendNewsUnlike", System.currentTimeMillis());
- handler.sendMessageDelayed(msg, 1000);
- } else if (v == essaydetails_ll_top) {
+ if (v == essaydetails_ll_top) {
Intent intent = new Intent(NewsActivity.this,
GameDetailsActivity.class);
intent.putExtra("gameId", gameEntity.getId());
@@ -1436,15 +1021,7 @@ 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 {
RelativeLayout relativeLayout = new RelativeLayout(NewsActivity.this);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(getApplicationContext(), 48));
@@ -1570,245 +1147,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
}
});
}
-// 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
@@ -1816,14 +1154,8 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
if (entity == null || entity.getAuthor() == null) {
return 0;
}
-// int commentSize = commentList.size();
int moreSize = entity.getMore() == null ? 0 : entity.getMore().size();
return 2 + moreSize;
-// if (isLoading) {
-// return 4 + moreSize + commentSize;
-// } else {
-// return 3 + moreSize + commentSize;
-// }
}
@Override
@@ -1832,22 +1164,7 @@ 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 {
return 5;
}
}
@@ -1882,10 +1199,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
essaydetails_ll_bottom.setVisibility(View.VISIBLE);
reuse_no_connection.setVisibility(View.GONE);
handler.postDelayed(runnable, 1000);
- } else if (isNetworkError) {
-// isNetworkError = false;
-// adapter.notifyItemChanged(adapter.getItemCount() - 1);
-// getComment(commentList.size());
}
}
}
@@ -1929,640 +1242,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
}
}
- // 获取文章评论
- private void getComment(int offset) {
- JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
- TimestampUtils.addTimestamp(
- Config.HOST + "v1d45/news/" + entity.getId() + "/comment?limit=10&offset=" + offset,
- Constants.COMMENT_CD),
- new Response.Listener() {
-
- @Override
- public void onResponse(JSONArray response) {
- Utils.log(response.toString());
- if (!isDestroy) {
- Gson gson = new Gson();
- Type listType = new TypeToken>() {}.getType();
- ArrayList list = gson.fromJson(response.toString(), listType);
- for (int i = 0, size = list.size() ; i < size ; i++){
- commentList.add(list.get(i));
- adapter.notifyItemInserted(adapter.getItemCount() - 2);
- }
- if (list.size() > 4){
- essaydetails_rv_show.smoothScrollToPosition(adapter.getItemCount() - list.size() + 2);
- } else {
- essaydetails_rv_show.smoothScrollToPosition(adapter.getItemCount() - 1);
- }
- if (list.size() < 10) {
-// isLoading = false;
- adapter.notifyItemRemoved(adapter.getItemCount() - 1);
- }
- }
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
- // 无网络连接和访问超时
- if (error.getClass().equals(NoConnectionError.class)
- || error.getClass().equals(TimeoutError.class)) {
- if (!isDestroy) {
- // TODO 处理加载时断网或超时情况
- toast("网络错误");
- isNetworkError = true;
- adapter.notifyItemChanged(adapter.getItemCount() - 2);
- }
- }
- }
- });
- AppController.addToRequestQueue(request, NewsActivity.class);
- }
-
- private void showCommentDialog(final View v, CharSequence text,
- int lineCount) {
- KeyboardLayout contentView = (KeyboardLayout) View.inflate(this,
- R.layout.dialog_essay_comment, null);
- popupWindow = new PopupWindow(contentView, LayoutParams.MATCH_PARENT,
- LayoutParams.MATCH_PARENT, true);
-
- final EditText content = (EditText) contentView
- .findViewById(R.id.dialog_et_comment_content);
-
- final TextView send = (TextView) contentView
- .findViewById(R.id.dialog_tv_comment_send);
-
- contentView.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- popupWindow.dismiss();
- essaydetails_tv_comment_content.setText(content.getText());
- }
- });
- contentView
- .setOnKeyboardChangedListener(new OnKeyboardChangedListener() {
- @Override
- public void OnKeyboardChanged(int w, int h, int oldw,
- int oldh) {
- if (oldh != 0 && h > oldh) {
- if (popupWindow != null && popupWindow.isShowing()) {
- popupWindow.dismiss();
- essaydetails_tv_comment_content.setText(content
- .getText());
- }
- }
- }
- });
-
- content.addTextChangedListener(new TextWatcher() {
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before,
- int count) {
-
- int line = content.getLineCount();
- if (line != 0) {
- LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) content
- .getLayoutParams();
- if (line == 1) {
- lparams.height = DisplayUtils.dip2px(
- getApplicationContext(), 34);
- } else {
- lparams.height = DisplayUtils.dip2px(
- getApplicationContext(), 20)
- + (line > 3 ? 3 : line)
- * DisplayUtils.dip2px(getApplicationContext(),
- 12);
- }
- content.setLayoutParams(lparams);
- }
- }
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
-
- }
-
- @Override
- public void afterTextChanged(Editable s) {
-
- }
- });
- content.setText(text);
- if (lineCount != 0) {
- LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) content
- .getLayoutParams();
- if (lineCount == 1) {
- lparams.height = DisplayUtils.dip2px(getApplicationContext(),
- 34);
- } else {
- lparams.height = DisplayUtils.dip2px(getApplicationContext(),
- 20)
- + (lineCount > 3 ? 3 : lineCount)
- * DisplayUtils.dip2px(getApplicationContext(), 12);
- }
- content.setLayoutParams(lparams);
- }
- content.requestFocus();
-
- send.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- popupWindow.dismiss();
- essaydetails_tv_comment_content.setText(content.getText());
- sendComment(content.getText());
- }
- });
-
- popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
- @Override
- public void onDismiss() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- getTintManager().setStatusBarTintResource(
- R.color.theme_colors);
- }
- }
- });
-
- popupWindow.setFocusable(true);
- popupWindow
- .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
- | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
- popupWindow.showAtLocation(v, Gravity.BOTTOM, 0, 0);
-
- // #0E6295 #0E6195
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- getTintManager().setStatusBarTintColor(0xff0E6295);
- }
- }
-
- // 发送评论
- private void sendComment(final CharSequence text) {
-
- if (text.length() == 0) {
- toast("请输入评论内容!");
- return;
- }
-
- final Dialog dialog = DialogUtils.showWaitDialog(this, "发送中...");
-
- new Thread() {
- @Override
- public void run() {
- String url = Config.HOST + "v1d45/news/" + entity.getId()
- + "/comment?time=" + System.currentTimeMillis();
- Map params = new HashMap();
- params.put("content", text.toString());
- JSONObject body = new JSONObject(params);
- JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
- Method.POST, url, body.toString(),
- new Response.Listener() {
-
- @Override
- public void onResponse(JSONObject response) {
- Utils.log(response.toString());
- dialog.dismiss();
- try {
- if (response.getString("status").equals("success")) {
- essaydetails_tv_comment_content.setText("");
- toast("发送成功");
- Gson gson = new Gson();
- CommentEntity commentEntity = gson.fromJson(response.getJSONObject("comment").toString(), CommentEntity.class);
- commentList.add(0, commentEntity);
- int moreSize = entity.getMore() == null ? 0 : entity.getMore().size();
- adapter.notifyItemInserted(2 + moreSize);
- if (commentList.size() == 1) {
- essaydetails_rv_show.smoothScrollToPosition(adapter.getItemCount() - 1);
- } else {
- essaydetails_rv_show.smoothScrollToPosition(1 + moreSize);
- }
-
- modifyNewsCommentVolleyCache(0, response.getJSONObject("comment"));
- } else if (response.getString("status").equals("refuse")) {
- toast("评论太频繁,请稍后再试");
- } else if (response.getString("status").equals("device_block")
- || response.getString("status").equals("user_block")) {
- toast("你已被禁言,请稍后再试");
- } else {
- toast("发送失败");
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
-
- Utils.log(error.toString());
- if (error.networkResponse != null) {
- Utils.log(new String(
- error.networkResponse.data));
- }
- dialog.dismiss();
- toast("发送失败");
- }
- });
- String token = TokenUtils.getToken(NewsActivity.this);
- request.addHeader("Auth", token);
- request.addHeader("Device",
- DeviceUtils.getDeviceHeader(NewsActivity.this));
- request.setShouldCache(false);
- AppController.addToRequestQueue(request, NewsActivity.class);
- }
- }.start();
- }
-
- /*
- * 修改新闻评论的volley缓存
- */
- private void modifyNewsCommentVolleyCache(int offset, JSONObject commentData) {
- File cacheDir = new File(getCacheDir(), DEFAULT_CACHE_DIR);
- DiskBasedCache cache = new DiskBasedCache(cacheDir);
- 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 newComment = new JSONArray();
- newComment.put(commentData);
- 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()));
- if (jsonArray.length() == 10) {
- modifyNewsCommentVolleyCache(offset + 10,
- jsonArray.getJSONObject(9));
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
-
- /*
- * 修改新闻反馈的volley缓存
- */
- private void modifyNewsFeedbackVolleyCache(String action, int value) {
- if (TextUtils.isEmpty(action)) {
- return;
- }
- 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.put(action, jsonObject.getInt(action) + value);
- Utils.log(jsonObject.toString());
- cache.modify(key, GzipUtils.compressBytes(jsonObject.toString()
- .getBytes()));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
-
- /*
- * 修改用户对新闻的反馈的volley缓存
- */
- private void modifyUserNewsFeedbackVolleyCache(String action) {
- 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)));
- if (!jsonObject.isNull("news")) {
- if (action == null) {
- modifyNewsFeedbackVolleyCache(jsonObject.getJSONObject("news").getString("action"), -1);
- jsonObject.getJSONObject("news").put("action", "");
- } else {
- modifyNewsFeedbackVolleyCache(jsonObject.getJSONObject("news").getString("action"), -1);
- jsonObject.getJSONObject("news").put("action", action);
- modifyNewsFeedbackVolleyCache(jsonObject.getJSONObject("news").getString("action"), 1);
- }
- } else {
- if (action != null) {
- JSONObject news = new JSONObject();
- news.put("action", action);
- jsonObject.put("news", news);
- modifyNewsFeedbackVolleyCache(action, 1);
- }
- }
- Utils.log(jsonObject.toString());
- cache.modify(key, GzipUtils.compressBytes(jsonObject.toString()
- .getBytes()));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
-
- /*
- * 修改用户对评论的反馈的volley缓存
- */
- private void modifyUserCommentFeedbackVolleyCache(String id, String action) {
- 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)));
- JSONArray comment = jsonObject.getJSONArray("comment");
- if (comment.length() != 0) {
- if (action == null) {
- JSONArray newComment = new JSONArray();
- for (int i = 0; i < comment.length(); i++) {
- JSONObject item = comment.getJSONObject(i);
- if (!item.getString("id").equals(id)) {
- newComment.put(item);
- } else {
- modifyCommentFeedbackVolleyCache(0, id, item.getString("action"), -1);
- }
- }
- jsonObject.put("comment", newComment);
- } else {
- for (int i = 0; i < comment.length(); i++) {
- JSONObject item = comment.getJSONObject(i);
- if (item.getString("id").equals(id)) {
- modifyCommentFeedbackVolleyCache(0, id, item.getString("action"), -1);
- item.put("action", action);
- modifyCommentFeedbackVolleyCache(0, id, item.getString("action"), 1);
- break;
- }
- }
- jsonObject.put("comment", comment);
- }
- } else {
- if (action != null) {
- JSONObject item = new JSONObject();
- item.put("id", id);
- item.put("action", action);
- comment.put(item);
- jsonObject.put("comment", comment);
- modifyCommentFeedbackVolleyCache(0, id, action, 1);
- }
- }
- Utils.log(jsonObject.toString());
- cache.modify(key, GzipUtils.compressBytes(jsonObject.toString()
- .getBytes()));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
-
- /*
- * 修改评论反馈的volley缓存
- */
- private void modifyCommentFeedbackVolleyCache(int offset, String id, String action, int value) {
- 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);
- byte[] data = cache.getData(key);
- if (data != null) {
- try {
- JSONArray jsonArray = new JSONArray(new String(GzipUtils.decompressBytes(data)));
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject comment = jsonArray.getJSONObject(i);
- if (comment.getString("_id").equals(id)) {
- JSONObject feedback = comment.getJSONObject("feedback");
- feedback.put(action, feedback.getLong(action) + value);
- feedback.put("val", feedback.getLong("up") - feedback.getLong("down"));
- Utils.log(jsonArray.toString());
- cache.modify(key, GzipUtils.compressBytes(jsonArray.toString().getBytes()));
- return;
- }
- }
- if (jsonArray.length() == 10) {
- modifyCommentFeedbackVolleyCache(offset + 10, id, action, value);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
-
- /*
- * 修改新闻的反馈
- */
- private void modifyNewsFeedback(String news_id, final String newAction, final int oldAction) {
- final String url = Config.HOST + "v1d45/news/" + news_id + "/feedback/" + newAction;
- new Thread() {
- @Override
- public void run() {
- JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
- Method.POST, url, new Response.Listener() {
-
- @Override
- public void onResponse(JSONObject response) {
- Utils.log("modifyNewsFeedback = " + response.toString());
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
- Utils.log("modifyNewsFeedback = " + error.toString());
- //TODO 失败回滚
- String action = null;
- if ("up".equals(newAction)) {
- if (oldAction == 2) {
- action = "down";
- entity.setUp(entity.getUp() - 1);
- entity.setDown(entity.getDown() + 1);
- } else if (oldAction == 0) {
- entity.setUp(entity.getUp() - 1);
- } else {
- action = "up";
- }
- } else if ("down".equals(newAction)) {
- if (oldAction == 1) {
- action = "up";
- entity.setUp(entity.getUp() + 1);
- entity.setDown(entity.getDown() - 1);
- } else if (oldAction == 0) {
- entity.setDown(entity.getDown() - 1);
- } else {
- action = "down";
- }
- }
- modifyUserNewsFeedbackVolleyCache(action);
- entity.setAction(action);
- int moreSize = entity.getMore() == null ? 0 : entity.getMore().size();
- adapter.notifyItemChanged(1 + moreSize);
- }
- });
- String token = TokenUtils.getToken(NewsActivity.this);
- request.addHeader("Auth", token);
- request.setShouldCache(false);
- AppController.addToRequestQueue(request, NewsActivity.this);
- }
- }.start();
- }
-
- /*
- * 取消对新闻的反馈
- */
- private void cancelNewsFeedback(String news_id, final int oldAction) {
- final String url = Config.HOST + "v1d45/news/" + news_id + "/feedback";
- new Thread() {
- @Override
- public void run() {
- JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
- Method.POST, url, new Response.Listener() {
-
- @Override
- public void onResponse(JSONObject response) {
- Utils.log("cancelNewsFeedback = " + response.toString());
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
- Utils.log("cancelNewsFeedback = " + error.toString());
- //TODO 失败回滚
- if (oldAction == 1) {
- entity.setAction("up");
- entity.setUp(entity.getUp() + 1);
- modifyUserNewsFeedbackVolleyCache("up");
- } else if (oldAction == 2) {
- entity.setAction("down");
- entity.setDown(entity.getDown() + 1);
- modifyUserNewsFeedbackVolleyCache("down");
- }
- int moreSize = entity.getMore() == null ? 0 : entity.getMore().size();
- adapter.notifyItemChanged(1 + moreSize);
- }
- });
- String token = TokenUtils.getToken(NewsActivity.this);
- request.addHeader("Auth", token);
- request.setShouldCache(false);
- AppController.addToRequestQueue(request, NewsActivity.this);
- }
- }.start();
- }
-
- /*
- * 修改评论的反馈
- */
- private void modifyCommentFeedback(String news_id, String comment_id, final String newAction, final String oldAction, final int index) {
- final String url = Config.HOST + "v1d45/news/" + news_id + "/comment/" + comment_id + "/feedback/" + newAction;
- new Thread() {
- @Override
- public void run() {
- JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
- Method.POST, url, new Response.Listener() {
-
- @Override
- public void onResponse(JSONObject response) {
- Utils.log("modifyCommentFeedback = " + response.toString());
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
- Utils.log("modifyCommentFeedback = " + error.toString());
- //TODO 失败回滚
- String action = null;
- if ("up".equals(newAction)) {
- if ("down".equals(oldAction)) {
- commentList.get(index).getFeedback().setUp(commentList.get(index).getFeedback().getUp() - 1);
- commentList.get(index).getFeedback().setDown(commentList.get(index).getFeedback().getDown() + 1);
- commentFeedbackMap.put(commentList.get(index).getId(), "down");
- action = "down";
- } else if (oldAction == null) {
- commentList.get(index).getFeedback().setUp(commentList.get(index).getFeedback().getUp() - 1);
- commentFeedbackMap.remove(commentList.get(index).getId());
- } else {
- action = "up";
- }
- } else if ("down".equals(newAction)) {
- if ("up".equals(oldAction)) {
- commentList.get(index).getFeedback().setUp(commentList.get(index).getFeedback().getUp() + 1);
- commentList.get(index).getFeedback().setDown(commentList.get(index).getFeedback().getDown() - 1);
- commentFeedbackMap.put(commentList.get(index).getId(), "up");
- action = "up";
- } else if (oldAction == null) {
- commentList.get(index).getFeedback().setDown(commentList.get(index).getFeedback().getDown() - 1);
- commentFeedbackMap.remove(commentList.get(index).getId());
- } else {
- action = "down";
- }
- }
- modifyUserCommentFeedbackVolleyCache(commentList.get(index).getId(), action);
- int moreSize = entity.getMore() == null ? 0 : entity.getMore().size();
- adapter.notifyItemChanged(index + 2 + moreSize);
- }
- });
- String token = TokenUtils.getToken(NewsActivity.this);
- request.addHeader("Auth", token);
- request.setShouldCache(false);
- AppController.addToRequestQueue(request, NewsActivity.this);
- }
- }.start();
- }
-
- /*
- * 取消对评论的反馈
- */
-
- private void cancelCommentFeedback(String news_id, String comment_id, final String oldAction, final int index) {
- final String url = Config.HOST + "v1d45/news/" + news_id + "/comment/"
- + comment_id + "/feedback";
- new Thread() {
- @Override
- public void run() {
- JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
- Method.POST, url, new Response.Listener() {
-
- @Override
- public void onResponse(JSONObject response) {
- Utils.log("cancelCommentFeedback = " + response.toString());
- }
- }, new Response.ErrorListener() {
-
- @Override
- public void onErrorResponse(VolleyError error) {
- Utils.log("cancelCommentFeedback = " + error.toString());
- //TODO 失败回滚
- if ("up".equals(oldAction)) {
- commentList.get(index).getFeedback().setUp(commentList.get(index).getFeedback().getUp() + 1);
- commentFeedbackMap.put(commentList.get(index).getId(), "up");
- modifyUserCommentFeedbackVolleyCache(commentList.get(index).getId(), "up");
- } else if ("down".equals(oldAction)) {
- commentList.get(index).getFeedback().setDown(commentList.get(index).getFeedback().getDown() + 1);
- commentFeedbackMap.put(commentList.get(index).getId(), "down");
- modifyUserCommentFeedbackVolleyCache(commentList.get(index).getId(), "down");
- }
- int moreSize = entity.getMore() == null ? 0 : entity.getMore().size();
- adapter.notifyItemChanged(index + 2 + moreSize);
- }
- });
- String token = TokenUtils.getToken(NewsActivity.this);
- request.addHeader("Auth", token);
- request.setShouldCache(false);
- AppController.addToRequestQueue(request, NewsActivity.this);
- }
- }.start();
- }
-
@Override
public void onResume() {
super.onResume();
@@ -2681,13 +1360,10 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
essaydetails_ll_loading = null;
essaydetails_ll_bottom = null;
reuse_no_connection = null;
- essaydetails_ll_comment = null;
entity = null;
actionbar_tv_title = null;
essaydetails_tv_download = null;
essaydetails_tv_per = null;
- essaydetails_tv_comment_content = null;
- essaydetails_tv_comment_send = null;
essaydetails_iv_share = null;
essaydetails_progressbar = null;
gameEntity = null;
@@ -2699,10 +1375,6 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
dismissEntity = null;
lastTimeMap = null;
statusMap = null;
- timeMap = null;
- commentList = null;
- commentFeedbackMap = null;
- popupWindow = null;
handler = null;
dataWatcher = null;
}
diff --git a/app/src/main/res/layout/activity_essaydetails.xml b/app/src/main/res/layout/activity_essaydetails.xml
index f73bc85630..435897e061 100644
--- a/app/src/main/res/layout/activity_essaydetails.xml
+++ b/app/src/main/res/layout/activity_essaydetails.xml
@@ -97,44 +97,6 @@
android:src="@drawable/btn_share" />
-
-
-
-
-
-
-