Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: borders on fullscreen Reviewer #9278

Merged
merged 4 commits into from Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -103,6 +103,7 @@
import com.ichi2.anki.receiver.SdCardReceiver;
import com.ichi2.anki.reviewer.CardMarker;
import com.ichi2.anki.cardviewer.CardTemplate;
import com.ichi2.anki.reviewer.FullScreenMode;
import com.ichi2.anki.reviewer.ReviewerCustomFonts;
import com.ichi2.anki.reviewer.ReviewerUi;
import com.ichi2.anki.cardviewer.TypedAnswer;
Expand Down Expand Up @@ -161,8 +162,6 @@

import timber.log.Timber;

import static com.ichi2.anki.Preferences.BUTTONS_AND_MENU;
import static com.ichi2.anki.Preferences.FULL_SCREEN_MODE;
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 @@ -237,7 +236,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity i
private boolean mPrefShowTopbar;
private boolean mShowTimer;
protected boolean mPrefWhiteboard;
private int mPrefFullscreenReview;
private FullScreenMode mPrefFullscreenReview = FullScreenMode.getDEFAULT();
private int mRelativeButtonSize;
private boolean mDoubleScrolling;
private boolean mScrollingButtons;
Expand Down Expand Up @@ -954,7 +953,12 @@ protected void onCreate(Bundle savedInstanceState) {
mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
}

protected int getContentViewAttr(int fullscreenMode) {
@NonNull
protected FullScreenMode getFullscreenMode() {
return mPrefFullscreenReview;
}

protected int getContentViewAttr(FullScreenMode fullscreenMode) {
return R.layout.reviewer;
}

Expand Down Expand Up @@ -1917,7 +1921,7 @@ protected SharedPreferences restorePreferences() {
// On newer Androids, ignore this setting, which should be hidden in the prefs anyway.
mDisableClipboard = "0".equals(preferences.getString("dictionary", "0"));
// mDeckFilename = preferences.getString("deckFilename", "");
mPrefFullscreenReview = Integer.parseInt(preferences.getString(FULL_SCREEN_MODE, BUTTONS_AND_MENU));
mPrefFullscreenReview = FullScreenMode.fromPreference(preferences);
mRelativeButtonSize = preferences.getInt("answerButtonSize", 100);
mSpeakText = preferences.getBoolean("tts", false);
mPrefUseTimer = preferences.getBoolean("timeoutAnswer", false);
Expand Down
18 changes: 2 additions & 16 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.java
Expand Up @@ -108,6 +108,7 @@
import com.ichi2.anki.exception.ConfirmModSchemaException;
import com.ichi2.anki.exception.FilteredAncestor;
import com.ichi2.anki.receiver.SdCardReceiver;
import com.ichi2.anki.reviewer.FullScreenMode;
import com.ichi2.anki.stats.AnkiStatsTaskHandler;
import com.ichi2.anki.web.HostNumFactory;
import com.ichi2.anki.widgets.DeckAdapter;
Expand Down Expand Up @@ -149,9 +150,6 @@

import timber.log.Timber;

import static com.ichi2.anki.Preferences.BUTTONS_AND_MENU;
import static com.ichi2.anki.Preferences.BUTTONS_ONLY;
import static com.ichi2.anki.Preferences.FULL_SCREEN_MODE;
import static com.ichi2.async.Connection.ConflictResolution.FULL_DOWNLOAD;

import static com.ichi2.anim.ActivityTransitionAnimation.Direction.*;
Expand Down Expand Up @@ -1379,19 +1377,7 @@ private void upgradePreferences(long previousVersionCode) {
preferences.edit().remove("intentAdditionInstantAdd").apply();
}

if (preferences.contains("fullscreenReview")) {
Timber.i("Old version of Anki - Fixing Fullscreen");
// clear fullscreen flag as we use a integer
try {
boolean old = preferences.getBoolean("fullscreenReview", false);
preferences.edit().putString(FULL_SCREEN_MODE, old ? BUTTONS_ONLY: BUTTONS_AND_MENU).apply();
} catch (ClassCastException e) {
Timber.w(e);
// TODO: can remove this catch as it was only here to fix an error in the betas
preferences.edit().remove(FULL_SCREEN_MODE).apply();
}
preferences.edit().remove("fullscreenReview").apply();
}
FullScreenMode.upgradeFromLegacyPreference(preferences);
}

private UndoTaskListener undoTaskListener(boolean isReview) {
Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.drakeet.drawer.FullDraggableContainer;
import com.google.android.material.navigation.NavigationView;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
Expand Down Expand Up @@ -85,11 +86,11 @@ public abstract class NavigationDrawerActivity extends AnkiActivity implements N
private Runnable mPendingRunnable;

@Override
public void setContentView(int layoutResID) {
public void setContentView(@LayoutRes int layoutResID) {
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());

// Using ClosableDrawerLayout as a parent view.
ClosableDrawerLayout closableDrawerLayout = (ClosableDrawerLayout) LayoutInflater.from(this).inflate(R.layout.navigation_drawer_layout, null, false);
ClosableDrawerLayout closableDrawerLayout = (ClosableDrawerLayout) LayoutInflater.from(this).inflate(getNavigationDrawerLayout(), null, false);
// Get CoordinatorLayout using resource ID
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) LayoutInflater.from(this).inflate(layoutResID, closableDrawerLayout, false);
if (preferences.getBoolean(FULL_SCREEN_NAVIGATION_DRAWER, false)) {
Expand All @@ -106,6 +107,15 @@ public void setContentView(int layoutResID) {
setContentView(closableDrawerLayout);
}

private @LayoutRes int getNavigationDrawerLayout() {
return fitsSystemWindows() ? R.layout.navigation_drawer_layout : R.layout.navigation_drawer_layout_fullscreen;
mikehardy marked this conversation as resolved.
Show resolved Hide resolved
}

/** Whether android:fitsSystemWindows="true" should be applied to the navigation drawer */
protected boolean fitsSystemWindows() {
return true;
}

// Navigation drawer initialisation
protected void initNavigationDrawer(View mainView) {
// Create inherited navigation drawer layout here so that it can be used by parent class
Expand Down
28 changes: 3 additions & 25 deletions AnkiDroid/src/main/java/com/ichi2/anki/Preferences.java
Expand Up @@ -47,6 +47,7 @@
import com.ichi2.anki.debug.DatabaseLock;
import com.ichi2.anki.exception.ConfirmModSchemaException;
import com.ichi2.anki.exception.StorageAccessException;
import com.ichi2.anki.reviewer.FullScreenMode;
import com.ichi2.anki.services.BootService;
import com.ichi2.anki.services.NotificationService;
import com.ichi2.anki.web.CustomSyncServer;
Expand Down Expand Up @@ -161,29 +162,6 @@ public class Preferences extends AppCompatPreferenceActivity implements Preferen
*/
private static final String SCHED_VER = "schedVer";

/**
* Whether the reviewer content should take the full screen. Its possible values are defined just below.
*/
public static final String FULL_SCREEN_MODE = "fullscreenMode";

public static final String BUTTONS_AND_MENU = "0";
/**
* Remove the menu bar, keeps answer button.
*/
public static final String BUTTONS_ONLY = "1";
/**
* Remove both menu bar and buttons. Can only be set if gesture is on.
*/
public static final String FULLSCREEN_ALL_GONE = "2";

@Retention(SOURCE)
@StringDef({
BUTTONS_AND_MENU,
BUTTONS_ONLY,
FULLSCREEN_ALL_GONE
})
public @interface REVIEWER_SCREEN_MODE {}

/**
* The number of cards that should be due today in a deck to justify adding a notification.
*/
Expand Down Expand Up @@ -323,10 +301,10 @@ private void initSubscreen(String action, PreferenceContext listener) {
screen = listener.getPreferenceScreen();
// Show error toast if the user tries to disable answer button without gestures on
android.preference.ListPreference fullscreenPreference = (android.preference.ListPreference)
screen.findPreference(FULL_SCREEN_MODE);
screen.findPreference(FullScreenMode.PREF_KEY);
fullscreenPreference.setOnPreferenceChangeListener((preference, newValue) -> {
SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(Preferences.this);
if (prefs.getBoolean("gestures", false) || !FULL_SCREEN_MODE.equals(newValue)) {
if (prefs.getBoolean("gestures", false) || !FullScreenMode.FULLSCREEN_ALL_GONE.getPreferenceValue().equals(newValue)) {
return true;
} else {
UIUtils.showThemedToast(getApplicationContext(),
Expand Down
23 changes: 13 additions & 10 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java
Expand Up @@ -68,6 +68,7 @@
import com.ichi2.anki.dialogs.ConfirmationDialog;
import com.ichi2.anki.multimediacard.AudioView;
import com.ichi2.anki.dialogs.RescheduleDialog;
import com.ichi2.anki.reviewer.FullScreenMode;
import com.ichi2.anki.reviewer.PeripheralKeymap;
import com.ichi2.anki.reviewer.ReviewerUi;
import com.ichi2.anki.workarounds.FirefoxSnackbarWorkaround;
Expand All @@ -93,9 +94,6 @@

import timber.log.Timber;

import static com.ichi2.anki.Preferences.BUTTONS_AND_MENU;
import static com.ichi2.anki.Preferences.FULLSCREEN_ALL_GONE;
import static com.ichi2.anki.Preferences.FULL_SCREEN_MODE;
import static com.ichi2.anki.reviewer.CardMarker.*;
import static com.ichi2.anim.ActivityTransitionAnimation.Direction.*;

Expand Down Expand Up @@ -256,17 +254,22 @@ protected void setTitle() {
}

@Override
protected int getContentViewAttr(int fullscreenMode) {
protected int getContentViewAttr(FullScreenMode fullscreenMode) {
switch (fullscreenMode) {
case 1:
case BUTTONS_ONLY:
return R.layout.reviewer_fullscreen;
case 2:
case FULLSCREEN_ALL_GONE:
return R.layout.reviewer_fullscreen_noanswers;
default:
return R.layout.reviewer;
}
}

@Override
protected boolean fitsSystemWindows() {
return getFullscreenMode().isFullScreenReview();
}

@Override
protected void onCollectionLoaded(Collection col) {
super.onCollectionLoaded(col);
Expand Down Expand Up @@ -956,7 +959,7 @@ protected SharedPreferences restorePreferences() {
mPrefHideDueCount = preferences.getBoolean("hideDueCount", false);
mPrefShowETA = preferences.getBoolean("showETA", true);
this.mProcessor.setup();
mPrefFullscreenReview = Integer.parseInt(preferences.getString(FULL_SCREEN_MODE, BUTTONS_AND_MENU)) > 0;
mPrefFullscreenReview = FullScreenMode.isFullScreenReview(preferences);
mActionButtons.setup(preferences);
return preferences;
}
Expand Down Expand Up @@ -1141,7 +1144,7 @@ private void setFullScreen(final AbstractFlashcardViewer a) {
);
// Show / hide the Action bar together with the status bar
SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(a);
final @Preferences.REVIEWER_SCREEN_MODE String fullscreenMode = prefs.getString(FULL_SCREEN_MODE, BUTTONS_AND_MENU);
FullScreenMode fullscreenMode = FullScreenMode.fromPreference(prefs);
a.getWindow().setStatusBarColor(Themes.getColorFromAttr(a, R.attr.colorPrimaryDark));
View decorView = a.getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
Expand All @@ -1158,13 +1161,13 @@ private void setFullScreen(final AbstractFlashcardViewer a) {
Timber.d("System UI visibility change. Visible: %b", visible);
if (visible) {
showViewWithAnimation(toolbar);
if (fullscreenMode.equals(FULLSCREEN_ALL_GONE)) {
if (fullscreenMode.equals(FullScreenMode.FULLSCREEN_ALL_GONE)) {
showViewWithAnimation(topbar);
showViewWithAnimation(answerButtons);
}
} else {
hideViewWithAnimation(toolbar);
if (fullscreenMode.equals(FULLSCREEN_ALL_GONE)) {
if (fullscreenMode.equals(FullScreenMode.FULLSCREEN_ALL_GONE)) {
hideViewWithAnimation(topbar);
hideViewWithAnimation(answerButtons);
}
Expand Down
67 changes: 67 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/reviewer/FullScreenMode.kt
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2021 David Allison <davidallisongithub@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ichi2.anki.reviewer

import android.content.SharedPreferences
import timber.log.Timber

/** Whether Reviewer content should take the full screen */
enum class FullScreenMode(private val mPrefValue: String) {

/** Display both navigation and buttons (default) */
BUTTONS_AND_MENU("0"),
/** Remove the menu bar, keeps answer button. */
BUTTONS_ONLY("1"),
/** Remove both menu bar and buttons. Can only be set if gesture is on. */
FULLSCREEN_ALL_GONE("2");

fun getPreferenceValue() = mPrefValue
fun isFullScreenReview() = this != BUTTONS_AND_MENU

companion object {
const val PREF_KEY = "fullscreenMode"
@JvmStatic
val DEFAULT = BUTTONS_AND_MENU

@JvmStatic
fun fromPreference(prefs: SharedPreferences): FullScreenMode {
val value = prefs.getString(PREF_KEY, DEFAULT.mPrefValue)
return enumValues<FullScreenMode>().firstOrNull { it.mPrefValue == value } ?: DEFAULT
}

@JvmStatic
fun isFullScreenReview(prefs: SharedPreferences): Boolean =
fromPreference(prefs).isFullScreenReview()

@JvmStatic
fun upgradeFromLegacyPreference(preferences: SharedPreferences) {
if (!preferences.contains("fullscreenReview")) return

Timber.i("Old version of Anki - Fixing Fullscreen")
// clear fullscreen flag as we use a integer
val fullScreenModeKey = PREF_KEY
val old = preferences.getBoolean("fullscreenReview", false)
val newValue = if (old) BUTTONS_ONLY else BUTTONS_AND_MENU
preferences.edit().putString(fullScreenModeKey, newValue.getPreferenceValue()).apply()
preferences.edit().remove("fullscreenReview").apply()
}

@JvmStatic
fun setPreference(prefs: SharedPreferences, mode: FullScreenMode) {
prefs.edit().putString(PREF_KEY, mode.getPreferenceValue()).apply()
}
}
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.ClosableDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/navigation_drawer" />
</androidx.drawerlayout.widget.ClosableDrawerLayout>
Expand Up @@ -17,13 +17,15 @@
package com.ichi2.anki;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;

import com.ichi2.anki.cardviewer.Gesture;
import com.ichi2.anki.cardviewer.GestureProcessor;
import com.ichi2.anki.cardviewer.ViewerCommand;
import com.ichi2.anki.model.WhiteboardPenColor;
import com.ichi2.anki.reviewer.FullScreenMode;
import com.ichi2.libanki.Consts;

import net.ankiweb.rsdroid.database.NotImplementedException;
Expand All @@ -38,8 +40,6 @@
import androidx.annotation.NonNull;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import static com.ichi2.anki.Preferences.BUTTONS_ONLY;
import static com.ichi2.anki.Preferences.FULL_SCREEN_MODE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -308,7 +308,8 @@ private String getKey(Gesture gesture) {
}

private ReviewerExt startReviewerFullScreen() {
AnkiDroidApp.getSharedPrefs(getTargetContext()).edit().putString(FULL_SCREEN_MODE, BUTTONS_ONLY).apply();
SharedPreferences sharedPrefs = AnkiDroidApp.getSharedPrefs(getTargetContext());
FullScreenMode.setPreference(sharedPrefs, FullScreenMode.BUTTONS_ONLY);
ReviewerExt reviewer = ReviewerTest.startReviewer(this, ReviewerExt.class);
return reviewer;
}
Expand Down