Ver Fonte

Album photos shown.

Iñigo Valentin há 9 anos atrás
pai
commit
490295da1a
4 ficheiros alterados com 88 adições e 58 exclusões
  1. 16 12
      app/AlbumViewController.swift
  2. 7 7
      app/Base.lproj/Main.storyboard
  3. 15 1
      app/RowAlbum.swift
  4. 50 38
      app/RowAlbum.xib

+ 16 - 12
app/AlbumViewController.swift

@@ -30,6 +30,7 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 	@IBOutlet weak var barTitle: UILabel!
 	@IBOutlet weak var albumTitle: UILabel!
 	@IBOutlet weak var albumContainer: UIStackView!
+	@IBOutlet weak var albumView: UIView!
 
 	// Album ID
 	var id: Int = -1
@@ -81,6 +82,10 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 		
 		NSLog(":ALBUMCONTROLLER:DEBUG: Loading album \(id)")
 		
+		albumContainer.backgroundColor = UIColor.red
+		
+		var row : RowAlbum
+		
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate
 		let lang : String = getLanguage()
@@ -88,6 +93,8 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 		let fetchRequest: NSFetchRequest<Photo_album> = Photo_album.fetchRequest()
 		fetchRequest.predicate = NSPredicate(format: "album = %i", id)
 		
+		var rowcount = 0
+		
 		do {
 			
 			// Get the photo list
@@ -95,11 +102,14 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 			var image: String
 			
 			NSLog(":GALLERYCONTROLLER:DEBUG: Total photos: \(searchResults.count)")
+			
 			for i in (0..<searchResults.count) where i % 2 == 0 {
 				
 				var r = searchResults[i]
 				var photoId = r.value(forKey: "photo")! as! Int
 				
+				row = RowAlbum.init(s: "rowAlbum\(i)", i: i)
+				
 				// Get photo info from Photo entity
 				let imgFetchRequest: NSFetchRequest<Photo> = Photo.fetchRequest()
 				let imgSortDescriptor = NSSortDescriptor(key: "uploaded", ascending: true)
@@ -112,6 +122,7 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 					var imgR = imgSearchResults[0]
 					image = imgR.value(forKey: "file")! as! String
 					NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) left: \(image)")
+					row.setImage(idx: 0, filename: image)
 					if i + 1 < searchResults.count {
 						r = searchResults[i + 1]
 						photoId = r.value(forKey: "photo")! as! Int
@@ -122,6 +133,7 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 						imgR = imgSearchResults[0]
 						image = imgR.value(forKey: "file")! as! String
 						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: \(image)")
+						row.setImage(idx: 1, filename: image)
 					}
 					else{
 						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: none")
@@ -132,22 +144,14 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 					print(":GALLERYCONTROLLER:ERROR: Error getting image for post \(id): \(error)")
 				}
 				
+				NSLog(":GALLERYCONTROLLER:DEBUG: Adding row: height: \(row.frame.height)")
+				albumContainer.addArrangedSubview(row)
+				
+				rowcount = rowcount + 1
 			}
 		} catch {
 			print("POST:ERROR: Error with request: \(error)")
 		}
-		
-		//Always at the end: update scrollview
-		// TODOs
-		//var h: Int = 0
-		//for view in scrollView.subviews {
-		//contentRect = contentRect.union(view.frame);
-		//	h = h + Int(view.frame.height) + 30 //Why 30?
-		//}
-		//print("POST:DEBUG: Height: \(h)")
-		// TODO: Calculate at the end
-		//self.scrollView.contentSize.height = 4500//CGFloat(h);
-		
 	}
 	
 	/**

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

@@ -64,7 +64,7 @@
                                 </collectionViewFlowLayout>
                                 <cells>
                                     <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="a4j-DF-epb" customClass="MenuCollectionViewCell" customModule="app" customModuleProvider="target">
-                                        <rect key="frame" x="0.0" y="-2.5" width="100" height="50"/>
+                                        <rect key="frame" x="0.0" y="-3" width="100" height="50"/>
                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                         <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                             <rect key="frame" x="0.0" y="0.0" width="100" height="50"/>
@@ -556,10 +556,10 @@
                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WEW-3s-kOI">
                                 <rect key="frame" x="0.0" y="50" width="320" height="518"/>
                                 <subviews>
-                                    <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kmd-tW-XIB">
+                                    <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" bounces="NO" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kmd-tW-XIB">
                                         <rect key="frame" x="0.0" y="0.0" width="320" height="518"/>
                                         <subviews>
-                                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="sej-1q-hlq" userLabel="Section">
+                                            <view contentMode="scaleToFill" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sej-1q-hlq" userLabel="Section">
                                                 <rect key="frame" x="10" y="10" width="300" height="1046"/>
                                                 <subviews>
                                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="Title" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YsV-il-CeR" userLabel="Title">
@@ -572,13 +572,13 @@
                                                         <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                                         <nil key="highlightedColor"/>
                                                     </label>
-                                                    <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="NlX-b5-vyb" userLabel="Content">
+                                                    <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="NlX-b5-vyb" userLabel="Content">
                                                         <rect key="frame" x="0.0" y="30" width="300" height="1016"/>
                                                         <subviews>
-                                                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YEF-04-q7Y" userLabel="Album">
+                                                            <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="YEF-04-q7Y" userLabel="Album">
                                                                 <rect key="frame" x="8" y="8" width="284" height="1000"/>
                                                                 <subviews>
-                                                                    <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="WRD-IZ-JpU">
+                                                                    <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="WRD-IZ-JpU">
                                                                         <rect key="frame" x="0.0" y="0.0" width="284" height="1000"/>
                                                                     </stackView>
                                                                 </subviews>
@@ -586,7 +586,6 @@
                                                                 <constraints>
                                                                     <constraint firstItem="WRD-IZ-JpU" firstAttribute="centerY" secondItem="YEF-04-q7Y" secondAttribute="centerY" id="HMS-4q-ns8"/>
                                                                     <constraint firstItem="WRD-IZ-JpU" firstAttribute="width" secondItem="YEF-04-q7Y" secondAttribute="width" id="Im5-F6-vGb"/>
-                                                                    <constraint firstAttribute="height" constant="1000" id="Ix6-5u-agq"/>
                                                                     <constraint firstItem="WRD-IZ-JpU" firstAttribute="height" secondItem="YEF-04-q7Y" secondAttribute="height" id="U7o-HF-khX"/>
                                                                     <constraint firstItem="WRD-IZ-JpU" firstAttribute="centerX" secondItem="YEF-04-q7Y" secondAttribute="centerX" id="jKg-n6-Kko"/>
                                                                 </constraints>
@@ -681,6 +680,7 @@
                     <connections>
                         <outlet property="albumContainer" destination="WRD-IZ-JpU" id="tSP-7c-APp"/>
                         <outlet property="albumTitle" destination="YsV-il-CeR" id="t9S-NX-eaE"/>
+                        <outlet property="albumView" destination="YEF-04-q7Y" id="7tR-Lr-9nh"/>
                         <outlet property="barButton" destination="Thj-0t-rxK" id="6bX-xo-abt"/>
                         <outlet property="barTitle" destination="LLe-aQ-Sbj" id="bFR-jT-Xmq"/>
                     </connections>

+ 15 - 1
app/RowAlbum.swift

@@ -27,8 +27,10 @@ Extension of UIView to be formatted as sections.
 @IBDesignable class RowAlbum: UIView {
 	
 	// Outlets
+	@IBOutlet weak var container: UIView!
 	@IBOutlet weak var photo0: UIImageView!
 	@IBOutlet weak var photo1: UIImageView!
+
 	
 	// Album ID
 	var id = -1
@@ -53,6 +55,18 @@ Extension of UIView to be formatted as sections.
 		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
+		
+		v = self
+		self.frame = self.bounds
+		self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+		self.translatesAutoresizingMaskIntoConstraints = true
+		
+		container.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+		container.translatesAutoresizingMaskIntoConstraints = true
+		
+		container.frame = self.bounds
+		self.addSubview(container)
+
 	}
 	
 	/**
@@ -63,7 +77,7 @@ Extension of UIView to be formatted as sections.
 	init(s: String, i: Int) {
 		NSLog(":ROWALBUM:DEBUG: Init \(s), \(i)")
 		
-		super.init(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))
+		super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
 		loadViewFromNib()
 		v = self
 		self.frame = self.bounds

+ 50 - 38
app/RowAlbum.xib

@@ -12,54 +12,66 @@
     <objects>
         <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RowAlbum" customModule="app" customModuleProvider="target">
             <connections>
-                <outlet property="image0" destination="STJ-Gn-fSb" id="jMa-Hj-9ea"/>
-                <outlet property="image1" destination="BRb-br-Rb9" id="mNJ-gK-1D1"/>
+                <outlet property="container" destination="HdV-Po-yYe" id="J6E-n0-STQ"/>
+                <outlet property="photo0" destination="STJ-Gn-fSb" id="KnJ-xP-W5E"/>
+                <outlet property="photo1" destination="BRb-br-Rb9" id="GSz-Ba-URb"/>
             </connections>
         </placeholder>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
-        <view contentMode="scaleToFill" id="iN0-l3-epB" userLabel="RowAlbum">
+        <view contentMode="scaleToFill" id="iN0-l3-epB" userLabel="RowAlbum" customClass="RowAlbum" customModule="app">
             <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="STJ-Gn-fSb" userLabel="PhotoL">
-                    <rect key="frame" x="10" y="10" width="172.5" height="108"/>
-                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="HdV-Po-yYe">
+                    <rect key="frame" x="-0.5" y="269" width="375" height="128"/>
+                    <subviews>
+                        <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="STJ-Gn-fSb" userLabel="PhotoL">
+                            <rect key="frame" x="10" y="10" width="172.5" height="108"/>
+                            <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                            <constraints>
+                                <constraint firstAttribute="height" constant="108" id="adJ-vY-QZ4"/>
+                            </constraints>
+                            <userDefinedRuntimeAttributes>
+                                <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                    <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                </userDefinedRuntimeAttribute>
+                                <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                    <real key="value" value="1"/>
+                                </userDefinedRuntimeAttribute>
+                            </userDefinedRuntimeAttributes>
+                        </imageView>
+                        <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="BRb-br-Rb9" userLabel="PhotoR">
+                            <rect key="frame" x="192.5" y="10" width="172.5" height="108"/>
+                            <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                            <constraints>
+                                <constraint firstAttribute="height" constant="108" id="LVi-0V-kFe"/>
+                            </constraints>
+                            <userDefinedRuntimeAttributes>
+                                <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                    <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                </userDefinedRuntimeAttribute>
+                                <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                    <real key="value" value="1"/>
+                                </userDefinedRuntimeAttribute>
+                            </userDefinedRuntimeAttributes>
+                        </imageView>
+                    </subviews>
+                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                     <constraints>
-                        <constraint firstAttribute="height" constant="108" id="adJ-vY-QZ4"/>
+                        <constraint firstItem="STJ-Gn-fSb" firstAttribute="width" secondItem="HdV-Po-yYe" secondAttribute="width" multiplier="0.5" constant="-15" id="4OG-wC-zDi"/>
+                        <constraint firstAttribute="trailing" secondItem="BRb-br-Rb9" secondAttribute="trailing" constant="10" id="52p-oq-lor"/>
+                        <constraint firstItem="BRb-br-Rb9" firstAttribute="centerY" secondItem="HdV-Po-yYe" secondAttribute="centerY" id="BdD-2d-ZcG"/>
+                        <constraint firstItem="STJ-Gn-fSb" firstAttribute="leading" secondItem="HdV-Po-yYe" secondAttribute="leading" constant="10" id="DAf-JG-dgr"/>
+                        <constraint firstItem="STJ-Gn-fSb" firstAttribute="centerY" secondItem="HdV-Po-yYe" secondAttribute="centerY" id="LpQ-Cf-UpA"/>
+                        <constraint firstItem="BRb-br-Rb9" firstAttribute="width" secondItem="HdV-Po-yYe" secondAttribute="width" multiplier="0.5" constant="-15" id="hFK-eR-Cdf"/>
+                        <constraint firstAttribute="height" constant="128" id="i8w-5X-QWB"/>
                     </constraints>
-                    <userDefinedRuntimeAttributes>
-                        <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
-                            <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
-                        </userDefinedRuntimeAttribute>
-                        <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
-                            <real key="value" value="1"/>
-                        </userDefinedRuntimeAttribute>
-                    </userDefinedRuntimeAttributes>
-                </imageView>
-                <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="BRb-br-Rb9" userLabel="PhotoR">
-                    <rect key="frame" x="197.5" y="10" width="172.5" height="108"/>
-                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
-                    <constraints>
-                        <constraint firstAttribute="height" constant="108" id="LVi-0V-kFe"/>
-                    </constraints>
-                    <userDefinedRuntimeAttributes>
-                        <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
-                            <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
-                        </userDefinedRuntimeAttribute>
-                        <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
-                            <real key="value" value="1"/>
-                        </userDefinedRuntimeAttribute>
-                    </userDefinedRuntimeAttributes>
-                </imageView>
+                </view>
             </subviews>
-            <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
             <constraints>
-                <constraint firstItem="BRb-br-Rb9" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" multiplier="0.5" constant="-15" id="Nsh-ju-JXC"/>
-                <constraint firstItem="BRb-br-Rb9" firstAttribute="trailing" secondItem="iN0-l3-epB" secondAttribute="trailing" constant="-5" id="Phu-9W-VdZ"/>
-                <constraint firstItem="STJ-Gn-fSb" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="10" id="jbT-nH-OfC"/>
-                <constraint firstItem="STJ-Gn-fSb" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" multiplier="0.5" constant="-15" id="nGe-Uj-Yhh"/>
-                <constraint firstItem="STJ-Gn-fSb" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="10" id="uhv-Ju-fhw"/>
-                <constraint firstItem="BRb-br-Rb9" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="10" id="vo9-a0-KTz"/>
+                <constraint firstItem="HdV-Po-yYe" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="4Aa-Fb-Ugf"/>
+                <constraint firstItem="HdV-Po-yYe" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" id="bFu-54-Zel"/>
+                <constraint firstItem="HdV-Po-yYe" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="jRe-xq-gcl"/>
             </constraints>
         </view>
     </objects>