|
@ -21,6 +21,7 @@ import com.electric.chargingpile.application.MainApplication;
|
21
|
21
|
import com.electric.chargingpile.data.ChatRecommendBean;
|
22
|
22
|
import com.electric.chargingpile.iview.RecyclerItemTypeClickListener;
|
23
|
23
|
import com.electric.chargingpile.util.CircleTransform;
|
|
24
|
import com.electric.chargingpile.util.CommonParams;
|
24
|
25
|
import com.electric.chargingpile.util.DensityUtil;
|
25
|
26
|
import com.electric.chargingpile.util.ImageDisplayUtils;
|
26
|
27
|
import com.electric.chargingpile.util.JsonUtils;
|
|
@ -172,7 +173,7 @@ public class ChatRecommendAdapter extends RecyclerView.Adapter<IViewHolder> {
|
172
|
173
|
if (TextUtils.isEmpty(chatRecommendBean.title)) {
|
173
|
174
|
simpleViewHolder.recycler_view_title.setText("分享内容");
|
174
|
175
|
} else {
|
175
|
|
simpleViewHolder.recycler_view_title.setText(position - 1 + ":" + chatRecommendBean.targetId + ":" + chatRecommendBean.title.substring(0, 5));
|
|
176
|
simpleViewHolder.recycler_view_title.setText(chatRecommendBean.title);
|
176
|
177
|
}
|
177
|
178
|
|
178
|
179
|
if (chatRecommendBean.likeNums == 0) {
|
|
@ -298,40 +299,55 @@ public class ChatRecommendAdapter extends RecyclerView.Adapter<IViewHolder> {
|
298
|
299
|
recycler_view_zan_icon.setOnClickListener(new View.OnClickListener() {
|
299
|
300
|
@Override
|
300
|
301
|
public void onClick(View view) { // 点赞操作
|
301
|
|
ChatRecommendBean talkRecommendBean = chatRecommendBeans.get(index);
|
302
|
|
String url = MainApplication.urlNew + "/topic/like.do";
|
303
|
|
Map<String, String> map = new HashMap<>();
|
304
|
|
if (MainApplication.isLogin()) {
|
305
|
|
map.put("userId", MainApplication.userId);
|
306
|
|
}
|
307
|
|
map.put("targetId", talkRecommendBean.targetId + "");
|
308
|
|
map.put("targetType", talkRecommendBean.targetType + "");
|
309
|
|
map.put("flag", "1");
|
310
|
|
map.put("authorId", talkRecommendBean.addUserId + "");
|
311
|
|
Log.d(TAG, "onClick: " + map);
|
312
|
|
OkHttpUtils.get().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
|
313
|
|
@Override
|
314
|
|
public void onError(Call call, Exception e) {
|
315
|
|
ToastUtil.showToast(context, "点赞失败,请重试", Toast.LENGTH_SHORT);
|
316
|
|
}
|
|
302
|
likeClick();
|
|
303
|
}
|
|
304
|
});
|
|
305
|
}
|
|
306
|
|
|
307
|
private void likeClick() {
|
|
308
|
final ChatRecommendBean bean = chatRecommendBeans.get(index);
|
|
309
|
if (bean.likeFlg == 1) { // 已点赞,无需再次点赞
|
|
310
|
return;
|
|
311
|
}
|
|
312
|
String url = MainApplication.urlNew + "/topic/like.do";
|
|
313
|
Map<String, String> map = new HashMap<>();
|
|
314
|
CommonParams.addCommonParams(map);
|
|
315
|
map.put("targetId", bean.targetId + "");
|
|
316
|
map.put("targetType", bean.targetType + "");
|
|
317
|
map.put("flag", "1");
|
|
318
|
map.put("authorId", bean.addUserId + "");
|
|
319
|
Log.d(TAG, "likeClick: " + map);
|
|
320
|
|
|
321
|
OkHttpUtils.get().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
|
|
322
|
@Override
|
|
323
|
public void onError(Call call, Exception e) {
|
|
324
|
ToastUtil.showToast(context, "点赞失败,请重试", Toast.LENGTH_SHORT);
|
|
325
|
}
|
317
|
326
|
|
318
|
|
@Override
|
319
|
|
public void onResponse(String response) {
|
320
|
|
Log.d(TAG, "onResponse: " + response);
|
321
|
|
String rtnCode = JsonUtils.getKeyResult(response, "code");
|
322
|
|
String desc = JsonUtils.getKeyResult(response, "desc");
|
323
|
|
if ("1000".equals(rtnCode)) {
|
324
|
|
recycler_view_zan_icon.setBackgroundResource(R.drawable.app_talk_main_list_zan_red_icon);
|
325
|
|
} else {
|
326
|
|
ToastUtil.showToast(context, desc, Toast.LENGTH_SHORT);
|
327
|
|
}
|
|
327
|
@Override
|
|
328
|
public void onResponse(String response) {
|
|
329
|
String rtnCode = JsonUtils.getKeyResult(response, "code");
|
|
330
|
String desc = JsonUtils.getKeyResult(response, "desc");
|
|
331
|
if ("1000".equals(rtnCode)) {
|
|
332
|
recycler_view_zan_icon.setBackgroundResource(R.drawable.app_talk_main_list_zan_red_icon);
|
|
333
|
bean.likeNums ++;
|
|
334
|
|
|
335
|
if (bean.likeNums > 999) {
|
|
336
|
recycler_view_zan.setText("999+");
|
|
337
|
} else {
|
|
338
|
recycler_view_zan.setText(bean.likeNums + "");
|
328
|
339
|
}
|
329
|
|
});
|
|
340
|
recycler_view_zan.setVisibility(View.VISIBLE);
|
|
341
|
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)recycler_view_zan_icon.getLayoutParams();
|
|
342
|
params.rightMargin = DensityUtil.dip2px(context, 5);
|
|
343
|
recycler_view_zan_icon.setLayoutParams(params);
|
|
344
|
} else {
|
|
345
|
ToastUtil.showToast(context, desc, Toast.LENGTH_SHORT);
|
|
346
|
}
|
330
|
347
|
}
|
331
|
348
|
});
|
332
|
349
|
}
|
333
|
350
|
|
334
|
|
|
335
|
351
|
public int getIndex() {
|
336
|
352
|
return index;
|
337
|
353
|
}
|