Skip to content

Commit

Permalink
Reviewer: Resume fullscreen after interaction
Browse files Browse the repository at this point in the history
* Command
* Flip Card
* Answer Card

Fixes 7643
  • Loading branch information
david-allison authored and mikehardy committed Jan 28, 2021
1 parent 5ed7eb0 commit 7459828
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
10 changes: 10 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
77 changes: 76 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/anki/ReviewerNoParamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 */
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();

Expand All @@ -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;
}
}
}
5 changes: 1 addition & 4 deletions AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -247,7 +245,6 @@ public void baseDeckName() {
waitForAsyncTasksToComplete();
assertThat(reviewer.getSupportActionBar().getTitle(), is("B"));
}


private void toggleWhiteboard(ReviewerForMenuItems reviewer) {
reviewer.toggleWhiteboard();
Expand Down Expand Up @@ -368,7 +365,7 @@ private <T extends Reviewer> T startReviewer(Class<T> clazz) {
return startReviewer(this, clazz);
}

private static <T extends Reviewer> T startReviewer(RobolectricTest testClass, Class<T> clazz) {
public static <T extends Reviewer> T startReviewer(RobolectricTest testClass, Class<T> clazz) {
T reviewer = startActivityNormallyOpenCollectionWithIntent(testClass, clazz, new Intent());
waitForAsyncTasksToComplete();
return reviewer;
Expand Down

0 comments on commit 7459828

Please sign in to comment.