From 6567e61d9535d4df289926c30f49deff25d1608f Mon Sep 17 00:00:00 2001 From: Shridhar Goel Date: Sat, 19 Jun 2021 22:23:23 +0530 Subject: [PATCH] Implement onboarding for Card Browser --- .../main/java/com/ichi2/anki/CardBrowser.java | 45 +++++++++++++++++++ AnkiDroid/src/main/res/drawable/hand_icon.xml | 5 +++ .../src/main/res/layout/card_browser.xml | 27 +++++++++++ AnkiDroid/src/main/res/values/colors.xml | 1 + 4 files changed, 78 insertions(+) create mode 100644 AnkiDroid/src/main/res/drawable/hand_icon.xml diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java index 3d06e341f17e..60e88f0e70a5 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java @@ -54,6 +54,7 @@ import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.CheckBox; +import android.widget.FrameLayout; import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; @@ -87,6 +88,8 @@ import com.ichi2.ui.CardBrowserSearchView; import com.ichi2.upgrade.Upgrade; import com.ichi2.utils.BooleanGetter; +import com.ichi2.utils.DimmedCirclePromptBackground; +import com.ichi2.utils.DimmedRectanglePromptBackground; import com.ichi2.utils.FunctionalInterfaces; import com.ichi2.utils.LanguageUtil; import com.ichi2.utils.PairWithBoolean; @@ -109,7 +112,10 @@ import java.util.Map; import java.util.Set; +import androidx.core.content.ContextCompat; import timber.log.Timber; +import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt; +import uk.co.samuelwall.materialtaptargetprompt.extras.focals.RectanglePromptFocal; import static com.ichi2.anki.CardBrowser.Column.*; import static com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY; @@ -306,6 +312,8 @@ enum Column { private boolean mShouldRestoreScroll = false; private boolean mPostAutoScroll = false; + private static final String CARD_BROWSER_ONBOARDING = "CardBrowserOnboarding"; + /** * Broadcast that informs us when the sd card is about to be unmounted */ @@ -600,8 +608,40 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.card_browser); initNavigationDrawer(findViewById(android.R.id.content)); startLoadingCollection(); + + if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(CardBrowserOnboardingEnum.DECK_CHANGER, this)) { + showTutorialForDeckChanger(); + } else if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(CardBrowserOnboardingEnum.CARD_PRESS_AND_HOLD, this)) { + showTutorialForCardClick(); + } + } + + public void showTutorialForDeckChanger() { + MaterialTapTargetPrompt.Builder tutorialBuilder = new MaterialTapTargetPrompt.Builder(this) + .setTarget(R.id.toolbar_spinner) + .setPrimaryText(this.getString(R.string.deck_changer_card_browser)) + .setSecondaryText(this.getString(R.string.deck_changer_card_browser_desc)) + .setPromptBackground(new DimmedRectanglePromptBackground()) + .setPromptFocal(new RectanglePromptFocal()) + .setFocalColour(ContextCompat.getColor(this, R.color.material_blue_500)) + .setPromptStateChangeListener((prompt, state) -> { + if (state == MaterialTapTargetPrompt.STATE_DISMISSED && + OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(CardBrowserOnboardingEnum.CARD_PRESS_AND_HOLD, this)) { + showTutorialForCardClick(); + } + }); + + OnboardingUtils.INSTANCE.showTutorialAndMarkVisited(tutorialBuilder, CardBrowserOnboardingEnum.DECK_CHANGER, this); } + public void showTutorialForCardClick() { + FrameLayout cardBrowserTutorial = findViewById(R.id.card_browser_tutorial); + cardBrowserTutorial.setVisibility(View.VISIBLE); + + new Handler().postDelayed(() -> cardBrowserTutorial.setVisibility(View.GONE), 4000); + + OnboardingUtils.INSTANCE.setAsVisited(CardBrowserOnboardingEnum.CARD_PRESS_AND_HOLD.ordinal(), this, CARD_BROWSER_ONBOARDING); + } // Finish initializing the activity after the collection has been correctly loaded @Override @@ -2930,4 +2970,9 @@ void searchCards(String searchQuery) { mSearchTerms = searchQuery; searchCards(); } + + private enum CardBrowserOnboardingEnum { + DECK_CHANGER, + CARD_PRESS_AND_HOLD + } } diff --git a/AnkiDroid/src/main/res/drawable/hand_icon.xml b/AnkiDroid/src/main/res/drawable/hand_icon.xml new file mode 100644 index 000000000000..737c9de803e9 --- /dev/null +++ b/AnkiDroid/src/main/res/drawable/hand_icon.xml @@ -0,0 +1,5 @@ + + + diff --git a/AnkiDroid/src/main/res/layout/card_browser.xml b/AnkiDroid/src/main/res/layout/card_browser.xml index 86b9890a013f..758fbf00becc 100644 --- a/AnkiDroid/src/main/res/layout/card_browser.xml +++ b/AnkiDroid/src/main/res/layout/card_browser.xml @@ -48,4 +48,31 @@ + + + + + + + + \ No newline at end of file diff --git a/AnkiDroid/src/main/res/values/colors.xml b/AnkiDroid/src/main/res/values/colors.xml index d42e9d77e624..b70664dfaa13 100644 --- a/AnkiDroid/src/main/res/values/colors.xml +++ b/AnkiDroid/src/main/res/values/colors.xml @@ -31,6 +31,7 @@ #00000000 #ffffff #000000 + #80000000 #66FFFFFF