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

Change subject: Add onboarding feed card for Offline Library.
......................................................................

Add onboarding feed card for Offline Library.

Also refine the logic of showing/hiding the offline onboarding card vs.
the offline notification card.

Bug: T172187
Bug: T172132
Change-Id: I1ea46e2867516aebcabfa15c1bfad2615545438b
---
M app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
M app/src/main/java/org/wikipedia/feed/FeedFragment.java
M app/src/main/java/org/wikipedia/feed/model/CardType.java
A app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java
M app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java
M app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java
M app/src/main/java/org/wikipedia/settings/PrefsIoUtil.java
M app/src/main/res/values/preference_keys.xml
M app/src/main/res/values/strings.xml
9 files changed, 77 insertions(+), 4 deletions(-)


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

diff --git a/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java 
b/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
index 5de6cb7..2fa54e8 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java
@@ -12,6 +12,7 @@
 import org.wikipedia.feed.onboarding.OnboardingClient;
 import org.wikipedia.feed.random.RandomClient;
 import org.wikipedia.feed.searchbar.SearchClient;
+import org.wikipedia.offline.OfflineManager;
 import org.wikipedia.util.DeviceUtil;
 
 import static org.wikipedia.util.ReleaseUtil.isPreBetaRelease;
@@ -27,7 +28,7 @@
         boolean online = DeviceUtil.isOnline();
 
         conditionallyAddPendingClient(new SearchClient(), age == 0);
-        conditionallyAddPendingClient(new OfflineCompilationClient(), age == 0 
&& !online && isPreBetaRelease());
+        conditionallyAddPendingClient(new OfflineCompilationClient(), age == 0 
&& !online && OfflineManager.hasCompilation() && isPreBetaRelease());
         conditionallyAddPendingClient(new OnboardingClient(), age == 0);
         conditionallyAddPendingClient(new AnnouncementClient(), age == 0 && 
online);
         conditionallyAddPendingClient(new AggregatedFeedContentClient(), 
online);
diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java 
b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
index 09d2701..59cdc96 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
@@ -425,7 +425,9 @@
 
         @Override
         public void onOnboardingPositiveAction(@NonNull Card card, @NonNull 
OnboardingCard.OnboardingAction action) {
-
+            if (action == OnboardingCard.OnboardingAction.OFFLINE_LIBRARY) {
+                onViewCompilations();
+            }
         }
     }
 
diff --git a/app/src/main/java/org/wikipedia/feed/model/CardType.java 
b/app/src/main/java/org/wikipedia/feed/model/CardType.java
index f5e8c1e..1310e9a 100644
--- a/app/src/main/java/org/wikipedia/feed/model/CardType.java
+++ b/app/src/main/java/org/wikipedia/feed/model/CardType.java
@@ -13,6 +13,7 @@
 import org.wikipedia.feed.news.NewsListCardView;
 import org.wikipedia.feed.offline.OfflineCardView;
 import org.wikipedia.feed.offline.OfflineCompilationCardView;
+import org.wikipedia.feed.onboarding.OnboardingCardView;
 import org.wikipedia.feed.progress.ProgressCardView;
 import org.wikipedia.feed.random.RandomCardView;
 import org.wikipedia.feed.searchbar.SearchCardView;
@@ -90,6 +91,11 @@
             return new OfflineCompilationCardView(ctx);
         }
     },
+    ONBOARDING_OFFLINE(17) {
+        @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
+            return new OnboardingCardView(ctx);
+        }
+    },
     OFFLINE(98) {
         @NonNull @Override public FeedCardView<?> newView(@NonNull Context 
ctx) {
             return new OfflineCardView(ctx);
diff --git 
a/app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java 
b/app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java
new file mode 100644
index 0000000..475cea9
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java
@@ -0,0 +1,43 @@
+package org.wikipedia.feed.onboarding;
+
+import android.net.Uri;
+import android.support.annotation.NonNull;
+
+import org.wikipedia.R;
+import org.wikipedia.feed.model.CardType;
+import org.wikipedia.offline.OfflineManager;
+import org.wikipedia.util.DeviceUtil;
+
+public class OfflineOnboardingCard extends OnboardingCard {
+    @NonNull @Override public CardType type() {
+        return CardType.ONBOARDING_OFFLINE;
+    }
+
+    @Override public boolean shouldShow() {
+        return super.shouldShow() && DeviceUtil.isOnline() && 
!OfflineManager.hasCompilation();
+    }
+
+    @Override public int prefKey() {
+        return R.string.preference_key_offline_onboarding_card_enabled;
+    }
+
+    @NonNull @Override public OnboardingAction action() {
+        return OnboardingAction.OFFLINE_LIBRARY;
+    }
+
+    @Override public int positiveText() {
+        return R.string.offline_library_onboarding_action;
+    }
+
+    @Override public int headerText() {
+        return R.string.offline_library_title;
+    }
+
+    @Override public int headerImage() {
+        return R.drawable.ic_offline_white_24dp;
+    }
+
+    @NonNull @Override public Uri fullImage() {
+        return 
Uri.parse("https://upload.wikimedia.org/wikipedia/commons/1/1c/Illustration_offline_onboarding.png";);
+    }
+}
diff --git 
a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java 
b/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java
index 020fe31..739726b 100644
--- a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java
+++ b/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java
@@ -6,11 +6,14 @@
 import android.support.annotation.StringRes;
 
 import org.wikipedia.feed.model.Card;
+import org.wikipedia.settings.PrefsIoUtil;
 
 public abstract class OnboardingCard extends Card {
     public enum OnboardingAction {
         OFFLINE_LIBRARY
     }
+
+    @StringRes public abstract int prefKey();
 
     @NonNull public abstract OnboardingAction action();
 
@@ -21,4 +24,17 @@
     @DrawableRes public abstract int headerImage();
 
     @NonNull public abstract Uri fullImage();
+
+    public boolean shouldShow() {
+        return PrefsIoUtil.getBoolean(prefKey(), true);
+    }
+
+    @Override public void onDismiss() {
+        PrefsIoUtil.setBoolean(prefKey(), false);
+    }
+
+    @Override public void onRestore() {
+        PrefsIoUtil.setBoolean(prefKey(), true);
+    }
+
 }
diff --git 
a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java 
b/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java
index 88e88fe..5ebff8e 100644
--- a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java
+++ b/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java
@@ -14,7 +14,10 @@
     @Override public void request(@NonNull Context context, @NonNull WikiSite 
wiki, int age,
                                   @NonNull FeedClient.Callback cb) {
         List<Card> cards = new ArrayList<>();
-        // TODO: add onboarding cards conditionally
+        OnboardingCard card = new OfflineOnboardingCard();
+        if (card.shouldShow()) {
+            cards.add(new OfflineOnboardingCard());
+        }
         cb.success(cards);
     }
 
diff --git a/app/src/main/java/org/wikipedia/settings/PrefsIoUtil.java 
b/app/src/main/java/org/wikipedia/settings/PrefsIoUtil.java
index 9883555..5a040a2 100644
--- a/app/src/main/java/org/wikipedia/settings/PrefsIoUtil.java
+++ b/app/src/main/java/org/wikipedia/settings/PrefsIoUtil.java
@@ -16,7 +16,7 @@
 /** Shared preferences input / output utility providing set* functionality 
that writes to SP on the
  * client's behalf, IO without client supplied {@link Context}, and wrappers 
for using string
  * resources as keys, and unifies SP access. */
-/*package*/ final class PrefsIoUtil {
+public final class PrefsIoUtil {
     @Nullable
     public static String getString(@StringRes int id, @Nullable String 
defaultValue) {
         return getString(getKey(id), defaultValue);
diff --git a/app/src/main/res/values/preference_keys.xml 
b/app/src/main/res/values/preference_keys.xml
index 54f1492..f83fcc7 100644
--- a/app/src/main/res/values/preference_keys.xml
+++ b/app/src/main/res/values/preference_keys.xml
@@ -59,4 +59,5 @@
     <string 
name="preference_key_reading_lists_current_user_hash">readingListsCurrentUserHash</string>
     <string name="preference_key_permission_asked">permissionAsked</string>
     <string name="preference_key_compilation_cache">compilationCache</string>
+    <string 
name="preference_key_offline_onboarding_card_enabled">offlineOnboardingCardEnabled</string>
 </resources>
diff --git a/app/src/main/res/values/strings.xml 
b/app/src/main/res/values/strings.xml
index 94f109b..daee794 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -500,6 +500,7 @@
     <string name="offline_library_empty_title">Nothing in your Offline 
Library</string>
     <string name="offline_library_empty_description">Choose a pack of 
Wikipedia articles to download now, for data-free access later.</string>
     <string name="offline_library_empty_search">Search Offline Library</string>
+    <string name="offline_library_onboarding_action">Learn about your Offline 
Library</string>
     <!-- /Offline -->
 
     <!-- Onboarding -->

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1ea46e2867516aebcabfa15c1bfad2615545438b
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