Browse Source

基础参数添加

huyuguo 5 years ago
parent
commit
f3e0092e8f

+ 45 - 29
app/src/main/java/com/electric/chargingpile/adapter/ChatRecommendAdapter.java

@ -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
        }

+ 4 - 0
app/src/main/java/com/electric/chargingpile/fragment/ChatRecommendFragment.java

@ -165,6 +165,7 @@ public class ChatRecommendFragment extends Fragment implements View.OnClickListe
165 165
166 166
    private void requestHeaderData() {
167 167
        String url = MainApplication.urlNew + "/topic/list.do";
168
168 169
        Map<String, String> map = new HashMap<>();
169 170
        map.put("selected", "1");
170 171
        if (MainApplication.isLogin()) {
@ -202,6 +203,9 @@ public class ChatRecommendFragment extends Fragment implements View.OnClickListe
202 203
    private void requestData() {
203 204
        String url = MainApplication.urlNew + "/topic/info/list.do";
204 205
        Map<String, String> map = new HashMap<>();
206
        if (MainApplication.isLogin()) {
207
            map.put("userId", MainApplication.userId);
208
        }
205 209
        map.put("page", page + "");
206 210
        map.put("limit", "20");
207 211

+ 35 - 0
app/src/main/java/com/electric/chargingpile/util/CommonParams.java

@ -0,0 +1,35 @@
1
package com.electric.chargingpile.util;
2
3
import android.os.Build;
4
5
import com.electric.chargingpile.BuildConfig;
6
import com.electric.chargingpile.application.MainApplication;
7
8
import java.util.Map;
9
10
import cn.jpush.android.api.JPushInterface;
11
12
public class CommonParams {
13
    public static void addCommonParams(Map<String, String> map) {
14
        if (MainApplication.isLogin()) {
15
            map.put("userId", MainApplication.userId);
16
            map.put("deviceOs", "android");
17
            map.put("appVer", BuildConfig.VERSION_NAME);
18
//            map.put("appToken", "");
19
            map.put("deviceOsVer", Build.VERSION.SDK_INT + "");
20
            map.put("deviceId", JPushInterface.getUdid(MainApplication.context));
21
//            map.put("tpToken", "");
22
            map.put("jpushId", JPushInterface.getRegistrationID(MainApplication.context));
23
            map.put("channel", BuildConfig.FLAVOR);
24
            // 硬件设备
25
//            map.put("deviceSysVar", "");
26
//            map.put("lng",);
27
//            map.put("lat",);
28
            // 2g 3g 4g wifi等
29
//            map.put("network",);
30
            // 网络运营商  移动  联通等
31
//            map.put("networkOperator", "");
32
        }
33
34
    }
35
}