Created
October 7, 2013 02:48
-
-
Save jpotts18/6861872 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
package me.jeffpotter.generaldietitian.adapter; | |
import java.util.ArrayList; | |
import java.util.List; | |
import com.nostra13.universalimageloader.core.DisplayImageOptions; | |
import com.nostra13.universalimageloader.core.ImageLoader; | |
import com.nostra13.universalimageloader.core.assist.ImageScaleType; | |
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener; | |
import me.jeffpotter.generaldietitian.R; | |
import me.jeffpotter.generaldietitian.models.DailyInput; | |
import me.jeffpotter.generaldietitian.models.GetOnlyMeal; | |
import me.jeffpotter.generaldietitian.models.Hydration; | |
import me.jeffpotter.generaldietitian.models.Meal; | |
import me.jeffpotter.generaldietitian.models.Message; | |
import me.jeffpotter.generaldietitian.models.PhysicalActivity; | |
import me.jeffpotter.generaldietitian.models.TimelineObject; | |
import android.annotation.SuppressLint; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ArrayAdapter; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import android.widget.RelativeLayout; | |
import android.widget.TextView; | |
public class TimeLineAdapter extends ArrayAdapter { | |
private final DailyInput dailyInput; | |
List<TimelineObject> timelineList = new ArrayList<TimelineObject>(); | |
private Context mContext; | |
@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; | |
} | |
@SuppressLint("ResourceAsColor") | |
public View getView(final int position, View appview, 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; | |
} | |
} | |
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; | |
} | |
private LinearLayout createParameters() { | |
LinearLayout dailyInputLayout = (LinearLayout) View.inflate(mContext, R.layout.partial_timeline_dailyinputs, null); | |
TextView sleepTxt = (TextView) dailyInputLayout.findViewById(R.id.timeline_top_sleep_txt); | |
TextView stressRedTxt = (TextView) dailyInputLayout.findViewById(R.id.timeline_top_stress_reducing_txt); | |
TextView stressTxt = (TextView) dailyInputLayout.findViewById(R.id.timeline_top_stress_level_txt); | |
TextView energTxt = (TextView) dailyInputLayout.findViewById(R.id.timeline_top_energy_txt); | |
sleepTxt.setText(""+dailyInput.getSleepHours()); | |
stressTxt.setText(""+dailyInput.getStressLevel()); | |
if(dailyInput.isStressReduction()){ | |
stressRedTxt.setText("Yes"); | |
}else{ | |
stressRedTxt.setText("No"); | |
} | |
energTxt.setText(""+dailyInput.getEnergyLevel()); | |
return dailyInputLayout; | |
} | |
private View createHydration(Hydration to) { | |
return null; | |
} | |
private View createMessage(Message m) { | |
LinearLayout msgLayout = (LinearLayout) View.inflate(mContext, R.layout.partial_timeline_message1, null); | |
TextView msgTime = (TextView) msgLayout.findViewById(R.id.timeline_message_time); | |
TextView msgBody = (TextView) msgLayout.findViewById(R.id.timeline_message_body); | |
msgTime.setText(m.getHumanTime()); | |
msgBody.setText(m.getBody()); | |
return msgLayout; | |
} | |
private View createPhysicalActivity(PhysicalActivity a) { | |
LinearLayout activityLayout = (LinearLayout) View.inflate(mContext, R.layout.partial_timeline_physical_activity1, null); | |
TextView activityTime = (TextView) activityLayout.findViewById(R.id.timeline_activity_time); | |
TextView activityType = (TextView) activityLayout.findViewById(R.id.timeline_activity_type); | |
ImageView activityImage = (ImageView) activityLayout.findViewById(R.id.timeline_activity_image); | |
TextView activityIntensity = (TextView) activityLayout.findViewById(R.id.timeline_activity_intensity); | |
TextView activityDuration = (TextView) activityLayout.findViewById(R.id.timeline_activity_duration); | |
// Load image | |
activityTime.setText(a.getHumanTime()); | |
activityType.setText(Integer.toString(a.getTypeId())); | |
activityIntensity.setText(a.getIntensity()); | |
activityDuration.setText(Integer.toString(a.getDuration())); | |
return activityLayout; | |
} | |
private View createMeal(GetOnlyMeal m) { | |
LinearLayout mealLayout = (LinearLayout) View.inflate(mContext, R.layout.partial_timeline_meal, null); | |
TextView mealTime = (TextView) mealLayout.findViewById(R.id.timeline_meal_time); | |
ImageView mealImage = (ImageView) mealLayout.findViewById(R.id.timeline_meal_image); | |
TextView mealPortion = (TextView) mealLayout.findViewById(R.id.timeline_meal_portion); | |
TextView mealDescription = (TextView) mealLayout.findViewById(R.id.timeline_meal_description); | |
TextView mealPremeal = (TextView) mealLayout.findViewById(R.id.timeline_meal_premeal); | |
TextView mealPostMeal = (TextView) mealLayout.findViewById(R.id.timeline_meal_postmeal); | |
TextView mealMood = (TextView) mealLayout.findViewById(R.id.timeline_meal_mood); | |
ImageLoader.getInstance().displayImage( | |
m.getPhoto().getUrl(), | |
mealImage, | |
new DisplayImageOptions.Builder() | |
.showImageForEmptyUri(R.drawable.no_photo) | |
.showImageOnFail(R.drawable.no_photo) | |
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) | |
.cacheOnDisc(true) | |
.build(), | |
new SimpleImageLoadingListener(){ | |
@Override | |
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { | |
super.onLoadingComplete(imageUri, view, loadedImage); | |
// view.startAnimation(AnimationUtils.loadAnimation(TimelineActivity.this, R.anim.fade_in)); | |
} | |
} | |
); | |
mealTime.setText(m.getHumanTime()); | |
mealPortion.setText(Integer.toString(m.getPortionConsumed()) + "/4"); | |
mealDescription.setText(m.getDescription()); | |
// Hide or show optional data | |
if(m.getPostMealFullness() != null){ | |
mealPostMeal.setText(m.getPreMealHunger().getDescription()); | |
} else { | |
mealLayout.findViewById(R.id.timeline_meal_postmeal_key).setVisibility(View.GONE); | |
mealPostMeal.setVisibility(View.GONE); | |
} | |
if(m.getPreMealHunger() != null){ | |
mealPremeal.setText(m.getPostMealFullness().getDescription()); | |
} else { | |
mealLayout.findViewById(R.id.timeline_meal_premeal_key).setVisibility(View.GONE); | |
mealPremeal.setVisibility(View.GONE); | |
} | |
if(m.getMood() != null){ | |
mealMood.setText(m.getMood().getDescription()); | |
} else { | |
mealLayout.findViewById(R.id.timeline_meal_mood_key).setVisibility(View.GONE); | |
mealMood.setVisibility(View.GONE); | |
} | |
return mealLayout; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment