LotusHubActivity.java 2.88 KB
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();
    }
  }
}