Пример #1
0
  private boolean updateByFeed(
      ArticleDao articleDao, FeedType feedType, UpdateType updateType, Integer id) {
    Log.d(TAG, "updateByFeed() started");

    InputStream is = null;
    try {
      // TODO: rewrite?
      try {
        is = getInputStream(getFeedUrl(feedType));
      } catch (IOException e) {
        Log.e("FeedUpdater.updateByF", "IOException on " + feedType, e);
        errorMessage = App.getInstance().getString(R.string.feedUpdater_IOException);
        return false;
      } catch (RuntimeException e) {
        Log.e("FeedUpdater.updateByF", "RuntimeException on " + feedType, e);
        errorMessage = e.getMessage();
        return false;
      }

      Log.d(TAG, "updateByFeed() got input stream; processing feed");
      try {
        processFeed(articleDao, is, feedType, updateType, id);
      } catch (IOException e) {
        Log.e("FeedUpdater.updateByF", "IOException on " + feedType, e);
        errorMessage =
            App.getInstance().getString(R.string.feedUpdater_IOExceptionOnProcessingFeed);
        return false;
      } catch (XmlPullParserException e) {
        Log.e("FeedUpdater.updateByF", "XmlPullParserException on " + feedType, e);
        errorMessage = App.getInstance().getString(R.string.feedUpdater_feedProcessingError);
        return false;
      }

      Log.d(TAG, "updateByFeed() finished successfully");

      return true;
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ignored) {
        }
      }
    }
  }
Пример #2
0
  private InputStream getInputStream(String urlStr) throws IOException {
    Request request = WallabagConnection.getRequest(WallabagConnection.getHttpURL(urlStr));

    Response response = WallabagConnection.getClient().newCall(request).execute();

    if (response.isSuccessful()) {
      return response.body().byteStream();
    } else {
      // TODO: fix
      throw new RuntimeException(
          String.format(
              App.getInstance().getString(R.string.unsuccessfulRequest_errorMessage),
              response.code(),
              response.message()));
    }
  }