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; }