Quellcode durchsuchen

Galery layout shown (wrong constraints).

Iñigo Valentin vor 9 Jahren
Ursprung
Commit
3d753acfe9
5 geänderte Dateien mit 171 neuen und 27 gelöschten Zeilen
  1. 1 1
      app/Base.lproj/Main.storyboard
  2. 11 12
      app/GalleryView.swift
  3. 30 8
      app/GalleryView.xib
  4. 118 4
      app/RowGallery.swift
  5. 11 2
      app/RowGallery.xib

+ 1 - 1
app/Base.lproj/Main.storyboard

@@ -290,7 +290,7 @@
                         <viewControllerLayoutGuide type="top" id="yvh-VS-RXe"/>
                         <viewControllerLayoutGuide type="bottom" id="tOB-l0-rCU"/>
                     </layoutGuides>
-                    <view key="view" contentMode="scaleToFill" id="pPe-Xd-teA">
+                    <view key="view" contentMode="scaleToFill" id="pPe-Xd-teA" customClass="GalleryView" customModule="app" customModuleProvider="target">
                         <rect key="frame" x="0.0" y="0.0" width="320" height="458"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>

+ 11 - 12
app/GalleryView.swift

@@ -62,7 +62,7 @@ class GalleryView: UIView {
 		let lang : String = getLanguage()
 		context.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Album> = Album.fetchRequest()
-		let sortDescriptor = NSSortDescriptor(key: "dtime", ascending: false)
+		let sortDescriptor = NSSortDescriptor(key: "time", ascending: false)
 		let sortDescriptors = [sortDescriptor]
 		fetchRequest.sortDescriptors = sortDescriptors
 		
@@ -73,25 +73,24 @@ class GalleryView: UIView {
 			//I like to check the size of the returned results!
 			print ("GALLERY:DEBUG: Total albums: \(searchResults.count)")
 			
-			var row : RowBlog
+			var row : RowGallery
 			var count = 0
 			var id: Int
 			var title: String
-			var text: String
-			var image: String
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
 				print("GALLERY:DEBUG: album perm: \(r.value(forKey: "permalink"))")
 				
 				
 				//Create a new row
-				row = RowBlog.init(s: "rowBlog\(count)", i: count)
+				row = RowGallery.init(s: "rowGallery\(count)", i: count)
 				id = r.value(forKey: "id")! as! Int
-				title = r.value(forKey: "title_\(lang)")! as! String
-				text = r.value(forKey: "text_\(lang)")! as! String
-				row.setTitle(text: title)
-				row.setText(text: text)
 				
+				print("GALLERY:DEBUG: Setting title")
+				//title = r.value(forKey: "title_\(lang)")! as! String
+				//row.setTitle(text: title)
+				
+				/* TODO: Get 4 random images from the album
 				// Get main image
 				image = ""
 				let imgFetchRequest: NSFetchRequest<Post_image> = Post_image.fetchRequest()
@@ -108,10 +107,10 @@ class GalleryView: UIView {
 						row.setImage(filename: image)
 					}
 				} catch {
-					print("BLOG:ERROR: Error getting image for post \(id): \(error)")
+					print("GALLERY:ERROR: Error getting image for post \(id): \(error)")
 				}
-				
-				print("BLOG:DEBUG: Row height: \(row.frame.height)")
+
+				*/
 				
 				parent.addArrangedSubview(row)
 				row.setNeedsLayout()

+ 30 - 8
app/GalleryView.xib

@@ -21,24 +21,46 @@
             <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aoy-Mh-gpR">
-                    <rect key="frame" x="67" y="269" width="240" height="128"/>
-                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aoy-Mh-gpR">
+                    <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
                     <subviews>
-                        <stackView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="ULw-PH-L95">
-                            <rect key="frame" x="65" y="-36" width="240" height="128"/>
-                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                        <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="ULw-PH-L95">
+                            <rect key="frame" x="0.0" y="0.0" width="360" height="1000"/>
                             <subviews>
-                                <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3TY-0K-6q1" customClass="Section" customModule="app">
-                                    <rect key="frame" x="0.0" y="0.0" width="240" height="128"/>
+                                <view autoresizesSubviews="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3TY-0K-6q1" customClass="Section" customModule="app">
+                                    <rect key="frame" x="0.0" y="0.0" width="360" height="1000"/>
                                     <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                                    <constraints>
+                                        <constraint firstAttribute="height" constant="1000" id="vPf-aG-EZ9"/>
+                                    </constraints>
+                                    <edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
                                 </view>
                             </subviews>
+                            <constraints>
+                                <constraint firstItem="3TY-0K-6q1" firstAttribute="top" secondItem="ULw-PH-L95" secondAttribute="top" id="0GM-gA-76X"/>
+                                <constraint firstItem="3TY-0K-6q1" firstAttribute="width" secondItem="ULw-PH-L95" secondAttribute="width" id="fZS-cn-vrg"/>
+                                <constraint firstAttribute="width" constant="360" id="hup-Kx-aQF"/>
+                                <constraint firstAttribute="bottom" secondItem="3TY-0K-6q1" secondAttribute="bottom" id="n9J-oi-jRF"/>
+                                <constraint firstAttribute="height" constant="1000" id="xuX-cU-pXu"/>
+                            </constraints>
                         </stackView>
                     </subviews>
+                    <constraints>
+                        <constraint firstAttribute="trailing" secondItem="ULw-PH-L95" secondAttribute="trailing" id="FEV-qn-MAO"/>
+                        <constraint firstItem="ULw-PH-L95" firstAttribute="leading" secondItem="aoy-Mh-gpR" secondAttribute="leading" id="LOc-iu-RwK"/>
+                        <constraint firstItem="ULw-PH-L95" firstAttribute="top" secondItem="aoy-Mh-gpR" secondAttribute="top" id="tCz-sX-2pl"/>
+                        <constraint firstAttribute="bottom" secondItem="ULw-PH-L95" secondAttribute="bottom" id="wJq-aC-CNc"/>
+                    </constraints>
                 </scrollView>
             </subviews>
             <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+            <constraints>
+                <constraint firstItem="aoy-Mh-gpR" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" id="1sn-WI-SeL"/>
+                <constraint firstItem="aoy-Mh-gpR" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="53f-dW-QfI"/>
+                <constraint firstItem="aoy-Mh-gpR" firstAttribute="height" secondItem="iN0-l3-epB" secondAttribute="height" id="JAc-a5-eSB"/>
+                <constraint firstItem="aoy-Mh-gpR" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="KbH-35-FjR"/>
+                <constraint firstItem="aoy-Mh-gpR" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" id="ftc-db-cKU"/>
+            </constraints>
         </view>
     </objects>
 </document>

+ 118 - 4
app/RowGallery.swift

@@ -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)")
+		}
+	}
+	
+}

+ 11 - 2
app/RowGallery.xib

@@ -10,9 +10,18 @@
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RowGallery"/>
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RowGallery" customModule="app">
+            <connections>
+                <outlet property="container" destination="5s9-Le-qTP" id="Z8m-m7-LEO"/>
+                <outlet property="photo0" destination="ALA-B7-xYr" id="gBh-vt-C7l"/>
+                <outlet property="photo1" destination="1yK-KV-day" id="uHg-pA-CYk"/>
+                <outlet property="photo2" destination="FJP-ZD-LGA" id="7As-zB-f1E"/>
+                <outlet property="photo3" destination="Xwd-Zx-bfE" id="wvz-zu-nXM"/>
+                <outlet property="title" destination="0t2-77-n8R" id="JXv-hD-axV"/>
+            </connections>
+        </placeholder>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
-        <view contentMode="scaleToFill" id="iN0-l3-epB" userLabel="RowGallery" customClass="RowGallery">
+        <view contentMode="scaleToFill" id="iN0-l3-epB" userLabel="RowGallery" customClass="RowGallery" customModule="app">
             <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>