-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForecastWeatherFragment.java
80 lines (57 loc) · 2.43 KB
/
ForecastWeatherFragment.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
package com.arifulislam.tourguidepro.weather;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.arifulislam.tourguidepro.R;
import com.arifulislam.tourguidepro.adapters.ForecastAdapter;
import java.util.ArrayList;
public class ForecastWeatherFragment extends Fragment implements WeatherServiceHelper
.ForecastResponseListener {
private ArrayList<ForecastDTO> forecastList;
private RecyclerView rvForecastWeather;
private WeatherServiceHelper serviceHelper;
private ForecastAdapter adapter;
public ForecastWeatherFragment() {
// Required empty public constructor
}
public static ForecastWeatherFragment getInstance() {
Bundle bundle = new Bundle();
ForecastWeatherFragment fragment = new ForecastWeatherFragment();
fragment.setArguments(bundle);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_forecast_weather, container, false);
// Initiating View
rvForecastWeather = view.findViewById(R.id.rvForecastWeather);
serviceHelper = new WeatherServiceHelper(this);
if (WeatherActivity.getWeatherUsingLatLon)
getForecastWeather(WeatherActivity.latitude, WeatherActivity.longitude);
else
getForecastWeather();
// Inflate the layout for this fragment
return view;
}
private void getForecastWeather() {
serviceHelper.getForecastWeather();
}
private void getForecastWeather(Double lat, Double lon) {
serviceHelper.getForecastWeather(lat, lon);
}
@Override
public void onForecastDataReceived(ArrayList<ForecastDTO> forecastList) {
this.forecastList = forecastList;
adapter = new ForecastAdapter(getContext(), forecastList);
RecyclerView.LayoutManager manager = new LinearLayoutManager(getContext(),
LinearLayoutManager.VERTICAL,
false);
rvForecastWeather.setLayoutManager(manager);
rvForecastWeather.setAdapter(adapter);
}
}