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
|
|
|
import AuthenticationServices
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
import AltStoreCore
|
2019-08-28 11:13:22 -07:00
|
|
|
import Roxas
|
|
|
|
|
|
2023-01-04 09:52:12 -05:00
|
|
|
final class PatreonViewController: UICollectionViewController
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extension PatreonViewController
|
|
|
|
|
{
|
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
|
|
|
}
|
2019-09-05 15:37:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extension PatreonViewController
|
|
|
|
|
{
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension PatreonViewController
|
|
|
|
|
{
|
|
|
|
|
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
|
|
|
|
|
{
|
2026-02-22 14:53:47 +05:30
|
|
|
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AboutHeader", for: indexPath) as! AboutPatreonHeaderView
|
|
|
|
|
self.prepare(headerView)
|
|
|
|
|
return headerView
|
2019-08-28 11:13:22 -07:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-05 15:37:58 -07:00
|
|
|
|
|
|
|
|
extension PatreonViewController: UICollectionViewDelegateFlowLayout
|
|
|
|
|
{
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize
|
|
|
|
|
{
|
2026-02-22 14:53:47 +05:30
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|