-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExchangeRatesLoader.java
More file actions
53 lines (43 loc) · 1.25 KB
/
ExchangeRatesLoader.java
File metadata and controls
53 lines (43 loc) · 1.25 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
package com.example.odeh.intermediate;
/**
* Created by odeh on 11/4/17.
*/
import android.content.Context;
import android.content.AsyncTaskLoader;
import java.util.List;
/**
* Loads a list of exchange rates by using an AsyncTask to perform the
* network request to the given URL.
*/
public class ExchangeRatesLoader extends AsyncTaskLoader<List<ExchangeRates>> {
/** Tag for log messages */
private static final String LOG_TAG = ExchangeRatesLoader.class.getName();
/** Query URL */
private String mUrl;
/**
* Constructs a new {@link ExchangeRatesLoader}.
*
* @param context of the activity
* @param url to load data from
*/
public ExchangeRatesLoader(Context context, String url) {
super(context);
mUrl = url;
}
@Override
protected void onStartLoading() {
forceLoad();
}
/**
* This is on a background thread.
*/
@Override
public List<ExchangeRates> loadInBackground() {
if (mUrl == null) {
return null;
}
// Perform the network request, parse the response, and extract a list of earthquakes.
List<ExchangeRates> exchangeRates = HelperMethods.fetchExchangeRates(mUrl);
return exchangeRates;
}
}