Dbrant has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373668 )
Change subject: Update and generalize design of onboarding cards for the Feed. ...................................................................... Update and generalize design of onboarding cards for the Feed. (and specifically update the offline onboarding card.) This removes the recently-added OnboardingCardView from the feed (which was used for delivering the offline onboarding card), and instead generalizes it to use the existing AnnouncementCardView, since the designs are now identical. An "Announcement" can now be constructed locally within the app (instead of only from a content service response), and fed directly into an announcement card in the feed. This also introduces the idea of "local" app URLs, which are fake URLs that can be plugged into the "action" of an announcement, and will cause the affirmative button to take the user to the desired activity in the app. So, in addition to having static in-app onboarding cards, we'll now be able to craft remote announcements that take the user to other specific activities in the app, rather than only external links. Bug: T172187 Bug: T140011 Change-Id: I2cb4d3e2caa19a42e236145fe0e01ec3d8532b5d --- M app/src/main/java/org/wikipedia/feed/FeedFragment.java M app/src/main/java/org/wikipedia/feed/announcement/Announcement.java M app/src/main/java/org/wikipedia/feed/announcement/AnnouncementCardView.java M app/src/main/java/org/wikipedia/feed/model/CardType.java M app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java M app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java D app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCardView.java M app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java M app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java M app/src/main/java/org/wikipedia/util/UriUtil.java M app/src/main/res/layout/view_card_announcement.xml D app/src/main/res/layout/view_card_onboarding.xml M app/src/main/res/values-qq/strings.xml M app/src/main/res/values/strings.xml 14 files changed, 65 insertions(+), 168 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/68/373668/1 diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java b/app/src/main/java/org/wikipedia/feed/FeedFragment.java index 59cdc96..3a3b8b1 100644 --- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java +++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java @@ -27,7 +27,6 @@ import org.wikipedia.feed.image.FeaturedImageCard; import org.wikipedia.feed.model.Card; import org.wikipedia.feed.news.NewsItemCard; -import org.wikipedia.feed.onboarding.OnboardingCard; import org.wikipedia.feed.random.RandomCardView; import org.wikipedia.feed.view.FeedAdapter; import org.wikipedia.feed.view.FeedView; @@ -397,7 +396,18 @@ @Override public void onAnnouncementPositiveAction(@NonNull Card card, @NonNull Uri uri) { funnel.cardClicked(card.type()); - UriUtil.handleExternalLink(getContext(), uri); + if (uri.toString().equals(UriUtil.LOCAL_URL_OFFLINE_LIBRARY)) { + onViewCompilations(); + } else if (uri.toString().equals(UriUtil.LOCAL_URL_LOGIN)) { + if (getCallback() != null) { + getCallback().onLoginRequested(); + } + } else if (uri.toString().equals(UriUtil.LOCAL_URL_SETTINGS)) { + startActivityForResult(SettingsActivity.newIntent(getContext()), + SettingsActivity.ACTIVITY_REQUEST_SHOW_SETTINGS); + } else { + UriUtil.handleExternalLink(getContext(), uri); + } } @Override @@ -421,13 +431,6 @@ public void onViewCompilations() { startActivity(LocalCompilationsActivity.newIntent(getContext())); - } - - @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/announcement/Announcement.java b/app/src/main/java/org/wikipedia/feed/announcement/Announcement.java index 339215c..785c98a 100644 --- a/app/src/main/java/org/wikipedia/feed/announcement/Announcement.java +++ b/app/src/main/java/org/wikipedia/feed/announcement/Announcement.java @@ -17,7 +17,7 @@ import static org.apache.commons.lang3.StringUtils.defaultString; -class Announcement extends BaseModel { +public class Announcement extends BaseModel { public static final String SURVEY = "survey"; public static final String FUNDRAISING = "fundraising"; @@ -32,6 +32,12 @@ @SuppressWarnings("unused,NullableProblems") @Required @NonNull private String text; @SuppressWarnings("unused") @Nullable private Action action; + + public Announcement(@NonNull String text, @NonNull String imageUrl, @NonNull Action action) { + this.text = text; + this.imageUrl = imageUrl; + this.action = action; + } @NonNull String id() { return id; @@ -97,10 +103,15 @@ return defaultString(imageUrl); } - static class Action { + public static class Action { @SuppressWarnings("unused,NullableProblems") @Required @NonNull private String title; @SuppressWarnings("unused,NullableProblems") @Required @NonNull private String url; + public Action(@NonNull String title, @NonNull String url) { + this.title = title; + this.url = url; + } + @NonNull String title() { return title; } diff --git a/app/src/main/java/org/wikipedia/feed/announcement/AnnouncementCardView.java b/app/src/main/java/org/wikipedia/feed/announcement/AnnouncementCardView.java index 57be555..51c8058 100644 --- a/app/src/main/java/org/wikipedia/feed/announcement/AnnouncementCardView.java +++ b/app/src/main/java/org/wikipedia/feed/announcement/AnnouncementCardView.java @@ -5,6 +5,7 @@ import android.support.annotation.NonNull; import android.text.TextUtils; import android.text.method.LinkMovementMethod; +import android.view.View; import android.widget.TextView; import org.wikipedia.R; @@ -30,6 +31,7 @@ @BindView(R.id.view_announcement_action_positive) TextView actionViewPositive; @BindView(R.id.view_announcement_action_negative) TextView actionViewNegative; @BindView(R.id.view_announcement_footer_text) TextView footerTextView; + @BindView(R.id.view_announcement_footer_border) View footerBorderView; public AnnouncementCardView(@NonNull Context context) { super(context); @@ -65,6 +67,9 @@ if (card.hasFooterCaption()) { footerTextView.setText(StringUtil.fromHtml(card.footerCaption())); + } else { + footerTextView.setVisibility(GONE); + footerBorderView.setVisibility(GONE); } } 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 1310e9a..f8c39b3 100644 --- a/app/src/main/java/org/wikipedia/feed/model/CardType.java +++ b/app/src/main/java/org/wikipedia/feed/model/CardType.java @@ -13,7 +13,6 @@ 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; @@ -93,7 +92,7 @@ }, ONBOARDING_OFFLINE(17) { @NonNull @Override public FeedCardView<?> newView(@NonNull Context ctx) { - return new OnboardingCardView(ctx); + return new AnnouncementCardView(ctx); } }, OFFLINE(98) { diff --git a/app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java b/app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java index e8fb99c..c5f9164 100644 --- a/app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java +++ b/app/src/main/java/org/wikipedia/feed/onboarding/OfflineOnboardingCard.java @@ -1,45 +1,29 @@ package org.wikipedia.feed.onboarding; -import android.net.Uri; import android.support.annotation.NonNull; import org.wikipedia.R; +import org.wikipedia.feed.announcement.Announcement; import org.wikipedia.feed.model.CardType; import org.wikipedia.offline.OfflineManager; import org.wikipedia.util.DeviceUtil; import org.wikipedia.util.ReleaseUtil; public class OfflineOnboardingCard extends OnboardingCard { + public OfflineOnboardingCard(@NonNull Announcement announcement) { + super(announcement); + } + @NonNull @Override public CardType type() { return CardType.ONBOARDING_OFFLINE; } - @Override public boolean shouldShow() { + public boolean shouldShow() { // TODO: remove pre-beta flag when ready. return super.shouldShow() && ReleaseUtil.isPreBetaRelease() && 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 739726b..bcc0d0a 100644 --- a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java +++ b/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCard.java @@ -1,29 +1,18 @@ package org.wikipedia.feed.onboarding; -import android.net.Uri; -import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.StringRes; -import org.wikipedia.feed.model.Card; +import org.wikipedia.feed.announcement.Announcement; +import org.wikipedia.feed.announcement.AnnouncementCard; import org.wikipedia.settings.PrefsIoUtil; -public abstract class OnboardingCard extends Card { - public enum OnboardingAction { - OFFLINE_LIBRARY +public abstract class OnboardingCard extends AnnouncementCard { + public OnboardingCard(@NonNull Announcement announcement) { + super(announcement); } @StringRes public abstract int prefKey(); - - @NonNull public abstract OnboardingAction action(); - - @StringRes public abstract int positiveText(); - - @StringRes public abstract int headerText(); - - @DrawableRes public abstract int headerImage(); - - @NonNull public abstract Uri fullImage(); public boolean shouldShow() { return PrefsIoUtil.getBoolean(prefKey(), true); @@ -37,4 +26,7 @@ PrefsIoUtil.setBoolean(prefKey(), true); } + @Override protected int dismissHashCode() { + return 0; + } } diff --git a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCardView.java b/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCardView.java deleted file mode 100644 index 0a074f1..0000000 --- a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingCardView.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.wikipedia.feed.onboarding; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.widget.ImageView; -import android.widget.TextView; - -import com.facebook.drawee.view.SimpleDraweeView; - -import org.wikipedia.R; -import org.wikipedia.feed.model.Card; -import org.wikipedia.feed.view.DefaultFeedCardView; -import org.wikipedia.views.ItemTouchHelperSwipeAdapter; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; - -public class OnboardingCardView extends DefaultFeedCardView<OnboardingCard> - implements ItemTouchHelperSwipeAdapter.SwipeableView { - public interface Callback { - void onOnboardingPositiveAction(@NonNull Card card, @NonNull OnboardingCard.OnboardingAction action); - } - - @BindView(R.id.onboarding_card_image) SimpleDraweeView imageView; - @BindView(R.id.onboarding_card_header_image) ImageView headerImageView; - @BindView(R.id.onboarding_card_header_title) TextView headerTitleView; - @BindView(R.id.onboarding_card_action_positive) TextView actionViewPositive; - - public OnboardingCardView(@NonNull Context context) { - super(context); - inflate(context, R.layout.view_card_onboarding, this); - ButterKnife.bind(this); - } - - @Override public void setCard(@NonNull OnboardingCard card) { - super.setCard(card); - - headerImageView.setImageResource(card.headerImage()); - headerTitleView.setText(card.headerText()); - imageView.setImageURI(card.fullImage()); - actionViewPositive.setText(card.positiveText()); - } - - @OnClick(R.id.onboarding_card_action_positive) - void onPositiveActionClick() { - if (getCallback() != null && getCard() != null) { - getCallback().onOnboardingPositiveAction(getCard(), getCard().action()); - } - } -} 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 5ebff8e..bf6d65e 100644 --- a/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java +++ b/app/src/main/java/org/wikipedia/feed/onboarding/OnboardingClient.java @@ -3,9 +3,12 @@ import android.content.Context; import android.support.annotation.NonNull; +import org.wikipedia.R; import org.wikipedia.dataclient.WikiSite; +import org.wikipedia.feed.announcement.Announcement; import org.wikipedia.feed.dataclient.FeedClient; import org.wikipedia.feed.model.Card; +import org.wikipedia.util.UriUtil; import java.util.ArrayList; import java.util.List; @@ -14,10 +17,16 @@ @Override public void request(@NonNull Context context, @NonNull WikiSite wiki, int age, @NonNull FeedClient.Callback cb) { List<Card> cards = new ArrayList<>(); - OnboardingCard card = new OfflineOnboardingCard(); + + OnboardingCard card = new OfflineOnboardingCard(new Announcement( + context.getString(R.string.offline_library_onboarding_text), + "https://upload.wikimedia.org/wikipedia/commons/5/5b/Illustration-OfflineLibraryPromo2_3x.png", + new Announcement.Action(context.getString(R.string.offline_library_onboarding_action), + UriUtil.LOCAL_URL_OFFLINE_LIBRARY))); if (card.shouldShow()) { - cards.add(new OfflineOnboardingCard()); + cards.add(card); } + cb.success(cards); } diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java b/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java index 0fa1d3f..99195f4 100644 --- a/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java +++ b/app/src/main/java/org/wikipedia/feed/view/FeedAdapter.java @@ -17,7 +17,6 @@ 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.random.RandomCardView; import org.wikipedia.feed.searchbar.SearchCardView; import org.wikipedia.views.DefaultRecyclerAdapter; @@ -29,8 +28,7 @@ ListCardItemView.Callback, CardHeaderView.Callback, FeaturedImageCardView.Callback, SearchCardView.Callback, NewsListCardView.Callback, AnnouncementCardView.Callback, FeaturedArticleCardView.Callback, - RandomCardView.Callback, OfflineCompilationCardView.Callback, - OnboardingCardView.Callback { + RandomCardView.Callback, OfflineCompilationCardView.Callback { void onShowCard(@Nullable Card card); void onRequestMore(); void onRetryFromOffline(); diff --git a/app/src/main/java/org/wikipedia/util/UriUtil.java b/app/src/main/java/org/wikipedia/util/UriUtil.java index 574e5bb..63f3251 100644 --- a/app/src/main/java/org/wikipedia/util/UriUtil.java +++ b/app/src/main/java/org/wikipedia/util/UriUtil.java @@ -23,6 +23,9 @@ import static org.wikipedia.zero.WikipediaZeroHandler.showZeroExitInterstitialDialog; public final class UriUtil { + public static final String LOCAL_URL_OFFLINE_LIBRARY = "#offlinelibrary"; + public static final String LOCAL_URL_SETTINGS = "#settings"; + public static final String LOCAL_URL_LOGIN = "#login"; /** * Decodes a URL-encoded string into its UTF-8 equivalent. If the string cannot be decoded, the diff --git a/app/src/main/res/layout/view_card_announcement.xml b/app/src/main/res/layout/view_card_announcement.xml index 5096b11..d886e4a 100644 --- a/app/src/main/res/layout/view_card_announcement.xml +++ b/app/src/main/res/layout/view_card_announcement.xml @@ -30,6 +30,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" + android:layout_marginBottom="12dp" android:paddingLeft="16dp" android:paddingRight="16dp"> @@ -50,9 +51,9 @@ </LinearLayout> <View + android:id="@+id/view_announcement_footer_border" android:layout_width="match_parent" android:layout_height="1dp" - android:layout_marginTop="12dp" android:background="@color/feed_image_border"/> <TextView diff --git a/app/src/main/res/layout/view_card_onboarding.xml b/app/src/main/res/layout/view_card_onboarding.xml deleted file mode 100644 index 561f826..0000000 --- a/app/src/main/res/layout/view_card_onboarding.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical"> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:padding="12dp"> - - <android.support.v7.widget.AppCompatImageView - android:id="@+id/onboarding_card_header_image" - android:layout_width="24dp" - android:layout_height="24dp" - android:layout_gravity="center" - android:layout_marginStart="4dp" - android:layout_marginLeft="4dp" - android:padding="3dp" - app:srcCompat="@drawable/ic_offline_white_24dp" - android:tint="@android:color/white" - android:background="@drawable/shape_circle" - app:backgroundTint="@color/base20" - android:contentDescription="@null"/> - - <TextView - android:id="@+id/onboarding_card_header_title" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center_vertical" - android:layout_marginStart="8dp" - android:layout_marginLeft="8dp" - android:fontFamily="sans-serif-medium" - android:textColor="?attr/feed_text_secondary_color" - tools:text="Lorem ipsum"/> - - </LinearLayout> - - <com.facebook.drawee.view.SimpleDraweeView - android:id="@+id/onboarding_card_image" - style="@style/SimpleDraweeViewPlaceholder" - android:layout_width="match_parent" - android:layout_height="178dp" - android:contentDescription="@null" /> - - <TextView - android:id="@+id/onboarding_card_action_positive" - style="@style/Widget.AppCompat.Button.Borderless" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center_horizontal" - android:layout_margin="4dp" - android:textColor="?attr/feed_text_tertiary_color" - tools:text="Lorem ipsum"/> - -</LinearLayout> \ No newline at end of file diff --git a/app/src/main/res/values-qq/strings.xml b/app/src/main/res/values-qq/strings.xml index 00ab964..9842fd3 100644 --- a/app/src/main/res/values-qq/strings.xml +++ b/app/src/main/res/values-qq/strings.xml @@ -455,6 +455,7 @@ <string name="offline_library_empty_title">Message shown when the offline library is empty.</string> <string name="offline_library_empty_description">Explanation encouraging the user to download an article pack for offline use later.</string> <string name="offline_library_empty_search">Button label for searching the list of possible article packs to download.</string> + <string name="offline_library_onboarding_text">Introductory text that explains the purpose of the Offline Library to the user.</string> <string name="offline_library_onboarding_action">Button label for discovering more about the Offline Library.</string> <string name="onboarding_skip">Button label to skip the current onboarding or tutorial screen.\n{{Identical|Skip}}</string> <string name="onboarding_continue">Button label to continue to the next onboarding or tutorial screen.\n{{Identical|Continue}}</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49dcc02..a3c6d56 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -508,7 +508,8 @@ <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> + <string name="offline_library_onboarding_text">Introducing Offline Library — download article packs now for offline reading later.</string> + <string name="offline_library_onboarding_action">Find out more</string> <!-- /Offline --> <!-- Onboarding --> -- To view, visit https://gerrit.wikimedia.org/r/373668 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2cb4d3e2caa19a42e236145fe0e01ec3d8532b5d 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