Android Open Source - UTHPortal-Android-Gradle Adapter Provider






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;
//from w  w w .  j a v a2  s  .  c  om
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import android.content.Context;

import com.uth.uthportal.R;
import com.uth.uthportal.collections.AnnItem;
import com.uth.uthportal.collections.Course;
import com.uth.uthportal.collections.DayMenu;
import com.uth.uthportal.collections.Dish;
import com.uth.uthportal.collections.Food;
import com.uth.uthportal.collections.GeneralAnnouncement;
/**
 * This class provides adapters for custom list views.
 * @author GeorgeT
 *
 */
public class AdapterProvider {
//TODO add for the rest tabs
  public static ExpandableListAdapter getCoursesAdapter(Context context,List<Course> courses){
    //Initialize list elements
    List<String> listParent = new ArrayList<String>();
    HashMap<String, List<String>> listChild = new HashMap<String, List<String>>();
    //--------------
    for(Course course : courses){
      listParent.add(
          String.format("%s - %S",course.info.name,course.code)
          ); //add parent items format: Name - Code
      
      List<String> childData = new ArrayList<String>(); //initialize child data
      for(AnnItem item : course.announcements.items){
        String date = formatDateToString(item.date,item.hasTime,true); //get date string
        childData.add(
              String.format("<font color=\"#9b0000\">- %s -</font><br />%s",
                  date,
                  item.html)
            );
        
      }
      listChild.put(listParent.get(listParent.size()-1),childData); //map childData to Parent
    }
    //create adapter
     return new ExpandableListAdapter(context, listParent, listChild);
     
  }
  public static ExpandableListAdapter getGeneralAnnAdapter(Context context, List<GeneralAnnouncement> announcements ){
    List<String> listParent = new ArrayList<String>();
    HashMap<String,List<String>> listChild = new HashMap<String, List<String>>();
    //--------------
    for (GeneralAnnouncement announcement: announcements){
      String date = formatDateToString(announcement.date, false, true); //get date string
      listParent.add( String.format("<font color=\"#9b0000\">%s</font> - %s", date, announcement.title) );
      
      List<String> childData = new ArrayList<String>(); //initialize child data
      childData.add(announcement.html);
      
      listChild.put(listParent.get(listParent.size() - 1 ), childData);
    }
  return new ExpandableListAdapter(context, listParent, listChild);
  }
  public static ExpandableListAdapter getFoodAdapter(Context context,Food food){
    //Initialize list elements
    List<String> listParent = new ArrayList<String>();
    HashMap<String, List<String>> listChild = new HashMap<String, List<String>>();
    //--------------
    for(DayMenu dayMenu : food.weekMenu){
      listParent.add( String.format("%s - <font color=\"#9b0000\">%s</font>",
            dayMenu.name, formatDateToString(dayMenu.date, false, false)) 
          );
      List<String> childData = new ArrayList<String>();
      
      //add lunch and dinner for each day
            childData.add(formatDinnerLunch(context, dayMenu.lunch, R.string.lunch));
      childData.add(formatDinnerLunch(context, dayMenu.dinner, R.string.dinner));
      //!--------------------------------
      listChild.put(listParent.get(listParent.size()-1),childData); //map childData to Parent
    }
    return new ExpandableListAdapter(context, listParent, listChild);
  }
  private static String formatDinnerLunch(Context context, Dish dinnerLunch, int name){
    return String.format("<font color=\"#9b0000\">- %s -</font><br>"
        + "<font color=\"#2b9eb5\">%s: </font> %s<br>"
        + "<font color=\"#2b9eb5\">%s: </font> %s<br>"
        + "<font color=\"#2b9eb5\">%s: </font> %s<br>"
        ,context.getString(name),
                context.getString(R.string.main_plate), dinnerLunch.main,
                context.getString(R.string.salad),dinnerLunch.salad,
                context.getString(R.string.desert),dinnerLunch.desert);
  }
  private static String formatDateToString(Date date,Boolean addTime, Boolean addDay){
    SimpleDateFormat sdFormat;
    String result;
    if (addTime){
      sdFormat = new SimpleDateFormat("E, MMMM d, yyyy HH:mm");
    } else {
      if(addDay){
        sdFormat = new SimpleDateFormat("E, MMMM d, yyyy");
      } else {
        sdFormat = new SimpleDateFormat("MMMM d, yyyy");
      }
    }
    result =  sdFormat.format(date);
    return result;
  }
}




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