Android Open Source - UTHPortal-Android-Gradle Adapter Manager






From Project

Back to project page UTHPortal-Android-Gradle.

License

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.

Java Source Code

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;
  }
}




Java Source Code List

com.uth.uthportal.AboutScreen.java
com.uth.uthportal.CoursesFragment.java
com.uth.uthportal.DepartmentFragment.java
com.uth.uthportal.FoodFragment.java
com.uth.uthportal.MainScreen.java
com.uth.uthportal.SettingsScreen.java
com.uth.uthportal.adapter.AdapterManager.java
com.uth.uthportal.adapter.AdapterProvider.java
com.uth.uthportal.adapter.ExpandableListAdapter.java
com.uth.uthportal.adapter.SettingsAdapter.java
com.uth.uthportal.adapter.TabsPagerAdapter.java
com.uth.uthportal.buffers.AvailableCoursesParser.java
com.uth.uthportal.buffers.CoursesParser.java
com.uth.uthportal.buffers.FileOperation.java
com.uth.uthportal.buffers.FoodParser.java
com.uth.uthportal.buffers.GeneralAnnParser.java
com.uth.uthportal.buffers.SettingsManager.java
com.uth.uthportal.collections.AnnItem.java
com.uth.uthportal.collections.Announcements.java
com.uth.uthportal.collections.AvailableCourse.java
com.uth.uthportal.collections.CourseInfo.java
com.uth.uthportal.collections.Course.java
com.uth.uthportal.collections.DayMenu.java
com.uth.uthportal.collections.DefaultIntervals.java
com.uth.uthportal.collections.Dish.java
com.uth.uthportal.collections.Food.java
com.uth.uthportal.collections.GeneralAnnouncement.java
com.uth.uthportal.collections.Settings.java
com.uth.uthportal.network.ApiLinks.java
com.uth.uthportal.network.AppRater.java
com.uth.uthportal.network.AsyncJSONDownloader.java
com.uth.uthportal.network.JSONDownloader.java
com.uth.uthportal.service.DataSyncService.java
com.uth.uthportal.util.SystemUiHiderBase.java
com.uth.uthportal.util.SystemUiHiderHoneycomb.java
com.uth.uthportal.util.SystemUiHider.java