Android Open Source - mobile2-android Activity Feed 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;
/*from   w w  w  .  jav  a 2 s .  com*/
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.TextView.BufferType;

import com.ecollege.android.ECollegeApplication;
import com.ecollege.android.R;
import com.ecollege.api.model.ActivityStreamItem;
import com.ecollege.api.model.ActivityStreamObject;
import com.ecollege.api.model.Course;
import com.ocpsoft.pretty.time.PrettyTime;

public class ActivityFeedAdapter extends UberAdapter<ActivityStreamItem> {

  private static final PrettyTime prettyTimeFormatter = new PrettyTime();
  
  public ActivityFeedAdapter(Context context, boolean canLoadMore) {
    super(context, true, false, canLoadMore);
  }
  
  @Override
  protected Object groupIdFunction(ActivityStreamItem item) {
    ActivityStreamItem asi = (ActivityStreamItem)item;
    if (asi.getTag() != null) return asi.getTag().toString();
    return "Unknown";
  }
  
  
    private static class ViewHolder {
        TextView titleText;
        TextView descriptionText;
        TextView timeText;
        TextView courseTitleText;
        ImageView icon;
    }
    
  @Override
  protected View getDataItemView(View convertView, ViewGroup parent, UberItem<ActivityStreamItem> item) {

        // A ViewHolder keeps references to children views to avoid unneccessary calls
        // to findViewById() on each row.
        ViewHolder holder;

        // When convertView is not null, we can reuse it directly, there is no need
        // to reinflate it. We only inflate a new View when the convertView supplied
        // by ListView is null.
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_item, null);

            // Creates a ViewHolder and store references to the two children views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.titleText = (TextView) convertView.findViewById(R.id.title_text);
            holder.descriptionText = (TextView) convertView.findViewById(R.id.description_text);
            holder.timeText = (TextView) convertView.findViewById(R.id.time_text);
            holder.courseTitleText = (TextView) convertView.findViewById(R.id.course_title_text);
            holder.icon = (ImageView) convertView.findViewById(R.id.icon);
            convertView.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }
        // Bind the data efficiently with the holder.
        ActivityStreamItem si = item.getDataItem();
        ActivityStreamObject ob = si.getObject();

        String title = ob.getObjectType();
        String desc = ob.getSummary();
        String objectType = ob.getObjectType();
        
        long courseId = ob.getCourseId();
        Course course = ((ECollegeApplication)parent.getContext().getApplicationContext()).getCourseById(courseId);
        
        if ("thread-topic".equals(objectType)) {
          title = "Topic: " + si.getTarget().getTitle();
          holder.icon.setImageResource(R.drawable.ic_discussions_responses);
        } else if ("thread-post".equals(objectType)) {
          title = "Re: " + si.getTarget().getTitle();
          holder.icon.setImageResource(R.drawable.ic_discussions_responses);
        } else if ("grade".equals(objectType)) {
          title = "Grade: " + si.getTarget().getTitle();
          holder.icon.setImageResource(R.drawable.ic_grade);
        } else if ("dropbox-submission".equals(objectType)) {
          title = "Dropbox: " + si.getTarget().getTitle();
          holder.icon.setImageResource(R.drawable.ic_dropbox);
        } else if ("exam-submission".equals(objectType)) {
          title = "Exam: " + si.getTarget().getTitle();
          holder.icon.setImageResource(R.drawable.ic_exam_submission);
        } else if ("remark".equals(objectType)) {
          title = "Remark: " + si.getTarget().getTitle();
          holder.icon.setImageResource(R.drawable.ic_remark);
        } 
        if (title == null) title = "";
        if (desc == null) desc = "";
        holder.titleText.setText(Html.fromHtml(title));
        holder.descriptionText.setText(Html.fromHtml(desc),BufferType.SPANNABLE);
        holder.timeText.setText(prettyTimeFormatter.format(si.getPostedTime().getTime()));
        if (course != null) {
          holder.courseTitleText.setText(Html.fromHtml(course.getTitle()));
        }
        
        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