jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/364577 )
Change subject: Compilations: integrate with Random feed card. ...................................................................... Compilations: integrate with Random feed card. This will transparently load a random page from a compilation (if the user is offline), and then fall back to loading a random page from a reading list, as before. Sadly, this does not use an interceptor... it simply wouldn't be a savings of complexity. Bug: T163706 Change-Id: I942f8b54b7da4a225f54568d7cf9b87bf525bae6 --- M app/src/main/java/org/wikipedia/feed/random/RandomCardView.java 1 file changed, 23 insertions(+), 5 deletions(-) Approvals: jenkins-bot: Verified Mholloway: Looks good to me, approved diff --git a/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java b/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java index 8bd26ef..0edaf5b 100644 --- a/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java +++ b/app/src/main/java/org/wikipedia/feed/random/RandomCardView.java @@ -10,10 +10,13 @@ import org.wikipedia.dataclient.restbase.page.RbPageSummary; import org.wikipedia.feed.view.StaticCardView; import org.wikipedia.history.HistoryEntry; +import org.wikipedia.offline.OfflineManager; import org.wikipedia.page.PageTitle; import org.wikipedia.random.RandomSummaryClient; import org.wikipedia.readinglist.page.database.ReadingListPageDao; import org.wikipedia.util.log.L; + +import java.io.IOException; import retrofit2.Call; @@ -42,7 +45,7 @@ public void getRandomPage() { if (getCallback() != null && getCard() != null) { setProgress(true); - new RandomSummaryClient().request(getCard().wikiSite(), new RandomSummaryClient.Callback() { + new RandomSummaryClient().request(getCard().wikiSite(), new RandomSummaryClient.Callback() { @Override public void onSuccess(@NonNull Call<RbPageSummary> call, @NonNull PageTitle title) { setProgress(false); @@ -54,17 +57,32 @@ @Override public void onError(@NonNull Call<RbPageSummary> call, @NonNull Throwable t) { - L.w("Failed to get random card from network. Falling back to reading lists.", t); - getRandomReadingListPage(t); + L.w("Failed to get random card from network. Falling back to compilations.", t); + getRandomPageFromCompilation(t); setProgress(false); } }); } } - private void getRandomReadingListPage(@NonNull final Throwable throwableIfEmpty) { + private void getRandomPageFromCompilation(@NonNull final Throwable throwableIfEmpty) { + if (OfflineManager.hasCompilation() && getCallback() != null && getCard() != null) { + try { + getCallback().onSelectPage(getCard(), new HistoryEntry( + new PageTitle(OfflineManager.instance().getRandomTitle(), getCard().wikiSite()), + HistoryEntry.SOURCE_FEED_RANDOM)); + } catch (IOException e) { + getCallback().onGetRandomError(e, RandomCardView.this); + } + } else { + getRandomPageFromReadingLists(throwableIfEmpty); + } + } + + private void getRandomPageFromReadingLists(@NonNull final Throwable throwableIfEmpty) { ReadingListPageDao.instance().randomPage(new CallbackTask.DefaultCallback<PageTitle>() { - @Override public void success(@Nullable PageTitle title) { + @Override + public void success(@Nullable PageTitle title) { if (getCallback() != null && getCard() != null) { if (title != null) { getCallback().onSelectPage(getCard(), -- To view, visit https://gerrit.wikimedia.org/r/364577 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I942f8b54b7da4a225f54568d7cf9b87bf525bae6 Gerrit-PatchSet: 4 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits