Răsfoiți Sursa

RowHomePastActivity rows loaded in the home screen.

Iñigo Valentin 9 ani în urmă
părinte
comite
62739a782d

BIN
app.xcodeproj/project.xcworkspace/xcuserdata/seavenois.xcuserdatad/UserInterfaceState.xcuserstate


+ 75 - 2
app/HomeView.swift

@@ -19,8 +19,8 @@
 // If not, see <http://www.gnu.org/licenses/>.
 
 import Foundation
+import CoreData
 import UIKit
-
 /**
  Class to handle the home view.
  */
@@ -62,6 +62,13 @@ class HomeView: UIView {
 		pastActivitiesSection.setTitle(text: "Ultimas actividades")
 		socialSection.setTitle(text: "Siguenos")
 		
+		//Get info to populate sections
+		let moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
+		let appDelegate = UIApplication.shared.delegate as! AppDelegate
+		let lang : String = getLanguage()
+		
+		//Populate sections
+		setUpPastActivities(context: moc, delegate: appDelegate, lang: lang, parent: pastActivitiesSection)
 		
 		//Always at the end: update scrollview
 		var h: Int = 0
@@ -73,6 +80,72 @@ class HomeView: UIView {
 		self.scrollView.contentSize.height = CGFloat(h);
 	}
 	
-	func setUpPastActivities(){
+	func getLanguage() -> String{
+		let pre = NSLocale.preferredLanguages[0].subStr(start: 0, end: 1)
+		print("Device language: \(pre)")
+		if(pre == "es" || pre == "en" || pre == "eu"){
+			return pre
+		}
+		else{
+			return "es"
+		}
+	}
+	
+	func setUpPastActivities(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : Section){
+		
+		context.persistentStoreCoordinator = delegate.persistentStoreCoordinator
+		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
+		let sortDescriptor = NSSortDescriptor(key: "date", ascending: false)
+		let sortDescriptors = [sortDescriptor]
+		fetchRequest.sortDescriptors = sortDescriptors
+		//TODO Compare dates
+		//fetchRequest.predicate = NSPredicate(format: "date < %@", sysdate)
+		fetchRequest.fetchLimit = 2
+		
+		do {
+			//go get the results
+			let searchResults = try context.fetch(fetchRequest)
+			
+			//I like to check the size of the returned results!
+			print ("Activities: \(searchResults.count)")
+			
+			var row : RowHomePastActivities
+			var count = 0;
+			var title : String
+			
+			//You need to convert to NSManagedObject to use 'for' loops
+			for r in searchResults as [NSManagedObject] {
+				count = count + 1
+				//get the Key Value pairs (although there may be a better way to do that...
+				print("Perm: \(r.value(forKey: "permalink"))")
+				
+				
+				//Create a new row
+				row = RowHomePastActivities(s: "rowHomePastActivities", i: count) //frame: CGRect(top: 0, left: 0, width: 200, height: 50)
+				row.frame = CGRect(x: 15, y: 15, width: 100, height: 100)
+				title = r.value(forKey: "permalink")! as! String
+				print(title)
+				row.setTitle(text: title)
+				parent.addSubview(row)
+				let lbl = UILabel()
+				lbl.text = "ABBA"
+				//view.addEntry(view: row)
+				//parent.addSubview(lbl)
+				var testView: UIView = UIView(frame: CGRect(x: 13, y: 13, width: 100, height: 100))
+    testView.backgroundColor = UIColor.blue
+    testView.alpha = 0.5
+    testView.tag = 100
+    testView.isUserInteractionEnabled = true
+    parent.addSubview(testView)
+				
+				//parent.addConstraint(NSLayoutConstraint(item: row, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: parent, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -10))
+				//parent.addConstraint(NSLayoutConstraint(item: row, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: parent, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: -10))
+				//row = RowHomePastActivities(s: "rowHomePastActivities", i: count)//Bundle.mainBundle("RowPastActivities").loadNibNamed("", owner: nil, options: nil)[0] as! RowHomePastActivities
+				//row.setupWithSuperView(superView: self)
+				
+			}
+		} catch {
+			print("Error with request: \(error)")
+		}
 	}
 }

+ 2 - 2
app/HomeView.xib

@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11542" 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="16B2657" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
     <device id="retina3_5" orientation="portrait">
         <adaptation id="fullscreen"/>
     </device>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>

+ 36 - 6
app/RowHomePastActivities.swift

@@ -24,24 +24,33 @@ import UIKit
 /**
 Extension of UIView to be formatted as sections.
 */
-class RowHomePastActivities: UIView {
+@IBDesignable class RowHomePastActivities: UIView {
 	
 	//The container.
-	@IBOutlet weak var container: UIView!
+	
 	
 	//The activity title.
-	@IBOutlet weak var title: UITextView!
+	@IBOutlet weak var title: UILabel!
+	
+	
 	
 	//The acvtivity text.
-	@IBOutlet weak var descrip: UITextView!
+	@IBOutlet weak var descrip: UILabel!
+	
+	
+	@IBOutlet weak var container: UIView!
 	
 	/**
 	Run when the section is loaded.
 	*/
 	required init?(coder aDecoder: NSCoder) {
 		super.init(coder: aDecoder)
-		
-		//Load the contents of the Section.xib file.
+	}
+	
+	init(s: String, i: Int) {
+		//self.s = s
+		//self.i = i
+		super.init(frame: CGRect(x: 20, y: 10, width: 300, height: 100))
 		Bundle.main.loadNibNamed("RowHomePastActivities", owner: self, options: nil)
 		self.addSubview(container)
 		container.frame = self.bounds
@@ -52,7 +61,9 @@ class RowHomePastActivities: UIView {
 	:param: text The new title.
 	*/
 	func setTitle(text: String){
+		print("Setting title: \(text)")
 		title.text = text
+		descrip.text = text
 	}
 	
 	/**
@@ -71,4 +82,23 @@ class RowHomePastActivities: UIView {
 	func setImage(path: String){
 		//TODO
 	}
+	
+	
+	
+	
+	/*var view:UIView!
+	
+	func setup() {
+		view = loadViewFromNib()
+		view.frame = bounds
+		view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeightaddSubview(view)
+	}
+	
+	func loadViewFromNib() -> UIView {
+		let bundle = Bundle(for:type(of: self))
+		let nib = UINib(nibName: "RowHomePastActivities", bundle: bundle)
+		let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
+		
+		return view
+	}*/
 }

+ 54 - 24
app/RowHomePastActivities.xib

@@ -1,43 +1,73 @@
 <?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">
-    <device id="retina3_5" orientation="portrait">
+    <device id="retina4_0" 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"/>
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RowHomePastActivities" customModule="app" customModuleProvider="target">
+            <connections>
+                <outlet property="container" destination="2hI-rc-KPm" id="0ga-QO-cvj"/>
+                <outlet property="descrip" destination="f4E-5p-Bid" id="ihi-Bg-Jib"/>
+                <outlet property="title" destination="Bkz-DV-HVr" id="2ey-2J-PCM"/>
+            </connections>
+        </placeholder>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
-        <view contentMode="scaleToFill" id="iN0-l3-epB" userLabel="RowHomePastActivities">
-            <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
+        <view contentMode="scaleToFill" id="iN0-l3-epB" userLabel="RowHomePastActivities" customClass="RowHomePastActivities" customModule="app" customModuleProvider="target">
+            <rect key="frame" x="0.0" y="0.0" width="402" height="148"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bkz-DV-HVr" userLabel="Title">
-                    <rect key="frame" x="0.0" y="0.0" width="42" height="21"/>
-                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
-                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
-                    <nil key="textColor"/>
-                    <nil key="highlightedColor"/>
-                </label>
-                <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="WSe-uz-Uhz" userLabel="Image">
-                    <rect key="frame" x="0.0" y="20" width="240" height="128"/>
-                </imageView>
-                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="f4E-5p-Bid" userLabel="Text">
-                    <rect key="frame" x="248" y="20" width="42" height="21"/>
-                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
-                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
-                    <nil key="textColor"/>
-                    <nil key="highlightedColor"/>
-                </label>
+                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2hI-rc-KPm" userLabel="Container">
+                    <rect key="frame" x="81" y="10" width="240" height="128"/>
+                    <subviews>
+                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="bg" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bkz-DV-HVr" userLabel="Title">
+                            <rect key="frame" x="-81" y="53" width="402" height="21"/>
+                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                            <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                            <nil key="textColor"/>
+                            <nil key="highlightedColor"/>
+                        </label>
+                        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="PhotoPlaceholder" translatesAutoresizingMaskIntoConstraints="NO" id="WSe-uz-Uhz" userLabel="Image">
+                            <rect key="frame" x="0.0" y="0.0" width="240" height="128"/>
+                            <constraints>
+                                <constraint firstAttribute="height" constant="128" id="lU5-Vi-wpM"/>
+                            </constraints>
+                        </imageView>
+                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="f4E-5p-Bid" userLabel="Text">
+                            <rect key="frame" x="99" y="53" width="42" height="21"/>
+                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                            <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                            <nil key="textColor"/>
+                            <nil key="highlightedColor"/>
+                        </label>
+                    </subviews>
+                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                </view>
             </subviews>
-            <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+            <color key="backgroundColor" red="0.0" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
             <constraints>
-                <constraint firstItem="WSe-uz-Uhz" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" multiplier="0.2" id="n42-1x-i2e"/>
+                <constraint firstItem="2hI-rc-KPm" firstAttribute="height" secondItem="iN0-l3-epB" secondAttribute="height" id="Ucm-wp-2PF"/>
+                <constraint firstItem="2hI-rc-KPm" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" id="kw0-mW-MeY"/>
             </constraints>
+            <nil key="simulatedStatusBarMetrics"/>
+            <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
+            <userDefinedRuntimeAttributes>
+                <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                    <color key="value" red="0.0" green="0.0" blue="0.3381076388888889" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                </userDefinedRuntimeAttribute>
+                <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                    <real key="value" value="10"/>
+                </userDefinedRuntimeAttribute>
+            </userDefinedRuntimeAttributes>
+            <connections>
+                <outlet property="descrip" destination="f4E-5p-Bid" id="Xda-6E-LNC"/>
+                <outlet property="title" destination="Bkz-DV-HVr" id="Eiz-p3-B1a"/>
+            </connections>
+            <point key="canvasLocation" x="46" y="-43"/>
         </view>
     </objects>
     <resources>

+ 6 - 0
app/Section.swift

@@ -54,4 +54,10 @@ class Section: UIView {
 	func setTitle(text: String){
 		title.text = text
 	}
+	
+	func addEntry(view : UIView){
+		let lbl = UILabel()
+		lbl.text = "ABBA"
+		content.addSubview(lbl)
+	}
 }