示例#1
0
  @Override
  public void onResponse(GsonResult response, String tag) {
    super.onResponse(response, tag);

    if (TAG_API_GET_ACTIVITY_ON_GOING.equals(tag)) {
      JSONObject jsonObject = JsonUtil.getJSONObject(response.getJsonStr());

      GsonBuilder gsonBuilder = new GsonBuilder();
      gsonBuilder.setDateFormat("yyyy-MM-dd hh:mm:ss");
      Gson gson = gsonBuilder.create();

      Type listType = new TypeToken<List<HiActivity>>() {}.getType();
      List<HiActivity> hiActivities =
          gson.fromJson(JsonUtil.getJSONArray(jsonObject, "list").toString(), listType);

      if (hiActivities != null) {
        mHiActivityAdapter.addAll(hiActivities);

        if (hiActivities.size() > 2) {
          mViewPager.setCurrentItem(1);
        } else if (hiActivities.size() == 1) {
          mViewPager.setCurrentItem(0);
        } else if (hiActivities.size() == 2) {
          mViewPager.setCurrentItem(1);
        }

        HiActivity currentSelectedHiActivity =
            mHiActivityAdapter.getItem(mViewPager.getCurrentItem());
        mCurrentSelectedHiActivityNameTextView.setText(currentSelectedHiActivity.getName());
      }
    }

    if (TAG_API_GET_ACTIVITY_END.equals(tag)) {
      JSONObject jsonObject = JsonUtil.getJSONObject(response.getJsonStr());

      GsonBuilder gsonBuilder = new GsonBuilder();
      gsonBuilder.setDateFormat("yyyy-MM-dd hh:mm:ss");
      Gson gson = gsonBuilder.create();

      Type listType = new TypeToken<List<HiActivity>>() {}.getType();
      List<HiActivity> hiActivities =
          gson.fromJson(JsonUtil.getJSONArray(jsonObject, "list").toString(), listType);

      if (hiActivities != null) {
        mHiActivityListAdapter.addAll(hiActivities);
        mHiActivityListAdapter.notifyDataSetChanged();
      }
    }
  }
示例#2
0
  @Override
  protected void loadViews() {
    super.loadViews();

    mEndActivityListView = (ListView) rootView.findViewById(R.id.list_favorite);
    mHiActivityListAdapter =
        new QuickAdapter<HiActivity>(getActivity(), R.layout.item_list_activity) {
          @Override
          protected void convert(BaseAdapterHelper helper, HiActivity item) {
            helper.setText(R.id.text_name, item.getName());
            helper.setText(R.id.text_address, item.getAddress());

            Calendar cal = Calendar.getInstance();
            cal.setTime(item.getStartDate());
            String time = "";
            if (cal.get(Calendar.AM_PM) == Calendar.PM) {
              time += "PM: ";
            } else {
              time += "AM: ";
            }

            time +=
                String.format(
                    "%s  %s",
                    DateUtils.formatTime(item.getStartDate()),
                    DateUtils.formatYear(item.getStartDate()));

            helper.setText(R.id.text_time, time);

            Picasso.with(getActivity())
                .load(item.getImgPath())
                .placeholder(R.drawable.img_default)
                .error(R.drawable.img_default)
                .into((ImageView) helper.getView().findViewById(R.id.img_img));
          }
        };

    LayoutInflater inflater = LayoutInflater.from(getActivity());

    View headerView = inflater.inflate(R.layout.header_list_favorite, mEndActivityListView, false);
    mCurrentSelectedHiActivityNameTextView = (TextView) headerView.findViewById(R.id.text_name);

    View footerView =
        inflater.inflate(R.layout.item_list_footer_common, mEndActivityListView, false);

    mEndActivityListView.addFooterView(footerView);

    mEndActivityListView.addHeaderView(headerView);
    mEndActivityListView.setAdapter(mHiActivityListAdapter);
    mEndActivityListView.setOnItemClickListener(this);

    mViewPager = (ClipViewPager) headerView.findViewById(R.id.viewpager);
    mViewPager.setPageTransformer(true, new ScalePageTransformer());

    rootView
        .findViewById(R.id.page_container)
        .setOnTouchListener(
            new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                return mViewPager.dispatchTouchEvent(event);
              }
            });

    mHiActivityAdapter = new HIActivityAdapter(getActivity());
    mViewPager.setAdapter(mHiActivityAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            HiActivity selectedHiActivity = mHiActivityAdapter.getItem(position);

            if (selectedHiActivity != null) {
              mCurrentSelectedHiActivityNameTextView.setText(selectedHiActivity.getName());
            }
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    mViewPager.setCurrentItem(0);
  }