Skip to content
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

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

pmtao
Copy link

@pmtao pmtao commented Mar 20, 2023

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.
  1. 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
  1. 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
  1. 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
      pdf_preview
      pdf_outline
  • 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
      cue_file
      play_list_from_cue
      playing_info
  • 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?

  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.
  1. 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.

pmtao added 7 commits March 20, 2023 11:05
Refactoring PreviewDocumentViewController, MEGAQLPreviewController, SearchInPdfViewControllerProtocol to Swift
…imize the code structure of the AudioPlayerViewModel.
Support PDF outline, Support playback of audio playlist file, Optimize the PDF scale when rotating, Refactoring PreviewDocumentViewController to Swift.
@harryyan1238
Copy link
Contributor

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

@andres-nav
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants