Browse Source

列表开发

huyuguo 5 years ago
parent
commit
9f927f0d57

+ 7 - 1
README.md

@ -17,5 +17,11 @@ activity_zhan_list.xml
17 17
18 18
## 推荐
19 19
RecommendChargingStationActivity.java  
20
activity_recommend_charging_station.xml
20
activity_recommend_charging_station.xml  
21
recommend_charging_station_item.xml
21 22
23
## 站点详情
24
NewZhanDetailsActivity.class  
25
activity_new_zhan_details.xml  
26
DetailsFragment.java  
27
fragmen_details_new.xml

+ 9 - 1
app/src/main/AndroidManifest.xml

@ -12,7 +12,9 @@
12 12
        android:largeHeap="true"
13 13
        android:resizeableActivity="true"
14 14
        android:theme="@style/AppTheme">
15
        <activity android:name=".activity.RecommendChargingStationActivity"></activity>
15
        <activity
16
            android:name=".activity.RecommendChargingStationActivity"
17
            android:screenOrientation="portrait"></activity>
16 18
        <activity
17 19
            android:name=".activity.ChatContentListActivity"
18 20
            android:screenOrientation="portrait" />
@ -800,6 +802,7 @@
800 802
            android:name=".activity.TopicDetailActivity"
801 803
            android:launchMode="singleTask"
802 804
            android:screenOrientation="portrait" />
805
803 806
        <meta-data
804 807
            android:name="com.amap.api.v2.apikey"
805 808
            android:value="fabcfbf869745789b151d0c88e9b4807" />
@ -827,6 +830,7 @@
827 830
        <meta-data
828 831
            android:name="JPUSH_APPKEY"
829 832
            android:value="19fde8a6fe56b6918522bfa3" />
833
830 834
        <provider
831 835
            android:name="android.support.v4.content.FileProvider"
832 836
            android:authorities="${applicationId}.provider"
@ -836,6 +840,7 @@
836 840
                android:name="android.support.FILE_PROVIDER_PATHS"
837 841
                android:resource="@xml/provider_paths" />
838 842
        </provider>
843
839 844
        <receiver
840 845
            android:name="cn.jpush.android.service.PushReceiver"
841 846
            android:enabled="true"
@ -874,6 +879,7 @@
874 879
                <category android:name="${applicationId}" />
875 880
            </intent-filter>
876 881
        </receiver>
882
877 883
        <service android:name="com.amap.api.location.APSService" />
878 884
        <service android:name="com.amap.api.location.APSService" />
879 885
        <service
@ -905,8 +911,10 @@
905 911
    <permission
906 912
        android:name="${applicationId}.permission.JPUSH_MESSAGE"
907 913
        android:protectionLevel="signature" />
914
908 915
    <uses-feature android:name="android.hardware.camera" />
909 916
    <uses-feature android:name="android.hardware.camera.autofocus" />
917
910 918
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
911 919
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
912 920
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

+ 225 - 0
app/src/main/java/com/electric/chargingpile/activity/RecommendChargingStationActivity.java

@ -1,19 +1,45 @@
1 1
package com.electric.chargingpile.activity;
2 2
3
import android.app.ProgressDialog;
4
import android.content.Intent;
3 5
import android.graphics.Color;
4 6
import android.support.constraint.ConstraintLayout;
5 7
import android.support.v7.app.AppCompatActivity;
6 8
import android.os.Bundle;
9
import android.support.v7.widget.LinearLayoutManager;
10
import android.support.v7.widget.RecyclerView;
11
import android.util.Log;
12
import android.view.LayoutInflater;
7 13
import android.view.View;
14
import android.view.ViewGroup;
8 15
import android.widget.Button;
9 16
import android.widget.ImageView;
10 17
import android.widget.LinearLayout;
11 18
import android.widget.TextView;
19
import android.widget.Toast;
12 20
13 21
import com.electric.chargingpile.R;
22
import com.electric.chargingpile.application.MainApplication;
23
import com.electric.chargingpile.data.RecommendZhan;
14 24
import com.electric.chargingpile.util.BarColorUtil;
25
import com.electric.chargingpile.util.JsonUtils;
26
import com.electric.chargingpile.util.LoadingDialog;
27
import com.electric.chargingpile.util.ToastUtil;
28
import com.zhy.http.okhttp.OkHttpUtils;
29
import com.zhy.http.okhttp.callback.StringCallback;
30
31
import java.util.ArrayList;
32
import java.util.List;
33
34
import okhttp3.Call;
15 35
16 36
public class RecommendChargingStationActivity extends AppCompatActivity implements View.OnClickListener {
37
    private static final String TAG = "RecommendChargingStationActivity";
38
    List<RecommendZhan> recommendZhanList;
39
    private LoadingDialog loadingDialog;
40
    private String center_jing = "";
41
    private String center_wei = "";
42
    private RecommendChargingStationActivity activity;
17 43
18 44
    private LinearLayout first_condition;
19 45
    private TextView first_condition_text;
@ -36,6 +62,9 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
36 62
    private Button second_4;
37 63
    private Button second_5;
38 64
65
    private RecyclerView recyclerView;
66
    private RecommendChargingStationAdapter recommendChargingStationAdapter;
67
39 68
40 69
    @Override
41 70
    protected void onCreate(Bundle savedInstanceState) {
@ -43,9 +72,18 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
43 72
        setContentView(R.layout.activity_recommend_charging_station);
44 73
        BarColorUtil.initStatusBarColor(RecommendChargingStationActivity.this);
45 74
        initView();
75
        recommendChargingStationFunc();
46 76
    }
47 77
48 78
    private void initView() {
79
        recommendZhanList = new ArrayList<RecommendZhan>();
80
        activity = this;
81
        loadingDialog = new LoadingDialog(this);
82
        loadingDialog.setCanceledOnTouchOutside(false);
83
84
        center_jing = getIntent().getStringExtra("center_jing");
85
        center_wei = getIntent().getStringExtra("center_wei");
86
49 87
        findViewById(R.id.iv_back).setOnClickListener(this);
50 88
51 89
        first_condition = findViewById(R.id.first_condition);
@ -76,6 +114,12 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
76 114
        second_3.setOnClickListener(this);
77 115
        second_4.setOnClickListener(this);
78 116
        second_5.setOnClickListener(this);
117
118
        recyclerView = findViewById(R.id.recyclerView);
119
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
120
        recyclerView.setLayoutManager(layoutManager);
121
        recommendChargingStationAdapter = new RecommendChargingStationAdapter();
122
        recyclerView.setAdapter(recommendChargingStationAdapter);
79 123
    }
80 124
81 125
    @Override
@ -179,6 +223,187 @@ public class RecommendChargingStationActivity extends AppCompatActivity implemen
179 223
                break;
180 224
        }
181 225
        foldSecondCondition();
226
        resetFirstCondition();
227
    }
228
229
    private void resetFirstCondition() {
230
        firstCanCharging = false;
231
        first_can_charging.setTextColor(Color.parseColor("#222222"));
232
233
        firstFreeParking = false;
234
        first_free_parking.setTextColor(Color.parseColor("#222222"));
235
236
        firstQuickCharging = false;
237
        first_quick_charging.setTextColor(Color.parseColor("#222222"));
238
239
        firstSlowCharging = false;
240
        first_slow_charging.setTextColor(Color.parseColor("#222222"));
241
242
    }
243
244
    private void recommendChargingStationFunc() {
245
        loadingDialog.show();
246
247
        String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/recommend?longitude=" + center_jing + "&latitude=" + center_wei;
248
249
        OkHttpUtils.get().url(url).build().readTimeOut(10000).connTimeOut(10000).execute(new StringCallback() {
250
251
            @Override
252
            public void onError(Call call, Exception e) {
253
                if (activity != null && !activity.isFinishing()) {
254
                    loadingDialog.dismiss();
255
                }
256
                ToastUtil.showToast(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT);
257
            }
258
259
            @Override
260
            public void onResponse(String response) {
261
                if (activity != null && !activity.isFinishing()) {
262
                    loadingDialog.dismiss();
263
                } else {
264
                    return;
265
                }
266
267
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
268
                if (rtnCode.equals("01")) {
269
                    String data = JsonUtils.getKeyResult(response, "data");
270
                    List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
271
                    if (list != null) {
272
                        recommendZhanList = list;
273
                        recommendChargingStationAdapter.setData(list);
274
                    }
275
                }
276
            }
277
        });
278
    }
279
280
281
    public class RecommendChargingStationAdapter extends RecyclerView.Adapter<RecommendChargingStationAdapter.ViewHolder> {
282
        private List<RecommendZhan> mList;
283
284
        class ViewHolder extends RecyclerView.ViewHolder {
285
286
            final TextView zhan_name;
287
            final ImageView red_pager_bag_icon;
288
            final Button recommend_nav;
289
            final ImageView score_img;
290
            final TextView score_text;
291
            final TextView charge_record_cnt;
292
            final TextView comment_cnt;
293
             final View times_line;
294
295
            public ViewHolder(View itemView) {
296
                super(itemView);
297
                zhan_name = itemView.findViewById(R.id.zhan_name);
298
                red_pager_bag_icon = itemView.findViewById(R.id.red_paper_bag);
299
                recommend_nav = itemView.findViewById(R.id.recommend_nav);
300
                score_img = itemView.findViewById(R.id.score_img);
301
                score_text = itemView.findViewById(R.id.score_text);
302
                charge_record_cnt = itemView.findViewById(R.id.charge_record_cnt);
303
                comment_cnt = itemView.findViewById(R.id.comment_cnt);
304
                times_line = itemView.findViewById(R.id.times_line);
305
            }
306
        }
307
308
        public RecommendChargingStationAdapter() {
309
            mList = new ArrayList<RecommendZhan>();
310
        }
311
312
        public void setData(List<RecommendZhan> list) {
313
            mList = list;
314
            notifyDataSetChanged();
315
        }
316
317
        @Override
318
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
319
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recommend_charging_station_item, parent, false);
320
            ViewHolder viewHolder = new ViewHolder(itemView);
321
            return viewHolder;
322
        }
323
324
        @Override
325
        public void onBindViewHolder(ViewHolder holder, int position) {
326
            RecommendZhan recommendZhan = mList.get(position);
327
            holder.zhan_name.setText(recommendZhan.getZhan_name());
328
            if ("1".equals(recommendZhan.getOwn_pay())) {
329
                holder.red_pager_bag_icon.setVisibility(View.VISIBLE);
330
            } else {
331
                holder.red_pager_bag_icon.setVisibility(View.GONE);
332
            }
333
334
            holder.red_pager_bag_icon.setOnClickListener(new View.OnClickListener() {
335
                @Override
336
                public void onClick(View v) {
337
                    Intent intent_example = new Intent(getApplicationContext(), ExampleActivity.class);
338
                    intent_example.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
339
                    startActivity(intent_example);
340
                    overridePendingTransition(0, 0);
341
                }
342
            });
343
344
            showStarInfoView(holder, recommendZhan);
345
            if (recommendZhan.getCharge_record_cnt() == 0) {
346
                holder.charge_record_cnt.setVisibility(View.GONE);
347
            } else {
348
                holder.charge_record_cnt.setVisibility(View.VISIBLE);
349
                holder.charge_record_cnt.setText(recommendZhan.getCharge_record_cnt() + "次公共充电");
350
            }
351
352
            if (recommendZhan.getComment_cnt() == 0) {
353
                holder.comment_cnt.setVisibility(View.GONE);
354
            } else {
355
                holder.comment_cnt.setVisibility(View.VISIBLE);
356
                holder.comment_cnt.setText(recommendZhan.getComment_cnt() + "次评论");
357
            }
358
359
            if (recommendZhan.getCharge_record_cnt() == 0 && recommendZhan.getComment_cnt() == 0) {
360
                holder.times_line.setVisibility(View.GONE);
361
            } else {
362
                holder.times_line.setVisibility(View.VISIBLE);
363
            }
364
365
        }
366
367
        @Override
368
        public int getItemCount() {
369
            return mList.size();
370
        }
371
372
        private void showStarInfoView(ViewHolder holder, RecommendZhan recommendZhan) {
373
            String starStr = recommendZhan.getStar();
374
            double star = 0.0;
375
            try {
376
                star = Double.parseDouble(starStr);
377
            } catch (NumberFormatException e) {
378
                e.printStackTrace();
379
            }
380
381
            holder.score_text.setText(String.format("%.1f分", star));
382
            if (star == 0) {
383
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_0xing));
384
                holder.score_text.setText("暂无评分");
385
            } else if (star > 0 && star < 1) {
386
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_05xing));
387
            } else if (star >= 1 && star < 1.5) {
388
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_1xing));
389
            } else if (star >= 1.5 && star < 2) {
390
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_15xing));
391
            } else if (star >= 2 && star < 2.5) {
392
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_2xing));
393
            } else if (star >= 2.5 && star < 3) {
394
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_25xing));
395
            } else if (star >= 3 && star < 3.5) {
396
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_3xing));
397
            } else if (star >= 3.5 && star < 4) {
398
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_35xing));
399
            } else if (star >= 4 && star < 4.5) {
400
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_4xing));
401
            } else if (star >= 4.5 && star < 5) {
402
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_45xing));
403
            } else {
404
                holder.score_img.setImageDrawable(getResources().getDrawable(R.drawable.icon_5xing));
405
            }
406
        }
182 407
    }
183 408
184 409
}

+ 44 - 1
app/src/main/java/com/electric/chargingpile/data/RecommendZhan.java

@ -22,7 +22,10 @@ public class RecommendZhan {
22 22
     * fast_able_num : 0
23 23
     * slow_able_num : 0
24 24
     * star : 0
25
     * own_pay : 1
25
     * own_pay : 1:可支付(红包站点) 2:不可支付
26
     * zongjia: 0.65 价格最低排序
27
     * charge_record_cnt: 1 充电成功次数
28
     * comment_cnt: 1 评论次数
26 29
     */
27 30
28 31
    private String id;
@ -41,6 +44,21 @@ public class RecommendZhan {
41 44
    private String slow_able_num;
42 45
    private String star;
43 46
    private String own_pay;
47
    private double zongjia;
48
    private int charge_record_cnt;
49
    private int comment_cnt;
50
51
    public double getZongjia() {
52
        return zongjia;
53
    }
54
55
    public int getCharge_record_cnt() {
56
        return charge_record_cnt;
57
    }
58
59
    public int getComment_cnt() {
60
        return comment_cnt;
61
    }
44 62
45 63
    public String getId() {
46 64
        return id;
@ -50,6 +68,31 @@ public class RecommendZhan {
50 68
        this.id = id;
51 69
    }
52 70
71
    @Override
72
    public String toString() {
73
        return "RecommendZhan{" +
74
                "id='" + id + '\'' +
75
                ", zhan_name='" + zhan_name + '\'' +
76
                ", supplier='" + supplier + '\'' +
77
                ", slow_num='" + slow_num + '\'' +
78
                ", fast_num='" + fast_num + '\'' +
79
                ", poi_jing='" + poi_jing + '\'' +
80
                ", poi_wei='" + poi_wei + '\'' +
81
                ", zhan_id='" + zhan_id + '\'' +
82
                ", charge_cost_way2='" + charge_cost_way2 + '\'' +
83
                ", distance='" + distance + '\'' +
84
                ", score=" + score +
85
                ", pile_status='" + pile_status + '\'' +
86
                ", fast_able_num='" + fast_able_num + '\'' +
87
                ", slow_able_num='" + slow_able_num + '\'' +
88
                ", star='" + star + '\'' +
89
                ", own_pay='" + own_pay + '\'' +
90
                ", zongjia=" + zongjia +
91
                ", charge_record_cnt=" + charge_record_cnt +
92
                ", comment_cnt=" + comment_cnt +
93
                '}';
94
    }
95
53 96
    public String getZhan_name() {
54 97
        return zhan_name;
55 98
    }

+ 7 - 0
app/src/main/res/layout/activity_recommend_charging_station.xml

@ -154,6 +154,13 @@
154 154
155 155
    </android.support.constraint.ConstraintLayout>
156 156
157
    <android.support.v7.widget.RecyclerView
158
        android:id="@+id/recyclerView"
159
        android:layout_width="match_parent"
160
        android:layout_height="0dp"
161
        app:layout_constraintBottom_toBottomOf="parent"
162
        app:layout_constraintTop_toBottomOf="@+id/condition_first_bar" />
163
157 164
    <android.support.constraint.ConstraintLayout
158 165
        android:id="@+id/condition_second_bar"
159 166
        android:layout_width="match_parent"

+ 155 - 0
app/src/main/res/layout/recommend_charging_station_item.xml

@ -0,0 +1,155 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:layout_width="match_parent"
6
    android:layout_height="wrap_content"
7
    android:background="#ffffff"
8
    android:orientation="vertical">
9
10
    <android.support.constraint.ConstraintLayout
11
        android:layout_width="match_parent"
12
        android:layout_height="38dp"
13
        android:layout_marginTop="12dp"
14
        android:paddingLeft="15dp"
15
        android:paddingRight="15dp">
16
17
        <TextView
18
            android:id="@+id/zhan_name"
19
            android:layout_width="wrap_content"
20
            android:layout_height="0dp"
21
            android:ellipsize="end"
22
            android:gravity="center_vertical"
23
            android:lines="1"
24
            android:maxEms="11"
25
            android:text="东方路希尔顿酒店充电站"
26
            android:textColor="#222222"
27
            android:textSize="18sp"
28
            app:layout_constraintBottom_toBottomOf="parent"
29
            app:layout_constraintLeft_toLeftOf="parent"
30
            app:layout_constraintTop_toTopOf="parent" />
31
32
33
        <ImageView
34
            android:id="@+id/red_paper_bag"
35
            android:layout_width="wrap_content"
36
            android:layout_height="wrap_content"
37
            android:paddingLeft="5dp"
38
            android:paddingTop="5dp"
39
            android:paddingRight="15dp"
40
            android:paddingBottom="5dp"
41
            android:src="@drawable/red_pager_bag_icon"
42
            android:visibility="visible"
43
            app:layout_constraintBottom_toBottomOf="parent"
44
            app:layout_constraintLeft_toRightOf="@+id/zhan_name"
45
            app:layout_constraintTop_toTopOf="parent"
46
            tools:visibility="visible" />
47
48
        <Button
49
            android:id="@+id/recommend_nav"
50
            android:layout_width="50dp"
51
            android:layout_height="24dp"
52
            android:background="@drawable/recommend_btn_normal"
53
            android:text="导航"
54
            android:textColor="#83d287"
55
            android:textSize="13sp"
56
            app:layout_constraintBottom_toBottomOf="parent"
57
            app:layout_constraintRight_toRightOf="parent"
58
            app:layout_constraintTop_toTopOf="parent" />
59
60
61
    </android.support.constraint.ConstraintLayout>
62
63
    <!-- 评分、距离 -->
64
    <LinearLayout
65
        android:layout_width="match_parent"
66
        android:layout_height="wrap_content"
67
        android:gravity="center_vertical"
68
        android:paddingLeft="15dp">
69
70
        <ImageView
71
            android:id="@+id/score_img"
72
            android:layout_width="wrap_content"
73
            android:layout_height="wrap_content"
74
            tools:src="@drawable/icon_0xing" />
75
76
        <TextView
77
            android:id="@+id/score_text"
78
            android:layout_width="wrap_content"
79
            android:layout_height="wrap_content"
80
            android:paddingLeft="5dp"
81
            android:textColor="#FFA300"
82
            android:textSize="14sp"
83
            tools:text="暂无评分" />
84
85
        <View
86
            android:layout_width="0.5dp"
87
            android:layout_height="12dp"
88
            android:layout_marginLeft="5dp"
89
            android:background="#d8d8d8"
90
            android:paddingRight="5dp" />
91
92
        <TextView
93
            android:id="@+id/distance"
94
            android:layout_width="wrap_content"
95
            android:layout_height="wrap_content"
96
            android:layout_marginLeft="5dp"
97
            android:textColor="#888888"
98
            android:textSize="12sp"
99
            tools:text="4.65km" />
100
    </LinearLayout>
101
102
    <!-- 充电成功次数、评论次数 -->
103
    <LinearLayout
104
        android:layout_width="match_parent"
105
        android:layout_height="wrap_content"
106
        android:gravity="center_vertical"
107
        android:layout_marginTop="10dp"
108
        android:paddingLeft="15sp">
109
110
        <TextView
111
            android:id="@+id/charge_record_cnt"
112
            android:layout_width="wrap_content"
113
            android:layout_height="wrap_content"
114
            android:textColor="#202020"
115
            android:textSize="14sp"
116
            tools:text="9次充电成功" />
117
118
        <View
119
            android:id="@+id/times_line"
120
            android:layout_width="0.5dp"
121
            android:layout_height="12dp"
122
            android:layout_marginLeft="10dp"
123
            android:background="#d8d8d8" />
124
125
        <TextView
126
            android:id="@+id/comment_cnt"
127
            android:layout_width="wrap_content"
128
            android:layout_height="wrap_content"
129
            android:layout_marginLeft="10dp"
130
            android:textColor="#202020"
131
            android:textSize="14sp"
132
            tools:text="9次评论" />
133
    </LinearLayout>
134
135
    <!-- 公共、地下、免费停车属性  价格 -->
136
    <LinearLayout
137
        android:layout_width="match_parent"
138
        android:layout_gravity="center_vertical"
139
        android:layout_height="wrap_content">
140
        <LinearLayout
141
            android:layout_width="wrap_content"
142
            android:layout_height="wrap_content">
143
        </LinearLayout>
144
    </LinearLayout>
145
146
    <View
147
        android:layout_width="match_parent"
148
        android:layout_height="0.5dp"
149
        android:background="#d8d8d8" />
150
151
    <View
152
        android:layout_width="match_parent"
153
        android:layout_height="5dp"
154
        android:background="#F4F4F4" />
155
</LinearLayout>