1 package de.example.exampletdd.fragment.current;
3 import android.content.Context;
4 import android.view.LayoutInflater;
5 import android.view.View;
6 import android.view.ViewGroup;
7 import android.widget.ArrayAdapter;
8 import android.widget.ImageView;
9 import android.widget.TextView;
10 import de.example.exampletdd.R;
12 public class WeatherCurrentDataAdapter extends ArrayAdapter<Object> {
13 private static final int FIRST = 0;
14 private static final int SECOND = 1;
15 private static final int THIRD = 2;
16 private final int[] resources;
18 public WeatherCurrentDataAdapter(final Context context, final int[] resources) {
21 this.resources = resources;
26 public View getView(final int position, final View convertView, final ViewGroup parent) {
28 final View view = this.getWorkingView(position, convertView);
29 final int viewType = this.getItemViewType(position);
31 if (viewType == FIRST) {
33 final ViewFirstHolder viewHolder = this.getViewFirstHolder(view);
34 final WeatherCurrentDataEntryFirst entry = (WeatherCurrentDataEntryFirst) this
36 viewHolder.picture.setImageBitmap(entry.getPicture());
37 viewHolder.tempMax.setText(entry.getTempMax());
38 viewHolder.tempMin.setText(entry.getTempMin());
39 } else if (viewType == SECOND) {
40 final ViewSecondHolder viewHolder = this.getViewSecondHolder(view);
41 final WeatherCurrentDataEntrySecond entry = (WeatherCurrentDataEntrySecond) this
43 viewHolder.weatherDescription.setText(entry.getWeatherDescription());
44 } else if (viewType == THIRD) {
45 final ViewThirdHolder viewHolder = this.getViewThirdHolder(view);
46 final WeatherCurrentDataEntryFifth entry = (WeatherCurrentDataEntryFifth) this
48 viewHolder.humidityValue.setText(entry.getHumidityValue());
49 viewHolder.pressureValue.setText(entry.getPressureValue());
50 viewHolder.rainValue.setText(entry.getRainValue());
51 viewHolder.cloudsValue.setText(entry.getCloudsValue());
52 viewHolder.windValue.setText(entry.getWindValue());
53 viewHolder.sunRiseTime.setText(entry.getSunRiseTime());
54 viewHolder.sunSetTime.setText(entry.getSunSetTime());
55 viewHolder.feelsLike.setText(entry.getFeelsLike());
56 viewHolder.snowValue.setText(entry.getSnowValue());
57 viewHolder.feelsLikeUnits.setText(entry.getFeelsLikeUnits());
64 public int getItemViewType(final int position) {
69 } else if (position == 1) {
71 } else if (position == 2) {
79 public int getViewTypeCount() {
83 private View getWorkingView(final int position, final View convertView) {
84 View workingView = null;
86 if (convertView == null) {
87 final int viewType = this.getItemViewType(position);
88 final Context context = this.getContext();
89 final LayoutInflater inflater = (LayoutInflater) context
90 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
92 workingView = inflater.inflate(this.resources[viewType], null);
94 workingView = convertView;
100 private ViewFirstHolder getViewFirstHolder(final View workingView) {
101 final Object tag = workingView.getTag();
102 ViewFirstHolder viewHolder = null;
104 if ((null == tag) || !(tag instanceof ViewFirstHolder)) {
105 viewHolder = new ViewFirstHolder();
107 viewHolder.picture = (ImageView) workingView
108 .findViewById(R.id.weather_current_data_picture);
109 viewHolder.tempMax = (TextView) workingView
110 .findViewById(R.id.weather_current_data_temp_max);
111 viewHolder.tempMin = (TextView) workingView
112 .findViewById(R.id.weather_current_data_temp_min);
114 workingView.setTag(viewHolder);
117 viewHolder = (ViewFirstHolder) tag;
123 private ViewSecondHolder getViewSecondHolder(final View workingView) {
124 final Object tag = workingView.getTag();
125 ViewSecondHolder viewHolder = null;
127 if ((null == tag) || !(tag instanceof ViewSecondHolder)) {
128 viewHolder = new ViewSecondHolder();
130 viewHolder.weatherDescription = (TextView) workingView
131 .findViewById(R.id.weather_current_data_description);
133 workingView.setTag(viewHolder);
136 viewHolder = (ViewSecondHolder) tag;
142 private ViewThirdHolder getViewThirdHolder(final View workingView) {
143 final Object tag = workingView.getTag();
144 ViewThirdHolder viewHolder = null;
146 if ((null == tag) || !(tag instanceof ViewThirdHolder)) {
147 viewHolder = new ViewThirdHolder();
149 viewHolder.humidityValue = (TextView) workingView
150 .findViewById(R.id.weather_current_now_data_humidity_value);
151 viewHolder.pressureValue = (TextView) workingView
152 .findViewById(R.id.weather_current_now_data_pressure_value);
153 viewHolder.rainValue = (TextView) workingView
154 .findViewById(R.id.weather_current_now_data_rain_value);
155 viewHolder.cloudsValue = (TextView) workingView
156 .findViewById(R.id.weather_current_now_data_clouds_value);
157 viewHolder.windValue = (TextView) workingView
158 .findViewById(R.id.weather_current_now_data_wind_value);
159 viewHolder.cloudsValue = (TextView) workingView
160 .findViewById(R.id.weather_current_now_data_clouds_value);
161 viewHolder.snowValue = (TextView) workingView
162 .findViewById(R.id.weather_current_now_data_snow_value);
163 viewHolder.sunRiseTime = (TextView) workingView
164 .findViewById(R.id.weather_current_now_data_sunrise_value);
165 viewHolder.sunSetTime = (TextView) workingView
166 .findViewById(R.id.weather_current_now_data_sunset_value);
167 viewHolder.feelsLike = (TextView) workingView
168 .findViewById(R.id.weather_current_now_data_feelslike_value);
169 viewHolder.feelsLikeUnits = (TextView) workingView
170 .findViewById(R.id.weather_current_now_data_feelslike_units);
172 workingView.setTag(viewHolder);
175 viewHolder = (ViewThirdHolder) tag;
182 private static class ViewFirstHolder {
183 public ImageView picture;
184 public TextView tempMax;
185 public TextView tempMin;
188 private static class ViewSecondHolder {
189 public TextView weatherDescription;
192 private static class ViewThirdHolder {
193 public TextView humidityValue;
194 public TextView pressureValue;
195 public TextView windValue;
196 public TextView rainValue;
197 public TextView cloudsValue;
198 public TextView snowValue;
199 public TextView sunRiseTime;
200 public TextView sunSetTime;
201 public TextView feelsLike;
202 public TextView feelsLikeUnits;