meganz / iOS

MEGA for iOS
https://apps.apple.com/app/mega/id706857885?mt=8
Other
342 stars 95 forks source link

Support PDF outline and playback of audio playlist file, optimize the PDF scale when rotating, refactoring PreviewDocumentViewController to Swift #86

Open pmtao opened 1 year ago

pmtao commented 1 year ago

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?

  1. Why adding PDF outline: many technical PDF documents have an outline, if the outline is displayed will be very convenient for reading.
  2. 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.
  3. 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

  1. 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.
  2. 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
  3. 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
  4. 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:

Any other comments?

  1. 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.
  2. 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.
harryyan1238 commented 1 year ago

Thanks @pmtao ! I will ask right engineer to review this code.

andres-nav commented 3 weeks ago

I would really enjoy this update as well. Hope the topic is picked up again!