Android Open Source - mobile2-android Topics Adapter






From Project

Back to project page mobile2-android.

License

The source code is released under:

Apache License

If you think the Android project mobile2-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ecollege.android.adapter;
// www  .  j av a2  s  . co  m
import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ecollege.android.R;
import com.ecollege.android.adapter.UberItem.UberItemType;
import com.ecollege.android.view.helpers.ResponseCountViewHelper;
import com.ecollege.api.model.ContainerInfo;
import com.ecollege.api.model.DiscussionTopic;
import com.ecollege.api.model.ResponseCount;
import com.ecollege.api.model.UserDiscussionTopic;

public class TopicsAdapter extends UberAdapter<UserDiscussionTopic> {

  public TopicsAdapter(Context context, TopicAdapterMode mode) {
    super(context,mode == TopicAdapterMode.GROUP_BY_COURSE_FILTER_INACTIVE
        ,mode == TopicAdapterMode.GROUP_BY_COURSE_FILTER_INACTIVE,false);
  }
  
  static class ViewHolder {
        ImageView icon;
        TextView titleText;
        TextView totalResponseCountText;
        TextView unreadResponseCountText;
        TextView userResponseCountText;
    }
    
  static class FooterViewHolder {
    TextView linkText;
  }
  
  public enum TopicAdapterMode {
    GROUP_BY_COURSE_FILTER_INACTIVE,
    NO_GROUP_NO_FILTER
  }
  
  public class CourseGroupId {
    
    private long courseId;
    private String courseTitle;
    
    public CourseGroupId(long courseId, String courseTitle) {
      this.courseId = courseId;
      this.courseTitle = courseTitle;
    }
    
    public long getCourseId() {
      return courseId;
    }
    
    @Override
    public String toString() {
      return courseTitle;
    }
    @Override
    public boolean equals(Object o) {
      if (o == null) return false;
      if (!(o instanceof CourseGroupId)) return false;
      return ((CourseGroupId)o).getCourseId() == getCourseId();
    }
  }
  
  @Override
  public boolean isEnabled(int position) {
    UberItem<UserDiscussionTopic> item = getItem(position);
    
    if (item.getItemType() == UberItemType.FOOTER) {
      return true;
    } else {
      return super.isEnabled(position);
    }
  }
  
  @Override
  protected Object groupIdFunction(UserDiscussionTopic item) {
    UserDiscussionTopic userTopic = (UserDiscussionTopic)item;
    DiscussionTopic topic = userTopic.getTopic();
    ContainerInfo info = topic.getContainerInfo();
    
    return new CourseGroupId(info.getCourseId(), Html.fromHtml(info.getCourseTitle()).toString());
  }
  
  @Override
  protected View getFooterView(int position, View convertView,
      ViewGroup parent, Object groupId) {
    FooterViewHolder holder;

        if (convertView == null) {
            convertView = ((Activity)parent.getContext()).getLayoutInflater().inflate(R.layout.see_all_discussions, null);

            holder = new FooterViewHolder();
            holder.linkText = (TextView) convertView.findViewById(R.id.see_all_text);
            convertView.setTag(holder);
        } else {
            holder = (FooterViewHolder) convertView.getTag();
        }
        
        holder.linkText.setText("See all topics for " + groupId.toString());
        return convertView;
  }
  
  @Override
  protected View getDataItemView(View convertView, ViewGroup parent,
      UberItem<UserDiscussionTopic> item) {
    ViewHolder holder;
    
    if (convertView == null) {
      convertView = ((Activity)context).getLayoutInflater().inflate(R.layout.user_topic_item, null);
      
      holder = new ViewHolder();
      holder.icon = (ImageView) convertView.findViewById(R.id.icon);
      holder.titleText = (TextView) convertView.findViewById(R.id.title_text);
      holder.totalResponseCountText = (TextView) convertView.findViewById(R.id.total_response_count_text);
      holder.unreadResponseCountText = (TextView) convertView.findViewById(R.id.unread_response_count_text);
      holder.userResponseCountText = (TextView) convertView.findViewById(R.id.user_response_count_text);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    
    UserDiscussionTopic userTopic = item.getDataItem();
    DiscussionTopic topic = userTopic.getTopic();
    ResponseCount responseCount = userTopic.getChildResponseCounts();
    holder.titleText.setText(Html.fromHtml(topic.getTitle()).toString());
    
    ResponseCountViewHelper responseCountViewHelper = new ResponseCountViewHelper(
        context,
        holder.icon,
        holder.unreadResponseCountText,
        holder.totalResponseCountText,
        holder.userResponseCountText
    );
    responseCountViewHelper.setResponseCount(responseCount);
    
    return convertView;
  }

  
}




Java Source Code List

com.ecollege.android.AnnouncementActivity.java
com.ecollege.android.CourseActivity.java
com.ecollege.android.CourseAnnouncementsActivity.java
com.ecollege.android.CourseDiscussionsActivity.java
com.ecollege.android.CourseGradebookActivity.java
com.ecollege.android.CoursePeopleActivity.java
com.ecollege.android.CourseThreadActivity.java
com.ecollege.android.CoursesActivity.java
com.ecollege.android.DiscussionsActivity.java
com.ecollege.android.DropboxMessageActivity.java
com.ecollege.android.ECollegeApplication.java
com.ecollege.android.GradeActivity.java
com.ecollege.android.HomeActivity.java
com.ecollege.android.HtmlContentActivity.java
com.ecollege.android.LoginActivity.java
com.ecollege.android.MainActivity.java
com.ecollege.android.PersonActivity.java
com.ecollege.android.ProfileActivity.java
com.ecollege.android.SingleSignonActivity.java
com.ecollege.android.SplashActivity.java
com.ecollege.android.UserDiscussionActivity.java
com.ecollege.android.UserResponseActivity.java
com.ecollege.android.UserTopicActivity.java
com.ecollege.android.activities.ECollegeActivityHelper.java
com.ecollege.android.activities.ECollegeActivity.java
com.ecollege.android.activities.ECollegeDefaultActivity.java
com.ecollege.android.activities.ECollegeListActivity.java
com.ecollege.android.activities.ECollegeTabActivity.java
com.ecollege.android.adapter.ActivityFeedAdapter.java
com.ecollege.android.adapter.GroupedAdapter.java
com.ecollege.android.adapter.LoadMoreAdapter.java
com.ecollege.android.adapter.ParentAdapterObserver.java
com.ecollege.android.adapter.ResponseAdapter.java
com.ecollege.android.adapter.TopicsAdapter.java
com.ecollege.android.adapter.UberAdapter.java
com.ecollege.android.adapter.UberItem.java
com.ecollege.android.adapter.UpcomingEventsAdapter.java
com.ecollege.android.adapter.WaitingForApiAdapter.java
com.ecollege.android.errors.ECollegeAlertException.java
com.ecollege.android.errors.ECollegeException.java
com.ecollege.android.errors.ECollegePromptException.java
com.ecollege.android.errors.ECollegePromptRetryException.java
com.ecollege.android.tasks.ECollegeAsyncTask.java
com.ecollege.android.tasks.ServiceCallTask.java
com.ecollege.android.tasks.TaskPostProcessor.java
com.ecollege.android.util.CacheConfiguration.java
com.ecollege.android.util.DateTimeUtil.java
com.ecollege.android.util.FileCacheManager.java
com.ecollege.android.util.VolatileCacheManager.java
com.ecollege.android.view.HeaderView.java
com.ecollege.android.view.helpers.ResponseCountViewHelper.java