diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java index 52c7f21af6ba..e0a5b32300e5 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java @@ -894,7 +894,8 @@ protected int getContentViewAttr(int fullscreenMode) { return R.layout.reviewer; } - protected boolean isFullscreen() { + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + boolean isFullscreen() { return !getSupportActionBar().isShowing(); } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java b/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java index 0ad173add24d..fc0722a06724 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java @@ -302,6 +302,8 @@ protected void onCollectionLoaded(Collection col) { @Override public boolean onOptionsItemSelected(MenuItem item) { + // 100ms was not enough on my device (Honor 9 Lite - Android Pie) + delayedHide(1000); if (getDrawerToggle().onOptionsItemSelected(item)) { return true; } @@ -974,9 +976,16 @@ public void fillFlashcard() { public void displayCardQuestion() { // show timer, if activated in the deck's preferences initTimer(); + delayedHide(100); super.displayCardQuestion(); } + @Override + protected void displayCardAnswer() { + delayedHide(100); + super.displayCardAnswer(); + } + @Override protected void initLayout() { mTextBarNew = findViewById(R.id.new_number); @@ -1057,6 +1066,7 @@ public void handleMessage(Message msg) { } }; + /** Hide the navigation if in full-screen mode after a given period of time */ protected void delayedHide(int delayMillis) { Timber.d("Fullscreen delayed hide in %dms", delayMillis); mFullScreenHandler.removeMessages(0); diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.java b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.java index 8e1403d44fa5..45a31abcb9b8 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.java +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.java @@ -18,6 +18,7 @@ import android.graphics.Color; +import com.ichi2.anki.cardviewer.ViewerCommand; import com.ichi2.anki.model.WhiteboardPenColor; import com.ichi2.libanki.Consts; @@ -30,6 +31,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; /** A non-parmaterized ReviewerTest - we should probably rename ReviewerTest in future */ @@ -117,6 +119,61 @@ public void differentDeckPenColorDoesNotAffectCurrentDeck() { } + @Test + public void flippingCardHidesFullscreen() { + addNoteUsingBasicModel("Hello", "World"); + ReviewerExt reviewer = startReviewerFullScreen(); + + int hideCount = reviewer.getDelayedHideCount(); + + reviewer.displayCardAnswer(); + + assertThat("Hide should be called after flipping a card", reviewer.getDelayedHideCount(), greaterThan(hideCount)); + } + + + @Test + public void showingCardHidesFullScreen() { + addNoteUsingBasicModel("Hello", "World"); + ReviewerExt reviewer = startReviewerFullScreen(); + + reviewer.displayCardAnswer(); + advanceRobolectricLooperWithSleep(); + + int hideCount = reviewer.getDelayedHideCount(); + + reviewer.answerCard(1); + advanceRobolectricLooperWithSleep(); + + assertThat("Hide should be called after answering a card", reviewer.getDelayedHideCount(), greaterThan(hideCount)); + } + + @Test + public void undoingCardHidesFullScreen() { + addNoteUsingBasicModel("Hello", "World"); + ReviewerExt reviewer = startReviewerFullScreen(); + + reviewer.displayCardAnswer(); + advanceRobolectricLooperWithSleep(); + reviewer.answerCard(1); + advanceRobolectricLooperWithSleep(); + + int hideCount = reviewer.getDelayedHideCount(); + + reviewer.executeCommand(ViewerCommand.COMMAND_UNDO); + advanceRobolectricLooperWithSleep(); + + + assertThat("Hide should be called after answering a card", reviewer.getDelayedHideCount(), greaterThan(hideCount)); + } + + + private ReviewerExt startReviewerFullScreen() { + AnkiDroidApp.getSharedPrefs(getTargetContext()).edit().putString("fullscreenMode", "1").apply(); + ReviewerExt reviewer = ReviewerTest.startReviewer(this, ReviewerExt.class); + return reviewer; + } + protected void storeDarkModeColor(@SuppressWarnings("SameParameterValue") int value) { MetaDB.storeWhiteboardPenColor(getTargetContext(), Consts.DEFAULT_DECK_ID, false, value); } @@ -144,7 +201,7 @@ protected Whiteboard startReviewerForWhiteboard() { // we need a card for the reviewer to start addNoteUsingBasicModel("Hello", "World"); - Reviewer reviewer = ReviewerTest.startReviewer(this); + Reviewer reviewer = startReviewer(); reviewer.toggleWhiteboard(); @@ -155,4 +212,22 @@ protected Whiteboard startReviewerForWhiteboard() { return whiteboard; } + + private Reviewer startReviewer() { + return ReviewerTest.startReviewer(this); + } + + private static class ReviewerExt extends Reviewer { + + int mDelayedCount = 0; + @Override + protected void delayedHide(int delayMillis) { + mDelayedCount++; + super.delayedHide(delayMillis); + } + + public int getDelayedHideCount() { + return mDelayedCount; + } + } } diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.java b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.java index 78d686617aae..dbc9e5797382 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.java +++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.java @@ -13,7 +13,6 @@ import com.ichi2.libanki.Card; import com.ichi2.libanki.Collection; import com.ichi2.libanki.Consts; -import com.ichi2.libanki.Deck; import com.ichi2.libanki.Decks; import com.ichi2.libanki.Model; import com.ichi2.libanki.Models; @@ -48,7 +47,6 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assume.assumeTrue; @RunWith(ParameterizedRobolectricTestRunner.class) public class ReviewerTest extends RobolectricTest { @@ -247,7 +245,6 @@ public void baseDeckName() { waitForAsyncTasksToComplete(); assertThat(reviewer.getSupportActionBar().getTitle(), is("B")); } - private void toggleWhiteboard(ReviewerForMenuItems reviewer) { reviewer.toggleWhiteboard(); @@ -368,7 +365,7 @@ private T startReviewer(Class clazz) { return startReviewer(this, clazz); } - private static T startReviewer(RobolectricTest testClass, Class clazz) { + public static T startReviewer(RobolectricTest testClass, Class clazz) { T reviewer = startActivityNormallyOpenCollectionWithIntent(testClass, clazz, new Intent()); waitForAsyncTasksToComplete(); return reviewer;