Rev 18 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 18 | Rev 20 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | import org.w3c.dom.NodeList; |
24 | import org.w3c.dom.NodeList; |
25 | import org.xml.sax.SAXException; |
25 | import org.xml.sax.SAXException; |
26 | 26 | ||
27 | import android.content.Intent; |
27 | import android.content.Intent; |
28 | import android.util.Log; |
28 | import android.util.Log; |
29 | import android.view.View; |
- | |
30 | import android.widget.TextView; |
- | |
31 | import de.pointedears.converter.R; |
- | |
32 | import de.pointedears.converter.app.CurrenciesActivity; |
29 | import de.pointedears.converter.app.CurrenciesActivity; |
33 | import de.pointedears.converter.db.ConversionData; |
30 | import de.pointedears.converter.db.ConversionData; |
34 | import de.pointedears.converter.helpers.ConverterThread; |
31 | import de.pointedears.converter.helpers.ConverterThread; |
35 | import de.pointedears.converter.helpers.UpdateService; |
32 | import de.pointedears.converter.helpers.UpdateService; |
36 | 33 | ||
Line 48... | Line 45... | ||
48 | private static final String ATTR_TIME = "time"; //$NON-NLS-1$ |
45 | private static final String ATTR_TIME = "time"; //$NON-NLS-1$ |
49 | 46 | ||
50 | private static final String URL_ECB = |
47 | private static final String URL_ECB = |
51 | "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; //$NON-NLS-1$ |
48 | "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; //$NON-NLS-1$ |
52 | 49 | ||
53 | private final CurrenciesActivity activityContext; |
- | |
54 | private ConverterThread updateThread = null; |
50 | private ConverterThread updateThread = null; |
55 | 51 | ||
56 | private final UpdateService service; |
52 | private final UpdateService service; |
57 | 53 | ||
58 | /**
|
54 | /**
|
Line 60... | Line 56... | ||
60 | * The activityContext for this updater.
|
56 | * The activityContext for this updater.
|
61 | * FIXME: Required only for database access
|
57 | * FIXME: Required only for database access
|
62 | * @param updateService
|
58 | * @param updateService
|
63 | * The service that started this updater
|
59 | * The service that started this updater
|
64 | */
|
60 | */
|
65 | public RatesUpdater(CurrenciesActivity activityContext, |
- | |
66 | UpdateService updateService)
|
61 | public RatesUpdater(UpdateService updateService) |
67 | {
|
62 | {
|
68 | this.activityContext = activityContext; |
- | |
69 | this.service = updateService; |
63 | this.service = updateService; |
70 | }
|
64 | }
|
71 | 65 | ||
72 | /**
|
66 | /**
|
73 | * @return the updateThread
|
67 | * @return the updateThread
|
Line 98... | Line 92... | ||
98 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$ |
92 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$ |
99 | Date updated = new Date(); |
93 | Date updated = new Date(); |
100 | 94 | ||
101 | if (this.getUpdateThread() != null) |
95 | if (this.getUpdateThread() != null) |
102 | {
|
96 | {
|
103 | TextView textUpdating = |
97 | // TextView textUpdating =
|
104 | (TextView) this.activityContext |
98 | // (TextView) this.activityContext
|
105 | .findViewById(R.id.currencies_text_updating); |
99 | // .findViewById(R.id.currencies_text_updating);
|
106 | textUpdating.setVisibility(View.VISIBLE); |
100 | // textUpdating.setVisibility(View.VISIBLE);
|
107 | 101 | ||
108 | DocumentBuilderFactory documentBuilderFactory = |
102 | DocumentBuilderFactory documentBuilderFactory = |
109 | DocumentBuilderFactory.newInstance(); |
103 | DocumentBuilderFactory.newInstance(); |
110 | documentBuilderFactory.setNamespaceAware(true); |
104 | documentBuilderFactory.setNamespaceAware(true); |
111 | DocumentBuilder builder; |
105 | DocumentBuilder builder; |
Line 161... | Line 155... | ||
161 | NodeList childCubes = nodes; |
155 | NodeList childCubes = nodes; |
162 | 156 | ||
163 | len = childCubes.getLength(); |
157 | len = childCubes.getLength(); |
164 | 158 | ||
165 | HashMap<String, ConversionData> conversionRates = |
159 | HashMap<String, ConversionData> conversionRates = |
166 | this.activityContext.getConversionRates(); |
160 | CurrenciesActivity.getConversionRates(); |
167 | for (int i = 0; i < len; ++i) |
161 | for (int i = 0; i < len; ++i) |
168 | {
|
162 | {
|
169 | Element item = (Element) childCubes.item(i); |
163 | Element item = (Element) childCubes.item(i); |
170 | String currency = item.getAttribute(RatesUpdater.ATTR_CURRENCY); |
164 | String currency = item.getAttribute(RatesUpdater.ATTR_CURRENCY); |
171 | 165 | ||
Line 180... | Line 174... | ||
180 | {
|
174 | {
|
181 | 175 | ||
182 | }
|
176 | }
|
183 | }
|
177 | }
|
184 | 178 | ||
185 | this.activityContext.getDatabase().writeConversionsToDatabase(null); |
179 | CurrenciesActivity.getDatabase().writeConversionsToDatabase(null); |
186 | }
|
180 | }
|
187 | catch (XPathExpressionException e) |
181 | catch (XPathExpressionException e) |
188 | {
|
182 | {
|
189 | Log.e(this.getClass().toString(), "Error in XPath expression", e); //$NON-NLS-1$ |
183 | Log.e(this.getClass().toString(), "Error in XPath expression", e); //$NON-NLS-1$ |
190 | }
|
184 | }
|
Line 216... | Line 210... | ||
216 | intent.putExtra(UpdateService.EXTRA_NUM_RATES, len); |
210 | intent.putExtra(UpdateService.EXTRA_NUM_RATES, len); |
217 | intent.putExtra(UpdateService.EXTRA_DATE, updated); |
211 | intent.putExtra(UpdateService.EXTRA_DATE, updated); |
218 | this.service.sendBroadcast(intent); |
212 | this.service.sendBroadcast(intent); |
219 | }
|
213 | }
|
220 | 214 | ||
221 | textUpdating.setVisibility(View.GONE); |
215 | // textUpdating.setVisibility(View.GONE);
|
222 | }
|
216 | }
|
223 | }
|
217 | }
|
224 | }
|
218 | }
|