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

JS API to know if answer is displaying or question #8199

Merged
merged 2 commits into from
Mar 14, 2021

Conversation

krmanik
Copy link
Member

@krmanik krmanik commented Mar 14, 2021

Pull Request template

Purpose / Description

Describe the problem or feature and motivation

It will be easier to know when question is displaying and answer using js api. I am implementing addon sometime card content only need to added to front side and some time to back side. So, there are no api to know the side of card.

Fixes

Fixes Link to the issues.

Approach

  1. Using JavascriptInterface
  2. Using AbstractFlashcardViewer::isDisplayingAnswer()

How Has This Been Tested?

  1. Tested on Nexus 5 emulator
  2. Add following to front/back side of card template to know if card currently displaying answer
console.log(AnkiDroidJS.ankiIsDisplayingAnswer());

Return value: true or false

Learning (optional, can help others)

https://developer.android.com/reference/android/webkit/JavascriptInterface

Checklist

Please, go through these checks before submitting the PR.

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

@codecov
Copy link

codecov bot commented Mar 14, 2021

Codecov Report

Merging #8199 (91bf179) into master (4481bad) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #8199      +/-   ##
============================================
- Coverage     37.04%   37.02%   -0.03%     
  Complexity     3776     3776              
============================================
  Files           352      352              
  Lines         35739    35740       +1     
  Branches       4732     4732              
============================================
- Hits          13239    13232       -7     
- Misses        20992    21001       +9     
+ Partials       1508     1507       -1     
Impacted Files Coverage Δ Complexity Δ
...n/java/com/ichi2/anki/AbstractFlashcardViewer.java 39.44% <0.00%> (-0.03%) 166.00 <0.00> (ø)
...src/main/java/com/ichi2/anki/CollectionHelper.java 29.31% <0.00%> (-2.59%) 21.00% <0.00%> (ø%)
...Droid/src/main/java/com/ichi2/libanki/Storage.java 31.83% <0.00%> (-1.80%) 18.00% <0.00%> (ø%)
...java/com/ichi2/anki/dialogs/CustomStudyDialog.java 32.45% <0.00%> (-1.32%) 11.00% <0.00%> (ø%)
...iDroid/src/main/java/com/ichi2/libanki/Finder.java 79.00% <0.00%> (-0.41%) 138.00% <0.00%> (ø%)
...src/main/java/com/ichi2/libanki/sched/SchedV2.java 81.20% <0.00%> (-0.15%) 401.00% <0.00%> (-1.00%)
.../src/main/java/com/ichi2/async/CollectionTask.java 36.75% <0.00%> (+0.22%) 16.00% <0.00%> (ø%)
AnkiDroid/src/main/java/com/ichi2/libanki/DB.java 87.60% <0.00%> (+0.82%) 42.00% <0.00%> (+1.00%)
...roid/src/main/java/com/ichi2/utils/JSONObject.java 49.16% <0.00%> (+1.66%) 31.00% <0.00%> (ø%)
...id/src/main/java/com/ichi2/utils/VersionUtils.java 21.62% <0.00%> (+5.40%) 1.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 330353c...91bf179. Read the comment docs.

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 works for me - thanks @infinyte7 - and thank you (again) for your infinite patience on reviewing the JS add-on PR.

@mikehardy mikehardy added the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Mar 14, 2021
@mikehardy mikehardy added this to the 2.15 release milestone Mar 14, 2021
@mikehardy mikehardy merged commit 5f71d96 into ankidroid:master Mar 14, 2021
@mikehardy mikehardy removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Mar 14, 2021
@krmanik krmanik deleted the js-api-isDisplayAnswer branch March 14, 2021 22:34
haran2248 pushed a commit to haran2248/Anki-Android that referenced this pull request Mar 20, 2021
@mikehardy
Copy link
Member

Hi there!

Just a friendly notice (one per person for PRs merged in March, regardless of PR quantity) that we try to process OpenCollective payments monthly - it's time for March 2021 submissions

If you are interested in compensation for this work, the process with details is here:

https://github.com/ankidroid/Anki-Android/wiki/OpenCollective-Payment-Process#how-to-get-paid

Thanks!

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