|
@@ -3,18 +3,77 @@ import UIKit
|
|
|
|
|
|
class GalleryViewController: UIViewController {
|
|
class GalleryViewController: UIViewController {
|
|
|
|
|
|
|
|
+ private struct GallerySection {
|
|
|
|
+ let header: String
|
|
|
|
+ let msgId: [Int]
|
|
|
|
+ }
|
|
|
|
+
|
|
private let mediaMessageIds: [Int]
|
|
private let mediaMessageIds: [Int]
|
|
|
|
|
|
|
|
+ private var gridSections: [GallerySection] = []
|
|
|
|
+
|
|
|
|
+ private lazy var grid: UICollectionView = {
|
|
|
|
+ let layout = UICollectionViewFlowLayout()
|
|
|
|
+ let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
|
|
|
+ collection.dataSource = self
|
|
|
|
+ collection.delegate = self
|
|
|
|
+ collection.register(MediaCell.self, forCellWithReuseIdentifier: MediaCell.reuseIdentifier)
|
|
|
|
+ return collection
|
|
|
|
+ }()
|
|
|
|
+
|
|
init(mediaMessageIds: [Int]) {
|
|
init(mediaMessageIds: [Int]) {
|
|
self.mediaMessageIds = mediaMessageIds
|
|
self.mediaMessageIds = mediaMessageIds
|
|
super.init(nibName: nil, bundle: nil)
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
+ self.gridSections = processData(messageIds: mediaMessageIds)
|
|
}
|
|
}
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // MARK: - lifecycle
|
|
override func viewDidLoad() {
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
super.viewDidLoad()
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // MARK: - setup
|
|
|
|
+ private func setupSubviews() {
|
|
|
|
+ view.addSubview(grid)
|
|
|
|
+ grid.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+
|
|
|
|
+ grid.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
|
|
|
+ grid.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
|
|
|
|
+ grid.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
|
|
|
+ grid.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // MARK: - data processing + update
|
|
|
|
+ private func processData(messageIds: [Int]) -> [GallerySection] {
|
|
|
|
+ return []
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// MARK: - UICollectionViewDataSource, UICollectionViewDelegate
|
|
|
|
+extension GalleryViewController: UICollectionViewDataSource, UICollectionViewDelegate {
|
|
|
|
+
|
|
|
|
+ func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
|
+ return gridSections.count
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
|
+ return gridSections[section].msgId.count
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
+ let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier: MediaCell.reuseIdentifier, for: indexPath) as! MediaCell
|
|
|
|
+
|
|
|
|
+ // cell update
|
|
|
|
+ return mediaCell
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+class MediaCell: UICollectionViewCell {
|
|
|
|
+ static let reuseIdentifier = "media_cell"
|
|
}
|
|
}
|