Browse Source

聊聊推荐顶部推荐话题UI调整完成

1.禁止父元素滑动到最后禁止父元素滑动(组件暂不支持,改版不修改)
2.分页滑动效果,下一版本再看
huyuguo 5 years ago
parent
commit
dd4536afa1

+ 46 - 10
app/src/main/java/com/electric/chargingpile/adapter/TalkRecommendHeaderAdapter.java

@ -3,10 +3,12 @@ package com.electric.chargingpile.adapter;
3 3
import android.content.Context;
4 4
import android.support.v7.widget.RecyclerView;
5 5
import android.text.TextUtils;
6
import android.util.Log;
6 7
import android.view.LayoutInflater;
7 8
import android.view.View;
8 9
import android.view.ViewGroup;
9 10
import android.widget.ImageView;
11
import android.widget.LinearLayout;
10 12
import android.widget.RelativeLayout;
11 13
import android.widget.TextView;
12 14
@ -14,6 +16,7 @@ import com.aspsine.irecyclerview.IViewHolder;
14 16
import com.electric.chargingpile.R;
15 17
import com.electric.chargingpile.data.TalkRecommendBean;
16 18
import com.electric.chargingpile.iview.RecyclerItemTypeClickListener;
19
import com.electric.chargingpile.util.DensityUtil;
17 20
import com.electric.chargingpile.util.ScreenUtils;
18 21
import com.squareup.picasso.Picasso;
19 22
@ -26,6 +29,8 @@ public class TalkRecommendHeaderAdapter extends RecyclerView.Adapter<IViewHolder
26 29
    private RecyclerItemTypeClickListener onRecyclerItemClickListener;
27 30
    private ArrayList<TalkRecommendBean> lists;
28 31
    private int screenWidth;
32
    private int talkRecommendWidth;  // 推荐顶部话题的宽度
33
    private int talkRecommendHeight; // 推荐顶部话题的高度
29 34
30 35
31 36
    public TalkRecommendHeaderAdapter(Context context) {
@ -33,6 +38,17 @@ public class TalkRecommendHeaderAdapter extends RecyclerView.Adapter<IViewHolder
33 38
        layoutInflater = LayoutInflater.from(context);
34 39
        lists = new ArrayList<>();
35 40
        screenWidth = ScreenUtils.getScreenWidth(context);
41
42
        int width = DensityUtil.dip2px(context, 94);
43
        int height = DensityUtil.dip2px(context, 85);
44
        int margin = DensityUtil.dip2px(context, 30);
45
46
        // 设置宽高
47
        talkRecommendWidth = (int) ((screenWidth - margin) / 3.5);
48
        talkRecommendHeight = (int) (talkRecommendWidth * height / width);
49
        Log.d("come on2", "TalkRecommendHeaderAdapter: " + talkRecommendWidth);
50
        Log.d("come on2", "TalkRecommendHeaderAdapter: " + talkRecommendHeight);
51
36 52
    }
37 53
38 54
@ -90,13 +106,28 @@ public class TalkRecommendHeaderAdapter extends RecyclerView.Adapter<IViewHolder
90 106
        final CollectionCarsHolder collectionCarsHolder = (CollectionCarsHolder) holder;
91 107
        final TalkRecommendBean talkRecommendBean = lists.get(position);
92 108
        collectionCarsHolder.header_title.setText(talkRecommendBean.name);
93
        if(talkRecommendBean.joinNums > 10000){
94
            String number = talkRecommendBean.joinNums+"";
95
            String number1 = number.substring(0,1);
96
            String number2 = number.substring(1,2);
97
            collectionCarsHolder.header_title_joinin.setText(number1+"."+number2 + "w参与");
98
        }else
109
        if (talkRecommendBean.joinNums > 10000) {
110
            String number = talkRecommendBean.joinNums + "";
111
            String number1 = number.substring(0, 1);
112
            String number2 = number.substring(1, 2);
113
            collectionCarsHolder.header_title_joinin.setText(number1 + "." + number2 + "w参与");
114
        } else {
99 115
            collectionCarsHolder.header_title_joinin.setText(talkRecommendBean.joinNums + "参与");
116
        }
117
118
        int margin = 0;
119
        if (position == 0) {
120
            margin = DensityUtil.dip2px(context, 15);
121
        } else {
122
            margin = DensityUtil.dip2px(context, 5);
123
        }
124
125
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)collectionCarsHolder.cardview.getLayoutParams();
126
        params.leftMargin = margin;
127
        if (lists.size() == position + 1) {
128
            params.rightMargin = DensityUtil.dip2px(context,15);
129
        }
130
        collectionCarsHolder.cardview.setLayoutParams(params);
100 131
101 132
        if (!TextUtils.isEmpty(talkRecommendBean.coverImgUrl)) {
102 133
            Picasso.with(context)
@ -111,6 +142,7 @@ public class TalkRecommendHeaderAdapter extends RecyclerView.Adapter<IViewHolder
111 142
        private ImageView iv_header_bg;
112 143
        private TextView header_title;
113 144
        private TextView header_title_joinin;
145
        private ImageView ivHeaderMask;
114 146
        private RelativeLayout cardview;
115 147
116 148
        public CollectionCarsHolder(View itemView) {
@ -118,12 +150,16 @@ public class TalkRecommendHeaderAdapter extends RecyclerView.Adapter<IViewHolder
118 150
            iv_header_bg = (ImageView) itemView.findViewById(R.id.iv_header_bg);
119 151
            header_title = (TextView) itemView.findViewById(R.id.header_title);
120 152
            header_title_joinin = (TextView) itemView.findViewById(R.id.header_title_joinin);
153
            ivHeaderMask = itemView.findViewById(R.id.iv_header_mask);
121 154
            cardview = (RelativeLayout) itemView.findViewById(R.id.cardview);
122 155
123
            ViewGroup.LayoutParams rl = (ViewGroup.LayoutParams) cardview.getLayoutParams();
124
            rl.width = screenWidth / 4 + 50;
125
            rl.height = screenWidth / 4 + 10;
126
            cardview.setLayoutParams(rl);
156
            // TODO change by hyg
157
//            ViewGroup.LayoutParams rl = (ViewGroup.LayoutParams) cardview.getLayoutParams();
158
//            rl.width = screenWidth / 4 + 50;
159
//            rl.height = screenWidth / 4 + 10;
160
161
            ivHeaderMask.setAlpha(0.5f);
162
//            cardview.setLayoutParams(rl);
127 163
128 164
            itemView.setOnClickListener(new View.OnClickListener() {
129 165
                @Override

+ 3 - 5
app/src/main/java/com/electric/chargingpile/application/MainApplication.java

@ -73,11 +73,9 @@ public class MainApplication extends MultiDexApplication {
73 73
    public static String firstPoint = "";
74 74
    public static Boolean firstSsyd;
75 75
    public static String password = "";
76
    //	public static String url = "http://123.57.6.131";
77
//    public static String url = "http://59.110.68.162";//测试环境
78
    public static String url = "http://cdz.evcharge.cc";//正式环境
79
//    public static String urlNew = "http://123.56.67.7:83/api/0200";//测试环境
80
    public static String urlNew = "https://api.touchev.com:83/api/0200";//正式环境
76
    public static String url = "http://cdz.evcharge.cc";// 充电桩正式环境
77
    public static String urlNew = "http://123.56.67.7:83/api/0200";// 一电测试环境
78
//    public static String urlNew = "https://api.touchev.com:83/api/0200";// 一电正式环境
81 79
    public static String pic_url = "http://cdz.evcharge.cc/zhannew/uploadfile/";
82 80
    //	public static String url = "https://cdz.d1ev.com";
83 81
    public static String build_flag = "0";

+ 3 - 8
app/src/main/java/com/electric/chargingpile/fragment/TalkRecommendFragment.java

@ -75,6 +75,7 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
75 75
                             Bundle savedInstanceState) {
76 76
        view = inflater.inflate(R.layout.activity_talk_recommend_tj, null);
77 77
        initXRefreshView();
78
        // 右下分享按钮及提示信息
78 79
        share_info_icon = view.findViewById(R.id.share_info_icon);
79 80
        TextView shareInfoText = view.findViewById(R.id.share_info_text);
80 81
        shareInfoText.setAlpha(0.8f);
@ -145,6 +146,7 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
145 146
        });
146 147
        requestHeaderData();
147 148
149
        // 顶部推荐话题点击事件
148 150
        layoutAdapter.setOnRecyclerItemClickListener(new RecyclerItemTypeClickListener() {
149 151
            @Override
150 152
            public void onItemClickListener(int position, int type) {
@ -264,9 +266,8 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
264 266
265 267
    private void requestHeaderData() {
266 268
        String url = MainApplication.urlNew + "/topic/list.do";
267
//        Log.e(TAG, "getQAData: "+url );
268 269
        Map<String, String> map = new HashMap<>();
269
        map.put("page", page + "");
270
        map.put("selected", "0");
270 271
        if (MainApplication.isLogin()) {
271 272
            map.put("user_id", MainApplication.userId);
272 273
        }
@ -284,12 +285,6 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
284 285
285 286
            @Override
286 287
            public void onResponse(String response) {
287
//                if(page == 1)
288
//                    xRefreshView.stopRefresh();
289
//                else
290
//                    xRefreshView.setLoadComplete(true);
291
292
                Log.e(TAG, "onResponse: " + response);
293 288
                String rtnCode = JsonUtils.getKeyResult(response, "code");
294 289
                if ("1000".equals(rtnCode)) {
295 290
                    String rtnMsg = JsonUtils.getKeyResult(response, "data");

+ 23 - 17
app/src/main/res/layout/activity_talkrecommend_header_item.xml

@ -2,44 +2,50 @@
2 2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4 4
    android:id="@+id/cardview"
5
    android:layout_width="match_parent"
6
    android:layout_height="match_parent"
7
    android:layout_marginLeft="15dp"
8
    >
5
    android:layout_width="94dp"
6
    android:layout_height="85dp"
7
    android:layout_marginTop="15dp"
8
    android:layout_marginBottom="15dp">
9 9

10 10
    <ImageView
11 11
        android:id="@+id/iv_header_bg"
12 12
        android:layout_width="match_parent"
13 13
        android:layout_height="match_parent"
14
        android:scaleType="centerCrop"
15
        android:minHeight="85dp"
14
        android:background="#44000000"
16 15
        android:minWidth="94dp"
17
        android:background="#44000000"/>
16
        android:minHeight="85dp"
17
        android:scaleType="centerCrop" />
18

19
    <ImageView
20
        android:id="@+id/iv_header_mask"
21
        android:layout_width="match_parent"
22
        android:layout_height="match_parent"
23
        android:background="#000000" />
18 24

19 25
    <TextView
20 26
        android:id="@+id/header_title"
21 27
        android:layout_width="wrap_content"
22 28
        android:layout_height="wrap_content"
23
        android:paddingTop="9dp"
29
        android:ellipsize="end"
30
        android:maxLines="2"
24 31
        android:paddingLeft="5dp"
32
        android:paddingTop="5dp"
25 33
        android:paddingRight="5dp"
26 34
        android:text="1111"
27
        android:maxLines="2"
28
        android:ellipsize="end"
29
        android:textSize="17sp"
30
        android:textColor="@color/white"/>
35
        android:textColor="@color/white"
36
        android:textSize="12sp" />
31 37

32 38
    <TextView
33 39
        android:id="@+id/header_title_joinin"
34 40
        android:layout_width="wrap_content"
35 41
        android:layout_height="wrap_content"
36 42
        android:layout_alignBottom="@+id/iv_header_bg"
37
        android:layout_marginBottom="5dp"
43
        android:layout_marginBottom="2dp"
44
        android:ellipsize="end"
38 45
        android:padding="5dp"
39
        android:text="1111"
40 46
        android:singleLine="true"
41
        android:ellipsize="end"
42
        android:textSize="9sp"
43
        android:textColor="@color/white"/>
47
        android:text="1111"
48
        android:textColor="@color/white"
49
        android:textSize="9sp" />
44 50

45 51
</RelativeLayout>