Dbrant has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370666 )

Change subject: Support loading Main Page from offline compilation.
......................................................................

Support loading Main Page from offline compilation.

Applies to loading the main page from the Feed card, as well as loading
the main page as the "default" page when opening a blank tab in
PageActivity.

Bug: T166312
Change-Id: Id18a1138b672e1d817e985f1592ab489123efec2
---
M app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
M app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
M app/src/main/java/org/wikipedia/feed/mainpage/MainPageClient.java
M app/src/main/java/org/wikipedia/page/PageActivity.java
4 files changed, 30 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/66/370666/1

diff --git a/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java 
b/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
index bc1f2d0..184d6c2 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
@@ -31,8 +31,7 @@
         conditionallyAddPendingClient(new AggregatedFeedContentClient(), 
online);
         addPendingClient(new ContinueReadingClient());
 
-        // TODO: enable this for offline when ready:
-        conditionallyAddPendingClient(new MainPageClient(), age == 0 && 
online);
+        conditionallyAddPendingClient(new MainPageClient(), age == 0);
 
         conditionallyAddPendingClient(new BecauseYouReadClient(), online);
         conditionallyAddPendingClient(new RandomClient(), age == 0);
diff --git 
a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java 
b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
index b85735f..7bdf2e2 100644
--- a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageCardView.java
@@ -6,12 +6,9 @@
 import android.view.View;
 
 import org.wikipedia.R;
-import org.wikipedia.WikipediaApp;
 import org.wikipedia.feed.view.FeedAdapter;
 import org.wikipedia.feed.view.StaticCardView;
 import org.wikipedia.history.HistoryEntry;
-import org.wikipedia.page.PageTitle;
-import org.wikipedia.staticdata.MainPageNameData;
 
 import java.text.DateFormat;
 import java.util.Date;
@@ -35,15 +32,12 @@
     }
 
     private class CallbackAdapter implements OnClickListener {
-        @NonNull private WikipediaApp app = WikipediaApp.getInstance();
-
         @Override
         public void onClick(View view) {
             if (getCallback() != null && getCard() != null) {
-                PageTitle title = new PageTitle(MainPageNameData
-                        .valueFor(app.getAppOrSystemLanguageCode()), 
app.getWikiSite());
                 getCallback().onSelectPage(getCard(),
-                        new HistoryEntry(title, 
HistoryEntry.SOURCE_FEED_MAIN_PAGE));
+                        new HistoryEntry(MainPageClient.getMainPageTitle(),
+                                HistoryEntry.SOURCE_FEED_MAIN_PAGE));
             }
         }
     }
diff --git a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageClient.java 
b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageClient.java
index 9ecd74d..fa2e502 100644
--- a/app/src/main/java/org/wikipedia/feed/mainpage/MainPageClient.java
+++ b/app/src/main/java/org/wikipedia/feed/mainpage/MainPageClient.java
@@ -1,11 +1,36 @@
 package org.wikipedia.feed.mainpage;
 
+import android.support.annotation.NonNull;
+
+import org.wikipedia.WikipediaApp;
 import org.wikipedia.dataclient.WikiSite;
 import org.wikipedia.feed.dataclient.DummyClient;
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.offline.OfflineManager;
+import org.wikipedia.page.PageTitle;
+import org.wikipedia.staticdata.MainPageNameData;
+import org.wikipedia.util.DeviceUtil;
+import org.wikipedia.util.log.L;
+
+import java.io.IOException;
 
 public class MainPageClient extends DummyClient {
     @Override public Card getNewCard(WikiSite wiki) {
         return new MainPageCard();
     }
+    
+    @NonNull
+    public static PageTitle getMainPageTitle() {
+        WikipediaApp app = WikipediaApp.getInstance();
+        PageTitle title = new PageTitle(MainPageNameData
+                .valueFor(app.getAppOrSystemLanguageCode()), 
app.getWikiSite());
+        if (OfflineManager.hasCompilation() && !DeviceUtil.isOnline()) {
+            try {
+                title = new 
PageTitle(OfflineManager.instance().getMainPageTitle(), app.getWikiSite());
+            } catch (IOException e) {
+                L.e(e);
+            }
+        }
+        return title;
+    }
 }
diff --git a/app/src/main/java/org/wikipedia/page/PageActivity.java 
b/app/src/main/java/org/wikipedia/page/PageActivity.java
index 4f37a45..0bea804 100644
--- a/app/src/main/java/org/wikipedia/page/PageActivity.java
+++ b/app/src/main/java/org/wikipedia/page/PageActivity.java
@@ -48,6 +48,7 @@
 import org.wikipedia.dataclient.WikiSite;
 import org.wikipedia.descriptions.DescriptionEditRevertHelpView;
 import org.wikipedia.events.ChangeTextSizeEvent;
+import org.wikipedia.feed.mainpage.MainPageClient;
 import org.wikipedia.gallery.GalleryActivity;
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.language.LangLinksActivity;
@@ -397,7 +398,7 @@
      * fragment manager. Useful for when this function is called from an 
AsyncTask result.
      */
     public void loadMainPage(TabPosition position) {
-        PageTitle title = new 
PageTitle(MainPageNameData.valueFor(app.getAppOrSystemLanguageCode()), 
app.getWikiSite());
+        PageTitle title = MainPageClient.getMainPageTitle();
         HistoryEntry historyEntry = new HistoryEntry(title, 
HistoryEntry.SOURCE_MAIN_PAGE);
         loadPage(title, historyEntry, position);
     }

-- 
To view, visit https://gerrit.wikimedia.org/r/370666
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id18a1138b672e1d817e985f1592ab489123efec2
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to