Skip to content

Commit

Permalink
Remove WPMediaPicker dependency (#22103)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Nov 28, 2023
2 parents 0317836 + f51be52 commit 9f6925e
Show file tree
Hide file tree
Showing 36 changed files with 82 additions and 2,194 deletions.
5 changes: 0 additions & 5 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ abstract_target 'Apps' do

pod 'NSURL+IDN', '~> 0.4'

pod 'WPMediaPicker', '~> 1.8', '>= 1.8.10'
## while PR is in review:
# pod 'WPMediaPicker', git: 'https://github.com/wordpress-mobile/MediaPicker-iOS.git', branch: ''
# pod 'WPMediaPicker', path: '../MediaPicker-iOS'

pod 'WordPressAuthenticator', '~> 7.3'
# pod 'WordPressAuthenticator', git: 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', commit: ''
# pod 'WordPressAuthenticator', git: 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', branch: ''
Expand Down
6 changes: 1 addition & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ PODS:
- wpxmlrpc (~> 0.10)
- WordPressShared (2.2.0)
- WordPressUI (1.15.0)
- WPMediaPicker (1.8.10)
- wpxmlrpc (0.10.0)
- ZendeskCommonUISDK (6.1.2)
- ZendeskCoreSDK (2.5.1)
Expand Down Expand Up @@ -125,7 +124,6 @@ DEPENDENCIES:
- WordPressKit (~> 8.11)
- WordPressShared (~> 2.2)
- WordPressUI (~> 1.15)
- WPMediaPicker (>= 1.8.10, ~> 1.8)
- ZendeskSupportSDK (= 5.3.0)
- ZIPFoundation (~> 0.9.8)

Expand Down Expand Up @@ -162,7 +160,6 @@ SPEC REPOS:
- WordPressKit
- WordPressShared
- WordPressUI
- WPMediaPicker
- wpxmlrpc
- ZendeskCommonUISDK
- ZendeskCoreSDK
Expand Down Expand Up @@ -219,7 +216,6 @@ SPEC CHECKSUMS:
WordPressKit: 13e01ed70f6ab2397c228959bc47cb2073521f63
WordPressShared: 87f3ee89b0a3e83106106f13a8b71605fb8eb6d2
WordPressUI: a491454affda3b0fb812812e637dc5e8f8f6bd06
WPMediaPicker: 332812329cbdc672cdb385b8ac3a389f668d3012
wpxmlrpc: 68db063041e85d186db21f674adf08d9c70627fd
ZendeskCommonUISDK: 5f0a83f412e07ae23701f18c412fe783b3249ef5
ZendeskCoreSDK: 19a18e5ef2edcb18f4dbc0ea0d12bd31f515712a
Expand All @@ -230,6 +226,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced

PODFILE CHECKSUM: beaa30560a95fe4f9e8153c20fa4b4ae54be1fd5
PODFILE CHECKSUM: 2edd8f6d2c7475c9aeda02ae80af96002ff1ca8b

COCOAPODS: 1.14.2
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* [**] Add media fitlers to the Site Media screen [#22096]
* [*] The "aspect ratio" mode on the Site Media screen is now also available on iPhone via the new title menu [#22096]
* [**] Update the classic editor to use the new Photos and Site Media pickers [#22060]
* [*] [internal] Remove WPMediaPicker dependency from Tenor and Stock Photos pickers [#22066, #22074]
* [**] [internal] Remove WPMediaPicker dependency [#22103]
* [*] [internal] Rework Tenor (Free GIF) and Stock Photos (Free Photos) pickers [#22066, #22074]

23.8
-----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#import "Media.h"
#import <WPMediaPicker/WPMediaPicker.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

/**
Provides an implementation of Media conforming to the WPMediaAsset protocol.
Note: Doesn't play nicely with Swift, see @property filename below.
*/
@interface Media (WPMediaAsset) <WPMediaAsset>
@interface Media (Extensions)

- (void)videoAssetWithCompletionHandler:(void (^ _Nonnull)(AVAsset * _Nullable asset, NSError * _Nullable error))completionHandler;

/**
- (CGSize)pixelSize;
- (NSTimeInterval)duration;

/**
Note: Redefine the filename property of Media to keep Swift happy.
Otherwise, currently, Swift will only see the protocol method of filename() available,
and not the (getter, setter) properity itself on Media.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
#import "Media+WPMediaAsset.h"
#import "Media+Extensions.h"
#import "MediaService.h"
#import "Blog.h"
#import "CoreDataStack.h"
#import "WordPress-Swift.h"

@implementation Media(WPMediaAsset)
@implementation Media (Extensions)

- (WPMediaRequestID)imageWithSize:(CGSize)size completionHandler:(WPMediaImageBlock)completionHandler
{
[MediaThumbnailCoordinator.shared thumbnailFor:self with:size onCompletion:^(UIImage *image, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
if (completionHandler) {
completionHandler(nil, error);
}
return;
}
if (completionHandler) {
completionHandler(image, nil);
}
});
}];

return [self.mediaID intValue];
- (NSError *)errorWithMessage:(NSString *)errorMessage {
return [NSError errorWithDomain:@"MediaErrorDomain"
code:4
userInfo:@{NSLocalizedDescriptionKey: errorMessage}];
}

- (WPMediaRequestID)videoAssetWithCompletionHandler:(WPMediaAssetBlock)completionHandler
{
- (void)videoAssetWithCompletionHandler:(void (^ _Nonnull)(AVAsset * _Nullable asset, NSError * _Nullable error))completionHandler {
if (!completionHandler) {
return 0;
return;
}

// Check if asset being used is a video, if not this method fails
if (!(self.assetType == WPMediaTypeVideo || self.assetType == WPMediaTypeAudio)) {
if (!(self.mediaType == MediaTypeVideo || self.mediaType == MediaTypeAudio)) {
NSString *errorMessage = NSLocalizedString(@"Selected media is not a video.", @"Error message when user tries to preview an image media like a video");
completionHandler(nil, [self errorWithMessage:errorMessage]);
return 0;
return;
}

NSURL *url = nil;
Expand Down Expand Up @@ -66,7 +52,7 @@ - (WPMediaRequestID)videoAssetWithCompletionHandler:(WPMediaAssetBlock)completio
} failure:^(NSError *error) {
completionHandler(nil, error);
}];
return 0;
return;
}
// Do we have a local url, or remote url to use for the video
if (!url && self.remoteURL) {
Expand All @@ -76,50 +62,25 @@ - (WPMediaRequestID)videoAssetWithCompletionHandler:(WPMediaAssetBlock)completio
if (!url) {
NSString *errorMessage = NSLocalizedString(@"Selected media is unavailable.", @"Error message when user tries a no longer existent video media object.");
completionHandler(nil, [self errorWithMessage:errorMessage]);
return 0;
return;
}

// Let see if can create an asset with this url
AVURLAsset *asset = [AVURLAsset assetWithURL:url];
if (!asset) {
NSString *errorMessage = NSLocalizedString(@"Selected media is unavailable.", @"Error message when user tries a no longer existent video media object.");
completionHandler(nil, [self errorWithMessage:errorMessage]);
return 0;
return;
}

completionHandler(asset, nil);
return [self.mediaID intValue];
}

- (NSError *)errorWithMessage:(NSString *)errorMessage {
return [NSError errorWithDomain:WPMediaPickerErrorDomain
code:WPMediaPickerErrorCodeVideoURLNotAvailable
userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
}

- (CGSize)pixelSize
{
return CGSizeMake([self.width floatValue], [self.height floatValue]);
}

- (void)cancelImageRequest:(WPMediaRequestID)requestID
{

}

- (WPMediaType)assetType
{
if (self.mediaType == MediaTypeImage) {
return WPMediaTypeImage;
} else if (self.mediaType == MediaTypeVideo) {
return WPMediaTypeVideo;
} else if (self.mediaType == MediaTypeAudio) {
return WPMediaTypeAudio;
} else {
return WPMediaTypeOther;
}
}

- (NSTimeInterval)duration
{
if (!(self.mediaType == MediaTypeVideo || self.mediaType == MediaTypeAudio)) {
Expand All @@ -139,28 +100,4 @@ - (NSTimeInterval)duration
return CMTimeGetSeconds(duration);
}

- (NSDate *)date
{
return self.creationDate;
}

- (id)baseAsset
{
return self;
}

- (NSString *)identifier
{
return [[self.objectID URIRepresentation] absoluteString];
}

- (NSString *)UTTypeIdentifier
{
NSString *extension = [self fileExtension];
if (!extension.length) {
return nil;
}
return [UTType typeWithFilenameExtension:extension].identifier;
}

@end
2 changes: 1 addition & 1 deletion WordPress/Classes/Extensions/Media+Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension Media {
}
// If they failed to upload themselfs because no local copy exists then we need to delete this media object
// This scenario can happen when media objects were created based on an asset that failed to import to the WordPress App.
// For example a PHAsset that is stored on the iCloud storage and because of the network connection failed the import process.
// For example a that is stored on the iCloud storage and because of the network connection failed the import process.
if media.remoteStatus == .failed,
let error = media.error as NSError?, error.domain == MediaServiceErrorDomain && error.code == MediaServiceError.fileDoesNotExist.rawValue {
context.delete(media)
Expand Down
19 changes: 0 additions & 19 deletions WordPress/Classes/Extensions/PHAsset+Exporters.swift

This file was deleted.

40 changes: 0 additions & 40 deletions WordPress/Classes/Extensions/PHAsset+Metadata.swift

This file was deleted.

4 changes: 2 additions & 2 deletions WordPress/Classes/Models/AbstractPost+HashHelpers.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "AbstractPost+HashHelpers.h"
#import "Media+WPMediaAsset.h"
#import "Media+Extensions.h"
#import "WordPress-Swift.h"

@implementation AbstractPost (HashHelpers)
Expand All @@ -21,7 +21,7 @@ - (NSString *)calculateConfirmedChangesContentHash {
[self hashForString:self.password],
[self hashForString:self.author],
[self hashForNSInteger:self.authorID.integerValue],
[self hashForString:self.featuredImage.identifier],
[self hashForString:self.featuredImage.objectID.URIRepresentation.absoluteString],
[self hashForString:self.wp_slug]];


Expand Down
37 changes: 0 additions & 37 deletions WordPress/Classes/Models/Blog+Media.swift

This file was deleted.

9 changes: 9 additions & 0 deletions WordPress/Classes/Models/Media.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,13 @@ typedef NS_ENUM(NSUInteger, MediaType) {

@end

// TODO: Remove it; it was added for compatibility during the WPMediaPicker removal
typedef NS_OPTIONS(NSInteger, WPMediaType){
WPMediaTypeImage = 1,
WPMediaTypeVideo = 1 << 1,
WPMediaTypeAudio = 1 << 2,
WPMediaTypeOther = 1 << 3,
WPMediaTypeAll= 0XFF
};

NS_ASSUME_NONNULL_END
1 change: 0 additions & 1 deletion WordPress/Classes/Models/Media.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import UniformTypeIdentifiers

extension Media {

// MARK: - AutoUpload Failure Count

static let maxAutoUploadFailureCount = 3
Expand Down
Loading

0 comments on commit 9f6925e

Please sign in to comment.