|
| 1 | +package com.cmput301f17t11.cupofjava.Views; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | +import android.app.usage.UsageEvents; |
| 5 | +import android.content.Context; |
| 6 | +import android.view.LayoutInflater; |
| 7 | +import android.view.View; |
| 8 | +import android.view.ViewGroup; |
| 9 | +import android.view.animation.AccelerateInterpolator; |
| 10 | +import android.widget.ArrayAdapter; |
| 11 | +import android.widget.BaseAdapter; |
| 12 | +import android.widget.ImageView; |
| 13 | +import android.widget.TextView; |
| 14 | + |
| 15 | +import com.cmput301f17t11.cupofjava.Controllers.EventFilteringHelper; |
| 16 | +import com.cmput301f17t11.cupofjava.Models.Habit; |
| 17 | +import com.cmput301f17t11.cupofjava.Models.HabitEvent; |
| 18 | +import com.cmput301f17t11.cupofjava.R; |
| 19 | + |
| 20 | +import java.util.ArrayList; |
| 21 | + |
| 22 | +/** |
| 23 | + * Created by naz_t on 12/4/2017. |
| 24 | + */ |
| 25 | + |
| 26 | +public class EventListAdapter extends BaseAdapter { |
| 27 | + LayoutInflater inflater = null; |
| 28 | + Activity context; |
| 29 | + ArrayList<HabitEvent> habitEvents; |
| 30 | + |
| 31 | + public EventListAdapter(Activity context, ArrayList<HabitEvent> events){ |
| 32 | + this.context = context; |
| 33 | + habitEvents = events; |
| 34 | + inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public int getCount(){ |
| 39 | + return habitEvents.size(); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public HabitEvent getItem(int position){ |
| 44 | + return habitEvents.get(position); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public long getItemId(int position){ |
| 49 | + return position; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public View getView(int position, View convertView, ViewGroup parent){ |
| 54 | + View view = convertView; |
| 55 | + view = (view == null) ? inflater.inflate(R.layout.fancy_event_list_view, null): view; |
| 56 | + |
| 57 | + TextView textViewHabitWhat = (TextView)view.findViewById(R.id.event_list_which_habit); |
| 58 | + TextView textViewHabitWhen = (TextView)view.findViewById(R.id.event_list_date); |
| 59 | + TextView textViewHabitComment = (TextView) view.findViewById(R.id.event_list_comment); |
| 60 | + ImageView imageView = (ImageView) view.findViewById(R.id.event_list_image_view); |
| 61 | + |
| 62 | + HabitEvent selectedHabit = habitEvents.get(position); |
| 63 | + |
| 64 | + textViewHabitWhat.setText(selectedHabit.getHabitTitle()); |
| 65 | + textViewHabitWhen.setText(selectedHabit.getDateAsString()); |
| 66 | + textViewHabitComment.setText(selectedHabit.getComment()); |
| 67 | + |
| 68 | + if (selectedHabit.hasImage()){ |
| 69 | + imageView.setImageBitmap(selectedHabit.getImage()); |
| 70 | + } |
| 71 | + |
| 72 | + return view; |
| 73 | + } |
| 74 | +} |
0 commit comments