Sfoglia il codice sorgente

Gallery section in home screen displayed.

Iñigo Valentin 9 anni fa
parent
commit
3545a8347c
5 ha cambiato i file con 265 aggiunte e 1 eliminazioni
  1. 8 0
      app.xcodeproj/project.pbxproj
  2. 43 0
      app/HomeView.swift
  3. 1 1
      app/HomeView.xib
  4. 101 0
      app/RowHomeGallery.swift
  5. 112 0
      app/RowHomeGallery.xib

+ 8 - 0
app.xcodeproj/project.pbxproj

@@ -24,6 +24,8 @@
 		935D6E331E867C7E00CED3A1 /* RowGallery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935D6E321E867C7E00CED3A1 /* RowGallery.swift */; };
 		937EA02D1E5B8B5300D0893A /* UIApplcation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937EA02C1E5B8B5300D0893A /* UIApplcation.swift */; };
 		93B408031D9ED44C000FBC99 /* MenuCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93B408021D9ED44C000FBC99 /* MenuCollectionViewCell.swift */; };
+		93B5C01A1E872B4B0069BFF8 /* RowHomeGallery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93B5C0191E872B4B0069BFF8 /* RowHomeGallery.swift */; };
+		93B5C01C1E872B600069BFF8 /* RowHomeGallery.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93B5C01B1E872B600069BFF8 /* RowHomeGallery.xib */; };
 		93B84B9A1D9C31AB006C0F67 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93B84B991D9C31AB006C0F67 /* AppDelegate.swift */; };
 		93B84B9C1D9C31AB006C0F67 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93B84B9B1D9C31AB006C0F67 /* ViewController.swift */; };
 		93B84B9F1D9C31AB006C0F67 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 93B84B9D1D9C31AB006C0F67 /* Main.storyboard */; };
@@ -64,6 +66,8 @@
 		935D6E321E867C7E00CED3A1 /* RowGallery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowGallery.swift; sourceTree = "<group>"; };
 		937EA02C1E5B8B5300D0893A /* UIApplcation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIApplcation.swift; sourceTree = "<group>"; };
 		93B408021D9ED44C000FBC99 /* MenuCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MenuCollectionViewCell.swift; path = ../MenuCollectionViewCell.swift; sourceTree = "<group>"; };
+		93B5C0191E872B4B0069BFF8 /* RowHomeGallery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowHomeGallery.swift; sourceTree = "<group>"; };
+		93B5C01B1E872B600069BFF8 /* RowHomeGallery.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RowHomeGallery.xib; sourceTree = "<group>"; };
 		93B84B961D9C31AB006C0F67 /* app.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = app.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		93B84B991D9C31AB006C0F67 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
 		93B84B9B1D9C31AB006C0F67 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -157,6 +161,8 @@
 				935D6E2E1E86792000CED3A1 /* GalleryView.swift */,
 				935D6E301E867C5E00CED3A1 /* RowGallery.xib */,
 				935D6E321E867C7E00CED3A1 /* RowGallery.swift */,
+				93B5C0191E872B4B0069BFF8 /* RowHomeGallery.swift */,
+				93B5C01B1E872B600069BFF8 /* RowHomeGallery.xib */,
 			);
 			path = app;
 			sourceTree = "<group>";
@@ -244,6 +250,7 @@
 				935D6E311E867C5E00CED3A1 /* RowGallery.xib in Resources */,
 				93B84B9F1D9C31AB006C0F67 /* Main.storyboard in Resources */,
 				93D9EA6C1DE3498500089002 /* HomeView.xib in Resources */,
+				93B5C01C1E872B600069BFF8 /* RowHomeGallery.xib in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -262,6 +269,7 @@
 				93BAD2F81E586741009DF853 /* RowHomeSocial.swift in Sources */,
 				93BAD2F01E585662009DF853 /* RowHomeBlog.swift in Sources */,
 				93294FFA1E337D0D00FDAF50 /* RowHomePastActivities.swift in Sources */,
+				93B5C01A1E872B4B0069BFF8 /* RowHomeGallery.swift in Sources */,
 				935892D01E493C2300E1CD5F /* UIImageView.swift in Sources */,
 				93D9EA761DE3ACBB00089002 /* Sync.swift in Sources */,
 				93BAD2F41E585EE6009DF853 /* RowHomeFutureActivities.swift in Sources */,

+ 43 - 0
app/HomeView.swift

@@ -80,6 +80,7 @@ class HomeView: UIView {
 		setUpBlog(context: moc, delegate: appDelegate, lang: lang, parent: blogSection.getContentStack())
 		setUpFutureActivities(context: moc, delegate: appDelegate, lang: lang, parent: futureActivitiesSection.getContentStack())
 		setUpSocial(parent: socialSection.getContentStack())
+		setUpGallery(context: moc, delegate: appDelegate, parent: gallerySection.getContentStack())
 		
 		
 		pastActivitiesSection.expandSection()
@@ -318,6 +319,48 @@ class HomeView: UIView {
 		}
 	}
 	
+	func setUpGallery(context : NSManagedObjectContext, delegate: AppDelegate,parent: UIStackView){
+		print("HOME:LOG: Setting up gallery.")
+		
+		// Create the row
+		var row: RowHomeGallery
+		row = RowHomeGallery.init(s: "rowHomeGallery", i: 0)
+		parent.addArrangedSubview(row)
+		
+		
+		// Set images
+		let fetchRequest: NSFetchRequest<Photo> = Photo.fetchRequest()
+		let sortDescriptor = NSSortDescriptor(key: "uploaded", ascending: false)
+		let sortDescriptors = [sortDescriptor]
+		fetchRequest.sortDescriptors = sortDescriptors
+		fetchRequest.fetchLimit = 4
+		
+		do {
+			//go get the results
+			let searchResults = try context.fetch(fetchRequest)
+	
+			var id: Int
+			var image: String
+			
+			// Loop images
+			var i = 0
+			for r in searchResults as [NSManagedObject] {
+				
+				image = r.value(forKey: "file")! as! String
+				row.setImage(idx: i, filename: image)
+				
+				//TODO Set click listener
+				
+				i = i + 1
+			}
+			
+		}
+		catch{
+			print("HOME:ERROR: Error setting gallery up: \(error)")
+		}
+		
+	}
+	
 	func setUpSocial(parent : UIStackView){
 		print("SETING UP SOCIAL")
 		//Create a new row

+ 1 - 1
app/HomeView.xib

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2657" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
     <device id="retina3_5" orientation="portrait">
         <adaptation id="fullscreen"/>
     </device>

+ 101 - 0
app/RowHomeGallery.swift

@@ -0,0 +1,101 @@
+// Copyright (C) 2016 Inigo Valentin
+//
+// This file is part of the Gasteizko Margolariak IOS app.
+//
+// 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 RowHomeGallery: UIView {
+	
+	//This view
+	var v: UIView!
+	
+	@IBOutlet weak var container: UIView!
+	@IBOutlet weak var photo0: UIImageView!
+	@IBOutlet weak var photo1: UIImageView!
+	@IBOutlet weak var photo2: UIImageView!
+	@IBOutlet weak var photo3: UIImageView!
+	
+	var photos: [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) {
+		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
+		container.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+		container.translatesAutoresizingMaskIntoConstraints = true
+		
+		container.frame = v.bounds
+		v.addSubview(container)
+		
+		photos = [photo0, photo1, photo2, photo3]
+		
+
+		
+		//TODO Set click listeners
+	}
+	
+	/**
+	Default constructor for the interface builder
+	*/
+	override init(frame: CGRect){
+		super.init(frame: frame)
+	}
+	
+	/**
+	Changes the preview image.
+	If null or empty, the igage is hidden.
+	:param: path The new text.
+	*/
+	func setImage(idx: Int, filename: String){
+		if (filename == ""){
+			print("ROWHOMEGALLERY:LOG: No image.")
+			//TODO hide the imageview
+		}
+		else{
+			let path = "img/galeria/thumb/\(filename)"
+			photos[idx].setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
+		}
+	}
+	
+}

+ 112 - 0
app/RowHomeGallery.xib

@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+    <device id="retina4_7" orientation="portrait">
+        <adaptation id="fullscreen"/>
+    </device>
+    <dependencies>
+        <deployment identifier="iOS"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
+        <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <objects>
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RowHomeGallery" customModule="app">
+            <connections>
+                <outlet property="container" destination="fQL-ej-f6f" id="gat-5m-Nlc"/>
+                <outlet property="photo0" destination="dnB-DT-XBi" id="Gcn-A3-qVV"/>
+                <outlet property="photo1" destination="WDB-y4-09J" id="yCC-HU-nfj"/>
+                <outlet property="photo2" destination="anB-pq-Srl" id="VWm-9P-5aK"/>
+                <outlet property="photo3" destination="fDa-I0-n0C" id="oyE-AI-yhP"/>
+            </connections>
+        </placeholder>
+        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
+        <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="RowHomeGallery" customModule="app">
+            <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
+            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+            <subviews>
+                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fQL-ej-f6f" userLabel="Container">
+                    <rect key="frame" x="-0.5" y="0.0" width="375" height="230"/>
+                    <subviews>
+                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wVc-lu-Pqh" userLabel="Entry">
+                            <rect key="frame" x="10" y="10" width="355" height="230"/>
+                            <subviews>
+                                <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="dnB-DT-XBi" userLabel="Photo0">
+                                    <rect key="frame" x="10" y="10" width="162.5" height="100"/>
+                                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                    <constraints>
+                                        <constraint firstAttribute="height" constant="100" id="c49-em-SBK"/>
+                                    </constraints>
+                                </imageView>
+                                <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="WDB-y4-09J" userLabel="Photo1">
+                                    <rect key="frame" x="182.5" y="10" width="162.5" height="100"/>
+                                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                    <constraints>
+                                        <constraint firstAttribute="height" constant="100" id="PMB-24-syn"/>
+                                    </constraints>
+                                </imageView>
+                                <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="anB-pq-Srl" userLabel="Photo2">
+                                    <rect key="frame" x="10" y="120" width="162.5" height="100"/>
+                                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                    <constraints>
+                                        <constraint firstAttribute="height" constant="100" id="A9o-VC-FHH"/>
+                                    </constraints>
+                                </imageView>
+                                <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="fDa-I0-n0C" userLabel="Photo3">
+                                    <rect key="frame" x="182.5" y="120" width="162.5" height="100"/>
+                                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                    <constraints>
+                                        <constraint firstAttribute="height" constant="100" id="Lw8-Ie-YJH"/>
+                                    </constraints>
+                                </imageView>
+                            </subviews>
+                            <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                            <constraints>
+                                <constraint firstItem="dnB-DT-XBi" firstAttribute="width" secondItem="wVc-lu-Pqh" secondAttribute="width" multiplier="0.5" constant="-15" id="68Z-py-m5z"/>
+                                <constraint firstItem="anB-pq-Srl" firstAttribute="top" secondItem="dnB-DT-XBi" secondAttribute="bottom" constant="10" id="Bad-nG-5z5"/>
+                                <constraint firstItem="dnB-DT-XBi" firstAttribute="leading" secondItem="wVc-lu-Pqh" secondAttribute="leading" constant="10" id="D5O-yf-YW8"/>
+                                <constraint firstItem="fDa-I0-n0C" firstAttribute="top" secondItem="WDB-y4-09J" secondAttribute="bottom" constant="10" id="EAz-Ai-4fI"/>
+                                <constraint firstItem="anB-pq-Srl" firstAttribute="leading" secondItem="wVc-lu-Pqh" secondAttribute="leading" constant="10" id="EBa-JH-t1r"/>
+                                <constraint firstItem="anB-pq-Srl" firstAttribute="width" secondItem="wVc-lu-Pqh" secondAttribute="width" multiplier="0.5" constant="-15" id="EcJ-3D-reB"/>
+                                <constraint firstAttribute="height" constant="230" id="Ffn-YP-qLO"/>
+                                <constraint firstItem="WDB-y4-09J" firstAttribute="top" secondItem="wVc-lu-Pqh" secondAttribute="top" constant="10" id="NRB-ED-7lT"/>
+                                <constraint firstItem="fDa-I0-n0C" firstAttribute="width" secondItem="wVc-lu-Pqh" secondAttribute="width" multiplier="0.5" constant="-15" id="gYW-t2-gNJ"/>
+                                <constraint firstItem="WDB-y4-09J" firstAttribute="trailing" secondItem="wVc-lu-Pqh" secondAttribute="trailing" constant="-10" id="lWA-u1-9Oi"/>
+                                <constraint firstItem="dnB-DT-XBi" firstAttribute="top" secondItem="wVc-lu-Pqh" secondAttribute="top" constant="10" id="mWE-kd-0X9"/>
+                                <constraint firstItem="fDa-I0-n0C" firstAttribute="trailing" secondItem="wVc-lu-Pqh" secondAttribute="trailing" constant="-10" id="tJB-Qz-gmc"/>
+                                <constraint firstItem="WDB-y4-09J" firstAttribute="width" secondItem="wVc-lu-Pqh" secondAttribute="width" multiplier="0.5" constant="-15" id="tJI-ji-ciu"/>
+                            </constraints>
+                            <edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
+                            <userDefinedRuntimeAttributes>
+                                <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                    <color key="value" red="0.42745098039215684" green="0.41176470588235292" blue="0.56470588235294117" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                </userDefinedRuntimeAttribute>
+                                <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                    <integer key="value" value="1"/>
+                                </userDefinedRuntimeAttribute>
+                                <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                    <integer key="value" value="3"/>
+                                </userDefinedRuntimeAttribute>
+                            </userDefinedRuntimeAttributes>
+                        </view>
+                    </subviews>
+                    <constraints>
+                        <constraint firstItem="wVc-lu-Pqh" firstAttribute="bottom" secondItem="fQL-ej-f6f" secondAttribute="bottom" constant="10" id="4Qm-4E-T6T"/>
+                        <constraint firstAttribute="trailing" secondItem="wVc-lu-Pqh" secondAttribute="trailing" constant="10" id="Gw9-3i-bdM"/>
+                        <constraint firstItem="wVc-lu-Pqh" firstAttribute="top" secondItem="fQL-ej-f6f" secondAttribute="top" constant="10" id="JpE-6m-QpJ"/>
+                        <constraint firstItem="wVc-lu-Pqh" firstAttribute="leading" secondItem="fQL-ej-f6f" secondAttribute="leading" constant="10" id="sx2-Al-2U2"/>
+                    </constraints>
+                    <edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
+                </view>
+            </subviews>
+            <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+            <constraints>
+                <constraint firstItem="fQL-ej-f6f" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="D1e-8E-fga"/>
+                <constraint firstItem="fQL-ej-f6f" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" id="Pfz-ns-fxp"/>
+                <constraint firstItem="fQL-ej-f6f" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="r6U-3K-HqE"/>
+            </constraints>
+        </view>
+    </objects>
+    <resources>
+        <image name="PhotoPlaceholder" width="170" height="108"/>
+    </resources>
+</document>