Пример #1
0
  /**
   * @param page
   * @param recommends
   * @param mException
   */
  public void onTaskComplete(Group<Event> events, int page, Exception ex) {
    mStateHolder.setRanOnce(true);
    mStateHolder.setIsRunningTask(false);
    mStateHolder.setCurrentPage(page);
    setProgressBarIndeterminateVisibility(false);

    ProgressBar pbRefresh = (ProgressBar) findViewById(R.id.list_refresh_progress);
    pbRefresh.setVisibility(View.GONE);
    ImageView ivRefresh = (ImageView) findViewById(R.id.list_refresh);
    ivRefresh.setVisibility(View.VISIBLE);

    // Clear list for new batch.
    mListAdapter.removeObserver();
    mListAdapter.clear();
    // if(mListAdapter == null){
    mListAdapter = new SeparatedListAdapter(this);
    // }

    if (events != null) {
      Group<RecommendMsg> recommends = filterEventsFromJiepang(events);

      if (mStateHolder.getCurrentPage() <= 1) {
        mStateHolder.setRecommends(recommends);
      } else {
        mStateHolder.addRecommends(recommends);
      }

      if (mStateHolder.getSortMethod() == SORT_METHOD_RECENT) {
        sortRecommendsRecent(mStateHolder.getRecommends(), mListAdapter);
      } else {
        sortRecommendsDistance(mStateHolder.getRecommends(), mListAdapter);
      }
    } else if (ex != null) {
      if (mStateHolder.getRecommends() == null) {
        Group<RecommendMsg> recommends = new Group<RecommendMsg>();
        mStateHolder.setRecommends(recommends);
      }

      NotificationsUtil.ToastReasonForFailure(this, ex);
    }

    if (mStateHolder.getRecommends().size() == 0) {
      setEmptyView(mLayoutEmpty);
    }

    getListView().setAdapter(mListAdapter);

    if (mStateHolder.getRecommends() != null && !mStateHolder.getRecommends().isHasMore()) {
      footerview.setVisibility(View.GONE);
    }
    // -1 footerview
    getListView().setSelection(mStateHolder.getCurrentListItem() - 2);
    // getListView().setSelection(3);
  }
Пример #2
0
  @Override
  public void onPause() {
    super.onPause();

    ((Jianjianroid) getApplication()).removeLocationUpdates();

    if (isFinishing()) {
      if (mListAdapter != null) {
        mListAdapter.removeObserver();
      }

      unregisterReceiver(mLoggedOutReceiver);
      mStateHolder.cancel();
    }
  }
Пример #3
0
  /**
   * @param recommends
   * @param mListAdapter2
   */
  private void sortRecommendsRecent(
      Group<RecommendMsg> recommends, SeparatedListAdapter listAdapter) {

    // Sort all by timestamp first.
    Collections.sort(recommends, Comparators.getRecommendsRecencyComparator());

    // We'll group in different section adapters based on some time thresholds.
    Group<RecommendMsg> recent = new Group<RecommendMsg>();
    Group<RecommendMsg> today = new Group<RecommendMsg>();
    Group<RecommendMsg> yesterday = new Group<RecommendMsg>();
    Group<RecommendMsg> older = new Group<RecommendMsg>();

    EventTimestampSort timestamps = new EventTimestampSort();

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    for (RecommendMsg it : recommends) {
      try {
        Date date = format.parse(it.getCreateDate());
        if (date.after(timestamps.getBoundaryRecent())) {
          recent.add(it);
        } else if (date.after(timestamps.getBoundaryToday())) {
          today.add(it);
        } else if (date.after(timestamps.getBoundaryYesterday())) {
          yesterday.add(it);
        } else {
          older.add(it);
        }
      } catch (Exception ex) {
        Log.e(TAG, "exception during parsing date: " + ex.getMessage());
        older.add(it);
      }
    }
    if (recent.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(recent);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_recent), adapter);
    }

    if (today.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(today);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_today), adapter);
    }
    if (yesterday.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(yesterday);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_yesterday), adapter);
    }
    if (older.size() > 0) {
      RecommendListAdapter adapter =
          new RecommendListAdapter(
              this, ((Jianjianroid) getApplication()).getRemoteResourceManager());
      adapter.setGroup(older);
      listAdapter.addSection(
          getResources().getString(R.string.friendsactivity_title_sort_older), adapter);
    }
  }
Пример #4
0
  private void ensureUiListView() {

    // if(mListAdapter == null){
    mListAdapter = new SeparatedListAdapter(this);
    // }

    if (mStateHolder.getSortMethod() == SORT_METHOD_RECENT) {
      sortRecommendsRecent(mStateHolder.getRecommends(), mListAdapter);
    } else {
      sortRecommendsDistance(mStateHolder.getRecommends(), mListAdapter);
    }
    listView = getListView();
    listView.setAdapter(mListAdapter);
    listView.setDividerHeight(0);

    listView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RecommendMsg recommend = (RecommendMsg) parent.getAdapter().getItem(position);
            if (recommend != null) {
              Intent intent = new Intent(FriendsActivity.this, RecommendDetailsActivity.class);
              intent.putExtra(RecommendDetailsActivity.EXTRA_RecommendMsg_PARCEL, recommend);
              startActivity(intent);
            }
          }
        });

    footerview =
        (LinearLayout)
            LayoutInflater.from(listView.getContext())
                .inflate(R.layout.recommend_list_footer, null);

    footerview.setClickable(true);
    footerview.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            mStateHolder.setCurrentListItem(listView.getCount());

            mStateHolder.startTask(FriendsActivity.this);
          }
        });
    footerview.setVisibility(View.VISIBLE);
    if (!mStateHolder.getRanOnce()) {
      listView.addFooterView(footerview);
    }

    // Prepare our no-results view. Something odd is going on with the layout parameters though.
    // If we don't explicitly set the layout to be fill/fill after inflating, the layout jumps
    // to a wrap/wrap layout. Furthermore, sdk 3 crashes with the original layout using two
    // buttons in a horizontal LinearLayout.
    LayoutInflater inflater = LayoutInflater.from(this);

    if (UiUtil.sdkVersion() > 3) {
      mLayoutEmpty = (ScrollView) inflater.inflate(R.layout.friends_activity_empty, null);

      Button btnAddFriends =
          (Button) mLayoutEmpty.findViewById(R.id.friendsActivityEmptyBtnAddFriends);
      btnAddFriends.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              /*
              Intent intent = new Intent(FriendsActivity.this, AddFriendsActivity.class);
              startActivity(intent);*/
            }
          });

      Button btnFriendRequests =
          (Button) mLayoutEmpty.findViewById(R.id.friendsActivityEmptyBtnFriendRequests);
      btnFriendRequests.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              /*
              Intent intent = new Intent(FriendsActivity.this, FriendRequestsActivity.class);
              startActivity(intent);*/
            }
          });

    } else {
      // Inflation on 1.5 is causing a lot of issues, dropping full layout.
      mLayoutEmpty = (ScrollView) inflater.inflate(R.layout.friends_activity_empty_sdk3, null);
    }

    mLayoutEmpty.setLayoutParams(
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));

    if (mListAdapter.getCount() == 0) {
      setEmptyView(mLayoutEmpty);
    }

    if (mStateHolder.getIsRunningTask()) {
      setProgressBarIndeterminateVisibility(true);
      if (!mStateHolder.getRanOnce()) {
        setLoadingView();
      }
    } else {
      setProgressBarIndeterminateVisibility(false);
    }
  }