-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Feat: Add path picker GUI #19855
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
base: main
Are you sure you want to change the base?
Feat: Add path picker GUI #19855
Conversation
|
@david-allison I did apply your patch for this, but I wasn't sure if you were planning on making a pr for it since I didn't really do much so if you are then I will close this. Otherwise, if there's more changes to be made UI wise, I'd be happy to continue working on it |
|
It's been a long while, thanks!!
I don't recall my patch, but I wasn't planning on submitting it any time soon, thanks for seeing it through!! |
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
|
Will resolve all the changes, I thought I had reacted sorry TT |
a8d65c5 to
7957d5d
Compare
|
The new UI look for the changes I just made are: While using android 10 (i.e. no scoped storage) While using android 15 (playDebug) While using android 15 (fullDebug) Note: it looks truncated but you can scroll down there, as seen in the videos |
|
There should be enough space on the screen that it doesn't need to be truncated |
Do you think it would be better to reduce the existing text like say shorten it by removing "/storage/emulated/0" or should I resize the dialog altogether, the latter will have a lot of changes since the only method I've found is to make a subclass of ListPreferenceTrait and use setlayout there to change the size according to the screen |
7957d5d to
bb41f23
Compare
|
Screen_recording_20251221_044059.webm |
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
|
@david-allison just a reminder since the needs author reply tag wasn't removed ^^ |
|
Still on my to-do list, I'll get to it shortly! |
david-allison
left a comment
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.
- Select Custom Path
/storage/emulated/0/Android/data/com.ichi2.anki.debug/files/AnkiDroi
- Open Dialog Again
- 🪲 Dialog does not show the current path as an option
- 🪲 Selecting the top option does not apply the provided path
I would move the 'custom path' to a button at the bottom of the screen, with a very brief name. This means it won't be truncated at the bottom of the list if there's a number of entries
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
bb41f23 to
ab78a9d
Compare
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
|
Screen_recording_20251222_221717.webm Edit: video seems to be buffering, hope its just on my end |
david-allison
left a comment
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.
My main concern is that the logic to switch between EditText and ListPreference is complicated.
Could you look into alternate solutions which require fewer variables/state?
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
| fun findAnkiDroidSubDirectories(f: File): List<File> { | ||
| // either returns '/AnkiDroid1...AnkiDroid100' from storage migration | ||
| // OR returns '/AnkiDroid' if no directories are available | ||
| val found = f.listFiles(ANKI_DIR_FILTER)?.toList() | ||
| return if (!found.isNullOrEmpty()) { | ||
| found | ||
| } else { | ||
| listOf(File(f, "AnkiDroid")) | ||
| } | ||
| } |
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.
This isn't good logic: multiprofile support needs to be considered, as does someone creating a custom directory on their SD Card/External Stroage via USB
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.
This was the only thing I wasn't sure about, with the new commit it should handle custom directories with the custompath var but as for multiprofile, I believe we haven't implemented it yet so I wasn't sure how to handle support for it, maybe I could put a TODO for multiprofile support.
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
|
I'll force push with the changes soon since there's a lot to be done I think, thank you for such a comprehensive review! |
|
just had a question regarding the file picker ui issue im doing. Right now, I have loadDirectories() running on the main thread and I had asked gemini to try and spot any issues and it said that having loadDirectories() on the main thread can cause ANR with devices having an older SD card and it's better to put it in the background (to me this makes sense since if the sd card can't load all the directories fast enough, the main thread is going to take too long and ANR occurs). I tried looking this up but wasn't able to find anything concrete, so I wanted to know if it's an actual issue and if its a better practice to throw it in the background? Flagging the above for discussion, I'll leave this as a TODO in the code |
ab78a9d to
cb5b6c0
Compare
4a6fbe0 to
7eb9ad7
Compare
|
@david-allison super sorry for the late ping, had a lot of college work to finish off but I've addressed all the comments best I could! |
bfd4a04 to
81d2155
Compare
david-allison
left a comment
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.
This looks solid!
Are tests possible here?
Fixing the AnkiDroid directory was critical functionality back in the day, and still is on older devices.
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Show resolved
Hide resolved
To be honest, tests have been something I've been meaning to learn more about, I'll look into whether we can add them here once I clear the reviews and give another update! |
81d2155 to
cd1e5fe
Compare
|
Still have to switch to using nio methods, will do this and look into the testing tomorrow |
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/preferences/ExternalDirectorySelectionPreference.kt
Outdated
Show resolved
Hide resolved
ad9be12 to
1218887
Compare
|
Pushed with the nio addition, as well as the patch given |
|
@david-allison do we want the full stack trace displayed to the user, I thought it would be easier for users to read a localised messaged |
1218887 to
d68a991
Compare
|
This is one of those places which is critical to use of the app. Feel free to add a 'copy debug info' button which copies the stack trace. If not, more information is better here, many users here are experienced, and filesystems (SD Cards etc...) are nasty |
I think adding another button would be too much, I've appended the stack trace in the most recent push do lmk if anymore changes are needed |
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're using the full debug build and can't enter a custom path to change it or is that directory not showing up in the list (in the play debug build) even though its valid? Edit: I believe I've reproduced the issue, the file doesnt show up in the list even when its supposed to, will fix this |
The above is a cause of how we are loading directories, obviously the heuristic in place isn't the best so going to look for other solutions, ideas are appreciated currently thinking about implementing file filter more generally, will force push with a commit including the same soon |
d68a991 to
0c30d9b
Compare
This feature allows users to choose a file path that exists on their device or an external storage device. If the user is using a full release version, or a pre android 11 version then they have the option to edit their path to a custom one Co-authored-by: David Allison <62114487+david-allison@users.noreply.github.com>
0c30d9b to
0fff304
Compare
| } | ||
|
|
||
| companion object { | ||
| private val ANKI_DIR_FILTER = FileFilter { it.isDirectory } |
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 think this is better (could add a ishidden check), the regex was blocking files that were valid and either way we should only be seeing ankidroid files since "CollectionHelper.getAppSpecificExternalDirectories(context).filterNotNull()"
hope this is better, open to improvements
| attrs: AttributeSet?, | ||
| ) : ListPreference(context, attrs), | ||
| ListPreferenceTrait { | ||
| init { |
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 removed the edit text pref layout, it was causing issues with the horizontal line. I do like the current ui but I understand the truncation and vertical scrolling may not be nice for all users so open to suggestions here too
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.
It seems that there's a misunderstanding here, [so a test would be fantastic]
AnkiDroid Version = 2.24.0alpha2-debug (0fff3047b24701acbcaa6524fb27d6d9df95e47d)
Backend Version = 0.1.63-anki25.09.2 (25.09.2 3890e12c9e48c028c3f12aa58cb64bd9f8895e30)
Android Version = 15 (SDK 35)
ProductFlavor = play
Device Info = Google | google | emu64a | sdk_gphone64_arm64 | sdk_gphone64_arm64 | ranchu
WebView Info = [com.google.android.webview | 749903433]: Mozilla/5.0 (Linux; Android 15; sdk_gphone64_arm64 Build/AE3A.240806.036; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/143.0.7499.34 Mobile Safari/537.36
ACRA UUID = 3e5d97f3-05bd-45e9-9942-4c392b26bf20
FSRS = 5.1.0 (Enabled: false)
Crash Reports Enabled = false
- I have a standard Android [emulator] with no SD card
- I am using
play, so we can't access standard folders on external storage (/storage/emulated/0/AnkiDroid) - The one reasonable location that I can have an AnkiDroid Directory in is
Android/data/com.ichi2.anki.debug/files/
But: Inside this folder, I can have multiple AnkiDroid Directories:
Android/data/com.ichi2.anki.debug/files/AnkiDroid(default)Android/data/com.ichi2.anki.debug/files/Testing(custom)
This dialog needs to handle this case
In addition: selecting the root of files caused this to occur:





Purpose / Description
This pr adds a path picker gui when a user wishes to select a path through the advanced settings, if the user is using the google play version, it restricts their options to their internal storage or to an external sd card (it automatically gives them the sd card option, whereas before they would have to manually find the path). If the user is on the fullrelease or full debug, then they can give permissions to manage all storage and they can manually enter their path since scoped storage wouldn't be an issue.
Fixes
Approach
David's patch ended up working very nicely and I just implemented his TO-DO's with the exception of one which I wasn't too sure about.
How Has This Been Tested?
Checklist
Please, go through these checks before submitting the PR.