public static ChanReaderRequest newInstance( Loadable loadable, List<Post> cached, Listener<List<Post>> listener, ErrorListener errorListener) { String url; if (loadable.isBoardMode()) { url = ChanUrls.getPageUrl(loadable.board, loadable.no); } else if (loadable.isThreadMode()) { url = ChanUrls.getThreadUrl(loadable.board, loadable.no); } else if (loadable.isCatalogMode()) { url = ChanUrls.getCatalogUrl(loadable.board); } else { throw new IllegalArgumentException("Unknown mode"); } ChanReaderRequest request = new ChanReaderRequest(url, listener, errorListener); // Copy the loadable and cached list. The cached array may changed/cleared by other threads. request.loadable = loadable.copy(); request.cached = new ArrayList<>(cached); return request; }
@Override public List<Post> readJson(JsonReader reader) throws Exception { List<Post> list; if (loadable.isBoardMode()) { list = loadBoard(reader); } else if (loadable.isThreadMode()) { list = loadThread(reader); } else if (loadable.isCatalogMode()) { list = loadCatalog(reader); } else { throw new IllegalArgumentException("Unknown mode"); } return processPosts(list); }