Exemplo n.º 1
0
  private void parseData(List<DynamicBean> list) {
    if (!ListUtils.isEmpty(list)) {

      for (final DynamicBean bean : list) {
        Map<String, Object> map = new HashMap<>();
        map.put(from[0], JDUtils.getRemoteImagePath(bean.getIcon()));
        map.put(from[1], bean.getName());
        map.put(from[2], JDUtils.formatDate(bean.getCreateTime(), "yyyy-MM-dd HH:mm"));
        map.put(from[3], bean.getContent());
        dataSource.add(map);
      }
      mAdapter.notifyDataSetChanged();
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_out_reservation_history);
    ButterKnife.inject(this);
    HashMap<Integer, String[]> fromMap = new HashMap<Integer, String[]>();
    fromMap.put(RESOUCE[0], from);
    HashMap<Integer, int[]> toMap = new HashMap<Integer, int[]>();
    toMap.put(RESOUCE[0], to);
    mAdapter =
        new SocialStreamAdapter(
            this, dataSource, RESOUCE, fromMap, toMap, 0, 0, ImageLoaderUtils.headDisplayOpts);
    listView.setAdapter(mAdapter);
    listView.setOnPullRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            historyBeanList.clear();
            dataSource.clear();
            mAdapter.notifyDataSetChanged();
            initDataSource();
          }
        });

    mAdapter.setViewBinder(
        new SocialStreamAdapter.ViewBinder() {
          @Override
          public boolean setViewValue(View view, Object data, Object comment) {
            if (view.getId() == R.id.tv_reservation_status
                && data != null
                && data instanceof Integer) {

              int status = (int) data;
              TextView tv = (TextView) view;
              if (status == 0) {
                tv.setTextColor(getResources().getColor(R.color.color_theme));
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.tobepaid), null, null, null);
              } else {
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.icon_finish), null, null, null);
                tv.setTextColor(getResources().getColor(R.color.text_74));
              }
              return true;
            }
            return false;
          }
        });
    listView.setCanLoadMore(false);

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent =
                new Intent(OutReservationHistoryActivity.this, OutReservationDetailActivity.class);
            OutReservationHistoryBean bean =
                (OutReservationHistoryBean) dataSource.get(position).get("data");
            intent.putExtra(OutReservationDetailActivity.KEY_OUT_RESERVATION_BEAN, bean);
            startActivity(intent);
          }
        });

    JDUtils.registerLocalReceiver(mReceiver, IntentConstants.ACTION_RESERVATION_REFRESH);
    initDataSource();
  }