-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForecastAdapter.java
99 lines (81 loc) · 3.7 KB
/
ForecastAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.arifulislam.tourguidepro.adapters;
import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.arifulislam.tourguidepro.R;
import com.arifulislam.tourguidepro.weather.ForecastDTO;
import com.arifulislam.tourguidepro.weather.WeatherActivity;
import com.arifulislam.tourguidepro.weather.WeatherServiceHelper;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class ForecastAdapter extends RecyclerView.Adapter<ForecastAdapter.ForecastViewHolder> {
private Context context;
private ArrayList<ForecastDTO> list;
public ForecastAdapter(Context context, ArrayList<ForecastDTO> list) {
this.context = context;
this.list = list;
}
@Override
public ForecastViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.rv_row_forecast, parent, false);
return new ForecastViewHolder(view);
}
@Override
public void onBindViewHolder(ForecastViewHolder holder, int position) {
ForecastDTO dto = list.get(position);
String icon = dto.getIcon();
Uri uri = Uri.parse("http://api.openweathermap.org/img/w/" + icon);
Picasso.with(context).load(uri).into(holder.ivIcon);
if (WeatherActivity.UNIT_SELECTED.equals(WeatherServiceHelper.UNIT_METRIC)) {
holder.tvCityF.setText(dto.getCityName());
holder.tvDate.setText(dto.getDate());
holder.tvWeatherMain.setText(dto.getMainWeather());
holder.tvWind.setText("Wind : " + dto.getWind() + "m/s");
holder.tvTemperature.setText(dto.getTemperature() + "°C");
holder.tvWeatherDescription.setText(dto.getDescription());
holder.tvMaxMin.setText(dto.getMax() + "°C/" + dto.getMin() + "°C");
holder.tvPressure.setText("Pressure : " + dto.getPressure() + "hPa");
} else {
holder.tvCityF.setText(dto.getCityName());
holder.tvDate.setText(dto.getDate());
holder.tvWeatherMain.setText(dto.getMainWeather());
holder.tvWind.setText("Wind : " + dto.getWind() + "meter/sec");
holder.tvTemperature.setText(dto.getTemperature() + "°F");
holder.tvWeatherDescription.setText(dto.getDescription());
holder.tvMaxMin.setText(dto.getMax() + "°F/" + dto.getMin() + "°F");
holder.tvPressure.setText("Pressure : " + dto.getPressure() + "hPa");
}
}
@Override
public int getItemCount() {
return list.size();
}
public class ForecastViewHolder extends RecyclerView.ViewHolder {
TextView tvCityF;
TextView tvDate;
TextView tvWeatherMain;
TextView tvWind;
ImageView ivIcon;
TextView tvTemperature;
TextView tvWeatherDescription;
TextView tvMaxMin;
TextView tvPressure;
public ForecastViewHolder(View itemView) {
super(itemView);
tvCityF = itemView.findViewById(R.id.tvCityF);
tvDate = itemView.findViewById(R.id.tvDate);
tvWeatherMain = itemView.findViewById(R.id.tvWeatherMain);
tvWind = itemView.findViewById(R.id.tvWind);
ivIcon = itemView.findViewById(R.id.ivIcon);
tvTemperature = itemView.findViewById(R.id.tvTemperature);
tvWeatherDescription = itemView.findViewById(R.id.tvWeatherDescription);
tvMaxMin = itemView.findViewById(R.id.tvMaxMin);
tvPressure = itemView.findViewById(R.id.tvPressure);
}
}
}