|
|
@@ -1,9 +1,123 @@
|
|
|
+// Copyright (C) 2016 Inigo Valentin
|
|
|
//
|
|
|
-// RowGallery.swift
|
|
|
-// app
|
|
|
+// This file is part of the Gasteizko Margolariak IOS app.
|
|
|
//
|
|
|
-// Created by Iñigo Valentin on 25/3/17.
|
|
|
-// Copyright © 2017 Margolariak. All rights reserved.
|
|
|
+// The Gasteizko Margolariak IOS app is free software: you can
|
|
|
+// redistribute it and/or modify it under the terms of the
|
|
|
+// GNU General Public License as published by the Free Software
|
|
|
+// Foundation, either version 3 of the License, or (at your
|
|
|
+// option) any later version.
|
|
|
//
|
|
|
+// The Gasteizko Margolariak IOS app is distributed in the
|
|
|
+// hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
+// without even the implied warranty of MERCHANTABILITY or
|
|
|
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
+// Public License for more details.
|
|
|
+//
|
|
|
+// You should have received a copy of the GNU General Public
|
|
|
+// License along with the Gasteizko Margolariak IOS app.
|
|
|
+// If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
import Foundation
|
|
|
+import UIKit
|
|
|
+
|
|
|
+/**
|
|
|
+Extension of UIView to be formatted as sections.
|
|
|
+*/
|
|
|
+@IBDesignable class RowGallery: UIView {
|
|
|
+
|
|
|
+ //This view
|
|
|
+ var v: UIView!
|
|
|
+
|
|
|
+ @IBOutlet weak var container: UIView!
|
|
|
+ @IBOutlet weak var title: UILabel!
|
|
|
+ @IBOutlet weak var photo0: UIImageView!
|
|
|
+ @IBOutlet weak var photo1: UIImageView!
|
|
|
+ @IBOutlet weak var photo2: UIImageView!
|
|
|
+ @IBOutlet weak var photo3: UIImageView!
|
|
|
+
|
|
|
+ //Array with the imageviews
|
|
|
+ var preview: [UIImageView] = []
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ Default constructor
|
|
|
+ */
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
+ super.init(coder: aDecoder)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func loadViewFromNib() {
|
|
|
+ let bundle = Bundle(for: type(of: self))
|
|
|
+ let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
|
|
|
+ nib.instantiate(withOwner: self, options: nil).first as! UIView
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ Default constructor.
|
|
|
+ :param: s Custom identifier
|
|
|
+ :param: i Custom identifier
|
|
|
+ */
|
|
|
+ init(s: String, i: Int) {
|
|
|
+ print("ROWGALLERY:DEBUG: Init s, i")
|
|
|
+ super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
|
|
|
+ loadViewFromNib()
|
|
|
+ v = self
|
|
|
+ v.frame = bounds
|
|
|
+ v.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
+ v.translatesAutoresizingMaskIntoConstraints = true
|
|
|
+
|
|
|
+ print("ROWGALLERY:DEBUG: Setting container")
|
|
|
+ container.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
+ container.translatesAutoresizingMaskIntoConstraints = true
|
|
|
+
|
|
|
+ container.frame = v.bounds
|
|
|
+ v.addSubview(container)
|
|
|
+
|
|
|
+ //Populate review array
|
|
|
+ //print("ROWGALLERY:DEBUG: Populating preview array")
|
|
|
+ //preview = [photo0, photo1, photo2, photo3]
|
|
|
+
|
|
|
+ // Set tap recognizer
|
|
|
+ /*print("ROW_BLOG:DEBUG: set tap recognizer")
|
|
|
+ let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector (self.openPost (_:)))
|
|
|
+ tapRecognizer.delegate = (UIApplication.shared.delegate as! AppDelegate).controller
|
|
|
+ addGestureRecognizer(tapRecognizer)*/
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ Default constructor for the interface builder
|
|
|
+ */
|
|
|
+ override init(frame: CGRect){
|
|
|
+ super.init(frame: frame)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ Changes the title of the album. Decodes HTML.
|
|
|
+ :param: text The new title.
|
|
|
+ */
|
|
|
+ func setTitle(text: String){
|
|
|
+ print("ROWGALLERY:DEBUG: Setting title: \(title)")
|
|
|
+ title.text = text.stripHtml()
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ Changes the preview image of the album.
|
|
|
+ If null or empty, the igage is hidden.
|
|
|
+ :param: path The new text.
|
|
|
+ */
|
|
|
+ func setImage(idx: Int, filename: String){
|
|
|
+ if (filename == ""){
|
|
|
+ print("No image")
|
|
|
+ //TODO hide the imageview
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ print("Set image \(filename)")
|
|
|
+ let path = "img/gallery/thumb/\(filename)"
|
|
|
+ preview[idx].setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|