Browse Source

推荐列表开发完成

huyuguo 5 years ago
parent
commit
331cbd2b87

+ 1 - 0
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

3867
                    @Override
3867
                    @Override
3868
                    public void run() {
3868
                    public void run() {
3869
                        windowLayout.setVisibility(View.GONE);
3869
                        windowLayout.setVisibility(View.GONE);
3870
                        rl_control.setVisibility(View.VISIBLE);
3870
                    }
3871
                    }
3871
                }, 500);
3872
                }, 500);
3872
                return false;
3873
                return false;

+ 63 - 20
app/src/main/java/com/electric/chargingpile/activity/RecommendChargingStationActivity.java

55
import java.util.HashMap;
55
import java.util.HashMap;
56
import java.util.List;
56
import java.util.List;
57
import java.util.Map;
57
import java.util.Map;
58
import java.util.function.Predicate;
59
import java.util.stream.Collectors;
58
60
59
import okhttp3.Call;
61
import okhttp3.Call;
60
62
269
                second_2.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
271
                second_2.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
270
                second_2.setTextColor(Color.parseColor("#FFFFFF"));
272
                second_2.setTextColor(Color.parseColor("#FFFFFF"));
271
                first_condition_text.setText("价格最低");
273
                first_condition_text.setText("价格最低");
272
                if (zhanList.size() == 0) {
274
                if (zhanList.size() == 0 && socket != null && socket.isClosed()) {
275
                    loadingDialog.show();
273
                    ete("{\"fun\":\"timer\"}");
276
                    ete("{\"fun\":\"timer\"}");
274
                } else {
277
                } else {
275
                    filterChargingStation();
278
                    filterChargingStation();
282
                second_3.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
285
                second_3.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
283
                second_3.setTextColor(Color.parseColor("#FFFFFF"));
286
                second_3.setTextColor(Color.parseColor("#FFFFFF"));
284
                first_condition_text.setText("距离最近");
287
                first_condition_text.setText("距离最近");
285
                if (zhanList.size() == 0) {
288
                if (zhanList.size() == 0 && socket != null && socket.isClosed()) {
289
                    loadingDialog.show();
286
                    ete("{\"fun\":\"timer\"}");
290
                    ete("{\"fun\":\"timer\"}");
287
                } else {
291
                } else {
288
                    filterChargingStation();
292
                    filterChargingStation();
294
                second_4.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
298
                second_4.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
295
                second_4.setTextColor(Color.parseColor("#FFFFFF"));
299
                second_4.setTextColor(Color.parseColor("#FFFFFF"));
296
                first_condition_text.setText("空闲最多");
300
                first_condition_text.setText("空闲最多");
297
                if (zhanList.size() == 0) {
301
                if (zhanList.size() == 0 && socket != null && socket.isClosed()) {
302
                    loadingDialog.show();
298
                    ete("{\"fun\":\"timer\"}");
303
                    ete("{\"fun\":\"timer\"}");
299
                } else {
304
                } else {
300
                    filterChargingStation();
305
                    filterChargingStation();
306
                second_5.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
311
                second_5.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
307
                second_5.setTextColor(Color.parseColor("#FFFFFF"));
312
                second_5.setTextColor(Color.parseColor("#FFFFFF"));
308
                first_condition_text.setText("评分最高");
313
                first_condition_text.setText("评分最高");
309
                if (zhanList.size() == 0) {
314
                if (zhanList.size() == 0 && socket != null && socket.isClosed()) {
315
                    loadingDialog.show();
310
                    ete("{\"fun\":\"timer\"}");
316
                    ete("{\"fun\":\"timer\"}");
311
                } else {
317
                } else {
312
                    filterChargingStation();
318
                    filterChargingStation();
586
592
587
        @Override
593
        @Override
588
        public int getItemCount() {
594
        public int getItemCount() {
589
            return mList.size();
595
            if (mList.size() > 30) {
596
                return 30;
597
            } else {
598
                return mList.size();
599
            }
590
        }
600
        }
591
601
592
        private void showStarInfoView(ViewHolder holder, RecommendZhan recommendZhan) {
602
        private void showStarInfoView(ViewHolder holder, RecommendZhan recommendZhan) {
788
        if (firstCondition == 1) {
798
        if (firstCondition == 1) {
789
            list = recommendZhanList;
799
            list = recommendZhanList;
790
        } else {
800
        } else {
791
//            list = zhanList; // TODO
792
            list = recommendZhanList;
801
            list = zhanList;
793
        }
802
        }
794
803
795
        List<RecommendZhan> list1 = new ArrayList<>();
804
        List<RecommendZhan> list1 = new ArrayList<>();
857
            }
866
            }
858
        }
867
        }
859
868
860
        if (firstCondition == 2) {
869
        if (firstCondition == 2) { // 价格最低
870
            List<RecommendZhan> priceList1 = new ArrayList<>();
871
            List<RecommendZhan> priceList2 = new ArrayList<>();
872
873
            for (RecommendZhan zhan : list4) {
874
                if (zhan.getZongjia() > 0) {
875
                    priceList1.add(zhan);
876
                } else {
877
                    priceList2.add(zhan);
878
                }
879
            }
880
881
            list4 = priceList1;
882
861
            Collections.sort(list4, new Comparator<RecommendZhan>() {
883
            Collections.sort(list4, new Comparator<RecommendZhan>() {
862
                @Override
884
                @Override
863
                public int compare(RecommendZhan o1, RecommendZhan o2) {
885
                public int compare(RecommendZhan o1, RecommendZhan o2) {
864
                    double diff = o1.getZongjia() - o2.getZongjia();
886
                    double diff = o1.getZongjia() - o2.getZongjia();
887
                    if (o1.getZongjia() == 0) {
888
                        diff = -1;
889
                    }
865
                    if (diff > 0) {
890
                    if (diff > 0) {
866
                        return 1;
891
                        return 1;
867
                    } else if (diff < 0) {
892
                    } else if (diff < 0) {
868
                        return  -1;
893
                        return -1;
869
                    }
894
                    }
870
                    return 0;
895
                    return 0;
871
                }
896
                }
872
            });
897
            });
898
899
            list4.addAll(priceList2);
873
        }
900
        }
874
901
875
        if (firstCondition == 3) {
902
        if (firstCondition == 3) { // 距离最近
876
            Collections.sort(list4, new Comparator<RecommendZhan>() {
903
            Collections.sort(list4, new Comparator<RecommendZhan>() {
877
                @Override
904
                @Override
878
                public int compare(RecommendZhan o1, RecommendZhan o2) {
905
                public int compare(RecommendZhan o1, RecommendZhan o2) {
880
                    if (diff > 0) {
907
                    if (diff > 0) {
881
                        return 1;
908
                        return 1;
882
                    } else if (diff < 0) {
909
                    } else if (diff < 0) {
883
                        return  -1;
910
                        return -1;
884
                    }
911
                    }
885
                    return 0;
912
                    return 0;
886
                }
913
                }
887
            });
914
            });
888
        }
915
        }
889
916
890
        if (firstCondition == 4) {
917
        if (firstCondition == 4) { // 空闲最多
891
            Collections.sort(list4, new Comparator<RecommendZhan>() {
918
            Collections.sort(list4, new Comparator<RecommendZhan>() {
892
                @Override
919
                @Override
893
                public int compare(RecommendZhan o1, RecommendZhan o2) {
920
                public int compare(RecommendZhan o1, RecommendZhan o2) {
931
                    if (diff > 0) {
958
                    if (diff > 0) {
932
                        return -1;
959
                        return -1;
933
                    } else if (diff < 0) {
960
                    } else if (diff < 0) {
934
                        return  1;
961
                        return 1;
935
                    }
962
                    }
936
                    return 0;
963
                    return 0;
937
                }
964
                }
938
            });
965
            });
939
        }
966
        }
940
967
941
        if (firstCondition == 5) {
968
        if (firstCondition == 5) { // 评分最高
942
            Collections.sort(list4, new Comparator<RecommendZhan>() {
969
            Collections.sort(list4, new Comparator<RecommendZhan>() {
943
                @Override
970
                @Override
944
                public int compare(RecommendZhan o1, RecommendZhan o2) {
971
                public int compare(RecommendZhan o1, RecommendZhan o2) {
960
                    if (diff > 0) {
987
                    if (diff > 0) {
961
                        return -1;
988
                        return -1;
962
                    } else if (diff < 0) {
989
                    } else if (diff < 0) {
963
                        return  1;
990
                        return 1;
964
                    }
991
                    }
965
                    return 0;
992
                    return 0;
966
                }
993
                }
970
        recommendChargingStationAdapter.setData(list4);
997
        recommendChargingStationAdapter.setData(list4);
971
998
972
        if (list4.size() == 0) {
999
        if (list4.size() == 0) {
1000
            if (socket != null && !socket.isClosed()) {
1001
                no_result.setText("数据加载中,请稍后...");
1002
            } else {
1003
                no_result.setText("周边没有符合筛选条件的站点,请检查您的筛选项");
1004
            }
973
            no_result.setVisibility(View.VISIBLE);
1005
            no_result.setVisibility(View.VISIBLE);
974
        } else {
1006
        } else {
975
            no_result.setVisibility(View.GONE);
1007
            no_result.setVisibility(View.GONE);
976
        }
1008
        }
977
978
979
    }
1009
    }
980
1010
981
    private void getGaode(Double jing, Double wei) {
1011
    private void getGaode(Double jing, Double wei) {
994
    private Socket socket;
1024
    private Socket socket;
995
    private Handler hand = new Handler() {
1025
    private Handler hand = new Handler() {
996
        public void handleMessage(android.os.Message msg) {
1026
        public void handleMessage(android.os.Message msg) {
1027
            if (activity != null && !activity.isFinishing()) {
1028
                loadingDialog.dismiss();
1029
            }
1030
997
            switch (msg.what) {
1031
            switch (msg.what) {
998
                case 3:
1032
                case 3:
999
                    try {
1033
                    try {
1003
                                String data = JsonUtils.getKeyResult(msg.obj.toString(), "data");
1037
                                String data = JsonUtils.getKeyResult(msg.obj.toString(), "data");
1004
                                List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
1038
                                List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
1005
                                if (list != null) {
1039
                                if (list != null) {
1006
                                    int count = list.size() > 30 ? 30 : list.size();
1040
                                    int count = list.size();
1007
                                    for (int i = 0; i < count; i++) {
1041
                                    for (int i = 0; i < count; i++) {
1008
                                        String wei = list.get(i).getPoi_wei().trim();
1042
                                        String wei = list.get(i).getPoi_wei().trim();
1009
                                        String jing = list.get(i).getPoi_jing().trim();
1043
                                        String jing = list.get(i).getPoi_jing().trim();
1050
            public void run() {
1084
            public void run() {
1051
                try {
1085
                try {
1052
                    // 创建Socket
1086
                    // 创建Socket
1053
                    socket = new Socket("cdz.evcharge.cc", 9503); // IP:10.14.114.127,端口54321
1087
                    socket = new Socket("59.110.68.162", 9503); // IP:59.110.68.162,端口54321 cdz.evcharge.cc  TODO
1054
                    // 向服务器发送消息
1088
                    // 向服务器发送消息
1055
                    PrintWriter out = new PrintWriter(new BufferedWriter(
1089
                    PrintWriter out = new PrintWriter(new BufferedWriter(
1056
                            new OutputStreamWriter(socket.getOutputStream())), true);
1090
                            new OutputStreamWriter(socket.getOutputStream())), true);
1078
                    ete1(socket_string);
1112
                    ete1(socket_string);
1079
                } catch (Exception e) {
1113
                } catch (Exception e) {
1080
                    e.printStackTrace();
1114
                    e.printStackTrace();
1115
                    Message mes = new Message();
1116
                    mes.obj = "error";
1117
                    mes.what = 100;
1118
                    hand.sendMessage(mes);
1081
                }
1119
                }
1082
            }
1120
            }
1083
        }).start();
1121
        }).start();
1089
            @Override
1127
            @Override
1090
            public void run() {
1128
            public void run() {
1091
                try {
1129
                try {
1092
                    socket = new Socket("cdz.evcharge.cc", 9503); // IP:10.14.114.127,端口54321
1130
                    socket = new Socket("59.110.68.162", 9503); // IP:59.110.68.162,端口54321 cdz.evcharge.cc TODO
1093
                    socket.setReceiveBufferSize(99999);  //  接收缓冲大小
1131
                    socket.setReceiveBufferSize(99999);  //  接收缓冲大小
1094
                    socket.setSendBufferSize(99999);
1132
                    socket.setSendBufferSize(99999);
1095
                    // 向服务器发送消息
1133
                    // 向服务器发送消息
1113
                    // 关闭Socket
1151
                    // 关闭Socket
1114
                    socket.close();
1152
                    socket.close();
1115
                } catch (Exception e) {
1153
                } catch (Exception e) {
1154
                    e.printStackTrace();
1155
                    Message mes = new Message();
1156
                    mes.obj = "error";
1157
                    mes.what = 100;
1158
                    hand.sendMessage(mes);
1116
                }
1159
                }
1117
            }
1160
            }
1118
        }).start();
1161
        }).start();

+ 3 - 3
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 distanceNum;
45
    private double score;
45
    private double score;
46
    private String pile_status;
46
    private String pile_status;
47
    private String fast_able_num;
47
    private String fast_able_num;
55
    private String park_location;
55
    private String park_location;
56
    private String stop_cost;
56
    private String stop_cost;
57
57
58
    public Double getDistanceNum() {
58
    public double getDistanceNum() {
59
        return distanceNum;
59
        return distanceNum;
60
    }
60
    }
61
61
62
    public void setDistanceNum(Double distanceNum) {
62
    public void setDistanceNum(double distanceNum) {
63
        this.distanceNum = distanceNum;
63
        this.distanceNum = distanceNum;
64
    }
64
    }
65
65