-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherForecastAdapter.java
More file actions
69 lines (52 loc) · 2.84 KB
/
WeatherForecastAdapter.java
File metadata and controls
69 lines (52 loc) · 2.84 KB
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
package com.example.weatherapp.Adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.weatherapp.Common.Common;
import com.example.weatherapp.Model.WeatherForecastResult;
import com.example.weatherapp.R;
import com.squareup.picasso.Picasso;
public class WeatherForecastAdapter extends RecyclerView.Adapter<WeatherForecastAdapter.MyViewHolder>{
Context context;
WeatherForecastResult weatherForecastResult;
public WeatherForecastAdapter(Context context, WeatherForecastResult weatherForecastResult) {
this.context = context;
this.weatherForecastResult = weatherForecastResult;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context).inflate(R.layout.item_weather_forecast, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
//Load Icons
Picasso.get().load(new StringBuilder("https://openweathermap.org/img/wn/") // /04n@2x.png
.append(weatherForecastResult.list.get(position).weather.get(0).getIcon())
.append(".png").toString()).into(holder.img_weather); //https:// icons
holder.text_forecast_date.setText(new StringBuilder(Common.convertUnixToForecastDate(weatherForecastResult.list.get(position).dt)));
holder.text_forecast_time.setText(new StringBuilder(Common.convertUnixToHour(weatherForecastResult.list.get(position).dt)));
holder.text_details.setText(new StringBuilder(weatherForecastResult.list.get(position).weather.get(0).getDescription()));
holder.text_temperature.setText((new StringBuilder(String.valueOf(weatherForecastResult.list.get(position).main.getTemp()))).append("°C"));
}
@Override
public int getItemCount() { return weatherForecastResult.list.size(); }
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView text_forecast_date, text_forecast_time, text_details, text_temperature;
ImageView img_weather;
public MyViewHolder (View itemView) {
super(itemView);
img_weather = itemView.findViewById(R.id.img_weather);
text_forecast_time = itemView.findViewById(R.id.text_forecast_time);
text_forecast_date = itemView.findViewById(R.id.text_forecast_date);
text_details = itemView.findViewById(R.id.text_details);
text_temperature = itemView.findViewById(R.id.text_temperature);
}
}
}