Repository navigation
fix(text-viewer): read the text file off the main thread - #6862
Conversation
The whole file was read in onCreate. Read it in produceState on Dispatchers.IO. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-sonnet-5-5
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
68f2891d-c70c-48ce-882b-99d5b60861ed
📒 Files selected for processing (1)
app/src/main/java/com/nextcloud/talk/fullscreenfile/FullScreenTextViewerActivity.kt
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
…d file is gone The system may clear the cache directory between the exists() check and the read. Catch IOException in the producer, tell the user and finish. Assisted-by: Claude-Code:claude-sonnet-5-5 Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
rapterjet2004
left a comment
There was a problem hiding this comment.
Thanks, moving the read off the main thread and handling a missing file instead of crashing are both good. Two things need to change before this can go in:
1. Markdown files now open blank. In FullScreenTextScreen, markdown is rendered in the AndroidView factory, which runs only once, on the first composition. With produceState, text is still "" at that point, and when the real text arrives the factory doesn't run again. Plain text is fine because Text(text) recomposes, but every .md file stays empty. Please move setMarkdown into update = { markwon.setMarkdown(it, text) } (with a remembered Markwon instance), or only compose the content once the text is loaded.
2. Please add a loading indicator. Until the read finishes, the screen is empty and looks exactly like an empty file, and the wait grows with file size. A String? state where null means loading, with a progress indicator until it's set, would cover this and also fixes point 1 if the content is only composed once the text is there.
Follow-up (not for this PR): for large files the freeze isn't gone yet, it moves from the read to the render:
- The plain-text view is a single
TextinverticalScroll, so the whole string is measured and laid out on the main thread at once, and Markwon also parses on the main thread. For a few MB that costs more than the read. readBytes()loads the whole file into memory (and the String about twice that again).FileViewerUtilshas no size cap for text files, so a very large file can run out of memory, and anOutOfMemoryErrorisn't caught by theIOExceptionhandler.
A size cap with "Open in Files" for anything bigger, or a lazy line-by-line list, would address both. Happy to see that as a separate issue or PR.
…loaded The text state was a String initialised to "", so the screen looked like an empty file while the read was running, and markdown was set once in the AndroidView factory with that empty text and never updated. Make the state a String? where null means loading: show a progress indicator until it is set and compose the content only afterwards. Markdown is applied in update with a remembered Markwon. Assisted-by: Claude-Code:claude-sonnet-5-5 Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
|
Thanks, both points are fixed in a17385e. The state is now a The follow-up on large files is now #6901. |
… other Robolectric tests Without @config the runner picks the target SDK (36) and has to download a second android-all jar, which already failed with an SSLException on CI for another class added the same way. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-opus-5-5
rapterjet2004
left a comment
There was a problem hiding this comment.
Thanks, both points fixed: markdown is applied in update with a remembered Markwon, and the String? loading state with the progress indicator looks good. Thanks for filing #6901 for the large-file follow-up.
The whole file was read in onCreate. Read it in produceState on Dispatchers.IO.
🤖 Generated with Claude Code