Parcourir la Source

完成排行榜功能

hy 3 ans auparavant
Parent
commit
bdd557e9bf

+ 3 - 1
app/src/main/java/com/electric/chargingpile/activity/RankingListActivity.java

@ -16,7 +16,9 @@ import com.electric.chargingpile.data.RankinglistRefreshEvent;
16 16
import com.electric.chargingpile.fragment.MonthListFragment;
17 17
import com.electric.chargingpile.fragment.TotalListFragment;
18 18
import com.electric.chargingpile.util.BarColorUtil;
19
19
/**
20
 * 总榜
21
 * */
20 22
public class RankingListActivity extends FragmentActivity implements View.OnClickListener {
21 23
    private ViewPager viewPager;
22 24
    private RelativeLayout rl_monthList, rl_totalList;

+ 21 - 6
app/src/main/java/com/electric/chargingpile/adapter/QuarterAdapter.java

@ -15,6 +15,8 @@ import com.electric.chargingpile.R;
15 15
import org.jetbrains.annotations.NotNull;
16 16
17 17
import java.util.ArrayList;
18
import java.util.Calendar;
19
import java.util.Date;
18 20
19 21
public class QuarterAdapter extends RecyclerView.Adapter<QuarterAdapter.ViewHolder> {
20 22
    private Context mContext=null;
@ -26,10 +28,23 @@ public class QuarterAdapter extends RecyclerView.Adapter<QuarterAdapter.ViewHold
26 28
27 29
    public QuarterAdapter(Context mContext) {
28 30
        this.mContext = mContext;
29
        mDatas.add("一季度");
30
        mDatas.add("二季度");
31
        mDatas.add("三季度");
32
        mDatas.add("季度");
31
        Calendar cal =Calendar.getInstance();
32
        int month = cal.get(Calendar.MONTH) + 1;
33
        if (month>=1 && month <=3){
34
            mDatas.add("季度");
35
            mDatas.add("二季度");
36
            mDatas.add("三季度");
37
            mDatas.add("四季度");
38
        }else if (month>= 4 && month <=6){
39
            mDatas.add("一季度");
40
        }else if (month>= 7 && month <=9){
41
            mDatas.add("一季度");
42
            mDatas.add("二季度");
43
        }else if (month>=10 && month <=12){
44
            mDatas.add("一季度");
45
            mDatas.add("二季度");
46
            mDatas.add("三季度");
47
        }
33 48
    }
34 49
35 50
    public ItemOnClick getItemOnClick() {
@ -59,7 +74,7 @@ public class QuarterAdapter extends RecyclerView.Adapter<QuarterAdapter.ViewHold
59 74
        holder.mTextView.setOnClickListener(v->{
60 75
            if (mItemOnClick!=null){
61 76
                mSelectPostion=position;
62
                mItemOnClick.onClick(position);
77
                mItemOnClick.onClick(position,mDatas.get(position));
63 78
                notifyDataSetChanged();
64 79
            }
65 80
        });
@ -81,6 +96,6 @@ public class QuarterAdapter extends RecyclerView.Adapter<QuarterAdapter.ViewHold
81 96
    }
82 97
83 98
    public interface ItemOnClick{
84
        void onClick(int posistion);
99
        void onClick(int posistion,String name);
85 100
    }
86 101
}

+ 16 - 9
app/src/main/java/com/electric/chargingpile/fragment/MonthListFragment.java

@ -4,6 +4,8 @@ import android.app.Activity;
4 4
import android.content.Intent;
5 5
import android.os.Bundle;
6 6
import androidx.fragment.app.Fragment;
7
8
import android.util.Log;
7 9
import android.view.LayoutInflater;
8 10
import android.view.View;
9 11
import android.view.ViewGroup;
@ -39,7 +41,9 @@ import java.net.URLEncoder;
39 41
import java.util.ArrayList;
40 42
41 43
import okhttp3.Call;
42
44
/**
45
 * 月榜
46
 * */
43 47
public class MonthListFragment extends Fragment {
44 48
    private TextView tv_month_name, tv_month_ranking, tv_month_charge, tv_notice, tv_ranking_zanwu;
45 49
    private CircleImageView iv_icon;
@ -94,7 +98,7 @@ public class MonthListFragment extends Fragment {
94 98
        }
95 99
96 100
//        Log.e("111",MainApplication.url+"/zhannew/basic/web/index.php/ranking/index?user_id="+MainApplication.userId+"&token="+URLEncoder.encode(token));
97
        OkHttpUtils.get().url(MainApplication.url + "/zhannew/basic/web/index.php/ranking/index")
101
        OkHttpUtils.get().url(MainApplication.url + "/zhannew/basic/web/index.php/ranking/month")
98 102
                .addParams("user_id", MainApplication.userId)
99 103
                .addParams("token", URLEncoder.encode(token))
100 104
                .addParams("phone", MainApplication.userPhone)
@ -118,12 +122,15 @@ public class MonthListFragment extends Fragment {
118 122
                        if (code.equals("200")) {
119 123
                            //当月该用户充电数据
120 124
                            String data = JsonUtils.getKeyResult(response, "data");
121
                            String current_total = JsonUtils.getKeyResult(data, "current_total");
122
                            String power = JsonUtils.getKeyResult(current_total, "power");
123
                            String nickname = JsonUtils.getKeyResult(current_total, "nickname");
124
                            String tel = JsonUtils.getKeyResult(current_total, "tel");
125
                            String sort = JsonUtils.getKeyResult(current_total, "sort");
126
                            String userpic = JsonUtils.getKeyResult(current_total, "userpic");
125
                            String own = JsonUtils.getKeyResult(response, "own");
126
127
                            String user_id = JsonUtils.getKeyResult(own, "user_id");
128
                            String power = JsonUtils.getKeyResult(own, "power");
129
                            String nickname = JsonUtils.getKeyResult(own, "nickname");
130
                            String tel = JsonUtils.getKeyResult(own, "tel");
131
                            String sort = JsonUtils.getKeyResult(own, "sort");
132
                            String userpic = JsonUtils.getKeyResult(own, "userpic");
133
127 134
                            if (power.equals("") && nickname.equals("") && tel.equals("") && sort.equals("") && userpic.equals("")) {
128 135
                                tv_no_login.setVisibility(View.VISIBLE);
129 136
                                tv_login.setVisibility(View.VISIBLE);
@ -176,7 +183,7 @@ public class MonthListFragment extends Fragment {
176 183
                            JSONArray jsonArray = null;
177 184
                            try {
178 185
                                jsonObjj = new JSONObject(data);
179
                                jsonArray = jsonObjj.getJSONArray("current_data");
186
                                jsonArray = jsonObjj.getJSONArray("month");
180 187
                            } catch (JSONException e) {
181 188
                                e.printStackTrace();
182 189
                            }

+ 73 - 62
app/src/main/java/com/electric/chargingpile/fragment/TotalListFragment.java

@ -22,6 +22,7 @@ import android.widget.RelativeLayout;
22 22
import android.widget.TextView;
23 23
import android.widget.Toast;
24 24
25
import com.alibaba.fastjson.JSON;
25 26
import com.blankj.utilcode.util.SizeUtils;
26 27
import com.blankj.utilcode.util.Utils;
27 28
import com.electric.chargingpile.R;
@ -60,6 +61,7 @@ public class TotalListFragment extends Fragment implements View.OnClickListener
60 61
    private RelativeLayout rl_totalList;
61 62
    private LinearLayout layoutQuarter;
62 63
    private PopupWindow mPopupWindow;
64
    private String mQuarter="1";
63 65
64 66
    @Override
65 67
    public void onCreate(Bundle savedInstanceState) {
@ -104,10 +106,11 @@ public class TotalListFragment extends Fragment implements View.OnClickListener
104 106
        } catch (Exception e) {
105 107
            e.printStackTrace();
106 108
        }
107
        OkHttpUtils.get().url(MainApplication.url + "/zhannew/basic/web/index.php/ranking/index")
109
        OkHttpUtils.get().url(MainApplication.url + "/zhannew/basic/web/index.php/ranking/quarter")
108 110
                .addParams("user_id", MainApplication.userId)
109 111
                .addParams("token", URLEncoder.encode(token))
110 112
                .addParams("phone", MainApplication.userPhone)
113
                .addParams("quarter", mQuarter)
111 114
                .addParams("password", URLEncoder.encode(MainApplication.userPassword))
112 115
                .build()
113 116
                .execute(new StringCallback() {
@ -118,74 +121,82 @@ public class TotalListFragment extends Fragment implements View.OnClickListener
118 121
119 122
                    @Override
120 123
                    public void onResponse(String response) {
121
//                        Log.e("response==",response);
124
//                        Log.e("response==",response);,
122 125
                        String code = JsonUtils.getKeyResult(response, "code");
126
123 127
                        if (code.equals("200")) {
124 128
                            //总计该用户充电数据
125 129
                            String data = JsonUtils.getKeyResult(response, "data");
126
                            String current_total = JsonUtils.getKeyResult(data, "user_total");
127
                            String power = JsonUtils.getKeyResult(current_total, "power");
128
                            String nickname = JsonUtils.getKeyResult(current_total, "nickname");
129
                            String tel = JsonUtils.getKeyResult(current_total, "tel");
130
                            String sort = JsonUtils.getKeyResult(current_total, "sort");
131
                            String userpic = JsonUtils.getKeyResult(current_total, "userpic");
132
                            if (power.equals("") && nickname.equals("") && tel.equals("") && sort.equals("") && userpic.equals("")) {
133
                                tv_no_login.setVisibility(View.VISIBLE);
134
                                tv_login.setVisibility(View.VISIBLE);
135
                                rl_totalList.setOnClickListener(new View.OnClickListener() {
136
                                    @Override
137
                                    public void onClick(View v) {
138
                                        if (!MainApplication.isLogin()) {
139
                                            startActivity(new Intent(getContext(), LoginActivity.class));
140
                                        }
141
142
                                    }
143
                                });
144
                                ll_ranking.setVisibility(View.GONE);
145
                                tv_total_charge.setVisibility(View.GONE);
146
                                tv_total_name.setVisibility(View.GONE);
147
                                tv_ranking_zanwu.setVisibility(View.GONE);
148
                            } else {
149
                                tv_no_login.setVisibility(View.GONE);
150
                                tv_login.setVisibility(View.GONE);
151
                                ll_ranking.setVisibility(View.VISIBLE);
152
                                tv_total_charge.setVisibility(View.VISIBLE);
153
                                tv_total_name.setVisibility(View.VISIBLE);
154
                                tv_ranking_zanwu.setVisibility(View.VISIBLE);
155
                                if (nickname.equals("")) {
156
                                    tv_total_name.setText(Util.handlePhoneComment(tel));
157
                                } else {
158
                                    tv_total_name.setText(nickname);
159
                                }
160
                                if (sort.equals("0")) {
161
                                    tv_ranking_zanwu.setVisibility(View.VISIBLE);
162
                                    ll_ranking.setVisibility(View.GONE);
163
164
                                } else {
165
                                    tv_ranking_zanwu.setVisibility(View.GONE);
166
                                    ll_ranking.setVisibility(View.VISIBLE);
167
                                    tv_total_ranking.setText(sort);
168
                                }
169
                                tv_total_charge.setText(power + "度");
170
//                                PicassoUtil.loadingNetImage(getActivity(), "http://cdz.d1ev.com/zhannew/uploadfile/" + userpic
171
//                                        , iv_icon);
172
                                Picasso.with(MainApplication.context)
173
                                        .load(MainApplication.pic_url + userpic)
174
                                        .error(R.drawable.icon_user1118)
175
                                        .placeholder(R.drawable.icon_user1118)
176
                                        .into(iv_icon);
177
                            }
130
//                            String current_total = JsonUtils.getKeyResult(data, "user_total");
131
//                            String power = JsonUtils.getKeyResult(current_total, "power");
132
//                            String nickname = JsonUtils.getKeyResult(current_total, "nickname");
133
//                            String tel = JsonUtils.getKeyResult(current_total, "tel");
134
//                            String sort = JsonUtils.getKeyResult(current_total, "sort");
135
//                            String userpic = JsonUtils.getKeyResult(current_total, "userpic");
136
//                            if (power.equals("") && nickname.equals("") && tel.equals("") && sort.equals("") && userpic.equals("")) {
137
//                                tv_no_login.setVisibility(View.VISIBLE);
138
//                                tv_login.setVisibility(View.VISIBLE);
139
//                                rl_totalList.setOnClickListener(new View.OnClickListener() {
140
//                                    @Override
141
//                                    public void onClick(View v) {
142
//                                        if (!MainApplication.isLogin()) {
143
//                                            startActivity(new Intent(getContext(), LoginActivity.class));
144
//                                        }
145
//
146
//                                    }
147
//                                });
148
//                                ll_ranking.setVisibility(View.GONE);
149
//                                tv_total_charge.setVisibility(View.GONE);
150
//                                tv_total_name.setVisibility(View.GONE);
151
//                                tv_ranking_zanwu.setVisibility(View.GONE);
152
//                            } else {
153
//                                tv_no_login.setVisibility(View.GONE);
154
//                                tv_login.setVisibility(View.GONE);
155
//                                ll_ranking.setVisibility(View.VISIBLE);
156
//                                tv_total_charge.setVisibility(View.VISIBLE);
157
//                                tv_total_name.setVisibility(View.VISIBLE);
158
//                                tv_ranking_zanwu.setVisibility(View.VISIBLE);
159
//                                if (nickname.equals("")) {
160
//                                    tv_total_name.setText(Util.handlePhoneComment(tel));
161
//                                } else {
162
//                                    tv_total_name.setText(nickname);
163
//                                }
164
//                                if (sort.equals("0")) {
165
//                                    tv_ranking_zanwu.setVisibility(View.VISIBLE);
166
//                                    ll_ranking.setVisibility(View.GONE);
167
//
168
//                                } else {
169
//                                    tv_ranking_zanwu.setVisibility(View.GONE);
170
//                                    ll_ranking.setVisibility(View.VISIBLE);
171
//                                    tv_total_ranking.setText(sort);
172
//                                }
173
//                                tv_total_charge.setText(power + "度");
174
////                                PicassoUtil.loadingNetImage(getActivity(), "http://cdz.d1ev.com/zhannew/uploadfile/" + userpic
175
////                                        , iv_icon);
176
//                                Picasso.with(MainApplication.context)
177
//                                        .load(MainApplication.pic_url + userpic)
178
//                                        .error(R.drawable.icon_user1118)
179
//                                        .placeholder(R.drawable.icon_user1118)
180
//                                        .into(iv_icon);
181
//                            }
178 182
                            //当月充电排行
183
//                            ArrayList<JSONObject> datas = new ArrayList<JSONObject>();
184
//                            JSONObject jsonObjj = null;
185
//                            JSONArray jsonArray = null;
186
//                            try {
187
//                                jsonObjj = new JSONObject(data);
188
//                                jsonArray = jsonObjj.getJSONArray("total_data");
189
//                            } catch (JSONException e) {
190
//                                e.printStackTrace();
191
//                            }
192
//                            datas.clear();
179 193
                            ArrayList<JSONObject> datas = new ArrayList<JSONObject>();
180
                            JSONObject jsonObjj = null;
181
                            JSONArray jsonArray = null;
194
                            JSONArray jsonArray= null;
182 195
                            try {
183
                                jsonObjj = new JSONObject(data);
184
                                jsonArray = jsonObjj.getJSONArray("total_data");
196
                                jsonArray = new JSONArray(data);
185 197
                            } catch (JSONException e) {
186 198
                                e.printStackTrace();
187 199
                            }
188
                            datas.clear();
189 200
                            for (int j = 0; j < jsonArray.length(); j++) {
190 201
                                JSONObject jsonObject4 = (JSONObject) jsonArray
191 202
                                        .opt(j);
@ -236,9 +247,9 @@ public class TotalListFragment extends Fragment implements View.OnClickListener
236 247
        RecyclerView recyclerView = rootView.findViewById(R.id.recyclerView);
237 248
        recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
238 249
        QuarterAdapter adapter = new QuarterAdapter(requireContext());
239
        adapter.setItemOnClick(posistion -> {
240
            //TODO
241
            Toast.makeText(requireContext(), ""+posistion, Toast.LENGTH_SHORT).show();
250
        adapter.setItemOnClick((posistion,name) -> {
251
            mQuarter=String.valueOf(posistion+1);
252
            getData(null);
242 253
            mPopupWindow.dismiss();
243 254
        });
244 255

+ 32 - 21
app/src/main/res/layout/fragment_total_list.xml

@ -9,32 +9,43 @@
9 9
10 10
11 11
    <LinearLayout
12
        android:id="@+id/layoutQuarter"
13
        android:layout_marginBottom="15dp"
14
        android:layout_marginStart="12dp"
15
        android:layout_marginEnd="12dp"
16
        android:layout_marginTop="15dp"
17
        android:layout_width="wrap_content"
12
        android:background="@color/white"
13
        android:layout_width="match_parent"
18 14
        android:layout_height="wrap_content">
19
        <TextView
20
            android:layout_width="wrap_content"
21
            android:layout_height="wrap_content"
22
            android:text="当年季度筛选"
23
            android:textColor="@color/color_green_style1"
24
            android:textSize="14sp"
25
            />
26
        <TextView
27
            android:layout_gravity="center_vertical"
28
            android:layout_marginStart="4dp"
15
        <LinearLayout
16
            android:id="@+id/layoutQuarter"
17
            android:layout_marginBottom="15dp"
18
            android:layout_marginStart="12dp"
19
            android:layout_marginEnd="12dp"
20
            android:layout_marginTop="15dp"
29 21
            android:layout_width="wrap_content"
30
            android:layout_height="wrap_content"
31
            android:text="▼"
32
            android:textColor="@color/color_green_style1"
33
            android:textSize="8dp"
34
            />
22
            android:layout_height="wrap_content">
23
            <TextView
24
                android:id="@+id/selectQuarter"
25
                android:layout_width="wrap_content"
26
                android:layout_height="wrap_content"
27
                android:text="当年季度筛选"
28
                android:textColor="@color/color_green_style1"
29
                android:textSize="14sp"
30
                />
31
            <TextView
32
                android:layout_gravity="center_vertical"
33
                android:layout_marginStart="4dp"
34
                android:layout_width="wrap_content"
35
                android:layout_height="wrap_content"
36
                android:text="▼"
37
                android:textColor="@color/color_green_style1"
38
                android:textSize="8dp"
39
                />
40
35 41
42
        </LinearLayout>
36 43
37 44
    </LinearLayout>
45
    <View
46
        android:layout_width="match_parent"
47
        android:layout_height="0.5dp"
48
        android:background="@color/ui_line"/>
38 49
39 50
    <RelativeLayout
40 51
        android:id="@+id/rl_totalList"