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

refactor: Automatic Display Answer #9631

Merged
merged 15 commits into from
Oct 13, 2021

Conversation

david-allison
Copy link
Member

@david-allison david-allison commented Oct 13, 2021

Purpose / Description

Refactor to remove more code from the CardViewer

Fixes

Pre #2609

How Has This Been Tested?

Unit tested, and it seems to work. I've added follow on commits (not pushed yet) with more functionality, and these work

Checklist

  • You have not changed whitespace unnecessarily (it makes diffs hard to read)
  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • Your code follows the style of the project (e.g. never omit braces in if statements)
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

The method is always called from onCollectionLoaded

so we can remove a dependency
Extracts "onCollectionLoadError" to a method to remove duplicated code

restoreCollectionPreferences:

If an exception occurs, this will be because there is a problem
with the collection, or a problem with the data

Either way, we want to return to the deck picker
We're going to add functionality here, and this is the first step to
making this change easier to reason about.

Removes two variables from AbstractFlashcardViewer
Removes 4 variables in AbstractFlashcardViewer
on DisplayCardQuestion, we used to check to see
which options to use. But these don't change
(mOptUseGeneralTimerSettings is loaded in onCollectionLoaded)

So we can remove the code, effectively keeping the class as a constant

preferences are loaded onCreate
collection is loaded onCollectionLoaded
Move loading the concern into its class
Move the generation logic into its own class

This moves the initialisation of the class from onCreate
to onCollectionLoaded

This seems sensible, and removes the need for double initialization
Removes mTimeoutHandler from AbstractFlashcardViewer

This is an incremental (bad) refactoring

Now we've removed the handler, we can move most of the internal
logic into the AutomaticAnswerSettings class

This will let us make more methods private
moves more behavior inside the object

Still not too well factored, but getting there
moves more behavior inside the object

By default, we start the timer after all media has played

If we are reading text, we don't calculate the time it takes.
Instead, we wait for the text to complete before we display Q/A

Allows us to make settings private
moves more behavior inside the object

Allows us to make settings private
Split out settings from the answerer
refactor easy methods out of the reviewer

getBackgroundColors
getTextColors
Even if a media delay is provided, there should be no auto answer
if the times are set to 0s
@david-allison
Copy link
Member Author

This should make #9170 a "good first issue" when it's in.

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all look fine - I hate to say "while you're in there..." but there's no better case of it with regard to finally put #2609 in and this probably blew apart the existing (dormant) PR

@mikehardy mikehardy merged commit 9c41742 into ankidroid:master Oct 13, 2021
@david-allison david-allison deleted the 2609-refactor branch October 13, 2021 16:32
@david-allison
Copy link
Member Author

Already got that ready for when this merges

@mikehardy
Copy link
Member

That's huge! So many people want that

@mikehardy mikehardy added this to the 2.16 release milestone Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants