Created
October 7, 2013 03:31
-
-
Save jpotts18/6862160 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TimeLineAdapter extends ArrayAdapter { | |
private final DailyInput dailyInput; | |
private LayoutInflater mInflater; | |
List<TimelineObject> timelineList = new ArrayList<TimelineObject>(); | |
private Context mContext; | |
private final int TYPE_MESSAGE = 1; | |
private final int TYPE_ACTIVITY = 2; | |
private final int TYPE_MEAL = 3; | |
private final int TYPE_DAILY_INPUT = 4; | |
private final int TYPE_DRINK = 5; | |
public static class MealViewHolder{ | |
TextView mealTime; | |
ImageView mealImage; | |
TextView mealPortion; | |
TextView mealDescription; | |
TextView mealPremeal; | |
TextView mealPostMeal; | |
TextView mealMood; | |
} | |
@SuppressWarnings("unchecked") | |
public TimeLineAdapter(Context mContext, int textViewResourceId, List<TimelineObject> timelineList, DailyInput dailyInput) { | |
super(mContext, textViewResourceId, timelineList); | |
this.timelineList = timelineList; | |
this.dailyInput = dailyInput; | |
this.mContext = mContext; | |
this.mInflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE); | |
} | |
@Override | |
public int getItemViewType(int position) { | |
int typeId = 0; | |
if(timelineList.get(position) instanceof Message){ | |
typeId = TYPE_MESSAGE; | |
} | |
if(timelineList.get(position) instanceof PhysicalActivity){ | |
typeId = TYPE_ACTIVITY; | |
} | |
if(timelineList.get(position) instanceof GetOnlyMeal){ | |
typeId = TYPE_MEAL; | |
} | |
if(timelineList.get(position) instanceof Hydration){ | |
typeId = TYPE_DRINK; | |
} | |
return typeId; | |
} | |
@SuppressLint("ResourceAsColor") | |
public View getView(int position, View convertView, ViewGroup parent) { | |
if(position == 0){ | |
if(dailyInput == null){ | |
RelativeLayout row = (RelativeLayout) View.inflate(mContext, R.layout.partial_timeline_daily_inputs_missing, null); | |
return row; | |
} else { | |
LinearLayout row = createParameters(); | |
return row; | |
} | |
} | |
switch (getItemViewType(position)){ | |
case TYPE_MEAL: | |
if(convertView == null){ | |
convertView = mInflater.inflate(R.layout.partial_timeline_meal, null); | |
MealViewHolder holder = new MealViewHolder(); | |
} | |
break; | |
case TYPE_ACTIVITY: | |
break; | |
case TYPE_DAILY_INPUT: | |
break; | |
case TYPE_DRINK: | |
break; | |
case TYPE_MESSAGE: | |
break; | |
default: | |
break; | |
} | |
TimelineObject to = timelineList.get(position); | |
View view = null; | |
if(to instanceof GetOnlyMeal ){view = createMeal((GetOnlyMeal) to); }; | |
if(to instanceof Message ){view = createMessage((Message) to); }; | |
if(to instanceof PhysicalActivity ){ view = createPhysicalActivity((PhysicalActivity) to); }; | |
if(to instanceof Hydration ){view = createHydration((Hydration) to); }; | |
return view; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment