MFYInboxTableViewCell.swift 3.48 KB
//
//  MFYInboxTableViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 24/6/22.
//

import UIKit

@objc public class MFYInboxTableViewCell: UITableViewCell {
    @IBOutlet weak var inboxView: UIView!
    @IBOutlet weak var campaignImage: UIImageView!
    @IBOutlet weak var newBadgeImage: UIImageView!
    @IBOutlet weak var campaignTitleLabel: UILabel!
    @IBOutlet weak var curvedBgImage: UIImageView!
    @IBOutlet weak var subtitleLabel: UILabel!
    @IBOutlet weak var descriptionLabel: UILabel!

    var postImageURL: String? {
        didSet {
            if let url = postImageURL {
                self.campaignImage.image = UIImage() // UIImage(named: "loading")

                UIImage.loadImageUsingCacheWithUrlString(url) { image in
                    // set the image only when we are still displaying the content for the image we finished downloading
                    if url == self.postImageURL {
                        self.campaignImage.image = image
                    }
                }
            }
            else {
                self.campaignImage.image = nil
            }
        }
    }
    
    public override func awakeFromNib() {
        super.awakeFromNib()
        
        inboxView.layer.cornerRadius = 5.0
        inboxView.clipsToBounds = true
        
       newBadgeImage.image = UIImage(named: "new_icon_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
       curvedBgImage.image = UIImage(named: "curved_bg_white", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        
        newBadgeImage.isHidden = true
    }

    public override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    public override func layoutSubviews() {
        super.layoutSubviews()
        //set the values for top,left,bottom,right margins
        let margins = UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
        contentView.frame = contentView.frame.inset(by: margins)
    }
    
    
    func configureCell(campaign: swiftApi.CampaignItemModel) {
        // campaignImage.load(link: campaign.logo_url ?? "", placeholder: UIImage(), cache: URLCache())
        self.postImageURL = campaign.logo_url ?? ""
        
        campaignTitleLabel.text = campaign.title ?? ""
        campaignTitleLabel.font = UIFont(name: "PFSquareSansPro-BoldItalic", size: 18)
        subtitleLabel.text = campaign.subtitle ?? ""
        subtitleLabel.font = UIFont(name: "PFSquareSansPro-Regular", size: 16)
        descriptionLabel.text = campaign.message ?? ""
        descriptionLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
        
        if (campaign.is_new == true) {
            newBadgeImage.isHidden = false
        } else{
            newBadgeImage.isHidden = true
        }
    }

    func configureCell(ccms: swiftApi.LoyaltyContextualOfferModel) {
        // campaignImage.load(link: ccms._imageUrl , placeholder: UIImage(), cache: URLCache())
        self.postImageURL = ccms._imageUrl
        
        campaignTitleLabel.text = ccms._title
        campaignTitleLabel.font = UIFont(name: "PFSquareSansPro-BoldItalic", size: 18)
        subtitleLabel.text = ccms._subtitle 
        subtitleLabel.font = UIFont(name: "PFSquareSansPro-Regular", size: 16)
        descriptionLabel.text = ccms._description 
        descriptionLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
        
        newBadgeImage.isHidden = true
    }

}