package org.wikipedia.onboarding;

import org.wikipedia.settings.Prefs;

public final class PrefsOnboardingStateMachine implements OnboardingStateMachine {
    private static final PrefsOnboardingStateMachine INSTANCE = new PrefsOnboardingStateMachine();

    private final boolean initialTocTutorialEnabled = Prefs.isTocTutorialEnabled();

    public static PrefsOnboardingStateMachine getInstance() {
        return INSTANCE;
    }

    @Override
    public boolean isTocTutorialEnabled() {
        return Prefs.isTocTutorialEnabled();
    }

    @Override
    public void setTocTutorial() {
        Prefs.setTocTutorialEnabled(false);
    }

    @Override
    public boolean isSelectTextTutorialEnabled() {
        return !initialTocTutorialEnabled && Prefs.isSelectTextTutorialEnabled();
    }

    @Override
    public void setSelectTextTutorial() {
        Prefs.setSelectTextTutorialEnabled(false);
    }

    @Override
    public boolean isShareTutorialEnabled() {
        return !initialTocTutorialEnabled
                && !isSelectTextTutorialEnabled()
                && Prefs.isShareTutorialEnabled();
    }

    @Override
    public void setShareTutorial() {
        Prefs.setShareTutorialEnabled(false);
    }

    private PrefsOnboardingStateMachine() { }
}
@@ -64,16 +64,54 @@
 s.Prefs;
+%0Aimport java.util.concurrent.TimeUnit;
 %0A%0Apublic
@@ -282,25 +282,24 @@
 eMachine();%0A
-%0A
     private 
@@ -302,78 +302,97 @@
 ate 
-final boolean initialTocTutorialEnabled = Prefs.isTocTutorialEnabled()
+static final long MIN_MINUTES_PER_TUTORIAL = 1;%0A%0A    private long millisSinceLastTutorial
 ;%0A%0A 
@@ -534,32 +534,155 @@
 rialEnabled() %7B%0A
+        // don't care about time since last tutorial here, since the ToC tooltip%0A        // is always the first one shown.%0A
         return P
@@ -802,32 +802,71 @@
 Enabled(false);%0A
+        updateTimeSinceLastTutorial();%0A
     %7D%0A%0A    @Over
@@ -932,32 +932,106 @@
      return 
-!initial
+minutesSinceLastTutorial() %3E= MIN_MINUTES_PER_TUTORIAL%0A               && !Prefs.is
 TocTutorialE
@@ -1036,16 +1036,18 @@
 lEnabled
+()
  && Pref
@@ -1185,32 +1185,71 @@
 Enabled(false);%0A
+        updateTimeSinceLastTutorial();%0A
     %7D%0A%0A    @Over
@@ -1311,23 +1311,151 @@
     
-return !initial
+// don't care about time since last tutorial here, since the share tooltip is%0A        // tied to the highlight action.%0A        return !Prefs.is
 TocT
@@ -1468,16 +1468,18 @@
 lEnabled
+()
 %0A       
@@ -1672,24 +1672,336 @@
 led(false);%0A
+        updateTimeSinceLastTutorial();%0A    %7D%0A%0A    private void updateTimeSinceLastTutorial() %7B%0A        millisSinceLastTutorial = System.currentTimeMillis();%0A    %7D%0A%0A    private long minutesSinceLastTutorial() %7B%0A        return TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - millisSinceLastTutorial);%0A
     %7D%0A%0A    p

Improve sequencing of ToC and Text-highlight tooltips.