Преглед изворни кода

setup collectionView delegate/datasource

nayooti пре 5 година
родитељ
комит
2fd129f5b8
1 измењених фајлова са 59 додато и 0 уклоњено
  1. 59 0
      deltachat-ios/Controller/GalleryViewController.swift

+ 59 - 0
deltachat-ios/Controller/GalleryViewController.swift

@@ -3,18 +3,77 @@ import UIKit
 
 class GalleryViewController: UIViewController {
 
+    private struct GallerySection {
+        let header: String
+        let msgId: [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]) {
         self.mediaMessageIds = mediaMessageIds
         super.init(nibName: nil, bundle: nil)
+        self.gridSections = processData(messageIds: mediaMessageIds)
     }
 
     required init?(coder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
 
+    // MARK: - lifecycle
     override func 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"
 }