2019-08-28 11:13:22 -07:00
|
|
|
//
|
|
|
|
|
// PatreonViewController.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
2019-09-05 15:37:58 -07:00
|
|
|
// Created by Riley Testut on 9/5/19.
|
2019-08-28 11:13:22 -07:00
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2019-09-05 15:37:58 -07:00
|
|
|
import SafariServices
|
2019-08-28 11:13:22 -07:00
|
|
|
|
2026-02-22 15:38:23 +05:30
|
|
|
final class PatreonViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout
|
2019-08-28 11:13:22 -07:00
|
|
|
{
|
2019-09-05 15:37:58 -07:00
|
|
|
private var prototypeAboutHeader: AboutPatreonHeaderView!
|
|
|
|
|
|
2019-08-28 11:13:22 -07:00
|
|
|
override func viewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
2019-09-05 15:37:58 -07:00
|
|
|
let aboutHeaderNib = UINib(nibName: "AboutPatreonHeaderView", bundle: nil)
|
|
|
|
|
self.prototypeAboutHeader = aboutHeaderNib.instantiate(withOwner: nil, options: nil)[0] as? AboutPatreonHeaderView
|
|
|
|
|
|
|
|
|
|
self.collectionView.register(aboutHeaderNib, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "AboutHeader")
|
2026-02-22 14:53:47 +05:30
|
|
|
self.collectionView.reloadData()
|
2019-08-28 11:13:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool)
|
|
|
|
|
{
|
|
|
|
|
super.viewWillAppear(animated)
|
2026-02-22 14:53:47 +05:30
|
|
|
self.collectionView.reloadData()
|
2019-09-05 15:37:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewDidLayoutSubviews()
|
|
|
|
|
{
|
|
|
|
|
super.viewDidLayoutSubviews()
|
|
|
|
|
|
|
|
|
|
let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
|
|
|
|
|
|
|
|
|
|
var itemWidth = (self.collectionView.bounds.width - (layout.sectionInset.left + layout.sectionInset.right + layout.minimumInteritemSpacing)) / 2
|
|
|
|
|
itemWidth.round(.down)
|
|
|
|
|
|
2022-11-21 21:04:59 -05:00
|
|
|
// TODO: if the intention here is to hide the cells, we should just modify the data source. @JoeMatt
|
2022-11-14 17:36:23 -07:00
|
|
|
layout.itemSize = CGSize(width: 0, height: 0)
|
2019-08-28 11:13:22 -07:00
|
|
|
}
|
|
|
|
|
|
2019-09-07 15:34:07 -07:00
|
|
|
func prepare(_ headerView: AboutPatreonHeaderView)
|
|
|
|
|
{
|
|
|
|
|
headerView.layoutMargins = self.view.layoutMargins
|
|
|
|
|
headerView.supportButton.addTarget(self, action: #selector(PatreonViewController.openPatreonURL(_:)), for: .primaryActionTriggered)
|
2023-06-13 23:14:01 -07:00
|
|
|
headerView.twitterButton.addTarget(self, action: #selector(PatreonViewController.openTwitterURL(_:)), for: .primaryActionTriggered)
|
|
|
|
|
headerView.instagramButton.addTarget(self, action: #selector(PatreonViewController.openInstagramURL(_:)), for: .primaryActionTriggered)
|
2019-08-28 11:13:22 -07:00
|
|
|
}
|
2026-02-22 15:38:23 +05:30
|
|
|
|
|
|
|
|
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
|
|
|
|
|
{
|
|
|
|
|
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AboutHeader", for: indexPath) as! AboutPatreonHeaderView
|
|
|
|
|
self.prepare(headerView)
|
|
|
|
|
return headerView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize
|
|
|
|
|
{
|
|
|
|
|
let widthConstraint = self.prototypeAboutHeader.widthAnchor.constraint(equalToConstant: collectionView.bounds.width)
|
|
|
|
|
NSLayoutConstraint.activate([widthConstraint])
|
|
|
|
|
defer { NSLayoutConstraint.deactivate([widthConstraint]) }
|
|
|
|
|
|
|
|
|
|
self.prepare(self.prototypeAboutHeader)
|
|
|
|
|
return self.prototypeAboutHeader.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
|
|
|
|
|
}
|
2019-09-05 15:37:58 -07:00
|
|
|
|
|
|
|
|
@objc func openPatreonURL(_ sender: UIButton)
|
|
|
|
|
{
|
2024-09-16 07:18:41 -04:00
|
|
|
let patreonURL = URL(string: "https://www.patreon.com/SideStoreIO")!
|
2019-09-05 15:37:58 -07:00
|
|
|
|
|
|
|
|
let safariViewController = SFSafariViewController(url: patreonURL)
|
|
|
|
|
safariViewController.preferredControlTintColor = self.view.tintColor
|
|
|
|
|
self.present(safariViewController, animated: true, completion: nil)
|
2023-06-13 23:14:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func openTwitterURL(_ sender: UIButton)
|
|
|
|
|
{
|
2024-11-19 16:00:48 -05:00
|
|
|
let twitterURL = URL(string: "https://twitter.com/sidestoreio")!
|
2023-06-13 23:14:01 -07:00
|
|
|
|
|
|
|
|
let safariViewController = SFSafariViewController(url: twitterURL)
|
|
|
|
|
safariViewController.preferredControlTintColor = self.view.tintColor
|
|
|
|
|
self.present(safariViewController, animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func openInstagramURL(_ sender: UIButton)
|
|
|
|
|
{
|
|
|
|
|
let twitterURL = URL(string: "https://instagram.com/sidestore.io")!
|
|
|
|
|
|
|
|
|
|
let safariViewController = SFSafariViewController(url: twitterURL)
|
|
|
|
|
safariViewController.preferredControlTintColor = self.view.tintColor
|
|
|
|
|
self.present(safariViewController, animated: true, completion: nil)
|
2019-09-05 15:37:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 15:38:23 +05:30
|
|
|
final class AboutPatreonHeaderView: UICollectionReusableView
|
2019-09-05 15:37:58 -07:00
|
|
|
{
|
2026-02-22 15:38:23 +05:30
|
|
|
@IBOutlet var supportButton: UIButton!
|
|
|
|
|
@IBOutlet var twitterButton: UIButton!
|
|
|
|
|
@IBOutlet var instagramButton: UIButton!
|
|
|
|
|
@IBOutlet var textView: UITextView!
|
|
|
|
|
|
|
|
|
|
@IBOutlet private var teamIcon: UIImageView!
|
|
|
|
|
@IBOutlet private var teamLabel: UILabel!
|
|
|
|
|
|
|
|
|
|
override func awakeFromNib()
|
2019-09-05 15:37:58 -07:00
|
|
|
{
|
2026-02-22 15:38:23 +05:30
|
|
|
super.awakeFromNib()
|
|
|
|
|
|
|
|
|
|
self.textView.clipsToBounds = true
|
|
|
|
|
self.textView.layer.cornerRadius = 20
|
|
|
|
|
self.textView.textContainer.lineFragmentPadding = 0
|
|
|
|
|
|
|
|
|
|
for imageView in [self.teamIcon].compactMap({$0})
|
|
|
|
|
{
|
|
|
|
|
imageView.clipsToBounds = true
|
|
|
|
|
imageView.layer.cornerRadius = imageView.bounds.midY
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for button in [self.supportButton, self.twitterButton, self.instagramButton].compactMap({$0})
|
|
|
|
|
{
|
|
|
|
|
button.clipsToBounds = true
|
|
|
|
|
button.layer.cornerRadius = 16
|
|
|
|
|
}
|
2019-08-28 11:13:22 -07:00
|
|
|
}
|
2026-02-22 15:38:23 +05:30
|
|
|
|
|
|
|
|
override func layoutMarginsDidChange()
|
2019-09-05 15:37:58 -07:00
|
|
|
{
|
2026-02-22 15:38:23 +05:30
|
|
|
super.layoutMarginsDidChange()
|
|
|
|
|
self.textView.textContainerInset = UIEdgeInsets(top: self.layoutMargins.left, left: self.layoutMargins.left, bottom: self.layoutMargins.right, right: self.layoutMargins.right)
|
2019-09-05 15:37:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-22 15:38:23 +05:30
|
|
|
|