Back to project page UTHPortal-Android-Gradle.
The source code is released under:
MIT License
If you think the Android project UTHPortal-Android-Gradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.uth.uthportal.adapter; // w w w . j a va 2s.c om import java.util.Collections; import java.util.Comparator; import java.util.List; import com.uth.uthportal.collections.Course; import com.uth.uthportal.collections.DayMenu; import com.uth.uthportal.collections.Food; import com.uth.uthportal.collections.GeneralAnnouncement; import android.content.Context; import android.widget.ExpandableListView; /** * Adapter manager class is responsible for managing the adapters * that contain information for custom list views. */ public class AdapterManager{ Context context = null; //main activity's context //keep collections and their generated adapters ExpandableListAdapter coursesAdapter = null; List<Course> coursesList = null; ExpandableListAdapter generalAnnAdapter = null; List<GeneralAnnouncement> generalAnnList = null; ExpandableListAdapter foodAdapter = null; Food foodKeep= null; //TODO find a better name :P public AdapterManager(Context _context){ context=_context; } public void setGeneralAnnList(List<GeneralAnnouncement> announcements, ExpandableListView view){ //update the adapter if(!announcements.isEmpty()){ UpdateGeneralAnnAdapter(announcements, view); } } public void setCoursesList(List<Course> courses, ExpandableListView view){ //update the adapter if(!courses.isEmpty()){ UpdateCoursesAdapter(courses,view); } } public void setFood(Food food, ExpandableListView view){ if(food != null){ food.weekMenu = sortDays(food.weekMenu); UpdateFoodAdapter(food,view); } } public void refreshFoodAdapter(ExpandableListView view){ if (view!=null && foodAdapter != null){ view.setAdapter(foodAdapter); } } public void refreshCoursesAdapter(ExpandableListView view){ if (view!=null && coursesAdapter != null){ view.setAdapter(coursesAdapter); } } public void refreshGeneralAnnAdapter(ExpandableListView view) { if (view != null && generalAnnAdapter != null) { view.setAdapter(generalAnnAdapter); } } private void UpdateGeneralAnnAdapter(List<GeneralAnnouncement> announcements, ExpandableListView view){ generalAnnAdapter = AdapterProvider.getGeneralAnnAdapter(context, announcements); //generate adapter refreshGeneralAnnAdapter(view); } private void UpdateCoursesAdapter(List<Course> courses, ExpandableListView view){ coursesAdapter = AdapterProvider.getCoursesAdapter(context, courses); //generate adapter refreshCoursesAdapter(view); } private void UpdateFoodAdapter(Food food, ExpandableListView view) { foodAdapter = AdapterProvider.getFoodAdapter(context, food); //generate adapter refreshFoodAdapter(view); } private List<DayMenu> sortDays(List<DayMenu> list){ //custom comparator that sorts list items by date! Collections.sort(list, new Comparator<DayMenu>(){ @Override public int compare(DayMenu lhs, DayMenu rhs) { return lhs.date.compareTo(rhs.date); } }); return list; } //TODO add date checking, this function is not called yet. private Boolean areCoursesUpdated(List<Course> oldList, List<Course> newList){ if(newList.size()!=oldList.size()) return true; //there are courses added or removed for(Course courseNew : newList){ for(Course courseOld : oldList){ if(courseNew.code.equals(courseOld.code)){ //we found the same course if(courseNew.announcements.updateDate.compareTo(courseOld.announcements.updateDate)>0){ return true; //at least one course has updated at least one announcement }//if }//if }//for }//for return false; } private Boolean isFoodUpdated(Food oldFood, Food newFood){ if(newFood.date.compareTo(oldFood.date)>0) return true; return false; } }