-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
"Deck Search" display now same as the Deck Viewer #10389
"Deck Search" display now same as the Deck Viewer #10389
Conversation
instead of displaying the entire deck path, now only the subdeck name is displayed along with appropriate indentation. Deck and subdeck creation works just like before.
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You asked for a thorough review. Hope this helps!
My only other comment would be that it'd be great to get a unit test on .displayName
, optional, but nice to have.
constructor(deckId: Long, name: String) { | ||
this.deckId = deckId | ||
this.name = name | ||
this.displayName = getDisplayName(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically want to avoid performing work in a constructor. I'd advise having displayName
as a get()
property
Potentially use lazy { }
so it's only evaluated once: https://kotlinlang.org/docs/delegated-properties.html#lazy-properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using get()
like this fine?
val displayName: String
get() {
return getDisplayName(name)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the only issue is that displayName
is calculated more than once if it's called more than once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried writing this as:
val displayName: String by lazy { getDisplayName(name)}
But, it gave me an error: Variable 'name' must be initialized
, but name
is already initialised, so I don't know what's wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lazy option: Go with get()
and leave a comment that it should be a lazy
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
Yep, it does! I'll make the changes soon. For the unit test, are there any docs I could look at to see how to get those? Don't know a lot about them. |
I had also difficulty in implementing test earlier but now I can implement test. My general workflow for implementing test class
@Test
fun testMediaIsNotExpected() {
// #0096 - Anki Desktop did not expect media.
val input = "ya[sound:36_ya.mp3]<div><img src=\"paste-efbfdfbff329f818e3b5568e578234d0d0054067.png\" /><br /></div>"
val expected = "ya"
val actual: String = cleanCorrectAnswer(input)
MatcherAssert.assertThat(actual, Matchers.equalTo(expected))
} Docs May be I missed something above, so google it or chat in discord. |
@krmanik That is really helpful! Thank you so much! I will let you know if I have other doubts. |
refactored comments as suggested. Optimized function `getDisplayName()` as suggested. `displayName` is now a val not a var, and is a `get()` property. to do next: add test.
Resolved all the changes suggested. PR not final, will add a test in the next commit. (Or, can add a test in another PR, either way fine with me. ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
Started working on the test, I think I'm making good progress. Will address the comments along with it. It should be done by tomorrow. If so, we can add it do this PR, otherwise, will let you know! :) |
I made a test file, which looks like this: @RunWith(AndroidJUnit4::class)
class DeckSelectionDialogTest: RobolectricTest() {
@Test
fun verifyDeckDisplayName() {
val input = "deck::sub-deck::sub-deck2::sub-deck3"
val expected = "\t\t\t\t\t\tsub-deck3"
val deck = SelectableDeck(1234, input)
val actual: String = deck.displayName
assertThat(actual, Matchers.equalTo(expected))
}
} When I try to run this test (or any other test) like
Is this a problem with my machine? How should I run these tests otherwise? |
@viciousAegis This is a bug on our side. We do not build I have an M1 Mac arriving sometime late March, so I'll be personally invested in testing As a workaround:
As a workaround, please enable GitHub actions on your GitHub clone of Properly fixing thisIssue
Please see: https://github.com/ankidroid/Anki-Android-Backend/tree/main/rsdroid-testing
|
Alternatively: run the test somehow under Rosetta2? Github Actions does not have any M1 runners unfortunately, and no concrete plans to add them. I have an M1 mac though and can likely generate the libraries if it had to build on an M1 mac. I think cross-compiling is possible though, to an M1 mac target (arm64e as you mention) from an intel macos github action runner assuming it has the right toolchain stuff setup, that's what the code link above seems to do, and it should be a good path forward Not sure if there are better ways to do this but here's a shell way to detect architecture (and Rosetta2 execution status, if needed), may help if [ "$(uname)" == "Darwin" ]; then
# We do not want to run under Rosetta 2, brew doesn't work and compiles might not work after
arch_name="$(uname -m)"
if [ "${arch_name}" = "x86_64" ]; then
if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then
echo "Running on Rosetta 2"
echo "This is not supported. Run \`env /usr/bin/arch -arm64 /bin/bash --login\` then try again"
exit 1
else
echo "Running on native Intel"
fi
elif [ "${arch_name}" = "arm64" ]; then
echo "Running on ARM"
else
echo "Unknown architecture: ${arch_name}"
fi
fi |
We should be able to cross-compile Rust for and installing the target platform: https://github.com/ankidroid/Anki-Android-Backend/blob/9302b3f89e09643e95c42166743f8563a3822ddc/.github/scripts/install_rust_robolectric_targets.sh And then:
Note that |
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckSelectionDialog.kt
Outdated
Show resolved
Hide resolved
I think this PR should be complete now, will move onto figuring out implementing tests on the m1 mac. Please review one final time for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Nice! |
Hi there! FEBRUARY OpenCollective Notice Just a friendly notice that we try to process OpenCollective payments monthly - it's time for February 2022 submissions (I'll do my best to follow this with the same process for March in a week) If you are interested in compensation for this work, the process with details is here: (I only post one comment per person to avoid spamming you, regardless of the number of PRs merged, but this note applies to all PRs merged for in the month of January) Thanks! |
Pull Request template
Purpose / Description
As described in #10378, the way decks are currently displayed in the "Deck Search" subscreen is not intuitive nor easy to understand, especially with multiple subdeck levels. This PR aims to make it more user friendly by indenting decks the same way as the main "Deck Viewer" screen.
EDIT: Also added a test for the same.
I feel the code can be better formatted and commented.
Fixes
Fixes #10378
Approach
instead of displaying the entire deck path, now only the subdeck name is displayed along with appropriate indentation. Deck and subdeck creation works just like before.
Before
After
Video showing creation of subdecks:
Video showing search capability:
WhatsApp.Video.2022-02-24.at.1.01.13.PM.mp4
How Has This Been Tested?
Emulator:
Pixel 5 API 32
Device:
Xaomi Redmi Note 8 Pro API 28 (Android 9)
Checklist
Please, go through these checks before submitting the PR.
if
statements)