Browse Source

代码优化

huyuguo 4 years ago
parent
commit
f8edf7d85c

+ 21 - 12
app/src/main/java/com/electric/chargingpile/activity/CarOwnerCertificateListActivity.java

5
import androidx.recyclerview.widget.RecyclerView;
5
import androidx.recyclerview.widget.RecyclerView;
6
6
7
import android.content.Intent;
7
import android.content.Intent;
8
import android.graphics.Color;
8
import android.os.Bundle;
9
import android.os.Bundle;
9
import android.util.Log;
10
import android.util.Log;
10
import android.view.View;
11
import android.view.View;
25
import com.zhy.http.okhttp.callback.StringCallback;
26
import com.zhy.http.okhttp.callback.StringCallback;
26
27
27
import java.net.URLEncoder;
28
import java.net.URLEncoder;
29
import java.util.ArrayList;
28
import java.util.List;
30
import java.util.List;
29
31
30
import okhttp3.Call;
32
import okhttp3.Call;
36
    private TextView add;
38
    private TextView add;
37
    private CarOwnerCertificateListAdapter adapter;
39
    private CarOwnerCertificateListAdapter adapter;
38
    private TextView no_data;
40
    private TextView no_data;
39
41
    List<CarOwnerCertificateBean> mList = new ArrayList<>();
42
    boolean canAdd = true;
40
    private boolean firstTime;
43
    private boolean firstTime;
41
44
42
    @Override
45
    @Override
61
        add.setOnClickListener(new View.OnClickListener() {
64
        add.setOnClickListener(new View.OnClickListener() {
62
            @Override
65
            @Override
63
            public void onClick(View v) {
66
            public void onClick(View v) {
67
                if (canAdd == false)
68
                    return;
64
                startActivity(new Intent(getApplication(), CarOwnerCertificateActivity.class));
69
                startActivity(new Intent(getApplication(), CarOwnerCertificateActivity.class));
65
            }
70
            }
66
        });
71
        });
68
        no_data = findViewById(R.id.no_data);
73
        no_data = findViewById(R.id.no_data);
69
74
70
        String data = getIntent().getStringExtra("data");
75
        String data = getIntent().getStringExtra("data");
71
        List<CarOwnerCertificateBean> list = JsonUtils.parseToObjectList(data, CarOwnerCertificateBean.class);
72
        if (list.size() >= 3) {
73
            add.setVisibility(View.GONE);
76
        mList = JsonUtils.parseToObjectList(data, CarOwnerCertificateBean.class);
77
        if (mList.size() >= 3) {
78
            canAdd = false;
79
            add.setTextColor(Color.parseColor("#CCCCCC"));
74
        }
80
        }
75
        recycler_view = findViewById(R.id.recycler_view);
81
        recycler_view = findViewById(R.id.recycler_view);
76
        adapter = new CarOwnerCertificateListAdapter(this, list);
82
        adapter = new CarOwnerCertificateListAdapter(this, mList);
77
        recycler_view.setLayoutManager(new LinearLayoutManager(this));
83
        recycler_view.setLayoutManager(new LinearLayoutManager(this));
78
        recycler_view.setAdapter(adapter);
84
        recycler_view.setAdapter(adapter);
79
        adapter.setRecyclerItemTypeClickListener(new RecyclerItemTypeClickListener() {
85
        adapter.setRecyclerItemTypeClickListener(new RecyclerItemTypeClickListener() {
80
            @Override
86
            @Override
81
            public void onItemClickListener(int position, int index) { // index 1:删除操作 2:编辑操作 3:设为主车型
87
            public void onItemClickListener(int position, int index) { // index 1:删除操作 2:编辑操作 3:设为主车型
82
88
83
                CarOwnerCertificateBean bean = list.get(position);
89
                CarOwnerCertificateBean bean = mList.get(position);
84
                if (index == 1) {
90
                if (index == 1) {
85
                    deleteCarOwnerCertificate(bean.getId());
91
                    deleteCarOwnerCertificate(bean.getId());
86
                } else if (index == 2) {
92
                } else if (index == 2) {
190
            e.printStackTrace();
196
            e.printStackTrace();
191
        }
197
        }
192
198
193
        String url = MainApplication.url + "/zhannew/basic/web/index.php/car/my?userid=" + MainApplication.userId + "&token=" + token;
199
        String url = MainApplication.url + "/zhannew/basic/web/index.php/car/my?userid=" + MainApplication.userId + "&order=1" + "&token=" + token;
194
        OkHttpUtils.get().url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
200
        OkHttpUtils.get().url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
195
            @Override
201
            @Override
196
            public void onError(Call call, Exception e) {
202
            public void onError(Call call, Exception e) {
205
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
211
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
206
                if ("01".equals(rtnCode)) {
212
                if ("01".equals(rtnCode)) {
207
                    String data = JsonUtils.getKeyResult(response, "data");
213
                    String data = JsonUtils.getKeyResult(response, "data");
208
                    List<CarOwnerCertificateBean> list = JsonUtils.parseToObjectList(data, CarOwnerCertificateBean.class);
209
                    adapter.setData(list);
210
                    no_data.setVisibility(list.size() == 0 ? View.VISIBLE : View.GONE);
214
                    mList = JsonUtils.parseToObjectList(data, CarOwnerCertificateBean.class);
215
                    adapter.setData(mList);
216
                    no_data.setVisibility(mList.size() == 0 ? View.VISIBLE : View.GONE);
211
217
212
                    if (list.size() >= 3) {
213
                        add.setVisibility(View.GONE);
218
                    if (mList.size() >= 3) {
219
                        canAdd = false;
220
                        add.setTextColor(Color.parseColor("#CCCCCC"));
214
                    } else {
221
                    } else {
222
                        canAdd = true;
215
                        add.setVisibility(View.VISIBLE);
223
                        add.setVisibility(View.VISIBLE);
224
                        add.setTextColor(Color.parseColor("#030303"));
216
                    }
225
                    }
217
                } else {
226
                } else {
218
                    String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
227
                    String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");

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

1073
            e.printStackTrace();
1073
            e.printStackTrace();
1074
        }
1074
        }
1075
1075
1076
        String url = MainApplication.url + "/zhannew/basic/web/index.php/car/my?userid=" + MainApplication.userId + "&token=" + token;
1076
        String url = MainApplication.url + "/zhannew/basic/web/index.php/car/my?userid=" + MainApplication.userId + "&order=1" + "&token=" + token;
1077
        OkHttpUtils.get().url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
1077
        OkHttpUtils.get().url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
1078
            @Override
1078
            @Override
1079
            public void onError(Call call, Exception e) {
1079
            public void onError(Call call, Exception e) {

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

1068
            e.printStackTrace();
1068
            e.printStackTrace();
1069
        }
1069
        }
1070
1070
1071
        String url = MainApplication.url + "/zhannew/basic/web/index.php/car/my?userid=" + MainApplication.userId + "&token=" + token;
1071
        String url = MainApplication.url + "/zhannew/basic/web/index.php/car/my?userid=" + MainApplication.userId + "&order=1" + "&token=" + token;
1072
        OkHttpUtils.get().url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
1072
        OkHttpUtils.get().url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
1073
            @Override
1073
            @Override
1074
            public void onError(Call call, Exception e) {
1074
            public void onError(Call call, Exception e) {

+ 1 - 0
app/src/main/java/com/electric/chargingpile/application/MainApplication.java

156
        JPushInterface.setDebugMode(true);
156
        JPushInterface.setDebugMode(true);
157
        JPushInterface.init(this);
157
        JPushInterface.init(this);
158

158

159

159
        String rid = JPushInterface.getRegistrationID(getApplicationContext());
160
        String rid = JPushInterface.getRegistrationID(getApplicationContext());
160
        push_id = rid;
161
        push_id = rid;
161
        Intent intent = new Intent();
162
        Intent intent = new Intent();