What does this implement/fix? Explain your changes.
Before
After
No PDF document outline in preview
Support PDF document outline in preview, add a toolbar button to show and hide outline, and PDF that has no outline will not show outline button.
Can't play audio playlist file, like cue
Support playback of audio playlist file, such as cue file, will show all tracks from cue in the playing queue, support both single audio file and multiple audio file list in one cue file. Show the album name in the player if it has one.
In PDF preview, it won't fit the device width when rotated to landscape
Optimize the PDF scale to fit device width when rotating the device
PreviewDocumentViewController is written in Objc
Refactoring PreviewDocumentViewController from Objective-c to Swift, also including MEGAQLPreviewController, SearchInPdfViewControllerProtocol.
Why doing this implement?
Why adding PDF outline: many technical PDF documents have an outline, if the outline is displayed will be very convenient for reading.
Why adding audio playlist playback: I'am a big fan of classical music, and I own a lot of CDs, these CDs have been transcribed into digital audio and stored on my PC, which used to have a cue file that acted as a playlist. Therefore, I want to support cue playback.
Why refactoring PreviewDocumentViewController to Swift: Over half of the code is written in Swift, and less is in Objective-C. For better subsequent code iteration, you should refactor as much Objc code as possible into Swift. Swift makes it easier to support the mvvm architecture as well as new Swift features like Concurrency.
Design details
PDF outline
Add outline toolbar button item, and choose a symbol icon.
Add a model of PDF outline data structure, including indent level, label, page number.
Add a custom view of outline tableView
Add a custom tableViewCell to display an outline item, and set the constraint with the corresponding indent level.
Get outline data of PDF document from preview page
Show outline view in document preview page when tapping tool bar button
Setting toolbar button hidden and showing.
Testing some PDF documents with and without outline
Optimise outline compatible with nonexist destination page.
Playback of audio playlist
Add cue file parser to get track list from it
Add cue file parser unit test
Add function to read text file synchronously for reading cue file content
Add support for recognition of cue file extension
Dealing with tapping cue file
Turn cue track list to audio file playlist
Support for playback of multiple tracks list in cue file with single audio file
Support for playback of one-to-one track in cue and single audio file
Show album info from audio file or cue file in AudioPlayerViewController
PreviewDocumentViewController refactor
Refactor PreviewDocumentViewController to Swift
Change any #import "PreviewDocumentViewController.h" to #import "MEGA-Swift.h" if not imported
Refactor MEGAQLPreviewController to Swift
Change any #import "MEGAQLPreviewController.h" to #import "MEGA-Swift.h" if not imported
Refactor SearchInPdfViewControllerProtocol to Swift, delete old objc protocol
Delete old objc class file
Add any oc header in MEGA-Bridging-Header.h if new Swift class use it
Difficulties and matters needing attention in refactoring Objective-C class to Swift(PreviewDocumentViewController):
Swift and Objective-C circular references: MEGA-Swift.h should be included in the .m file but not in the .h file to break the reference circle. Also, add xxx.h in MEGA-Bridging-Header.h if Swift needs to use an Objective-C class.
Rename Swift corresponding functions (methodWithParam -> method(param))
Translate Objective-C protocols to Swift protocols
If an Objective-C version of a viewController is associated with a storyboard, when rewriting it to a Swift class version, it's necessary to reset the viewController in the storyboard, including the class name, module, and storyboard ID (no need to reconnect IBOutlet).
Beware of optional properties from Objective-C
Check the delegate method name and determine if public access control is needed to ensure the delegate method will be invoked.
Test that all methods are called correctly.
Does this close any currently open issues?
No
Where has this been tested?
Devices: iPhone 12 Pro
iOS Version: iOS 16.3.1
MEGA Version: 9.9
Any relevant logs, error output, etc?
No errors, and test with the lastest master branch commit 3bca860 of release 9.9 using these user cases:
Test PDF outline:
PDF with outline
PDF without outline
PDF with wrong outline destination
Test Playback of audio playlist:
Playback of multiple tracks list in cue file with single audio file
Playback of one-to-one track in cue and single audio file
Playback of normal audio file
Play next and previous in the player
Play next and previous from remote control
Test PreviewDocumentViewController refactor:
Test text file preview
Test PDF file preview
Test JPEG file preview
Test Apple Numbers file preview
Test zip file preview
Test send in chat file preview
Test share link file preview
Test all node action
Any other comments?
Other optimization ideas:
The project mainly consists of Swift code, it is worthwhile to keep refactoring the remaining Objective-C code。
Add more features for cloud file usage.
As the project grows bigger, extending more Swift packages to separate different business modules can be beneficial, merging single big Xcode project can become a headache.
Last words:
MEGA is an impressive app, particularly with its encryption capabilities. The open-sourcing of all client code is a surprising and admirable display of openness and honesty. It must be an interesting organization.
What does this implement/fix? Explain your changes.
Why doing this implement?
Design details
PDF outline
Playback of audio playlist
PreviewDocumentViewController refactor
Difficulties and matters needing attention in refactoring Objective-C class to Swift(PreviewDocumentViewController):
Does this close any currently open issues?
No
Where has this been tested?
Devices: iPhone 12 Pro
iOS Version: iOS 16.3.1
MEGA Version: 9.9
Any relevant logs, error output, etc?
No errors, and test with the lastest master branch commit 3bca860 of release 9.9 using these user cases:
Test PDF outline:
Test Playback of audio playlist:
Test PreviewDocumentViewController refactor:
Any other comments?