LotusHubActivity.java
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.lotus.town;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import com.lotus.town.dao.HubDatabaseHelper;
import com.lotus.town.dao.HubNotes;
import com.lotus.town.hub.HubAdapter;
import com.lotus.town.hub.HubItem;
import com.lotus.town.widget.SpaceItemDecoration;
import com.sdk.Sdk;
import com.sdk.log.LogConstants;
import com.sdk.utils.TimeUtils;
import java.util.ArrayList;
import java.util.TimeZone;
public class LotusHubActivity extends BaseActivity implements View.OnClickListener {
private RecyclerView mHubRecycleView;
private HubAdapter mHubAdapter;
private View mBack;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lotus_hub);
mHubRecycleView = findViewById(R.id.contents);
mBack = findViewById(R.id.back);
mBack.setOnClickListener(this);
mHubAdapter = new HubAdapter(this, getList());
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mHubRecycleView.addItemDecoration(new SpaceItemDecoration(0, getResources().getDimensionPixelSize(R.dimen.hub_item_space)));
mHubRecycleView.setLayoutManager(linearLayoutManager);
mHubRecycleView.setAdapter(mHubAdapter);
Sdk.logger().logEvent(this, LogConstants.LOG_DT_DISPLAY);
}
private ArrayList<HubItem> getList(){
ArrayList<HubItem> items = new ArrayList<>();
String currentDate = "";
for(HubNotes note : HubDatabaseHelper.getInstance(this).getList()){
String date = "";
String time = "";
String userName = "";
String behaviour = "";
String result = "";
if(TimeUtils.isSameDay(note.getDatetime(),System.currentTimeMillis(), TimeZone.getDefault())){
date = "今天";
} else {
date = TimeUtils.getDateToString(note.getDatetime(),"MM-dd");
}
if(TextUtils.isEmpty(currentDate)){
items.add(new HubItem(HubItem.Type.DATE, "今天", null, null));
currentDate = "今天";
} else if(!currentDate.equals(date)){
items.add(new HubItem(HubItem.Type.DATE, date, null, null));
currentDate = date;
}
time = TimeUtils.getDateToString(note.getDatetime(),"HH:mm");
if(note.getType() == 0){
userName = "邻居"+note.getName()+"在你的小镇";
} else {
userName = note.getName();
}
behaviour = note.getBehaviour();
result = note.getResult();
HubItem hubItem = new HubItem(HubItem.Type.TIME, date, time, userName+behaviour+result);
items.add(hubItem);
}
return items;
}
@Override
public void onClick(View view) {
if(view == mBack){
finish();
}
}
}