forked from shadowfacts/Tusker
45 lines
1.5 KiB
Swift
45 lines
1.5 KiB
Swift
//
|
|
// AccountActivityItemSource.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 5/14/20.
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import LinkPresentation
|
|
|
|
class AccountActivityItemSource: NSObject, UIActivityItemSource {
|
|
let account: AccountMO
|
|
|
|
init(_ account: AccountMO) {
|
|
self.account = account
|
|
}
|
|
|
|
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
|
|
return account
|
|
}
|
|
|
|
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
|
|
return account
|
|
}
|
|
|
|
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
|
|
let metadata = LPLinkMetadata()
|
|
metadata.originalURL = account.url
|
|
metadata.url = account.url
|
|
metadata.title = "\(account.displayName) (@\(account.username)@\(account.url.host!)"
|
|
if let avatar = account.avatar,
|
|
let data = ImageCache.avatars.getData(avatar),
|
|
let image = UIImage(data: data) {
|
|
metadata.iconProvider = NSItemProvider(object: image)
|
|
}
|
|
return metadata
|
|
}
|
|
|
|
func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String {
|
|
return "\(account.displayName) (@\(account.acct)"
|
|
}
|
|
|
|
}
|