You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // RewardItemCollectionViewCell.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon Devik Kim on 11/04/2019.
  6. // Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. import Kingfisher
  10. class RewardItemCollectionViewCell: UICollectionViewCell {
  11. @IBOutlet weak var itemImage: UIImageView!
  12. @IBOutlet weak var itemNameLabel: UILabel!
  13. @IBOutlet weak var itemPriceLabel: UILabel!
  14. @IBOutlet weak var redeemButton: UIButton!
  15. @IBOutlet weak var contentsView: UIView!
  16. @IBOutlet weak var pointTitleLabel: UILabel!
  17. private var model: RewardProduct?
  18. var delegate: RewardViewInterface?
  19. func setModel(with model: RewardProduct?, delegate: RewardViewInterface?){
  20. if let imageData = model?.productImgPath,
  21. let url = URL(string: imageData) {
  22. itemImage.kf.setImage(with: url)
  23. }
  24. self.itemNameLabel.text = model?.productName
  25. self.itemPriceLabel.text = model?.pointPrice?.likeCommaMoney()
  26. self.model = model
  27. self.delegate = delegate
  28. self.setUI()
  29. }
  30. private func setUI(){
  31. self.contentsView.layer.cornerRadius = 10
  32. self.setButton()
  33. setMultiLanguage()
  34. }
  35. func setButton(){
  36. self.redeemButton.layer.cornerRadius = 10
  37. self.redeemButton.addTarget(self, action: #selector(redeemButtonTouch), for: .touchUpInside)
  38. let totalPoint = GMEDB.shared.user.integer(.rewardPoint)
  39. let isEnable = totalPoint >= Int(self.model?.pointPrice ?? "") ?? 0
  40. self.redeemButton.backgroundColor = isEnable ? AppConstants.themeRedColor : .lightGray
  41. self.redeemButton.isEnabled = isEnable
  42. }
  43. private func setMultiLanguage(){
  44. pointTitleLabel.text = "points_text".localized()
  45. redeemButton.setTitle("redeem_text".localized(), for: .normal)
  46. }
  47. @objc
  48. func redeemButtonTouch() {
  49. print("touched \(self.itemNameLabel.text ?? "") redeem button")
  50. delegate?.goRedeemViewController(with: self.model)
  51. }
  52. }