Skip to content

Commit

Permalink
NFT-Overview: Replace buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed Sep 20, 2023
1 parent 5a996ae commit 38d98ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import UIKit
import ComponentKit
import UIKit

class NftAssetButtonCell: UITableViewCell {
private let providerButton = PrimaryButton()
private let sendButton = PrimaryButton()
private let moreButton = PrimaryCircleButton()
private let saveButton = PrimaryButton()
private let shareButton = PrimaryButton()

private let stackView = UIStackView()

private var onTapSend: (() -> ())?
private var onTapProvider: (() -> ())?
private var onTapMore: (() -> ())?
private var onTapShare: (() -> Void)?
private var onTapSave: (() -> Void)?

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
Expand All @@ -25,51 +23,37 @@ class NftAssetButtonCell: UITableViewCell {
maker.height.equalTo(CGFloat.heightButton)
}

stackView.addArrangedSubview(sendButton)
stackView.addArrangedSubview(providerButton)
stackView.addArrangedSubview(moreButton)
stackView.addArrangedSubview(shareButton)
stackView.addArrangedSubview(saveButton)

stackView.spacing = .margin8
stackView.alignment = .fill
stackView.distribution = .fill
stackView.distribution = .fillEqually

sendButton.set(style: .yellow)
sendButton.addTarget(self, action: #selector(onTapSendButton), for: .touchUpInside)
sendButton.setTitle("button.send".localized, for: .normal)
shareButton.set(style: .yellow)
shareButton.addTarget(self, action: #selector(onTapShareButton), for: .touchUpInside)
shareButton.setTitle("button.share".localized, for: .normal)

providerButton.set(style: .gray)
providerButton.addTarget(self, action: #selector(onTapProviderButton), for: .touchUpInside)

moreButton.set(style: .gray)
moreButton.set(image: UIImage(named: "more_24"))
moreButton.addTarget(self, action: #selector(onTapMoreButton), for: .touchUpInside)
saveButton.set(style: .gray)
saveButton.addTarget(self, action: #selector(onTapSaveButton), for: .touchUpInside)
saveButton.setTitle("button.save".localized, for: .normal)
}

required init?(coder aDecoder: NSCoder) {
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc private func onTapSendButton() {
onTapSend?()
}

@objc private func onTapProviderButton() {
onTapProvider?()
@objc private func onTapSaveButton() {
onTapSave?()
}

@objc private func onTapMoreButton() {
onTapMore?()
@objc private func onTapShareButton() {
onTapShare?()
}

func bind(providerTitle: String?, onTapSend: (() -> ())?, onTapProvider: @escaping () -> (), onTapMore: @escaping () -> ()) {
providerButton.setTitle(providerTitle, for: .normal)

sendButton.isHidden = onTapSend == nil
providerButton.isHidden = onTapSend != nil

self.onTapSend = onTapSend
self.onTapProvider = onTapProvider
self.onTapMore = onTapMore
func bind(onTapShare: @escaping () -> Void, onTapSave: @escaping () -> Void) {
self.onTapShare = onTapShare
self.onTapSave = onTapSave
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -180,35 +180,6 @@ class NftAssetOverviewViewController: ThemeViewController {
urlManager.open(url: url, from: parentNavigationController ?? self)
}

private func openSend() {
guard let viewController = SendNftModule.viewController(nftUid: viewModel.nftUid) else {
return
}

parentNavigationController?.present(viewController, animated: true)
}

private func openOptionsMenu() {
let controller = AlertViewControllerNew.instance(
viewItems: [
.init(text: "button.share".localized),
.init(text: "nft_asset.options.save_to_photos".localized),
// .init(text: "nft_asset.options.set_as_watch_face".localized)
],
reportAfterDismiss: true,
onSelect: { [weak self] index in
switch index {
case 0: self?.handleShare()
case 1: self?.handleSaveToPhotos()
// case 2: self?.handleSetWatchFace()
default: ()
}
}
)

(parentNavigationController ?? self).present(controller, animated: true)
}

private func handleShare() {
if let providerUrl = providerUrl {
openShare(text: providerUrl)
Expand Down Expand Up @@ -319,17 +290,11 @@ extension NftAssetOverviewViewController: SectionsDataSource {
height: .heightButton,
bind: { [weak self] cell, _ in
cell.bind(
providerTitle: self?.viewModel.providerTitle,
onTapSend: sendVisible ? { [weak self] in
self?.openSend()
} : nil,
onTapProvider: {
if let url = self?.providerUrl {
self?.openLink(url: url)
}
onTapShare: { [weak self] in
self?.handleShare()
},
onTapMore: {
self?.openOptionsMenu()
onTapSave: { [weak self] in
self?.handleSaveToPhotos()
}
)
}
Expand Down

0 comments on commit 38d98ef

Please sign in to comment.