Browse Source

我的收藏修改

huyuguo 4 years ago
parent
commit
9b113d9fa2

+ 89 - 378
app/src/main/java/com/electric/chargingpile/activity/MyCollectActivity.java

1
package com.electric.chargingpile.activity;
1
package com.electric.chargingpile.activity;
2

2

3
import android.annotation.TargetApi;
4
import android.app.Activity;
3
import android.app.Activity;
5
import android.content.Context;
6
import android.content.Intent;
4
import android.content.Intent;
7
import android.database.Cursor;
5
import android.database.Cursor;
8
import android.os.Build;
6
import android.database.sqlite.SQLiteDatabase;
9
import android.os.Bundle;
7
import android.os.Bundle;
10
import android.os.Handler;
11
import android.os.Message;
12
import android.util.Log;
13
import android.view.Gravity;
14
import android.view.View;
8
import android.view.View;
15
import android.view.ViewGroup;
16
import android.widget.AdapterView;
9
import android.widget.AdapterView;
17
import android.widget.ImageView;
10
import android.widget.ImageView;
18
import android.widget.LinearLayout;
11
import android.widget.LinearLayout;
19
import android.widget.ListView;
20
import android.widget.SimpleCursorAdapter;
21
import android.widget.Toast;
12
import android.widget.Toast;
22

13

14
import androidx.recyclerview.widget.LinearLayoutManager;
15
import androidx.recyclerview.widget.RecyclerView;
16

23
import com.electric.chargingpile.R;
17
import com.electric.chargingpile.R;
24
import com.electric.chargingpile.adapter.CollectAdapter;
18
import com.electric.chargingpile.adapter.MyCollectAdapter;
25
import com.electric.chargingpile.application.MainApplication;
19
import com.electric.chargingpile.application.MainApplication;
26
import com.electric.chargingpile.data.CollectData;
20
import com.electric.chargingpile.data.CollectData;
27
import com.electric.chargingpile.data.Zhan;
28
import com.electric.chargingpile.util.BarColorUtil;
21
import com.electric.chargingpile.util.BarColorUtil;
29
import com.electric.chargingpile.util.DES3;
30
import com.electric.chargingpile.util.DatabaseHandler;
22
import com.electric.chargingpile.util.DatabaseHandler;
31
import com.electric.chargingpile.util.OkHttpUtil;
32
import com.electric.chargingpile.util.SharedPreferencesHelper;
23
import com.electric.chargingpile.util.SharedPreferencesHelper;
33
import com.electric.chargingpile.view.AlertDialog;
24
import com.electric.chargingpile.view.AlertDialog;
34
import com.electric.chargingpile.view.CustomProgressDialog;
35
import com.google.gson.Gson;
36
import com.google.gson.reflect.TypeToken;
37
import com.squareup.okhttp.Request;
38
import com.squareup.okhttp.Response;
39
import com.umeng.analytics.MobclickAgent;
25
import com.umeng.analytics.MobclickAgent;
40

26

41
import org.json.JSONObject;
42

43
import java.util.ArrayList;
27
import java.util.ArrayList;
28
import java.util.HashMap;
44
import java.util.List;
29
import java.util.List;
30
import java.util.Map;
45

31

46
public class MyCollectActivity extends Activity implements
47
        View.OnClickListener, AdapterView.OnItemLongClickListener,
48
        AdapterView.OnItemClickListener {
32
public class MyCollectActivity extends Activity implements View.OnClickListener {
49

33

50
    private ImageView back;
34
    private ImageView back;
51
    private ListView collectListView;
52
    private MainApplication mapp;
53
    private List<Zhan> list = new ArrayList<Zhan>();
35
    private RecyclerView collectListView;
54
    private CollectData collectData;
36
    private CollectData collectData;
55
    private List<CollectData> mCollect = new ArrayList<CollectData>();
56
    private CollectAdapter adapter;
57
    private ImageView tv_share;
37
    private ImageView tv_share;
58
    private LinearLayout ll_collect;
38
    private LinearLayout ll_collect;
59
    private CustomProgressDialog pd_info;
60
    private Context mContext;
61
    int currPos;
39
    int currPos;
62
    SharedPreferencesHelper sharedPreferencesHelper;
40
    SharedPreferencesHelper sharedPreferencesHelper;
63

64
    private Handler handler = new Handler() {
65
        // 主线程通过这个方法处理消息
66
        @Override
67
        public void handleMessage(Message msg) {
68
            switch (msg.what) {
69

70
                case 3:
71
//                    Toast.makeText(getActivity(), "服务器处理错误", Toast.LENGTH_SHORT).show();
72
                    break;
73

74
                case 5:
75
                    dismissDialog();
76
                    try {
77
                        JSONObject jsonObj = new JSONObject(msg.obj.toString());
78
                        String data = jsonObj.getString("data");
79
                        String time = jsonObj.getString("time");
80
//                    String pic = jsonObj.getString("pic");
81
                        Log.i("data-----", data);
82
//                    Log.i("pic------",pic);
83
                        String zhan_data = DES3.decode(data);
84
                        Log.i("zhan_data-----", zhan_data);
85

86
//                    Log.d("appTime---", DateUtils.getCurrentDate());
87

88

89
                        try {
90
                            Gson g = new Gson();
91
                            List<Zhan> l = g.fromJson(zhan_data, new TypeToken<List<Zhan>>() {
92
                            }.getType());
93

94

95
                            mapp.collectList.clear();
96
//                            mBaiduMap.clear();
97
                            if (l != null && l.size() > 0) {
98
//                        List<Zhan> ll = DES3.encode(l);
99
                                mapp.collectList.addAll(l);
100
//                                if (list.get(i).getSupplier().equals("特来电"))
101
//                                initOverlay(list);
102

103

104
                            }
105
//                                if (list.get(i).getSupplier().equals("特来电")){
106
//                                    zhanOne=list.get(i);
107
//                                    getDetailThread(list.get(i).getTid());
108
//                                    Log.e("Tid",list.get(i).getTid());
109
//                                }
110
//                                initOverlay(list);
111

112
                            Log.d("dddddd", mapp.collectList.size() + "");
113
//							getData();
114

115

116
                        } catch (Exception e) {
117
                            e.printStackTrace();
118
                        }
119

120
                    } catch (Exception e) {
121
                        e.printStackTrace();
122
                    }
123

124
                    break;
125

126

127
                default:
128
                    break;
129
            }
130
        }
131
    };
41
    private ImageView no_data;
42
    private List<CollectData> mCollectDataList = new ArrayList<CollectData>();
43
    private MyCollectAdapter myCollectAdapter;
132

44

133
    @Override
45
    @Override
134
    protected void onCreate(Bundle savedInstanceState) {
46
    protected void onCreate(Bundle savedInstanceState) {
135
        super.onCreate(savedInstanceState);
47
        super.onCreate(savedInstanceState);
136
        setContentView(R.layout.activity_my_collect);
48
        setContentView(R.layout.activity_my_collect);
137
        BarColorUtil.initStatusBarColor(MyCollectActivity.this);
49
        BarColorUtil.initStatusBarColor(MyCollectActivity.this);
138
//		Log.d("eeeeee", list.size() + "");
139
        mContext = this;
140

141
        collectListView = ((ListView) findViewById(R.id.collect_listView));
142
        ll_collect = (LinearLayout) findViewById(R.id.ll_collect);
143

144
        MainMap();
145
//		getData();
146

147
        initView();
50
        initView();
148
//		collectListView.setAdapter(adapter);
149

150

151
    }
51
    }
152

52

153

154
    // 利用SharedPreferences中收藏的数据和获取到的所有数据进行匹配,得到数据源
155
    // 添加顺序
156
    private void getData() {
157
        mapp = (MainApplication) getApplication();
158
        Log.d("aaaaa", mapp.collectList.size() + "");
159
        for (int i = 0; i < mapp.collectList.size(); i++) {
160
            String name = mapp.collectList.get(i).getZhan_name();
161
            if (mapp.sph.getInt(name) != -1) {
162
                list.add(mapp.collectList.get(i));
163
            }
164
        }
165
        Log.d("!!!!!", list.size() + "");
166

167
        initView();
168

169
        if (list.size() == 0) {
170

171

172
            ImageView emptyView = new ImageView(MyCollectActivity.this);
173
            emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
174
            emptyView.setImageResource(R.drawable.bg_collection2_0);
175
            ll_collect.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
176
            emptyView.setVisibility(View.GONE);
177
            ((ViewGroup) collectListView.getParent()).addView(emptyView);
178
            collectListView.setEmptyView(emptyView);
179
        }
180
    }
181

182
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
183
    private void initView() {
53
    private void initView() {
184
//		adapter = new CollectAdapter(list, this);
185
        collectListView = ((ListView) findViewById(R.id.collect_listView));
186
        back = (ImageView) findViewById(R.id.iv_back);
187
        collectListView.setOnItemClickListener(this);
188
        collectListView.setOnItemLongClickListener(this);
54
        ll_collect = (LinearLayout) findViewById(R.id.ll_collect);
189
        tv_share = (ImageView) findViewById(R.id.tv_share);
55
        tv_share = (ImageView) findViewById(R.id.tv_share);
190
        tv_share.setOnClickListener(this);
56
        tv_share.setOnClickListener(this);
191

57
        back = (ImageView) findViewById(R.id.iv_back);
192
        back.setOnClickListener(this);
58
        back.setOnClickListener(this);
59
        no_data = findViewById(R.id.no_data);
60
        collectListView = findViewById(R.id.collect_listView);
61
        List<CollectData> list = getCollectList();
62
        myCollectAdapter = new MyCollectAdapter(this, list);
63
        collectListView.setLayoutManager(new LinearLayoutManager(this));
64
        collectListView.setAdapter(myCollectAdapter);
65

66
        myCollectAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
67
            @Override
68
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
69
                onCollectItemClick(position);
70
            }
71
        });
193

72

194

195
//		collectListView.setAdapter(adapter);
196
//
197

198
    }
199

200
    public void createDialog() {
201
        if (pd_info == null) {
202
            pd_info = CustomProgressDialog.createDialog(mContext);
203
            pd_info.setMessage("收藏信息加载中");
204
            pd_info.show();
205
        }
206
    }
207

208
    public void dismissDialog() {
209
        if (pd_info != null) {
210
            pd_info.dismiss();
211
            pd_info = null;
212
        }
73
        myCollectAdapter.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
74
            @Override
75
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
76
                onCollectItemLongClick(position);
77
                return true;
78
            }
79
        });
213
    }
80
    }
214

81

215
    @Override
82
    @Override
224
        }
91
        }
225
    }
92
    }
226

93

227
    public void MainMap() {
94
    public List<CollectData> getCollectList() {
95
        mCollectDataList.clear();
228
        DatabaseHandler db = new DatabaseHandler(MyCollectActivity.this, "");
96
        DatabaseHandler db = new DatabaseHandler(MyCollectActivity.this, "");
229
        Cursor c = db.query();
97
        Cursor c = db.query();
230
        System.err.println(c.getCount());
231
        if (c.getCount() <= 0) {
98
        if (c.getCount() <= 0) {
232
//			Toast.makeText(this,"没有",Toast.LENGTH_SHORT).show();
233
            ImageView emptyView = new ImageView(MyCollectActivity.this);
234
            emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
235
            emptyView.setImageResource(R.drawable.bg_collection2_0);
236
            ll_collect.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
237
            emptyView.setVisibility(View.GONE);
238
            ((ViewGroup) collectListView.getParent()).addView(emptyView);
239
            collectListView.setEmptyView(emptyView);
240
            return;
99
            no_data.setVisibility(View.VISIBLE);
100
            return mCollectDataList;
101
        } else {
102
            no_data.setVisibility(View.GONE);
241
        }
103
        }
242
        String[] from = {"zhan_name", "zhan_address", "fast_num", "slow_num"};
243
        int[] to = {R.id.item_collect_title, R.id.collect_item_address, R.id.item_collect_descriptionOR, R.id.item_collect_descriptionTR};
244
        mCollect.clear();
104

105
        List<CollectData> tmpList = new ArrayList<CollectData>();
245
        while (c.moveToNext()) {
106
        while (c.moveToNext()) {
246
            collectData = new CollectData();
107
            collectData = new CollectData();
247
            collectData.setZhan_id(c.getString(c
248
                    .getColumnIndex("zhan_id")));
249
            collectData.setZhan_name(c.getString(c
250
                    .getColumnIndex("zhan_name")));
251
            collectData.setZhan_address(c.getString(c
252
                    .getColumnIndex("zhan_address")));
253
            collectData.setFast_num(c.getString(c
254
                    .getColumnIndex("fast_num")));
255
            collectData.setSlow_num(c.getString(c
256
                    .getColumnIndex("slow_num")));
257
            mCollect.add(collectData);
108
            collectData.setZhan_id(c.getString(c.getColumnIndex("zhan_id")));
109
            collectData.setZhan_name(c.getString(c.getColumnIndex("zhan_name")));
110
            collectData.setZhan_address(c.getString(c.getColumnIndex("zhan_address")));
111
            collectData.setFast_num(c.getString(c.getColumnIndex("fast_num")));
112
            collectData.setSlow_num(c.getString(c.getColumnIndex("slow_num")));
113
            tmpList.add(collectData);
258
        }
114
        }
259
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(MyCollectActivity.this, R.layout.item_collect, c, from, to);
260
        collectListView.setAdapter(adapter);
261

262

115

263
    }
116
        String inStr = "(";
117
        for (CollectData data : tmpList) {
118
            inStr += data.getZhan_id() + ",";
119
        }
120
        inStr = inStr.substring(0, inStr.length() - 1);
121
        inStr += ")";
264

122

265
    private void submitShowAll(String sms) {
123
        Map<String, String> map = new HashMap<String, String>();
266

124

267
        Log.e("url", sms);
268
        Request request = new Request.Builder().url(sms).build();
269
        Response response = null;
125
        String sql = "select id,status from zhan_list where status = 4 and id in " + inStr;
126
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
270
        try {
127
        try {
271
            if (request == null) {
272
                Message msg = new Message();
273
                msg.what = 3;
274
                handler.sendMessage(msg);
275
                return;
276
            }
277
            response = OkHttpUtil.execute(request);
278
            if (response.code() == 200) {
279
                String json = "";
280
                try {
281
                    json = response.body().string();
282
                    Message msg = new Message();
283
                    msg.obj = json;
284
                    msg.what = 5;
285
                    handler.sendMessage(msg);
286
                    Log.e("url", json);
287
                } catch (Exception e) {
288
                    e.printStackTrace();
289
                    Message msg = new Message();
290
                    msg.what = 3;
291
                    handler.sendMessage(msg);
292
                }
128
            SQLiteDatabase sqLiteDatabase = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
129
            Cursor cursor = sqLiteDatabase.rawQuery(sql, null);
130
            while (cursor.moveToNext()) {
131
                String id = cursor.getString(cursor.getColumnIndex("id"));
132
                String status = cursor.getString(cursor.getColumnIndex("status"));
133
                map.put(id, status);
293
            }
134
            }
135
            cursor.close();
136
            db.close();
294
        } catch (Exception e) {
137
        } catch (Exception e) {
295
            e.printStackTrace();
138
            e.printStackTrace();
296
            Message msg = new Message();
297
            msg.what = 3;
298
            handler.sendMessage(msg);
299
        }
139
        }
140

141
        for (CollectData d : tmpList) {
142
            if (map.get(d.getZhan_id()) != null) {
143
                mCollectDataList.add(d);
144
            }
145
        }
146
        return mCollectDataList;
300
    }
147
    }
301

148

302
    @Override
303
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
149
    public void onCollectItemClick(int currPos) {
150
        this.currPos = currPos;
304
        Intent intent = new Intent(this, NewZhanDetailsActivity.class);
151
        Intent intent = new Intent(this, NewZhanDetailsActivity.class);
305
        currPos = i;
306
        intent.putExtra("zhan_id", mCollect.get(i).getZhan_id());
152
        intent.putExtra("zhan_id", mCollectDataList.get(currPos).getZhan_id());
307
        startActivityForResult(intent, 3);
153
        startActivityForResult(intent, 3);
308
        MainApplication.details_flag = "2";
154
        MainApplication.details_flag = "2";
309
    }
155
    }
310

156

311
    @Override
312
    public boolean onItemLongClick(AdapterView<?> adapterView, View view,
313
                                   final int i, long l) {
314
//
315
//		String[] str = new String[] { "删除记录", "取消" };
316
//		Builder dialog = new Builder(MyCollectActivity.this)
317
//				.setTitle("请选择").setItems(str,
318
//						new DialogInterface.OnClickListener() {
319
//							public void onClick(DialogInterface dialog,
320
//									int which) {
321
//								switch (which) {
322
//								case 0:
323
//									SharedPreferencesHelper sharedPreferencesHelper = new SharedPreferencesHelper(
324
//											MyCollectActivity.this);
325
//									sharedPreferencesHelper.removeData(list
326
//											.get(i).getZhan_name());
327
//									list.remove(i);
328
//									Toast.makeText(MyCollectActivity.this,
329
//											"该站信息已删除", Toast.LENGTH_SHORT)
330
//											.show();
331
//									adapter.notifyDataSetChanged();
332
//									break;
333
//								case 1:
334
//									dialog.dismiss();
335
//									break;
336
//								default:
337
//									System.out.println("default...");
338
//									break;
339
//								}
340
//							}
341
//						});
342
//		dialog.create();
343
//		dialog.show();
157
    public void onCollectItemLongClick(int currPos) {
344
        new AlertDialog(MyCollectActivity.this).builder().setTitle("删除该条收藏")
158
        new AlertDialog(MyCollectActivity.this).builder().setTitle("删除该条收藏")
345
                .setMsg("删除后将无法在我的收藏中查看该站信息,请确认是否删除?")
159
                .setMsg("删除后将无法在我的收藏中查看该站信息,请确认是否删除?")
346
                .setPositiveButton("删除记录", new View.OnClickListener() {
160
                .setPositiveButton("删除记录", new View.OnClickListener() {
347
                    @Override
161
                    @Override
348
                    public void onClick(View v) {
162
                    public void onClick(View v) {
349
                        sharedPreferencesHelper = new SharedPreferencesHelper(
350
                                MyCollectActivity.this);
163
                        sharedPreferencesHelper = new SharedPreferencesHelper(MyCollectActivity.this);
351
                        DatabaseHandler db = new DatabaseHandler(MyCollectActivity.this, "");
164
                        DatabaseHandler db = new DatabaseHandler(MyCollectActivity.this, "");
352
                        db.del(mCollect.get(i).getZhan_id());
353
                        sharedPreferencesHelper.removeData(mCollect
354
                                .get(i).getZhan_name());
355
                        currPos = i;
356
                        mCollect.remove(i);
357
                        Toast.makeText(MyCollectActivity.this,
358
                                "删除记录成功", Toast.LENGTH_SHORT)
359
                                .show();
360
//						adapter.notifyDataSetChanged();
361
//						DatabaseHandler db = new DatabaseHandler(MyCollectActivity.this,"");
362
                        Cursor c = db.query();
363
                        System.err.println(c.getCount());
364
                        if (c.getCount() <= 0) {
365
//							Toast.makeText(this,"没有",Toast.LENGTH_SHORT).show();
366
                            collectListView.setVisibility(View.GONE);
367
                            ll_collect.setBackgroundResource(R.drawable.bg_collection2_0);
165
                        db.del(mCollectDataList.get(currPos).getZhan_id());
166
                        sharedPreferencesHelper.removeData(mCollectDataList.get(currPos).getZhan_name());
167
                        mCollectDataList.remove(currPos);
168
                        Toast.makeText(MyCollectActivity.this, "删除记录成功", Toast.LENGTH_SHORT).show();
368

169

369
                            return;
370
                        }
371
                        String[] from = {"zhan_name", "zhan_address", "fast_num", "slow_num"};
372
                        int[] to = {R.id.item_collect_title, R.id.collect_item_address, R.id.item_collect_descriptionOR, R.id.item_collect_descriptionTR};
373
                        mCollect.clear();
374
                        while (c.moveToNext()) {
375
                            collectData = new CollectData();
376
                            collectData.setZhan_id(c.getString(c
377
                                    .getColumnIndex("zhan_id")));
378
                            collectData.setZhan_name(c.getString(c
379
                                    .getColumnIndex("zhan_name")));
380
                            collectData.setZhan_address(c.getString(c
381
                                    .getColumnIndex("zhan_address")));
382
                            collectData.setFast_num(c.getString(c
383
                                    .getColumnIndex("fast_num")));
384
                            collectData.setSlow_num(c.getString(c
385
                                    .getColumnIndex("slow_num")));
386
                            mCollect.add(collectData);
387
                        }
388
                        SimpleCursorAdapter adapter = new SimpleCursorAdapter(MyCollectActivity.this, R.layout.item_collect, c, from, to);
389
                        collectListView.setAdapter(adapter);
390
//						Log.d("listSize",list.size()+"");
391
//						getData();
392
//						if (list.size() == 0){
393
//							ImageView emptyView = new ImageView(MyCollectActivity.this);
394
//							emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
395
//							emptyView.setImageResource(R.drawable.bg_collection2_0);
396
//							ll_collect.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
397
//							emptyView.setVisibility(View.GONE);
398
//							((ViewGroup)collectListView.getParent()).addView(emptyView);
399
//							collectListView.setEmptyView(emptyView);
400
//						}
170
                        List<CollectData> list = getCollectList();
171
                        myCollectAdapter.setData(list);
401
                    }
172
                    }
402
                }).setNegativeButton("取消", new View.OnClickListener() {
173
                }).setNegativeButton("取消", new View.OnClickListener() {
403
            @Override
174
            @Override
404
            public void onClick(View v) {
175
            public void onClick(View v) {
405

406
            }
176
            }
407
        }).show();
177
        }).show();
408

409
        return true;
410
    }
178
    }
411

179

412
    @Override
180
    @Override
413
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
181
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
414

415
        //先判断是哪个页面返回过来的
182
        //先判断是哪个页面返回过来的
416
        switch (requestCode) {
183
        switch (requestCode) {
417
            case 3:
184
            case 3:
418

419
                //再判断返回过来的情况,是成功还是失败还是其它的什么……
185
                //再判断返回过来的情况,是成功还是失败还是其它的什么……
420
                switch (resultCode) {
186
                switch (resultCode) {
421
                    case 0:
422
                        Log.e("!!!", "没删除");
423
                        //没删除
424
//						Log.e("!!!", "成功了");
425
//						sharedPreferencesHelper = new SharedPreferencesHelper(
426
//								MyCollectActivity.this);
427
//						sharedPreferencesHelper.removeData(list
428
//						.get(currPos).getZhan_name());
429
//						list.remove(currPos);
430
//						adapter.notifyDataSetChanged();
431
                        break;
432
                    case 1:
433
                        //删除
434
//						String d = getIntent().getStringExtra("data");
187
                    case 1: // 删除
188
                        sharedPreferencesHelper = new SharedPreferencesHelper(MyCollectActivity.this);
189
                        sharedPreferencesHelper.removeData(mCollectDataList.get(currPos).getZhan_name());
190
                        mCollectDataList.remove(currPos);
435

191

436
                        Log.e("!!!", "删除");
437
//						Log.e("!!!", d);
438
                        sharedPreferencesHelper = new SharedPreferencesHelper(
439
                                MyCollectActivity.this);
440
                        sharedPreferencesHelper.removeData(mCollect.get(currPos).getZhan_name());
441
                        mCollect.remove(currPos);
442
                        DatabaseHandler db = new DatabaseHandler(MyCollectActivity.this, "");
443
                        Cursor c = db.query();
444
                        System.err.println(c.getCount());
445
                        if (c.getCount() <= 0) {
446
                            collectListView.setVisibility(View.GONE);
447
                            ll_collect.setBackgroundResource(R.drawable.bg_collection2_0);
448
                            return;
449
                        }
450
                        String[] from = {"zhan_name", "zhan_address", "fast_num", "slow_num"};
451
                        int[] to = {R.id.item_collect_title, R.id.collect_item_address, R.id.item_collect_descriptionOR, R.id.item_collect_descriptionTR};
452
                        mCollect.clear();
453
                        while (c.moveToNext()) {
454
                            collectData = new CollectData();
455
                            collectData.setZhan_id(c.getString(c
456
                                    .getColumnIndex("zhan_id")));
457
                            collectData.setZhan_name(c.getString(c
458
                                    .getColumnIndex("zhan_name")));
459
                            collectData.setZhan_address(c.getString(c
460
                                    .getColumnIndex("zhan_address")));
461
                            collectData.setFast_num(c.getString(c
462
                                    .getColumnIndex("fast_num")));
463
                            collectData.setSlow_num(c.getString(c
464
                                    .getColumnIndex("slow_num")));
465
                            mCollect.add(collectData);
466
                        }
467
                        SimpleCursorAdapter adapter = new SimpleCursorAdapter(MyCollectActivity.this, R.layout.item_collect, c, from, to);
468
                        collectListView.setAdapter(adapter);
469
///						adapter.notifyDataSetChanged();
470
//						if (list.size() == 0) {
471
//							ImageView emptyView = new ImageView(MyCollectActivity.this);
472
//							emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
473
//							emptyView.setImageResource(R.drawable.bg_collection2_0);
474
//							ll_collect.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
475
//							emptyView.setVisibility(View.GONE);
476
//							((ViewGroup) collectListView.getParent()).addView(emptyView);
477
//							collectListView.setEmptyView(emptyView);
478
//						}
479
                        break;
192
                        List<CollectData> list = getCollectList();
193
                        myCollectAdapter.setData(list);
480
                }
194
                }
481
                break;
195
                break;
482
//			case REQUEST_B:
483
//				//同上……
484
//				break;
485
        }
196
        }
486
    }
197
    }
487

198


+ 99 - 0
app/src/main/java/com/electric/chargingpile/adapter/MyCollectAdapter.java

1
package com.electric.chargingpile.adapter;
2
3
import android.content.Context;
4
import android.view.LayoutInflater;
5
import android.view.View;
6
import android.view.ViewGroup;
7
import android.widget.AdapterView;
8
import android.widget.LinearLayout;
9
import android.widget.TextView;
10
11
import androidx.annotation.NonNull;
12
import androidx.recyclerview.widget.RecyclerView;
13
14
import com.electric.chargingpile.R;
15
import com.electric.chargingpile.data.CollectData;
16
17
import java.util.ArrayList;
18
import java.util.List;
19
20
public class MyCollectAdapter extends RecyclerView.Adapter<MyCollectAdapter.MyCollectHolder> {
21
    private Context mContext;
22
    private LayoutInflater mLayoutInflater;
23
    private List<CollectData> mCollect = new ArrayList<CollectData>();
24
25
    public MyCollectAdapter(Context context, List<CollectData> list) {
26
        mContext = context;
27
        this.mCollect.addAll(list);
28
        mLayoutInflater = LayoutInflater.from(context);
29
    }
30
31
    @NonNull
32
    @Override
33
    public MyCollectHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
34
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_collect, null);
35
        return new MyCollectAdapter.MyCollectHolder(view);
36
    }
37
38
    @Override
39
    public void onBindViewHolder(@NonNull MyCollectHolder holder, int position) {
40
        CollectData collectData = mCollect.get(position);
41
        holder.name.setText(collectData.getZhan_name());
42
        holder.address.setText(collectData.getZhan_address());
43
44
        holder.item.setOnClickListener(new View.OnClickListener() {
45
            @Override
46
            public void onClick(View v) {
47
                if (onItemClickListener!=null) {
48
                    onItemClickListener.onItemClick(null, null, position, 0);
49
                }
50
            }
51
        });
52
53
        holder.item.setOnLongClickListener(new View.OnLongClickListener() {
54
            @Override
55
            public boolean onLongClick(View v) {
56
                if (onItemLongClickListener != null) {
57
                    onItemLongClickListener.onItemLongClick(null, null, position, 0);
58
                }
59
                return true;
60
            }
61
        });
62
    }
63
64
    @Override
65
    public int getItemCount() {
66
        return mCollect.size();
67
    }
68
69
    public void setData(List<CollectData> list) {
70
        mCollect.clear();
71
        mCollect.addAll(list);
72
        notifyDataSetChanged();
73
    }
74
75
    public class MyCollectHolder extends RecyclerView.ViewHolder {
76
        private final TextView name;
77
        private final TextView address;
78
        private final LinearLayout item;
79
80
        public MyCollectHolder(View itemView) {
81
            super(itemView);
82
            item = itemView.findViewById(R.id.item);
83
            name = itemView.findViewById(R.id.name);
84
            address = itemView.findViewById(R.id.address);
85
        }
86
    }
87
88
    AdapterView.OnItemClickListener onItemClickListener;
89
    AdapterView.OnItemLongClickListener onItemLongClickListener;
90
91
    public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
92
        this.onItemClickListener = onItemClickListener;
93
    }
94
95
    public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener onItemLongClickListener) {
96
        this.onItemLongClickListener = onItemLongClickListener;
97
    }
98
99
}

+ 29 - 26
app/src/main/res/layout/activity_my_collect.xml

1
<com.zhy.autolayout.AutoLinearLayout
2
    xmlns:android="http://schemas.android.com/apk/res/android"
3
              xmlns:tools="http://schemas.android.com/tools"
4
              android:layout_width="match_parent"
5
              android:layout_height="match_parent"
1
<com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
    xmlns:tools="http://schemas.android.com/tools"
6
    android:id="@+id/ll_collect"
3
    android:id="@+id/ll_collect"
4
    android:layout_width="match_parent"
5
    android:layout_height="match_parent"
7
    android:background="@drawable/bg_collection2_0"
6
    android:background="@drawable/bg_collection2_0"
8
    android:orientation="vertical">
7
    android:orientation="vertical">
9

8

12
        android:layout_width="match_parent"
11
        android:layout_width="match_parent"
13
        android:layout_height="130px"
12
        android:layout_height="130px"
14
        android:background="@color/title_background">
13
        android:background="@color/title_background">
14

15
        <ImageView
15
        <ImageView
16
            android:id="@+id/iv_back"
16
            android:id="@+id/iv_back"
17
            android:layout_width="wrap_content"
17
            android:layout_width="wrap_content"
19
            android:layout_alignParentLeft="true"
19
            android:layout_alignParentLeft="true"
20
            android:layout_centerVertical="true"
20
            android:layout_centerVertical="true"
21
            android:contentDescription="@null"
21
            android:contentDescription="@null"
22
            android:paddingBottom="4dp"
23
            android:paddingLeft="44px"
22
            android:paddingLeft="44px"
24
            android:paddingRight="44px"
25
            android:paddingTop="4dp"
23
            android:paddingTop="4dp"
24
            android:paddingRight="44px"
25
            android:paddingBottom="4dp"
26
            android:src="@drawable/icon_lvback1119" />
26
            android:src="@drawable/icon_lvback1119" />
27

27
        <TextView
28
        <TextView
28
            android:layout_width="wrap_content"
29
            android:layout_width="wrap_content"
29
            android:layout_height="match_parent"
30
            android:layout_height="match_parent"
31
            android:layout_centerInParent="true"
32
            android:gravity="center"
30
            android:text="我的收藏"
33
            android:text="我的收藏"
31
            android:textColor="#222222"
34
            android:textColor="#222222"
32
            android:textSize="16sp"
33
            android:gravity="center"
34
            android:layout_centerInParent="true"
35
            />
35
            android:textSize="16sp" />
36

36

37
        <ImageView
37
        <ImageView
38
            android:id="@+id/tv_share"
38
            android:id="@+id/tv_share"
39
            android:layout_width="wrap_content"
39
            android:layout_width="wrap_content"
40
            android:layout_height="match_parent"
40
            android:layout_height="match_parent"
41
            android:paddingRight="16dp"
41
            android:layout_alignParentEnd="true"
42
            android:layout_alignParentRight="true"
43
            android:layout_centerVertical="true"
44
            android:gravity="center"
42
            android:paddingLeft="16dp"
45
            android:paddingLeft="16dp"
46
            android:paddingRight="16dp"
43
            android:src="@drawable/icon_more1124"
47
            android:src="@drawable/icon_more1124"
44
            android:gravity="center"
45
            android:textColor="@color/titleone"
48
            android:textColor="@color/titleone"
46
            android:layout_centerVertical="true"
47
            android:layout_alignParentRight="true"
48
            android:layout_alignParentEnd="true"
49
            android:visibility="gone"/>
49
            android:visibility="gone" />
50

50

51

51

52
    </com.zhy.autolayout.AutoRelativeLayout>
52
    </com.zhy.autolayout.AutoRelativeLayout>
53

53
    <View
54
    <View
54
        android:layout_width="match_parent"
55
        android:layout_width="match_parent"
55
        android:layout_height="0.5dp"
56
        android:layout_height="0.5dp"
56
        android:background="@color/ui_titleline"/>
57
        android:background="@color/ui_titleline" />
57

58

59
    <ImageView
60
        android:id="@+id/no_data"
61
        android:visibility="gone"
62
        tools:visibility="visible"
63
        android:layout_width="match_parent"
64
        android:layout_height="match_parent"
65
        android:background="@drawable/bg_collection2_0" />
58

66

59
    <ListView
67
    <androidx.recyclerview.widget.RecyclerView
60
        android:id="@+id/collect_listView"
68
        android:id="@+id/collect_listView"
61
        android:layout_width="match_parent"
69
        android:layout_width="match_parent"
62
        android:layout_height="match_parent"
70
        android:layout_height="match_parent"
63
        android:background="@color/background"
64
        android:divider="@color/Line"
65
        android:dividerHeight="0.5dp"
66
        android:layout_below="@+id/rl_title"
71
        android:layout_below="@+id/rl_title"
72
        android:layout_alignParentStart="true"
67
        android:layout_alignParentLeft="true"
73
        android:layout_alignParentLeft="true"
68
        android:layout_alignParentStart="true">
69
    </ListView>
70

71

74
        android:background="@color/background" />
72

75

73
</com.zhy.autolayout.AutoLinearLayout>
76
</com.zhy.autolayout.AutoLinearLayout>

+ 57 - 109
app/src/main/res/layout/item_collect.xml

1
<?xml version="1.0" encoding="utf-8"?>
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:tools="http://schemas.android.com/tools"
3
    android:layout_width="match_parent"
4
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:background="@color/bg_row">
6

7

8
    <ImageView
9
        android:layout_width="45dp"
10
        android:layout_height="45dp"
11
        android:id="@+id/item_collect_imageView"
12
        android:src="@drawable/icon_listzhan76"
13
        android:layout_marginLeft="8dp"
14
        android:layout_marginTop="16dp"
15
        android:layout_marginBottom="16dp"
16
        android:layout_alignParentTop="true"
17
        android:layout_alignParentLeft="true"
18
        android:layout_alignParentStart="true" />
19

20
    <TextView
21
        android:layout_width="wrap_content"
22
        android:layout_height="wrap_content"
23
        android:text="Medium Text"
24
        android:textColor="@color/ui_65"
25
        android:textSize="15sp"
26
        android:layout_marginLeft="10dp"
27
        android:id="@+id/item_collect_title"
28
        android:maxLines="1"
29
        android:layout_marginTop="18dp"
30
        android:layout_toRightOf="@+id/item_collect_imageView"
31
        android:layout_toEndOf="@+id/item_collect_imageView" />
32

33
    <TextView
34
        android:layout_width="wrap_content"
35
        android:layout_height="wrap_content"
36
        android:textAppearance="?android:attr/textAppearanceSmall"
37
        android:textSize="13sp"
38
        android:textColor="@color/hintColor"
39
        android:layout_marginTop="10dp"
40
        android:drawableLeft="@drawable/icon_fast612"
41
        android:gravity="center"
42
        android:drawablePadding="3dp"
43
        android:visibility="gone"
44
        android:id="@+id/item_collect_descriptionO"
45
        android:layout_below="@+id/item_collect_title"
46
        android:layout_alignLeft="@+id/item_collect_title"
47
        android:layout_alignStart="@+id/item_collect_title" />
48

49
    <TextView
50
        android:layout_width="wrap_content"
51
        android:layout_height="wrap_content"
52
        android:textAppearance="?android:attr/textAppearanceMedium"
53
        android:text="Medium Text"
54
        android:textColor="@color/hintColor"
55
        android:layout_marginTop="5dp"
56
        android:textSize="13sp"
57
        android:maxEms="35"
58
        android:singleLine="true"
59
        android:ellipsize="end"
60
        android:id="@+id/collect_item_address"
61
        android:layout_below="@+id/item_collect_title"
62
        android:layout_alignLeft="@+id/item_collect_descriptionO"
63
        android:layout_alignStart="@+id/item_collect_descriptionO" />
64

65
    <TextView
66
        android:layout_width="wrap_content"
67
        android:layout_height="wrap_content"
68
        android:textAppearance="?android:attr/textAppearanceSmall"
69
        android:textColor="@color/hintColor"
70
        android:textSize="13sp"
71
        android:drawableLeft="@drawable/icon_slow612"
72
        android:drawablePadding="3dp"
73
        android:layout_marginLeft="15dp"
74
        android:visibility="gone"
75
        android:gravity="center"
76
        android:id="@+id/textView16"
77
        android:layout_alignTop="@+id/item_collect_descriptionOR"
78
        android:layout_toRightOf="@+id/item_collect_descriptionOR"
79
        android:layout_toEndOf="@+id/item_collect_descriptionOR" />
80

81
    <TextView
82
        android:layout_width="wrap_content"
83
        android:layout_height="18dp"
84
        android:textAppearance="?android:attr/textAppearanceMedium"
85
        android:text="1"
86
        android:visibility="gone"
87
        android:textSize="14sp"
88
        android:textColor="@color/hintColor"
89
        android:layout_marginLeft="5dp"
90
        android:gravity="center"
91
        android:id="@+id/item_collect_descriptionOR"
92
        android:layout_alignTop="@+id/item_collect_descriptionO"
93
        android:layout_toRightOf="@+id/item_collect_descriptionO"
94
        android:layout_toEndOf="@+id/item_collect_descriptionO" />
95

96
    <TextView
97
        android:layout_width="wrap_content"
98
        android:layout_height="18dp"
99
        android:textAppearance="?android:attr/textAppearanceMedium"
100
        android:text="3"
101
        android:textColor="@color/hintColor"
102
        android:textSize="14sp"
103
        android:gravity="center"
104
        android:visibility="gone"
105
        android:layout_marginLeft="5dp"
106
        android:id="@+id/item_collect_descriptionTR"
107
        android:layout_alignTop="@+id/textView16"
108
        android:layout_toRightOf="@+id/textView16"
109
        android:layout_toEndOf="@+id/textView16" />
110

111
</RelativeLayout>
5
    android:layout_height="wrap_content"
6
    android:background="@color/bg_row"
7
    android:orientation="vertical">
8

9
    <LinearLayout
10
        android:id="@+id/item"
11
        android:layout_width="match_parent"
12
        android:layout_height="wrap_content">
13

14
        <ImageView
15
            android:layout_width="45dp"
16
            android:layout_height="45dp"
17
            android:layout_marginLeft="8dp"
18
            android:layout_marginTop="16dp"
19
            android:layout_marginBottom="16dp"
20
            android:src="@drawable/icon_listzhan76" />
21

22
        <LinearLayout
23
            android:layout_width="match_parent"
24
            android:layout_height="match_parent"
25
            android:layout_marginRight="15dp"
26
            android:orientation="vertical">
27

28
            <TextView
29
                android:id="@+id/name"
30
                android:layout_width="match_parent"
31
                android:layout_height="wrap_content"
32
                android:layout_marginLeft="10dp"
33
                android:layout_marginTop="18dp"
34
                android:maxLines="1"
35
                tools:text="名称"
36
                android:textColor="@color/ui_65"
37
                android:textSize="15sp" />
38

39
            <TextView
40
                android:id="@+id/address"
41
                android:layout_width="wrap_content"
42
                android:layout_height="wrap_content"
43
                android:layout_marginLeft="10dp"
44
                android:layout_marginTop="5dp"
45
                android:ellipsize="end"
46
                android:maxEms="35"
47
                android:singleLine="true"
48
                tools:text="地址"
49
                android:textAppearance="?android:attr/textAppearanceMedium"
50
                android:textColor="@color/hintColor"
51
                android:textSize="13sp" />
52
        </LinearLayout>
53
    </LinearLayout>
54

55
    <View
56
        android:layout_width="match_parent"
57
        android:layout_height="1dp"
58
        android:background="@color/lineColor" />
59
</LinearLayout>