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

Media: Add support for remaining asset types #21664

Merged
merged 11 commits into from
Oct 5, 2023

Conversation

kean
Copy link
Contributor

@kean kean commented Sep 29, 2023

Part of #21457

There are multiple changes in this PR, so please bear with me. Once this is merged, the new screens will cover 100% of the original MediaLibraryViewController functionally (and a little bit more). I've been commenting out the re-implement lines as I was working on this project, so this is how I know.

Changes:

  • Add support for remaining document types: video, document, audio
  • Add GIF rendering and increase the scale of requested GIFs to the max of 2x. Downscaling too much resulted in artifacts during playback.
  • Add accessibility support
  • Pop details view controller if media is deleted

I have a couple of more performance improvements in mind, but these will be done later.

Screenshot 2023-09-29 at 5 30 49 PM Screenshot 2023-09-29 at 5 30 51 PM

To test:

  • Verify that the existing video assets display the duration
  • Verify that when you upload a new video, it displays the duration
  • Verify that documents and audio have a respective icon and their filenames displayed
  • Verify that cells are accessibility elements (copied from the previous version)
  • Verify that after going to the details page and deleting the asset on it, the details page gets popped from the stack (see recording)
  • Verify that GIFs are now animated (we already had the files, so I thought, why not just animate them; it wasn't supported before)

Regression Notes

  1. Potential unintended areas of impact: n/a (no production code changed)
  2. What I did to test those areas of impact (or what existing automated tests I relied on): manual
  3. What automated tests I added (or what prevented me from doing so): n/a

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes testing checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

let scale = UIScreen.main.scale
var targetSize = targetSize
if remoteURL.isGif {
targetSize = targetSize
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downscaling from 3x to 1x turned out to be a bit too much.

import Combine
import Gifu

final class SiteMediaCollectionCell: UICollectionViewCell {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why it didn't register the rename 😞

@kean kean mentioned this pull request Sep 29, 2023
21 tasks
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Sep 29, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr21664-3cfa373
Version23.4
Bundle IDcom.jetpack.alpha
Commit3cfa373
App Center Buildjetpack-installable-builds #6329
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Sep 29, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr21664-3cfa373
Version23.4
Bundle IDorg.wordpress.alpha
Commit3cfa373
App Center BuildWPiOS - One-Offs #7293
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@kean kean requested a review from momo-ozawa October 2, 2023 20:34
@kean kean force-pushed the task/media-foundation-remaining-types branch from 20d6bb2 to 669c2e4 Compare October 2, 2023 20:51
@kean
Copy link
Contributor Author

kean commented Oct 2, 2023

Next steps is to test it with self-hosted sites, add some unit tests. I expect there are going to be some complication with video thumbnails.

@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

Copy link
Contributor

@momo-ozawa momo-ozawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as described!

When uploading files, the cell doesn't update to include the filename once it's finished uploading the file. Pull to refresh doesn't update the cells either. You have to exit the screen then come back to see the correct icon / filename.

RPReplay_Final1696427175.MP4

@@ -299,6 +311,9 @@ private extension Data {
// JPEG magic numbers https://en.wikipedia.org/wiki/JPEG
static let jpegMagicNumbers: [UInt8] = [0xFF, 0xD8, 0xFF]

// GIF magic numbers https://en.wikipedia.org/wiki/GIF
static let gifMagicNumbers: [UInt8] = [0x47, 0x49, 0x46]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

@@ -95,7 +95,7 @@ final class SiteMediaCollectionViewController: UIViewController, NSFetchedResult
}

private func configureCollectionView() {
collectionView.register(MediaCollectionCell.self, forCellWithReuseIdentifier: Constants.cellID)
collectionView.register(SiteMediaCollectionCell.self, forCellWithReuseIdentifier: Constants.cellID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] If you make SiteMediaCollectionCell conform to Reusable, you can use defaultReuseID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know it was there. Thanks – updated!

…ollectionCellViewModel.swift

Co-authored-by: Momo Ozawa <[email protected]>
@kean
Copy link
Contributor Author

kean commented Oct 4, 2023

When uploading files, the cell doesn't update to include the filename once it's finished uploading the file.

I think I haven't tested this flow: only existing uploads from the web. Let me address that in a separate PR. I put it on the list.

@kean
Copy link
Contributor Author

kean commented Oct 4, 2023

Just to add to the last comment: there are too many parts of the media that can change after the initial cell display. I want to simplify the way it reloads a bit to fix this issue. I think it'll be best to review it separately.

@kean kean requested a review from momo-ozawa October 5, 2023 13:32
@@ -95,7 +95,7 @@ final class SiteMediaCollectionViewController: UIViewController, NSFetchedResult
}

private func configureCollectionView() {
collectionView.register(SiteMediaCollectionCell.self, forCellWithReuseIdentifier: Constants.cellID)
collectionView.register(cell: SiteMediaCollectionCell.self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to do

collectionView.register(SiteMediaCollectionCell.self, forCellWithReuseIdentifier: SiteMediaCollectioinCell.defaultReuseID)

Looks like you're using a extension method defined in Kanvas

    func register<T: UICollectionViewCell>(cell cellType: T.Type) {
        register(cellType, forCellWithReuseIdentifier: cellType.identifier)
    }

This works, because UICollectionReusableView conforms to Kanvas.Identifiable. Just wanted to point out that it's not leveraging Reusable, but Kanvas.Identifiable instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, Kanvas.Identifiable is nice, but we should probably not rely on it. I want to get this merged before the trunk gets too far ahead. Let me address it separately together with the filename fix.

Copy link
Contributor

@momo-ozawa momo-ozawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving - up to you to decide about my comment above 🙇‍♀️

@kean kean enabled auto-merge October 5, 2023 17:06
@kean kean merged commit d7c69fd into trunk Oct 5, 2023
@kean kean deleted the task/media-foundation-remaining-types branch October 5, 2023 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants