Ver Código Fonte

智能推荐开发完成

huyuguo 5 anos atrás
pai
commit
c7840fa629

+ 92 - 4
app/src/main/java/com/electric/chargingpile/activity/RecommendChargingStationActivity.java

32
import com.electric.chargingpile.util.LoadingDialog;
32
import com.electric.chargingpile.util.LoadingDialog;
33
import com.electric.chargingpile.util.ToastUtil;
33
import com.electric.chargingpile.util.ToastUtil;
34
import com.electric.chargingpile.util.Util;
34
import com.electric.chargingpile.util.Util;
35
import com.umeng.analytics.MobclickAgent;
36
import com.zhy.http.okhttp.OkHttpUtils;
35
import com.zhy.http.okhttp.OkHttpUtils;
37
import com.zhy.http.okhttp.callback.StringCallback;
36
import com.zhy.http.okhttp.callback.StringCallback;
38
37
39
import java.net.URISyntaxException;
38
import java.net.URISyntaxException;
40
import java.util.ArrayList;
39
import java.util.ArrayList;
41
import java.util.HashMap;
42
import java.util.List;
40
import java.util.List;
43
41
44
import okhttp3.Call;
42
import okhttp3.Call;
80
78
81
    private RecyclerView recyclerView;
79
    private RecyclerView recyclerView;
82
    private RecommendChargingStationAdapter recommendChargingStationAdapter;
80
    private RecommendChargingStationAdapter recommendChargingStationAdapter;
81
    private TextView no_result;
83
82
84
83
85
    @Override
84
    @Override
96
        activity = this;
95
        activity = this;
97
        loadingDialog = new LoadingDialog(this);
96
        loadingDialog = new LoadingDialog(this);
98
        loadingDialog.setCanceledOnTouchOutside(false);
97
        loadingDialog.setCanceledOnTouchOutside(false);
98
        no_result = findViewById(R.id.no_result);
99
99
100
        center_jing = getIntent().getStringExtra("center_jing");
100
        center_jing = getIntent().getStringExtra("center_jing");
101
        center_wei = getIntent().getStringExtra("center_wei");
101
        center_wei = getIntent().getStringExtra("center_wei");
154
                } else {
154
                } else {
155
                    unfoldSecondCondition();
155
                    unfoldSecondCondition();
156
                }
156
                }
157
158
                break;
157
                break;
159
            case R.id.first_can_charging:
158
            case R.id.first_can_charging:
160
                firstCanCharging = !firstCanCharging;
159
                firstCanCharging = !firstCanCharging;
161
                first_can_charging.setTextColor(firstCanCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
160
                first_can_charging.setTextColor(firstCanCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
162
                foldSecondCondition();
161
                foldSecondCondition();
162
                filterChargingStation(recommendZhanList);
163
                break;
163
                break;
164
            case R.id.first_free_parking:
164
            case R.id.first_free_parking:
165
                firstFreeParking = !firstFreeParking;
165
                firstFreeParking = !firstFreeParking;
166
                first_free_parking.setTextColor(firstFreeParking ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
166
                first_free_parking.setTextColor(firstFreeParking ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
167
                foldSecondCondition();
167
                foldSecondCondition();
168
                filterChargingStation(recommendZhanList);
168
                break;
169
                break;
169
            case R.id.first_quick_charging:
170
            case R.id.first_quick_charging:
170
                firstQuickCharging = !firstQuickCharging;
171
                firstQuickCharging = !firstQuickCharging;
171
                first_quick_charging.setTextColor(firstQuickCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
172
                first_quick_charging.setTextColor(firstQuickCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
172
                foldSecondCondition();
173
                foldSecondCondition();
174
                filterChargingStation(recommendZhanList);
173
                break;
175
                break;
174
            case R.id.first_slow_charging:
176
            case R.id.first_slow_charging:
175
                firstSlowCharging = !firstSlowCharging;
177
                firstSlowCharging = !firstSlowCharging;
176
                first_slow_charging.setTextColor(firstSlowCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
178
                first_slow_charging.setTextColor(firstSlowCharging ? Color.parseColor("#2FC45B") : Color.parseColor("#222222"));
177
                foldSecondCondition();
179
                foldSecondCondition();
180
                filterChargingStation(recommendZhanList);
178
                break;
181
                break;
179
            case R.id.second_1:
182
            case R.id.second_1:
180
            case R.id.second_2:
183
            case R.id.second_2:
219
                second_1.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
222
                second_1.setBackground(getResources().getDrawable(R.drawable.recommend_btn_selected));
220
                second_1.setTextColor(Color.parseColor("#FFFFFF"));
223
                second_1.setTextColor(Color.parseColor("#FFFFFF"));
221
                first_condition_text.setText("智能推荐");
224
                first_condition_text.setText("智能推荐");
225
                if (recommendZhanList.size() == 0) {
226
                    recommendChargingStationFunc();
227
                }
222
                break;
228
                break;
223
            case R.id.second_2:
229
            case R.id.second_2:
224
                firstCondition = 2;
230
                firstCondition = 2;
266
272
267
    private void recommendChargingStationFunc() {
273
    private void recommendChargingStationFunc() {
268
        loadingDialog.show();
274
        loadingDialog.show();
275
        no_result.setVisibility(View.GONE);
269
276
270
        String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/recommend?longitude=" + center_jing + "&latitude=" + center_wei;
277
        String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/recommend?longitude=" + center_jing + "&latitude=" + center_wei;
271
278
292
                    String data = JsonUtils.getKeyResult(response, "data");
299
                    String data = JsonUtils.getKeyResult(response, "data");
293
                    List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
300
                    List<RecommendZhan> list = JsonUtils.parseToObjectList(data, RecommendZhan.class);
294
                    if (list != null) {
301
                    if (list != null) {
295
296
                        for (int i = 0; i < list.size(); i++) {
302
                        for (int i = 0; i < list.size(); i++) {
297
                            String wei = list.get(i).getPoi_wei().trim();
303
                            String wei = list.get(i).getPoi_wei().trim();
298
                            String jing = list.get(i).getPoi_jing().trim();
304
                            String jing = list.get(i).getPoi_jing().trim();
316
                        }
322
                        }
317
                        recommendZhanList = list;
323
                        recommendZhanList = list;
318
                        recommendChargingStationAdapter.setData(list);
324
                        recommendChargingStationAdapter.setData(list);
325
                        if (list.size() == 0) {
326
                            no_result.setVisibility(View.VISIBLE);
327
                        } else {
328
                            no_result.setVisibility(View.GONE);
329
                        }
319
                    }
330
                    }
320
                }
331
                }
321
            }
332
            }
710
        }
721
        }
711
    }
722
    }
712
723
724
    private void filterChargingStation(List<RecommendZhan> zhanList) {
725
        no_result.setVisibility(View.GONE);
726
727
        List<RecommendZhan> list1 = new ArrayList<>();
728
        if (firstCanCharging) {
729
            for (RecommendZhan item : zhanList) {
730
                if ("1".equals(item.getOwn_pay())) {
731
                    list1.add(item);
732
                }
733
            }
734
        } else {
735
            for (RecommendZhan item : zhanList) {
736
                list1.add(item);
737
            }
738
        }
739
740
        List<RecommendZhan> list2 = new ArrayList<>();
741
        if (firstFreeParking) {
742
            for (RecommendZhan item : list1) {
743
                if (item.getStop_cost().contains("免费")) {
744
                    list2.add(item);
745
                }
746
            }
747
        } else {
748
            for (RecommendZhan item : list1) {
749
                list2.add(item);
750
            }
751
        }
752
753
        List<RecommendZhan> list3 = new ArrayList<>();
754
        if (firstQuickCharging) {
755
            for (RecommendZhan item : list2) {
756
                int fastNum;
757
                if ("".equals(item.getFast_num())) {
758
                    fastNum = 0;
759
                } else {
760
                    fastNum = Integer.parseInt(item.getFast_num());
761
                }
762
763
                if (fastNum > 0) {
764
                    list3.add(item);
765
                }
766
            }
767
        } else {
768
            for (RecommendZhan item : list2) {
769
                list3.add(item);
770
            }
771
        }
772
773
        List<RecommendZhan> list4 = new ArrayList<>();
774
        if (firstSlowCharging) {
775
            for (RecommendZhan item : list3) {
776
                int slowNum;
777
                if ("".equals(item.getSlow_num())) {
778
                    slowNum = 0;
779
                } else {
780
                    slowNum = Integer.parseInt(item.getSlow_num());
781
                }
782
                if (slowNum > 0) {
783
                    list4.add(item);
784
                }
785
            }
786
        } else {
787
            for (RecommendZhan item : list3) {
788
                list4.add(item);
789
            }
790
        }
791
792
        recommendChargingStationAdapter.setData(list4);
793
794
        if (list4.size() == 0) {
795
            no_result.setVisibility(View.VISIBLE);
796
        } else {
797
            no_result.setVisibility(View.GONE);
798
        }
799
    }
800
713
    private void getGaode(Double jing, Double wei) {
801
    private void getGaode(Double jing, Double wei) {
714
        double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
802
        double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
715
        double gg_lon;
803
        double gg_lon;

+ 13 - 1
app/src/main/res/layout/activity_recommend_charging_station.xml

160
        android:layout_height="0dp"
160
        android:layout_height="0dp"
161
        app:layout_constraintBottom_toBottomOf="parent"
161
        app:layout_constraintBottom_toBottomOf="parent"
162
        app:layout_constraintTop_toBottomOf="@+id/condition_first_bar" />
162
        app:layout_constraintTop_toBottomOf="@+id/condition_first_bar" />
163
164
    <android.support.constraint.ConstraintLayout
163
    <android.support.constraint.ConstraintLayout
165
        android:id="@+id/condition_second_bar"
164
        android:id="@+id/condition_second_bar"
166
        android:layout_width="match_parent"
165
        android:layout_width="match_parent"
293
292
294
    </android.support.constraint.ConstraintLayout>
293
    </android.support.constraint.ConstraintLayout>
295
294
295
    <TextView
296
        android:id="@+id/no_result"
297
        android:visibility="gone"
298
        tools:visibility="visible"
299
        android:gravity="center"
300
        android:textSize="14sp"
301
        android:textColor="#666666"
302
        android:text="周边没有符合筛选条件的站点,请检查您的筛选项"
303
        android:layout_width="match_parent"
304
        android:layout_height="0dp"
305
        app:layout_constraintBottom_toBottomOf="parent"
306
        app:layout_constraintTop_toBottomOf="@+id/condition_first_bar"/>
307
296
</android.support.constraint.ConstraintLayout>
308
</android.support.constraint.ConstraintLayout>