|
|
@@ -26,20 +26,17 @@ The view controller of the app.
|
|
|
*/
|
|
|
class PostViewController: UIViewController, UIGestureRecognizerDelegate {
|
|
|
|
|
|
+
|
|
|
@IBOutlet weak var barTitle: UILabel!
|
|
|
@IBOutlet weak var barButton: UIButton!
|
|
|
@IBOutlet weak var postText: UILabel!
|
|
|
@IBOutlet weak var postTitle: UILabel!
|
|
|
@IBOutlet weak var postImage: UIImageView!
|
|
|
- var id: Int = -1
|
|
|
- var delegate: AppDelegate?
|
|
|
|
|
|
+ var id: Int = -1
|
|
|
var passId: Int = -1
|
|
|
+ var delegate: AppDelegate?
|
|
|
|
|
|
- /**
|
|
|
- Get the app context.
|
|
|
- :return: The app context.
|
|
|
- */
|
|
|
func getContext () -> NSManagedObjectContext {
|
|
|
return NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
|
|
|
}
|
|
|
@@ -49,16 +46,17 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
|
|
|
Run when the app loads.
|
|
|
*/
|
|
|
override func viewDidLoad() {
|
|
|
+
|
|
|
super.viewDidLoad()
|
|
|
self.loadPost(id: id)
|
|
|
+
|
|
|
// Set button action
|
|
|
barButton.addTarget(self, action: #selector(self.back), for: .touchUpInside)
|
|
|
}
|
|
|
|
|
|
+ //TODO implement all the logic for post loading here, including iboutlts
|
|
|
+
|
|
|
|
|
|
- /**
|
|
|
- Dismisses the controller.
|
|
|
- */
|
|
|
func back() {
|
|
|
print("POSTCONTROLLER:DEBUG: Back")
|
|
|
self.dismiss(animated: true, completion: nil)
|
|
|
@@ -72,15 +70,8 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
|
|
|
super.didReceiveMemoryWarning()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- Loads the selected post.
|
|
|
- :param: id Post id.
|
|
|
- */
|
|
|
public func loadPost(id: Int){
|
|
|
|
|
|
- NSLog(":POSTCONTROLLER:DEBUG: Loading post \(id)")
|
|
|
-
|
|
|
let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
let lang : String = getLanguage()
|
|
|
@@ -89,18 +80,20 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
|
|
|
fetchRequest.predicate = NSPredicate(format: "id = %i", id)
|
|
|
|
|
|
do {
|
|
|
+ //go get the results
|
|
|
let searchResults = try context.fetch(fetchRequest)
|
|
|
- var count = 0
|
|
|
+
|
|
|
var sTitle: String
|
|
|
var sText: String
|
|
|
var image: String
|
|
|
|
|
|
+ //You need to convert to NSManagedObject to use 'for' loops
|
|
|
for r in searchResults as [NSManagedObject] {
|
|
|
- count = count + 1
|
|
|
+
|
|
|
sTitle = r.value(forKey: "title_\(lang)")! as! String
|
|
|
sText = r.value(forKey: "text_\(lang)")! as! String
|
|
|
- postTitle.text = " \(sTitle)"
|
|
|
- postText.text = sText.stripHtml()
|
|
|
+ postTitle.text = " \(sTitle.decode().stripHtml())"
|
|
|
+ postText.text = sText.decode().stripHtml()
|
|
|
|
|
|
// Get main image
|
|
|
image = ""
|
|
|
@@ -110,12 +103,18 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
|
|
|
imgFetchRequest.sortDescriptors = imgSortDescriptors
|
|
|
imgFetchRequest.predicate = NSPredicate(format: "post == %i", id)
|
|
|
imgFetchRequest.fetchLimit = 1
|
|
|
+ //TODO get more images
|
|
|
do{
|
|
|
let imgSearchResults = try context.fetch(imgFetchRequest)
|
|
|
for imgR in imgSearchResults as [NSManagedObject]{
|
|
|
image = imgR.value(forKey: "image")! as! String
|
|
|
- let path = "img/blog/preview/\(image)"
|
|
|
- self.postImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
|
|
|
+ if image == ""{
|
|
|
+ self.postImage.isHidden = true
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ let path = "img/actividades/thumb/\(image)"
|
|
|
+ self.postImage.setImage(localPath: path, remotePath: "https://margolariak.com/\(path)")
|
|
|
+ }
|
|
|
}
|
|
|
} catch {
|
|
|
NSLog(":POST:ERROR: Error getting image for post \(id): \(error)")
|
|
|
@@ -127,6 +126,7 @@ class PostViewController: UIViewController, UIGestureRecognizerDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
Gets the device language. The only recognized languages are Spanish, English and Basque.
|
|
|
If the device has another language, Spanish will be selected by default.
|