Browse Source

列表开发完成

huyuguo 5 years ago
parent
commit
71b37e5893

+ 2 - 2
app/src/main/AndroidManifest.xml

1
<?xml version="1.0" encoding="utf-8"?>
1
<?xml version="1.0" encoding="utf-8"?>
2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
    package="com.electric.chargingpile"
3
    package="com.electric.chargingpile"
4
    android:versionCode="80"
5
    android:versionName="3.4.2">
4
    android:versionCode="81"
5
    android:versionName="3.4.3">
6
    <!-- 极光 -->
6
    <!-- 极光 -->
7
    <application
7
    <application
8
        android:name=".application.MainApplication"
8
        android:name=".application.MainApplication"

+ 187 - 19
app/src/main/java/com/electric/chargingpile/activity/RecommendChargingStationActivity.java

50
import java.net.Socket;
50
import java.net.Socket;
51
import java.net.URISyntaxException;
51
import java.net.URISyntaxException;
52
import java.util.ArrayList;
52
import java.util.ArrayList;
53
import java.util.Collections;
54
import java.util.Comparator;
53
import java.util.HashMap;
55
import java.util.HashMap;
54
import java.util.List;
56
import java.util.List;
55
import java.util.Map;
57
import java.util.Map;
57
import okhttp3.Call;
59
import okhttp3.Call;
58
60
59
import static com.electric.chargingpile.activity.MainMapActivity.getMD5;
61
import static com.electric.chargingpile.activity.MainMapActivity.getMD5;
62
import static com.electric.chargingpile.activity.MainMapActivity.list;
60
63
61
public class RecommendChargingStationActivity extends AppCompatActivity implements View.OnClickListener {
64
public class RecommendChargingStationActivity extends AppCompatActivity implements View.OnClickListener {
62
    private static final String TAG = "RecommendChargingStationActivity";
65
    private static final String TAG = "RecommendChargingStationActivity";
63
    List<RecommendZhan> recommendZhanList;
66
    List<RecommendZhan> recommendZhanList;
67
    List<RecommendZhan> zhanList;
64
    private LoadingDialog loadingDialog;
68
    private LoadingDialog loadingDialog;
65
    private View popupWindowView;
69
    private View popupWindowView;
66
    private PopupWindow popupWindow;
70
    private PopupWindow popupWindow;
109
    }
113
    }
110
114
111
    private void initView() {
115
    private void initView() {
112
        recommendZhanList = new ArrayList<RecommendZhan>();
116
        recommendZhanList = new ArrayList<>();
117
        zhanList = new ArrayList<>();
113
        activity = this;
118
        activity = this;
114
        loadingDialog = new LoadingDialog(this);
119
        loadingDialog = new LoadingDialog(this);
115
        loadingDialog.setCanceledOnTouchOutside(false);
120
        loadingDialog.setCanceledOnTouchOutside(false);
177
                firstCanCharging = !firstCanCharging;
182
                firstCanCharging = !firstCanCharging;
178
                first_can_charging.setTextColor(firstCanCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
183
                first_can_charging.setTextColor(firstCanCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
179
                foldSecondCondition();
184
                foldSecondCondition();
180
                filterChargingStation(recommendZhanList);
185
                filterChargingStation();
181
                if (firstCanCharging) {
186
                if (firstCanCharging) {
182
                    MobclickAgent.onEvent(getApplicationContext(), "1141");
187
                    MobclickAgent.onEvent(getApplicationContext(), "1141");
183
                }
188
                }
186
                firstFreeParking = !firstFreeParking;
191
                firstFreeParking = !firstFreeParking;
187
                first_free_parking.setTextColor(firstFreeParking ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
192
                first_free_parking.setTextColor(firstFreeParking ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
188
                foldSecondCondition();
193
                foldSecondCondition();
189
                filterChargingStation(recommendZhanList);
194
                filterChargingStation();
190
                if (firstFreeParking) {
195
                if (firstFreeParking) {
191
                    MobclickAgent.onEvent(getApplicationContext(), "1143");
196
                    MobclickAgent.onEvent(getApplicationContext(), "1143");
192
                }
197
                }
195
                firstQuickCharging = !firstQuickCharging;
200
                firstQuickCharging = !firstQuickCharging;
196
                first_quick_charging.setTextColor(firstQuickCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
201
                first_quick_charging.setTextColor(firstQuickCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
197
                foldSecondCondition();
202
                foldSecondCondition();
198
                filterChargingStation(recommendZhanList);
203
                filterChargingStation();
199
                if (firstQuickCharging) {
204
                if (firstQuickCharging) {
200
                    MobclickAgent.onEvent(getApplicationContext(), "1142");
205
                    MobclickAgent.onEvent(getApplicationContext(), "1142");
201
                }
206
                }
204
                firstSlowCharging = !firstSlowCharging;
209
                firstSlowCharging = !firstSlowCharging;
205
                first_slow_charging.setTextColor(firstSlowCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
210
                first_slow_charging.setTextColor(firstSlowCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
206
                foldSecondCondition();
211
                foldSecondCondition();
207
                filterChargingStation(recommendZhanList);
212
                filterChargingStation();
208
                if (firstSlowCharging) {
213
                if (firstSlowCharging) {
209
                    MobclickAgent.onEvent(getApplicationContext(), "1144");
214
                    MobclickAgent.onEvent(getApplicationContext(), "1144");
210
                }
215
                }
254
                first_condition_text.setText("智能推荐");
259
                first_condition_text.setText("智能推荐");
255
                if (recommendZhanList.size() == 0) {
260
                if (recommendZhanList.size() == 0) {
256
                    recommendChargingStationFunc();
261
                    recommendChargingStationFunc();
262
                } else {
263
                    filterChargingStation();
257
                }
264
                }
258
                MobclickAgent.onEvent(getApplicationContext(), "1136");
265
                MobclickAgent.onEvent(getApplicationContext(), "1136");
259
                break;
266
                break;
262
                second_2.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
269
                second_2.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
263
                second_2.setTextColor(Color.parseColor("#FFFFFF"));
270
                second_2.setTextColor(Color.parseColor("#FFFFFF"));
264
                first_condition_text.setText("价格最低");
271
                first_condition_text.setText("价格最低");
272
                if (zhanList.size() == 0) {
273
                    ete("{\"fun\":\"timer\"}");
274
                } else {
275
                    filterChargingStation();
276
                }
277
265
                MobclickAgent.onEvent(getApplicationContext(), "1138");
278
                MobclickAgent.onEvent(getApplicationContext(), "1138");
266
                break;
279
                break;
267
            case R.id.second_3:
280
            case R.id.second_3:
269
                second_3.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
282
                second_3.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
270
                second_3.setTextColor(Color.parseColor("#FFFFFF"));
283
                second_3.setTextColor(Color.parseColor("#FFFFFF"));
271
                first_condition_text.setText("距离最近");
284
                first_condition_text.setText("距离最近");
285
                if (zhanList.size() == 0) {
286
                    ete("{\"fun\":\"timer\"}");
287
                } else {
288
                    filterChargingStation();
289
                }
272
                MobclickAgent.onEvent(getApplicationContext(), "1139");
290
                MobclickAgent.onEvent(getApplicationContext(), "1139");
273
                break;
291
                break;
274
            case R.id.second_4:
292
            case R.id.second_4:
276
                second_4.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
294
                second_4.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
277
                second_4.setTextColor(Color.parseColor("#FFFFFF"));
295
                second_4.setTextColor(Color.parseColor("#FFFFFF"));
278
                first_condition_text.setText("空闲最多");
296
                first_condition_text.setText("空闲最多");
297
                if (zhanList.size() == 0) {
298
                    ete("{\"fun\":\"timer\"}");
299
                } else {
300
                    filterChargingStation();
301
                }
279
                MobclickAgent.onEvent(getApplicationContext(), "1140");
302
                MobclickAgent.onEvent(getApplicationContext(), "1140");
280
                break;
303
                break;
281
            case R.id.second_5:
304
            case R.id.second_5:
283
                second_5.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
306
                second_5.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
284
                second_5.setTextColor(Color.parseColor("#FFFFFF"));
307
                second_5.setTextColor(Color.parseColor("#FFFFFF"));
285
                first_condition_text.setText("评分最高");
308
                first_condition_text.setText("评分最高");
309
                if (zhanList.size() == 0) {
310
                    ete("{\"fun\":\"timer\"}");
311
                } else {
312
                    filterChargingStation();
313
                }
286
                MobclickAgent.onEvent(getApplicationContext(), "1137");
314
                MobclickAgent.onEvent(getApplicationContext(), "1137");
287
                break;
315
                break;
288
        }
316
        }
353
                            }
381
                            }
354
382
355
                            double d = AMapUtils.calculateLineDistance(center, ll);
383
                            double d = AMapUtils.calculateLineDistance(center, ll);
384
                            list.get(i).setDistanceNum(d);
356
                            list.get(i).setDistance(Util.getDistance(d));
385
                            list.get(i).setDistance(Util.getDistance(d));
357
                        }
386
                        }
358
                        recommendZhanList = list;
387
                        recommendZhanList = list;
359
                        recommendChargingStationAdapter.setData(list);
360
                        if (list.size() == 0) {
361
                            no_result.setVisibility(View.VISIBLE);
362
                        } else {
363
                            no_result.setVisibility(View.GONE);
364
                        }
388
                        filterChargingStation();
365
                    }
389
                    }
366
                }
390
                }
367
                ete("{\"fun\":\"timer\"}");
391
                ete("{\"fun\":\"timer\"}");
757
        }
781
        }
758
    }
782
    }
759
783
760
    private void filterChargingStation(List<RecommendZhan> zhanList) {
784
    private void filterChargingStation() {
761
        no_result.setVisibility(View.GONE);
785
        no_result.setVisibility(View.GONE);
762
786
787
        List<RecommendZhan> list;
788
        if (firstCondition == 1) {
789
            list = recommendZhanList;
790
        } else {
791
//            list = zhanList; // TODO
792
            list = recommendZhanList;
793
        }
794
763
        List<RecommendZhan> list1 = new ArrayList<>();
795
        List<RecommendZhan> list1 = new ArrayList<>();
764
        if (firstCanCharging) {
796
        if (firstCanCharging) {
765
            for (RecommendZhan item : zhanList) {
797
            for (RecommendZhan item : list) {
766
                if ("1".equals(item.getOwn_pay())) {
798
                if ("1".equals(item.getOwn_pay())) {
767
                    list1.add(item);
799
                    list1.add(item);
768
                }
800
                }
769
            }
801
            }
770
        } else {
802
        } else {
771
            for (RecommendZhan item : zhanList) {
803
            for (RecommendZhan item : list) {
772
                list1.add(item);
804
                list1.add(item);
773
            }
805
            }
774
        }
806
        }
825
            }
857
            }
826
        }
858
        }
827
859
860
        if (firstCondition == 2) {
861
            Collections.sort(list4, new Comparator<RecommendZhan>() {
862
                @Override
863
                public int compare(RecommendZhan o1, RecommendZhan o2) {
864
                    double diff = o1.getZongjia() - o2.getZongjia();
865
                    if (diff > 0) {
866
                        return 1;
867
                    } else if (diff < 0) {
868
                        return  -1;
869
                    }
870
                    return 0;
871
                }
872
            });
873
        }
874
875
        if (firstCondition == 3) {
876
            Collections.sort(list4, new Comparator<RecommendZhan>() {
877
                @Override
878
                public int compare(RecommendZhan o1, RecommendZhan o2) {
879
                    double diff = o1.getDistanceNum() - o2.getDistanceNum();
880
                    if (diff > 0) {
881
                        return 1;
882
                    } else if (diff < 0) {
883
                        return  -1;
884
                    }
885
                    return 0;
886
                }
887
            });
888
        }
889
890
        if (firstCondition == 4) {
891
            Collections.sort(list4, new Comparator<RecommendZhan>() {
892
                @Override
893
                public int compare(RecommendZhan o1, RecommendZhan o2) {
894
                    int fast_able_num1;
895
                    int fast_able_num2;
896
                    int slow_able_num1;
897
                    int slow_able_num2;
898
899
                    int total_num1;
900
                    int total_num2;
901
902
                    if (o1.getFast_able_num() == null || "".equals(o1.getFast_able_num())) {
903
                        fast_able_num1 = 0;
904
                    } else {
905
                        fast_able_num1 = Integer.parseInt(o1.getFast_able_num());
906
                    }
907
908
                    if (o1.getSlow_able_num() == null || "".equals(o1.getSlow_able_num())) {
909
                        slow_able_num1 = 0;
910
                    } else {
911
                        slow_able_num1 = Integer.parseInt(o1.getSlow_able_num());
912
                    }
913
914
915
                    if (o2.getFast_able_num() == null || "".equals(o2.getFast_able_num())) {
916
                        fast_able_num2 = 0;
917
                    } else {
918
                        fast_able_num2 = Integer.parseInt(o2.getFast_able_num());
919
                    }
920
921
                    if (o2.getSlow_able_num() == null || "".equals(o2.getSlow_able_num())) {
922
                        slow_able_num2 = 0;
923
                    } else {
924
                        slow_able_num2 = Integer.parseInt(o2.getSlow_able_num());
925
                    }
926
927
                    total_num1 = fast_able_num1 + slow_able_num1;
928
                    total_num2 = fast_able_num2 + slow_able_num2;
929
930
                    int diff = total_num1 - total_num2;
931
                    if (diff > 0) {
932
                        return -1;
933
                    } else if (diff < 0) {
934
                        return  1;
935
                    }
936
                    return 0;
937
                }
938
            });
939
        }
940
941
        if (firstCondition == 5) {
942
            Collections.sort(list4, new Comparator<RecommendZhan>() {
943
                @Override
944
                public int compare(RecommendZhan o1, RecommendZhan o2) {
945
                    double star1;
946
                    double star2;
947
                    if (o1.getStar() == null || "".equals(o1.getStar())) {
948
                        star1 = 0;
949
                    } else {
950
                        star1 = Double.parseDouble(o1.getStar());
951
                    }
952
953
                    if (o2.getStar() == null || "".equals(o2.getStar())) {
954
                        star2 = 0;
955
                    } else {
956
                        star2 = Double.parseDouble(o2.getStar());
957
                    }
958
959
                    double diff = star1 - star2;
960
                    if (diff > 0) {
961
                        return -1;
962
                    } else if (diff < 0) {
963
                        return  1;
964
                    }
965
                    return 0;
966
                }
967
            });
968
        }
969
828
        recommendChargingStationAdapter.setData(list4);
970
        recommendChargingStationAdapter.setData(list4);
829
971
830
        if (list4.size() == 0) {
972
        if (list4.size() == 0) {
832
        } else {
974
        } else {
833
            no_result.setVisibility(View.GONE);
975
            no_result.setVisibility(View.GONE);
834
        }
976
        }
977
978
835
    }
979
    }
836
980
837
    private void getGaode(Double jing, Double wei) {
981
    private void getGaode(Double jing, Double wei) {
855
                    try {
999
                    try {
856
                        String rtnCode = JsonUtils.getKeyResult(msg.obj.toString(), "rtnCode");
1000
                        String rtnCode = JsonUtils.getKeyResult(msg.obj.toString(), "rtnCode");
857
                        if ("0".equals(rtnCode)) {
1001
                        if ("0".equals(rtnCode)) {
858
                            try{
1002
                            try {
859
                                String data = JsonUtils.getKeyResult(msg.obj.toString(), "data");
1003
                                String data = JsonUtils.getKeyResult(msg.obj.toString(), "data");
860
                                List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
1004
                                List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
861
                                if (list != null && list.size() > 0) {
1005
                                if (list != null) {
1006
                                    int count = list.size() > 30 ? 30 : list.size();
1007
                                    for (int i = 0; i < count; i++) {
1008
                                        String wei = list.get(i).getPoi_wei().trim();
1009
                                        String jing = list.get(i).getPoi_jing().trim();
1010
1011
                                        int position_jing = jing.length() - jing.indexOf(".") - 1;
1012
                                        int position_wei = wei.length() - wei.indexOf(".") - 1;
1013
1014
1015
                                        LatLng ll;
1016
                                        if (position_jing > 13 || position_wei > 13) {
1017
                                            ll = new LatLng(Double.parseDouble(wei), Double.parseDouble(jing));
1018
                                        } else {
1019
                                            double dwei = Double.parseDouble(wei);
1020
                                            double djing = Double.parseDouble(jing);
1021
                                            getGaode(djing, dwei);
1022
                                            ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
1023
                                        }
1024
1025
                                        double d = AMapUtils.calculateLineDistance(center, ll);
1026
                                        list.get(i).setDistanceNum(d);
1027
                                        list.get(i).setDistance(Util.getDistance(d));
1028
                                    }
1029
                                    zhanList = list;
1030
                                    filterChargingStation();
862
                                }
1031
                                }
863
                            }catch (Exception e) {
1032
                            } catch (Exception e) {
864
                                e.printStackTrace();
1033
                                e.printStackTrace();
865
                            }
1034
                            }
866
                        }
1035
                        }
906
                    map.put("poi_rdy", rlat);
1075
                    map.put("poi_rdy", rlat);
907
                    map.put("timer", Token);
1076
                    map.put("timer", Token);
908
                    String socket_string = JsonUtils.mapToJson(map);
1077
                    String socket_string = JsonUtils.mapToJson(map);
909
                    LogUtils.e(socket_string);
910
                    ete1(socket_string);
1078
                    ete1(socket_string);
911
                } catch (Exception e) {
1079
                } catch (Exception e) {
1080
                    e.printStackTrace();
912
                }
1081
                }
913
            }
1082
            }
914
        }).start();
1083
        }).start();
934
                    if (msg != null) {
1103
                    if (msg != null) {
935
                        Message mes = new Message();
1104
                        Message mes = new Message();
936
                        mes.obj = msg;
1105
                        mes.obj = msg;
937
                        LogUtils.e(msg);
938
                        mes.what = 3;
1106
                        mes.what = 3;
939
                        hand.sendMessage(mes);
1107
                        hand.sendMessage(mes);
940
                    } else {
1108
                    } else {

+ 9 - 0
app/src/main/java/com/electric/chargingpile/data/RecommendZhan.java

41
    private String zhan_id;
41
    private String zhan_id;
42
    private String charge_cost_way2;
42
    private String charge_cost_way2;
43
    private String distance;
43
    private String distance;
44
    private Double distanceNum;
44
    private double score;
45
    private double score;
45
    private String pile_status;
46
    private String pile_status;
46
    private String fast_able_num;
47
    private String fast_able_num;
54
    private String park_location;
55
    private String park_location;
55
    private String stop_cost;
56
    private String stop_cost;
56
57
58
    public Double getDistanceNum() {
59
        return distanceNum;
60
    }
61
62
    public void setDistanceNum(Double distanceNum) {
63
        this.distanceNum = distanceNum;
64
    }
65
57
    public void setZongjia(double zongjia) {
66
    public void setZongjia(double zongjia) {
58
        this.zongjia = zongjia;
67
        this.zongjia = zongjia;
59
    }
68
    }