generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from Team-Ampersand/84-music-propose-share-ex…
…tension 🔀 :: 음악 신청 ShareExtension 지원
- Loading branch information
Showing
17 changed files
with
370 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Projects/App/ShareExtension/Resources/MainInterface.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="j1y-V4-xli"> | ||
<device id="retina6_12" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Dotori Share View Controller--> | ||
<scene sceneID="ceB-am-kn3"> | ||
<objects> | ||
<viewController id="j1y-V4-xli" customClass="DotoriShareViewController" customModule="DotoriShareExtension" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" opaque="NO" contentMode="scaleToFill" id="wbc-yd-nQP"> | ||
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<viewLayoutGuide key="safeArea" id="1Xd-am-t49"/> | ||
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="CEy-Cv-SGf" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="138.1679389312977" y="-2.1126760563380285"/> | ||
</scene> | ||
</scenes> | ||
</document> |
205 changes: 205 additions & 0 deletions
205
Projects/App/ShareExtension/Sources/DotoriShareViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import Combine | ||
import Configure | ||
import DesignSystem | ||
import Foundation | ||
import LinkPresentation | ||
import Localization | ||
import MSGLayout | ||
import MusicDomainInterface | ||
import Social | ||
import UIKit | ||
import UniformTypeIdentifiers | ||
|
||
final class DotoriShareViewController: UIViewController { | ||
private let contentView = UIView() | ||
.set(\.backgroundColor, .dotori(.background(.card))) | ||
.set(\.cornerRadius, 10) | ||
.then { | ||
$0.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] | ||
} | ||
private let proposeMusicLabel = DotoriLabel(L10n.ProposeMusic.proposeMusicTitle, font: .subtitle1) | ||
private let cancelButton = DotoriTextButton(L10n.Global.cancelButtonTitle, textColor: .neutral(.n20), font: .body2) | ||
private let thumbnailImageView = UIImageView() | ||
.set(\.contentMode, .scaleAspectFill) | ||
.set(\.cornerRadius, 4) | ||
.set(\.clipsToBounds, true) | ||
private let imageActivityIndicator = UIActivityIndicatorView(style: .medium) | ||
private let titleLabel = DotoriLabel(font: .smalltitle) | ||
.set(\.numberOfLines, 0) | ||
private let proposeButton = DotoriButton(text: L10n.ProposeMusic.proposeButtonTitle) | ||
.set(\.contentEdgeInsets, .vertical(16)) | ||
private let proposeMusicUseCase: any ProposeMusicUseCase | ||
|
||
private var shareURL: URL? | ||
private var subscription = Set<AnyCancellable>() | ||
|
||
required init?(coder: NSCoder) { | ||
self.proposeMusicUseCase = MusicContainer.shared.container.resolve(ProposeMusicUseCase.self)! | ||
super.init(coder: coder) | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
addView() | ||
setLayout() | ||
bindAction() | ||
bindExtensionInput() | ||
} | ||
} | ||
|
||
private extension DotoriShareViewController { | ||
func addView() { | ||
view.addSubviews { | ||
contentView | ||
} | ||
thumbnailImageView.addSubviews { | ||
imageActivityIndicator | ||
} | ||
} | ||
|
||
func setLayout() { | ||
MSGLayout.buildLayout { | ||
contentView.layout | ||
.horizontal(.toSuperview()) | ||
.bottom(.toSuperview()) | ||
.height(268) | ||
|
||
imageActivityIndicator.layout | ||
.center(.toSuperview()) | ||
} | ||
|
||
MSGLayout.stackedLayout(self.contentView) { | ||
VStackView(spacing: 8) { | ||
HStackView { | ||
proposeMusicLabel | ||
|
||
SpacerView() | ||
|
||
cancelButton | ||
} | ||
.alignment(.lastBaseline) | ||
|
||
HStackView(spacing: 8) { | ||
thumbnailImageView | ||
.width(96) | ||
.height(72) | ||
|
||
titleLabel | ||
} | ||
.distribution(.fill) | ||
.alignment(.center) | ||
.height(88) | ||
.margin(.horizontal(8)) | ||
.set(\.backgroundColor, .dotori(.neutral(.n50))) | ||
.set(\.cornerRadius, 8) | ||
|
||
VStackView { | ||
proposeButton | ||
} | ||
.margin(.init(top: 16, left: 0, bottom: 8, right: 0)) | ||
} | ||
.margin(.all(16)) | ||
} | ||
} | ||
|
||
func bindAction() { | ||
cancelButton.tapPublisher | ||
.sink(with: self, receiveValue: { owner, _ in | ||
owner.hideExtension { _ in | ||
owner.extensionContext?.cancelRequest(withError: NSError(domain: "Share Canceled", code: 1)) | ||
} | ||
}) | ||
.store(in: &subscription) | ||
|
||
proposeButton.tapPublisher | ||
.sink(with: self, receiveValue: { owner, _ in | ||
guard let url = owner.shareURL else { return } | ||
Task { | ||
do { | ||
try await owner.proposeMusicUseCase(url: url.absoluteString) | ||
owner.hideExtension { _ in | ||
owner.extensionContext?.completeRequest(returningItems: nil) | ||
} | ||
} catch { | ||
owner.hideExtension { _ in | ||
owner.extensionContext?.cancelRequest( | ||
withError: NSError(domain: "Jwt Token is expired", code: 6) | ||
) | ||
} | ||
} | ||
} | ||
}) | ||
.store(in: &subscription) | ||
} | ||
|
||
func hideExtension(completion: @escaping (Bool) -> Void) { | ||
UIView.animate(withDuration: 0.3, animations: { | ||
self.view.transform = CGAffineTransform( | ||
translationX: 0, | ||
y: self.view.frame.size.height | ||
) | ||
}, completion: completion) | ||
} | ||
|
||
func bindExtensionInput() { | ||
guard let extensionInput = extensionContext?.inputItems as? [NSExtensionItem] else { | ||
self.extensionContext?.cancelRequest(withError: NSError(domain: "Invalid Inputs", code: 2)) | ||
return | ||
} | ||
for input in extensionInput where input.attachments?.isEmpty == false { | ||
let itemProviders = input.attachments ?? [] | ||
|
||
for itemProvider in itemProviders where itemProvider.hasItemConformingToTypeIdentifier("public.url") { | ||
itemProvider.loadItem(forTypeIdentifier: "public.url", options: nil) { [weak self] item, error in | ||
guard let self, let url = item as? URL, error == nil else { | ||
self?.hideExtension { _ in | ||
self?.extensionContext?.cancelRequest( | ||
withError: NSError(domain: "Invalid URL Input", code: 3) | ||
) | ||
} | ||
return | ||
} | ||
self.shareURL = url | ||
|
||
DispatchQueue.global(qos: .userInteractive).async { | ||
self.bindYoutubeThumbnail(url: url) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func bindYoutubeThumbnail(url: URL) { | ||
DispatchQueue.main.async { | ||
self.imageActivityIndicator.startAnimating() | ||
} | ||
let provider = LPMetadataProvider() | ||
provider.startFetchingMetadata(for: url) { [weak owner = self] metadata, error in | ||
guard let owner, let metadata, error == nil else { | ||
owner?.hideExtension { _ in | ||
owner?.extensionContext?.cancelRequest( | ||
withError: NSError(domain: "Invalid Youtube Metadata", code: 4) | ||
) | ||
} | ||
return | ||
} | ||
|
||
metadata.imageProvider?.loadObject(ofClass: UIImage.self) { image, error in | ||
guard let image = image as? UIImage, error == nil else { | ||
owner.hideExtension { _ in | ||
owner.extensionContext?.cancelRequest( | ||
withError: NSError(domain: "Invalid Youtube Thumbnail Image", code: 5) | ||
) | ||
} | ||
return | ||
} | ||
|
||
DispatchQueue.main.async { | ||
self.thumbnailImageView.image = image | ||
self.titleLabel.text = metadata.title | ||
self.imageActivityIndicator.stopAnimating() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Swinject | ||
import MusicDomain | ||
import JwtStore | ||
import Networking | ||
import KeyValueStore | ||
|
||
final class MusicContainer { | ||
static let shared = MusicContainer() | ||
|
||
let container = Container() | ||
var assembler: Assembler? | ||
|
||
init() { | ||
assembler = Assembler([ | ||
KeyValueStoreAssembly(), | ||
JwtStoreAssembly(), | ||
NetworkingAssembly(), | ||
MusicDomainAssembly() | ||
], container: container) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Projects/App/ShareExtension/Support/DotoriShare.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>keychain-access-groups</key> | ||
<array> | ||
<string>$(AppIdentifierPrefix)com.msg.Dotori.keychainGroup</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>AppIdentifierPrefix</key> | ||
<string>$(AppIdentifierPrefix)</string> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>DotoriShareExtension</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).shareextension</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionAttributes</key> | ||
<dict> | ||
<key>NSExtensionActivationRule</key> | ||
<dict> | ||
<key>NSExtensionActivationDictionaryVersion</key> | ||
<integer>1</integer> | ||
<key>NSExtensionActivationSupportsText</key> | ||
<true/> | ||
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key> | ||
<string>1</string> | ||
</dict> | ||
</dict> | ||
<key>NSExtensionMainStoryboard</key> | ||
<string>MainInterface</string> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.share-services</string> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.