Beispiel #1
0
    @Override
    protected Void doInBackground(final Integer... args) {
      final int textNo = args[0];
      final TextInfo textInfo = mTextCache.getText(textNo);
      final Text text;
      try {
        text = mKom.getSession().getText(textNo);
      } catch (final Exception e) {
        e.printStackTrace();
        return null;
      }

      final List<Integer> texts = new ArrayList<Integer>();
      for (int comment : text.getComments()) {
        Log.i(TAG, "CacheRelevantTask " + comment + " is a comment to " + textNo);
        texts.add(comment);
      }
      for (int footnote : text.getFootnotes()) {
        Log.i(TAG, "CacheRelevantTask " + footnote + " is a footnote to " + textNo);
        texts.add(footnote);
      }
      for (int commented : text.getCommented()) {
        Log.i(TAG, "CacheRelevantTask " + commented + " is a parent to " + textNo);
        texts.add(commented);
      }

      final Matcher m = TEXT_LINK_FINDER.matcher(textInfo.getBody());
      while (m.find()) {
        final String str = textInfo.getBody().substring(m.start(), m.end());
        try {
          final int linkNo = Integer.valueOf(str);
          Log.i(TAG, "CacheRelevantTask, text number " + linkNo + " found in body of " + textNo);
          texts.add(linkNo);
        } catch (final NumberFormatException e) {
          Log.i(
              TAG,
              "CacheRelevantTask, unable to parse " + str + " as text number in body of " + textNo);
        }
      }

      for (final int t : texts) {
        mTextCache.getText(t);
      }

      return null;
    }
Beispiel #2
0
  TextInfo getNextUnreadText(final boolean cacheRelevant) {
    // If mPrefetchRunner is null, we have already reached the end of the queue
    if (mPrefetchRunner == null) {
      return TextInfo.createText(mKom.getBaseContext(), TextInfo.ALL_READ);
    }

    // Get the next unread text from the queue
    final TextConf tc;
    try {
      tc = mUnreadQueue.take();
    } catch (final InterruptedException e) {
      return TextInfo.createText(mKom.getBaseContext(), TextInfo.ERROR_FETCHING_TEXT);
    }

    // This is how the prefetcher marks that there are no more unread texts. mPrefetchRunner should
    // be finished,
    // so we can delete the reference to it.
    if (tc.textNo < 0) {
      mPrefetchRunner = null;
      return TextInfo.createText(mKom.getBaseContext(), TextInfo.ALL_READ);
    }

    // If the text is already locally marked as read, get the next one instead
    if (mKom.isLocalRead(tc.textNo)) {
      return getNextUnreadText(cacheRelevant);
    }

    // Switch conference name
    mKom.setConferenceName(mKom.getConferenceName(tc.confNo));

    // Retrieve the text
    final TextInfo text = mTextCache.getText(tc.textNo);

    // Cache relevant info both for this text and for the next in the queue (if available)
    if (cacheRelevant) {
      doCacheRelevant(tc.textNo);
      final TextConf tcNext = mUnreadQueue.peek();
      if (tcNext != null) {
        doCacheRelevant(tcNext.textNo);
      }
    }

    return text;
  }