Skip to content

Commit

Permalink
Update with required changes and better implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShridharGoel committed Jun 14, 2021
1 parent 8104e38 commit a36bbc7
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
import uk.co.samuelwall.materialtaptargetprompt.extras.focals.RectanglePromptFocal;

import static com.ichi2.anki.OnboardingConstants.ONBOARDING_CARD_DIFFICULTY_SELECTOR;
import static com.ichi2.anki.OnboardingConstants.ONBOARDING_SHOW_ANSWER;
import static com.ichi2.anki.cardviewer.CardAppearance.calculateDynamicFontSize;
import static com.ichi2.anki.cardviewer.ViewerCommand.*;
import static com.ichi2.anki.reviewer.CardMarker.*;
Expand Down Expand Up @@ -397,8 +395,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity i

private final OnRenderProcessGoneDelegate mOnRenderProcessGoneDelegate = new OnRenderProcessGoneDelegate(this);

private SharedPreferences mSharedPreferences;

// ----------------------------------------------------------------------------
// LISTENERS
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -958,18 +954,16 @@ protected void onCreate(Bundle savedInstanceState) {

mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);

mSharedPreferences = getSharedPreferences("PERSISTENT_STATE_FILE", 0);

if (mSharedPreferences.getBoolean(ONBOARDING_SHOW_ANSWER, true)) {
if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(4, this)) {
new MaterialTapTargetPrompt.Builder(this)
.setTarget(R.id.flip_card)
.setPrimaryText("See the answer")
.setSecondaryText("When you are ready to view the answer, click here")
.setPrimaryText(this.getString(R.string.see_answer))
.setSecondaryText(this.getString(R.string.see_answer_desc))
.setPromptBackground(new DimmedRectanglePromptBackground())
.setPromptFocal(new RectanglePromptFocal())
.show();

mSharedPreferences.edit().putBoolean(ONBOARDING_SHOW_ANSWER, false);
OnboardingUtils.INSTANCE.setAsVisited(4, this);
}
}

Expand Down Expand Up @@ -1843,16 +1837,16 @@ protected void displayAnswerBottomBar() {
mFlipCardLayout.animate().alpha(0).setDuration(mShortAnimDuration).withEndAction(after);
}

if (mSharedPreferences.getBoolean(ONBOARDING_CARD_DIFFICULTY_SELECTOR, true)) {
if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(7, this)) {
new MaterialTapTargetPrompt.Builder(this)
.setTarget(mEaseButtonsLayout)
.setPrimaryText("Select the difficulty")
.setSecondaryText("This will decide the time when this card will be displayed again")
.setPrimaryText(this.getString(R.string.select_difficulty))
.setSecondaryText(this.getString(R.string.select_difficulty_desc))
.setPromptBackground(new DimmedRectanglePromptBackground())
.setPromptFocal(new RectanglePromptFocal())
.show();

mSharedPreferences.edit().putBoolean(ONBOARDING_CARD_DIFFICULTY_SELECTOR, false).apply();
OnboardingUtils.INSTANCE.setAsVisited(7, this);
}
}

Expand Down
44 changes: 19 additions & 25 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
import uk.co.samuelwall.materialtaptargetprompt.extras.focals.RectanglePromptFocal;

import static com.ichi2.anki.OnboardingConstants.FIRST_LAUNCH;
import static com.ichi2.anki.OnboardingConstants.ONBOARDING_COUNTS_LAYOUT;
import static com.ichi2.anki.OnboardingConstants.ONBOARDING_DECK_PICKER_FAB;
import static com.ichi2.anki.OnboardingConstants.ONBOARDING_SELECT_DECK;
import static com.ichi2.async.Connection.ConflictResolution.FULL_DOWNLOAD;

import static com.ichi2.anim.ActivityTransitionAnimation.Direction.*;
Expand Down Expand Up @@ -263,8 +259,6 @@ public class DeckPicker extends NavigationDrawerActivity implements

private CustomStudyDialogFactory mCustomStudyDialogFactory;

private SharedPreferences mSharedPreferences;

// ----------------------------------------------------------------------------
// LISTENERS
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -465,10 +459,8 @@ protected void onCreate(Bundle savedInstanceState) throws SQLException {
return;
}

SharedPreferences sharedPreferences = getSharedPreferences("PERSISTENT_STATE_FILE", 0);

if (sharedPreferences.getBoolean(FIRST_LAUNCH, true)) {
sharedPreferences.edit().putBoolean(FIRST_LAUNCH, false).apply();
if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(0, this)) {
OnboardingUtils.INSTANCE.setAsVisited(0, this);
Intent introductionIntent = new Intent(this, IntroductionActivity.class);
startActivityWithoutAnimation(introductionIntent);
}
Expand Down Expand Up @@ -556,19 +548,16 @@ protected void onCreate(Bundle savedInstanceState) throws SQLException {

mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);

mSharedPreferences = getSharedPreferences("PERSISTENT_STATE_FILE", 0);

if (mSharedPreferences.getBoolean(ONBOARDING_DECK_PICKER_FAB, true)) {
if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(1, this)) {
showTutorialForFAB();
mSharedPreferences.edit().putBoolean(ONBOARDING_DECK_PICKER_FAB, false).apply();
}
}

public void showTutorialForFAB() {
new MaterialTapTargetPrompt.Builder(this)
.setTarget(R.id.fab_main)
.setPrimaryText("Get started")
.setSecondaryText("Create a deck, download a pre-made deck or add a note")
.setPrimaryText(this.getString(R.string.fab_tutorial_title))
.setSecondaryText(this.getString(R.string.fab_tutorial_desc))
.setPromptBackground(new DimmedCirclePromptBackground())
.setFocalColour(ContextCompat.getColor(this, R.color.material_light_blue_500))
.setPromptStateChangeListener((prompt, state) -> {
Expand All @@ -577,6 +566,8 @@ public void showTutorialForFAB() {
}
})
.show();

OnboardingUtils.INSTANCE.setAsVisited(1, this);
}

/**
Expand Down Expand Up @@ -994,42 +985,45 @@ protected void onResume() {


private void startDeckAndCountsTutorial() {
if (mDeckListAdapter.getItemCount() > 0 && mSharedPreferences.getBoolean(ONBOARDING_SELECT_DECK, true)) {
if (mDeckListAdapter.getItemCount() > 0 && OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(2, this)) {
showTutorialForDeck();
} else if (mDeckListAdapter.getItemCount() > 0 && mSharedPreferences.getBoolean(ONBOARDING_COUNTS_LAYOUT, true)) {
} else if (mDeckListAdapter.getItemCount() > 0 && OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(3, this)) {
showTutorialForCountsLayout();
}
}


private void showTutorialForDeck() {
if (mRecyclerViewLayoutManager.getChildAt(0) == null) return;

new MaterialTapTargetPrompt.Builder(this)
.setTarget(mRecyclerViewLayoutManager.getChildAt(0).findViewById(R.id.deck_name_linear_layout))
.setPrimaryText("Click on a deck to start studying")
.setSecondaryText("Long press on a deck to get more options related to it")
.setPrimaryText(this.getString(R.string.start_studying))
.setSecondaryText(this.getString(R.string.start_studying_desc))
.setPromptBackground(new DimmedRectanglePromptBackground())
.setPromptFocal(new RectanglePromptFocal())
.setPromptStateChangeListener((prompt, state) -> {
if (state == MaterialTapTargetPrompt.STATE_DISMISSED) {
showTutorialForCountsLayout();
mSharedPreferences.edit().putBoolean(ONBOARDING_COUNTS_LAYOUT, false).apply();
}
})
.show();

mSharedPreferences.edit().putBoolean(ONBOARDING_SELECT_DECK, false).apply();
OnboardingUtils.INSTANCE.setAsVisited(2, this);
}

private void showTutorialForCountsLayout() {
if (mRecyclerViewLayoutManager.getChildAt(0) == null) return;

new MaterialTapTargetPrompt.Builder(this)
.setTarget(mRecyclerViewLayoutManager.getChildAt(0).findViewById(R.id.counts_layout))
.setPrimaryText("Study options")
.setSecondaryText("Open study options to see card review details for a deck")
.setPrimaryText(this.getString(R.string.menu__study_options))
.setSecondaryText(this.getString(R.string.study_options_desc))
.setPromptBackground(new DimmedRectanglePromptBackground())
.setPromptFocal(new RectanglePromptFocal())
.show();

mSharedPreferences.edit().putBoolean(ONBOARDING_COUNTS_LAYOUT, false).apply();
OnboardingUtils.INSTANCE.setAsVisited(3, this);
}


Expand Down
105 changes: 56 additions & 49 deletions AnkiDroid/src/main/java/com/ichi2/anki/IntroductionActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,52 @@ class IntroductionActivity : AppIntro() {

setTransformer(AppIntroPageTransformerType.Zoom)

addSlide(
AppIntroFragment.newInstance(
title = "Welcome to AnkiDroid!",
description = "AnkiDroid is a spaced repetition flashcard app. Memorize anything with AnkiDroid!",
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = R.drawable.ankidroid_logo
)
val welcomeSlide = Triple(
R.string.collection_load_welcome_request_permissions_title,
R.string.introduction_desc,
R.drawable.ankidroid_logo
)
addSlide(
AppIntroFragment.newInstance(
title = "Create powerful decks with customised cards",
description = "Choose from multiple card types",
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = R.drawable.decks
)

val decksSlide = Triple(
R.string.decks_intro,
R.string.decks_intro_desc,
R.drawable.decks
)
addSlide(
AppIntroFragment.newInstance(
title = "Create cards which support multiple content formats",
description = "Text - Images - Sounds - MathJax - LaTeX",
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = R.drawable.create_cards,
)

val cardsSlide = Triple(
R.string.create_cards_intro,
R.string.create_cards_intro_desc,
R.drawable.create_cards
)
addSlide(
AppIntroFragment.newInstance(
title = "Choose from 6000+ pre-made decks",
description = "You can browse and import decks made by others.",
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = R.drawable.premade_decks
)

val premadeDecksSlide = Triple(
R.string.pre_made_decks,
R.string.pre_made_decks_desc,
R.drawable.premade_decks
)
addSlide(
AppIntroFragment.newInstance(
title = "Study time",
description = "Review cards and select their difficulty according to which the time interval for their next appearance will be decided",
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = R.drawable.review
)

val reviewerSlide = Triple(
R.string.study_time,
R.string.study_desc,
R.drawable.review
)
addSlide(
AppIntroFragment.newInstance(
title = "Detailed Statistics",
description = "Helps you track your study progress",
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = R.drawable.statistics
)

val statisticsSlide = Triple(
R.string.detailed_statistics,
R.string.detailed_statistics_desc,
R.drawable.statistics
)
addSlide(
AppIntroFragment.newInstance(
title = "Night Mode",
description = "Put less strain on your eyes",
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = R.drawable.night_mode
)

val nightModeSlide = Triple(
R.string.night_mode,
R.string.night_mode_desc,
R.drawable.night_mode
)

val slidesList = listOf(welcomeSlide, decksSlide, cardsSlide, premadeDecksSlide, reviewerSlide, statisticsSlide, nightModeSlide)
slidesList.forEach {
insertSlide(it)
}
}

override fun onSkipPressed(currentFragment: Fragment?) {
Expand All @@ -80,4 +70,21 @@ class IntroductionActivity : AppIntro() {
super.onDonePressed(currentFragment)
finish()
}

/**
* Insert a slide to be shown in the introduction
* resources.first -> Title of the slide
* resources.second -> Description of the slide
* resources.third -> Image of the slide
*/
private fun insertSlide(resources: Triple<Int, Int, Int>) {
addSlide(
AppIntroFragment.newInstance(
title = this.getString(resources.first),
description = this.getString(resources.second),
backgroundColor = ContextCompat.getColor(this, R.color.material_blue_500),
imageDrawable = resources.third
)
)
}
}
24 changes: 9 additions & 15 deletions AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
import uk.co.samuelwall.materialtaptargetprompt.extras.focals.RectanglePromptFocal;

import static com.ichi2.anki.OnboardingConstants.ONBOARDING_CARD_FORMATTING_TOOLS;
import static com.ichi2.anki.OnboardingConstants.ONBOARDING_FRONT_AND_BACK;
import static com.ichi2.compat.Compat.ACTION_PROCESS_TEXT;
import static com.ichi2.compat.Compat.EXTRA_PROCESS_TEXT;

Expand Down Expand Up @@ -263,8 +261,6 @@ public class NoteEditor extends AnkiActivity implements
// Use the same HTML if the same image is pasted multiple times.
private HashMap<String, String> mPastedImageCache = new HashMap<>();

private SharedPreferences mSharedPreferences;

private SaveNoteHandler saveNoteHandler() {
return new SaveNoteHandler(this);
}
Expand Down Expand Up @@ -442,44 +438,42 @@ protected void onCreate(Bundle savedInstanceState) {

startLoadingCollection();

mSharedPreferences = getSharedPreferences("PERSISTENT_STATE_FILE", 0);

if (mSharedPreferences.getBoolean(ONBOARDING_FRONT_AND_BACK, true)) {
if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(8, this)) {
showTutorialForFrontAndBack();
} else if (mSharedPreferences.getBoolean(ONBOARDING_CARD_FORMATTING_TOOLS, true)) {
} else if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(9, this)) {
showTutorialForFormattingTools();
}
}

public void showTutorialForFrontAndBack() {
new MaterialTapTargetPrompt.Builder(this)
.setTarget(R.id.CardEditorEditFieldsLayout)
.setPrimaryText("Enter card contents here")
.setSecondaryText("Enter the front part of card in 'Front' field and the answer in 'Back' field")
.setPrimaryText(this.getString(R.string.card_contents))
.setSecondaryText(this.getString(R.string.card_contents_desc))
.setPromptBackground(new DimmedRectanglePromptBackground())
.setPromptFocal(new RectanglePromptFocal())
.setPromptStateChangeListener((prompt, state) -> {
if (state == MaterialTapTargetPrompt.STATE_DISMISSED) {
if (mSharedPreferences.getBoolean(ONBOARDING_CARD_FORMATTING_TOOLS, true)) {
if (OnboardingUtils.INSTANCE.checkIfNotAlreadyVisited(9, this)) {
showTutorialForFormattingTools();
}
}
})
.show();

mSharedPreferences.edit().putBoolean(ONBOARDING_FRONT_AND_BACK, false).apply();
OnboardingUtils.INSTANCE.setAsVisited(8, this);
}

public void showTutorialForFormattingTools() {
new MaterialTapTargetPrompt.Builder(this)
.setTarget(R.id.editor_toolbar)
.setPrimaryText("Format content")
.setSecondaryText("Format your card's content using various formatting options")
.setPrimaryText(this.getString(R.string.format_content))
.setSecondaryText(this.getString(R.string.format_content_desc))
.setPromptBackground(new DimmedRectanglePromptBackground())
.setPromptFocal(new RectanglePromptFocal())
.show();

mSharedPreferences.edit().putBoolean(ONBOARDING_CARD_FORMATTING_TOOLS, false).apply();
OnboardingUtils.INSTANCE.setAsVisited(9, this);
}

@Override
Expand Down
14 changes: 0 additions & 14 deletions AnkiDroid/src/main/java/com/ichi2/anki/OnboardingConstants.kt

This file was deleted.

Loading

0 comments on commit a36bbc7

Please sign in to comment.