Fix document name extraction from document properties#630
Fix document name extraction from document properties#630thestinger merged 1 commit intoGrapheneOS:mainfrom
Conversation
|
|
|
Yeah you're right the prefixes To fix it properly I'm thinking:
That way name resolution is entirely decoupled from UI strings, so future translations can't break it. Happy to update the PR with this approach if that works for you. |
|
Yes, the approach that you've described should be fine. |
|
I also noticed the |
getCurrentDocumentName() previously matched against the formatted strings
shown in the Document Properties dialog ("File name:\n...", "Title:\n...").
Those labels come from R.string.file_name and R.string.title via
DocumentPropertiesLoader, so once the strings get translated the parser
silently returns "" and both the Save As default name and the toolbar
title break. The original code also had several smaller bugs: the
"Title:-" prefix never matched, "File name:" was missing the trailing
newline so replace() left a leading \n in the result, and the brittle
length > 2 check could reject valid short filenames.
Resolve the document name from the raw Map<DocumentProperty, String>
in DocumentPropertiesLoader using the stable enum keys (FileName,
falling back to Title when its value isn't DEFAULT_VALUE). The loader
now returns a DocumentPropertiesResult carrying both the formatted list
used by the dialog and the pre-resolved document name. PdfViewer caches
the name in mDocumentName and getCurrentDocumentName() becomes a
trivial accessor; the field is reset alongside mDocumentProperties on
document change and loader reset.
This PR fixes
getCurrentDocumentName()in PdfViewer.java, which produced wrong or empty document names (used for the toolbar title and the Save-As default filename).What was wrong
"File name:\n…","Title:\n…"). The labels come fromR.string.file_name/R.string.titleinDocumentPropertiesLoader, so any future translation would silently break it."File name:"was missing the trailing newline soreplace()left a leading\nin the result, and"Title:-"never matched anything, so the title fallback was dead code.length > 2check that could reject valid short filenames.What this changes
Map<DocumentProperty, String>produced byDocumentPropertiesLoader, using the stable enum keysDocumentProperty.FileName(falling back toDocumentProperty.Titlewhen its value isn'tDEFAULT_VALUE). No string parsing of localized output.DocumentPropertiesLoadernow returns aDocumentPropertiesResultcarrying both the formattedList<CharSequence>used by the existing dialog and the pre-resolveddocumentName. The dialog UI is unchanged.PdfViewercaches the resolved name in a newmDocumentNamefield;getCurrentDocumentName()becomes a trivial accessor. The field is reset alongsidemDocumentPropertieson document change and loader reset.Net effect: name resolution is fully decoupled from UI strings, so future translations of the property labels won't break the toolbar/Save-As behavior.