public ArrayList<String> getUrls() { int i = 0; ArrayList<String> urls = new ArrayList<>(); for (String id : catIds) { if (i >= index) { String url; if (catUrls.containsKey(id)) url = catUrls.get(id).toString(); else url = CatApiHelper.getCatById(id).toString(); urls.add(url); } i++; } return urls; }
private void sourceCats(boolean includeGifs) { int count = 100; if (BuildConfig.DEBUG) count = 5; URL url = CatApiHelper.getCats(count, includeGifs); if (url != null) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName("image"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); NodeList idList = ((Element) node).getElementsByTagName("id"); String id = idList.item(0).getChildNodes().item(0).getNodeValue(); NodeList urlList = ((Element) node).getElementsByTagName("url"); String urlString = urlList.item(0).getChildNodes().item(0).getNodeValue(); index = 0; catIds.add(id); catUrls.put(id, Uri.parse(urlString)); } } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } } }