Browse Source

电价详情开发完成

huyuguo 4 years ago
parent
commit
b3b68355f5

+ 65 - 8
app/src/main/java/com/electric/chargingpile/activity/PriceDetailsActivity.java

@ -19,6 +19,7 @@ import org.json.JSONObject;
19 19
import java.math.BigDecimal;
20 20
import java.util.ArrayList;
21 21
import java.util.Arrays;
22
import java.util.Calendar;
22 23
23 24
public class PriceDetailsActivity extends Activity implements View.OnClickListener {
24 25
    private LinearLayout ll_details;
@ -48,34 +49,89 @@ public class PriceDetailsActivity extends Activity implements View.OnClickListen
48 49
    }
49 50
50 51
    private void addView() throws JSONException {
51
        ArrayList<PileData.FenshiInfoBean> beans = new ArrayList<PileData.FenshiInfoBean>();
52
        int size = DetailsFragment.datas.size();
53
        if (size == 0) {
54
            return;
55
        }
52 56
57
        PileData.FenshiInfoBean[] beans = new PileData.FenshiInfoBean[size];
53 58
        int index = 0;
54 59
        for (JSONObject obj : DetailsFragment.datas) {
55 60
            PileData.FenshiInfoBean bean = JsonUtils.parseToObjectBean(obj.toString(), PileData.FenshiInfoBean.class);
56
            bean.index = index;
57
            beans.add(bean);
61
            bean.setIndex(index);
62
            bean.setIcon(getDrawable(R.drawable.price_ping));
63
            beans[index] = bean;
58 64
            index++;
59 65
        }
60 66
61
        Arrays.sort(beans, (o1, o2) -> {
62
            PileData.FenshiInfoBean b1 = (PileData.FenshiInfoBean) o1;
63
            PileData.FenshiInfoBean b2 = (PileData.FenshiInfoBean) o2;
64
            if (b1.getTotalPrice() > b2.getTotalPrice()) {
67
        // 按总价降序排列
68
        Arrays.sort(beans, (b1, b2) -> {
69
            if (b1.getTotalPrice() < b2.getTotalPrice()) {
70
                return 1;
71
            } else if (b1.getTotalPrice() > b2.getTotalPrice()) {
72
                return -1;
73
            } else {
74
                return 0;
75
            }
76
        });
77
78
        if (size == 1) {
79
            beans[0].setIcon(getDrawable(R.drawable.price_ping));
80
        } else if (size == 2) {
81
            beans[0].setIcon(getDrawable(R.drawable.price_feng));
82
            beans[1].setIcon(getDrawable(R.drawable.price_ping));
83
        } else {
84
            beans[0].setIcon(getDrawable(R.drawable.price_feng));
85
            beans[size - 1].setIcon(getDrawable(R.drawable.price_gu));
86
        }
87
88
        for (PileData.FenshiInfoBean bean : beans) {
89
            if (Math.abs(bean.getTotalPrice() - beans[0].getTotalPrice()) < 0.01) {
90
                bean.setIcon(beans[0].getIcon());
91
            } else {
92
                break;
93
            }
94
        }
95
96
        for (int j = size - 1; j >= 0; j--) {
97
            PileData.FenshiInfoBean bean = beans[j];
98
            if (Math.abs(bean.getTotalPrice() - beans[size - 1].getTotalPrice()) < 0.01) {
99
                bean.setIcon(beans[size - 1].getIcon());
100
            } else {
101
                break;
102
            }
103
        }
104
105
106
        Arrays.sort(beans, (b1, b2) -> {
107
            if (b1.getIndex() > b2.getIndex()) {
65 108
                return 1;
66
            } else if (b1.getTotalPrice() < b2.getTotalPrice()) {
109
            } else if (b1.getIndex() < b2.getIndex()) {
67 110
                return -1;
68 111
            } else {
69 112
                return 0;
70 113
            }
71 114
        });
72 115
116
        Calendar calendar = Calendar.getInstance();
117
        int hours = calendar.get(Calendar.HOUR_OF_DAY);
118
        int minutes = calendar.get(Calendar.MINUTE);
119
        int totalMinutes = hours * 60 + minutes;
120
73 121
        int i = 0;
74 122
        for (PileData.FenshiInfoBean bean : beans) {
75 123
            View itemView = getLayoutInflater().inflate(R.layout.item_details_list, null);
76 124
            TextView time = (TextView) itemView.findViewById(R.id.time);
77 125
            TextView total_price = (TextView) itemView.findViewById(R.id.total_price);
78 126
            TextView price = (TextView) itemView.findViewById(R.id.price);
127
            ImageView icon = itemView.findViewById(R.id.icon);
128
            ImageView now_icon = itemView.findViewById(R.id.now_icon);
129
130
            if (totalMinutes >= bean.getStartTotalMinutes() && totalMinutes <= bean.getEndTotalMinutes()) {
131
                now_icon.setVisibility(View.VISIBLE);
132
            } else {
133
                now_icon.setVisibility(View.GONE);
134
            }
79 135
80 136
            time.setText(bean.getStart() + "-" + bean.getEnd());
81 137
@ -85,6 +141,7 @@ public class PriceDetailsActivity extends Activity implements View.OnClickListen
85 141
            BigDecimal bd = new BigDecimal(c);
86 142
            double d = bd.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
87 143
            total_price.setText(d + "");
144
            icon.setImageDrawable(bean.getIcon());
88 145
89 146
            ll_details.addView(itemView, i);
90 147
            i++;

+ 32 - 1
app/src/main/java/com/electric/chargingpile/data/PileData.java

@ -1,5 +1,7 @@
1 1
package com.electric.chargingpile.data;
2 2
3
import android.graphics.drawable.Drawable;
4
3 5
import java.io.Serializable;
4 6
import java.util.ArrayList;
5 7
import java.util.List;
@ -207,13 +209,30 @@ public class PileData implements Serializable {
207 209
    }
208 210
209 211
    public static class FenshiInfoBean implements Serializable {
212
        public int getIndex() {
213
            return index;
214
        }
215
216
        public void setIndex(int index) {
217
            this.index = index;
218
        }
219
220
        public Drawable getIcon() {
221
            return icon;
222
        }
223
224
        public void setIcon(Drawable icon) {
225
            this.icon = icon;
226
        }
227
210 228
        /**
211 229
         * start : 00:00
212 230
         * end : 24:00
213 231
         * service_free : 0.8
214 232
         * charge_free : 1.39
215 233
         */
216
        public int index;
234
        private int index;
235
        private Drawable icon;
217 236
        private String start;
218 237
        private String end;
219 238
        private String service_free;
@ -254,6 +273,18 @@ public class PileData implements Serializable {
254 273
        public double getTotalPrice() {
255 274
            return Double.parseDouble(getCharge_free()) + Double.parseDouble(getService_free());
256 275
        }
276
277
        public int getEndTotalMinutes() {
278
            String[] times = end.split(":");
279
            if (times.length == 2) {
280
                int hour = Integer.valueOf(times[0]);
281
                int minutes = Integer.valueOf(times[1]);
282
                return hour * 60 + minutes;
283
            } else {
284
                return 0;
285
            }
286
        }
287
257 288
        public int getStartTotalMinutes() {
258 289
            String[] times = start.split(":");
259 290
            if (times.length == 2) {

BIN
app/src/main/res/drawable-hdpi/now_icon.png


BIN
app/src/main/res/drawable-mdpi/now_icon.png


BIN
app/src/main/res/drawable-xhdpi/now_icon.png


BIN
app/src/main/res/drawable-xxhdpi/now_icon.png


BIN
app/src/main/res/drawable-xxxhdpi/now_icon.png


+ 2 - 4
app/src/main/res/layout/activity_price_details.xml

@ -46,8 +46,8 @@
46 46
    <ScrollView
47 47
        android:layout_width="match_parent"
48 48
        android:layout_height="match_parent"
49
        android:layout_below="@+id/rl_title">
50
49
        android:layout_below="@+id/rl_title"
50
        android:scrollbars="none">
51 51
        <LinearLayout
52 52
            android:layout_width="match_parent"
53 53
            android:layout_height="match_parent"
@ -57,8 +57,6 @@
57 57
                android:id="@+id/ll_details"
58 58
                android:layout_width="match_parent"
59 59
                android:layout_height="wrap_content"
60
                android:layout_marginLeft="15dp"
61
                android:layout_marginRight="15dp"
62 60
                android:orientation="vertical"
63 61
                android:paddingTop="10dp"
64 62
                android:paddingBottom="10dp"></LinearLayout>

+ 61 - 43
app/src/main/res/layout/item_details_list.xml

@ -1,74 +1,92 @@
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
3 4
    xmlns:tools="http://schemas.android.com/tools"
4 5
    android:layout_width="match_parent"
5 6
    android:layout_height="match_parent"
6 7
    android:orientation="vertical">
7 8
8
    <LinearLayout
9
    <androidx.constraintlayout.widget.ConstraintLayout
9 10
        android:layout_width="match_parent"
10
        android:layout_height="wrap_content"
11
        android:orientation="horizontal">
12
13
        <ImageView
14
            android:id="@+id/icon"
15
            android:layout_width="wrap_content"
16
            android:layout_height="wrap_content"
17
            android:layout_gravity="center_vertical"
18
            android:layout_marginLeft="15dp"
19
            android:layout_marginRight="24dp"
20
            android:src="@drawable/fast_icon" />
11
        android:layout_height="wrap_content">
21 12
22 13
        <LinearLayout
23 14
            android:layout_width="match_parent"
24 15
            android:layout_height="wrap_content"
25
            android:orientation="vertical">
16
            android:orientation="horizontal"
17
            app:layout_constraintBottom_toBottomOf="parent"
18
            app:layout_constraintTop_toTopOf="parent">
26 19
27
            <TextView
28
                android:id="@+id/time"
20
            <ImageView
21
                android:id="@+id/icon"
29 22
                android:layout_width="wrap_content"
30 23
                android:layout_height="wrap_content"
31
                android:paddingTop="15dp"
32
                android:textColor="#333333"
33
                android:textSize="15sp"
34
                tools:text="00:00-07:00" />
24
                android:layout_gravity="center_vertical"
25
                android:layout_marginLeft="15dp"
26
                android:layout_marginRight="24dp"
27
                android:src="@drawable/price_feng" />
35 28
36 29
            <LinearLayout
37
                android:layout_width="wrap_content"
30
                android:layout_width="match_parent"
38 31
                android:layout_height="wrap_content"
39
                android:orientation="horizontal"
40
                android:paddingTop="5dp">
32
                android:orientation="vertical">
41 33
42 34
                <TextView
43
                    android:id="@+id/total_price"
35
                    android:id="@+id/time"
44 36
                    android:layout_width="wrap_content"
45 37
                    android:layout_height="wrap_content"
46
                    android:textColor="#FA6400"
47
                    android:textSize="20sp"
48
                    android:textStyle="bold"
49
                    tools:text="1.1406" />
38
                    android:paddingTop="15dp"
39
                    android:textColor="#333333"
40
                    android:textSize="15sp"
41
                    tools:text="00:00-07:00" />
50 42
51
                <TextView
43
                <LinearLayout
52 44
                    android:layout_width="wrap_content"
53 45
                    android:layout_height="wrap_content"
54
                    android:paddingLeft="2dp"
55
                    android:text="元/度"
56
                    android:textColor="#FA6400"
57
                    android:textSize="12sp" />
46
                    android:orientation="horizontal"
47
                    android:paddingTop="5dp">
58 48
59
            </LinearLayout>
49
                    <TextView
50
                        android:id="@+id/total_price"
51
                        android:layout_width="wrap_content"
52
                        android:layout_height="wrap_content"
53
                        android:textColor="#FA6400"
54
                        android:textSize="20sp"
55
                        android:textStyle="bold"
56
                        tools:text="1.1406" />
60 57
61
            <TextView
62
                android:id="@+id/price"
63
                android:layout_width="wrap_content"
64
                android:layout_height="wrap_content"
65
                android:paddingTop="2dp"
66
                android:paddingBottom="15dp"
67
                android:textColor="#999999"
68
                android:textSize="12sp"
69
                tools:text="电费:0.5906元/度 服务费:0.5906元/度" />
58
                    <TextView
59
                        android:layout_width="wrap_content"
60
                        android:layout_height="wrap_content"
61
                        android:paddingLeft="2dp"
62
                        android:text="元/度"
63
                        android:textColor="#FA6400"
64
                        android:textSize="12sp" />
65
66
                </LinearLayout>
67
68
                <TextView
69
                    android:id="@+id/price"
70
                    android:layout_width="wrap_content"
71
                    android:layout_height="wrap_content"
72
                    android:paddingTop="2dp"
73
                    android:paddingBottom="15dp"
74
                    android:textColor="#999999"
75
                    android:textSize="12sp"
76
                    tools:text="电费:0.5906元/度 服务费:0.5906元/度" />
77
            </LinearLayout>
70 78
        </LinearLayout>
71
    </LinearLayout>
79
80
        <ImageView
81
            android:id="@+id/now_icon"
82
            android:layout_width="wrap_content"
83
            android:layout_height="wrap_content"
84
            android:src="@drawable/now_icon"
85
            android:visibility="gone"
86
            app:layout_constraintRight_toRightOf="parent"
87
            app:layout_constraintTop_toTopOf="parent"
88
            tools:visibility="visible" />
89
    </androidx.constraintlayout.widget.ConstraintLayout>
72 90
73 91
    <View
74 92
        android:layout_width="match_parent"