Manos Chorianopoulos

add dfy active code copy functionality

......@@ -18,6 +18,7 @@
1E87A9EF28C2021200C79F90 /* ContextualViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E87A9EE28C2021200C79F90 /* ContextualViewController.swift */; };
1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */; };
1EA2BB792865BFE8003F2AB0 /* InboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA2BB782865BFE8003F2AB0 /* InboxTableViewCell.swift */; };
1EA771AC290977CA0030924C /* CopyableLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA771AB290977CA0030924C /* CopyableLabel.swift */; };
1EB236AB28816B680063777A /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB236AA28816B680063777A /* ShareViewController.swift */; };
1EB236AD28816C560063777A /* NumberPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB236AC28816C560063777A /* NumberPopupViewController.swift */; };
1EB236AF28816CAC0063777A /* NumbersTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB236AE28816CAB0063777A /* NumbersTableViewCell.swift */; };
......@@ -180,6 +181,7 @@
1E87A9EE28C2021200C79F90 /* ContextualViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextualViewController.swift; sourceTree = "<group>"; };
1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponsTableViewCell.swift; sourceTree = "<group>"; };
1EA2BB782865BFE8003F2AB0 /* InboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxTableViewCell.swift; sourceTree = "<group>"; };
1EA771AB290977CA0030924C /* CopyableLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopyableLabel.swift; sourceTree = "<group>"; };
1EB236AA28816B680063777A /* ShareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewController.swift; sourceTree = "<group>"; };
1EB236AC28816C560063777A /* NumberPopupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberPopupViewController.swift; sourceTree = "<group>"; };
1EB236AE28816CAB0063777A /* NumbersTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumbersTableViewCell.swift; sourceTree = "<group>"; };
......@@ -464,6 +466,7 @@
E6A77A35282BB4CB0045BBA8 /* MakeItAPresentViewController.swift */,
E6A7785A282933E40045BBA8 /* Helpers */,
E6A77861282933E50045BBA8 /* Main.storyboard */,
1EA771AB290977CA0030924C /* CopyableLabel.swift */,
1E4410B028F5855000859F92 /* CampaignCategory.swift */,
1EDCDFAB28DB29E8002ED8F0 /* AnalysisMoreViewCell.swift */,
1E87A9EE28C2021200C79F90 /* ContextualViewController.swift */,
......@@ -940,6 +943,7 @@
E6A77A36282BB4CB0045BBA8 /* MakeItAPresentViewController.swift in Sources */,
E6A77947282933E70045BBA8 /* FMDatabaseQueue.m in Sources */,
E6A77922282933E60045BBA8 /* NSData+SSToolkitAdditions.m in Sources */,
1EA771AC290977CA0030924C /* CopyableLabel.swift in Sources */,
1EB236AB28816B680063777A /* ShareViewController.swift in Sources */,
E6A778E7282933E60045BBA8 /* DetailsViewController.swift in Sources */,
1EB5F4CA285370C90016F36E /* LoyaltyAnalysisViewController.swift in Sources */,
......
//
// CopyableLabel.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 26/10/22.
//
import Foundation
import UIKit
class CopyableLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
sharedInit()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
sharedInit()
}
func sharedInit() {
isUserInteractionEnabled = true
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(showMenu(sender:))))
}
@objc
func showMenu(sender: AnyObject?) {
becomeFirstResponder()
let menu = UIMenuController.shared
if !menu.isMenuVisible {
menu.setTargetRect(bounds, in: self)
menu.setMenuVisible(true, animated: true)
}
}
override var canBecomeFirstResponder: Bool {
return true
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.copy(_:)) {
return true
}
return false
}
override func copy(_ sender: Any?) {
let board = UIPasteboard.general
if var textToCopy = text {
if (textToCopy.contains(", ")) {
textToCopy = textToCopy.replacingOccurrences(of: ", ", with: "")
}
print(textToCopy)
board.string = textToCopy
}
// board.string = text
let menu = UIMenuController.shared
menu.setMenuVisible(false, animated: true)
}
}
......@@ -944,7 +944,7 @@
<rect key="frame" x="10" y="475" width="394" height="100"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="2" translatesAutoresizingMaskIntoConstraints="NO" id="MCY-xv-vpg">
<rect key="frame" x="20" y="23" width="254" height="54"/>
<rect key="frame" x="20" y="32.5" width="254" height="35"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Ενεργός κωδικός:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ucC-u4-AQL">
<rect key="frame" x="0.0" y="0.0" width="254" height="19"/>
......@@ -952,19 +952,52 @@
<color key="textColor" red="0.23529411759999999" green="0.32549019610000002" blue="0.39607843139999999" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vUM-ac-164">
<rect key="frame" x="0.0" y="21" width="254" height="0.0"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cjr-c8-pL3">
<rect key="frame" x="0.0" y="0.0" width="254" height="0.0"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" id="eQ1-yY-Dk0"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Cjr-c8-pL3" firstAttribute="top" secondItem="gKJ-wy-UjY" secondAttribute="top" id="00U-6c-1f2"/>
<constraint firstItem="Cjr-c8-pL3" firstAttribute="bottom" secondItem="gKJ-wy-UjY" secondAttribute="bottom" id="PDW-hq-mQs"/>
<constraint firstItem="Cjr-c8-pL3" firstAttribute="trailing" secondItem="gKJ-wy-UjY" secondAttribute="trailing" id="S8N-x6-zh1"/>
<constraint firstItem="Cjr-c8-pL3" firstAttribute="leading" secondItem="gKJ-wy-UjY" secondAttribute="leading" id="SbU-3v-rwK"/>
<constraint firstItem="Cjr-c8-pL3" firstAttribute="width" secondItem="4rG-Ia-uel" secondAttribute="width" id="tMz-sE-6TW"/>
<constraint firstAttribute="height" id="zkI-mG-qPM"/>
</constraints>
<viewLayoutGuide key="contentLayoutGuide" id="gKJ-wy-UjY"/>
<viewLayoutGuide key="frameLayoutGuide" id="4rG-Ia-uel"/>
</scrollView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="961544809" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qBe-Jw-QUx">
<rect key="frame" x="0.0" y="21" width="254" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="PFSquareSansPro-Bold" family="PF Square Sans Pro" pointSize="19"/>
<color key="textColor" red="0.23529411759999999" green="0.32549019610000002" blue="0.39607843139999999" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Λήγει σε 4 ημέρες" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qL0-3b-eqA">
<rect key="frame" x="0.0" y="42" width="254" height="12"/>
<rect key="frame" x="0.0" y="23" width="254" height="12"/>
<fontDescription key="fontDescription" name="PFSquareSansPro-Regular" family="PF Square Sans Pro" pointSize="12"/>
<color key="textColor" red="0.2274509804" green="0.32156862749999998" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="vUM-ac-164" firstAttribute="leading" secondItem="MCY-xv-vpg" secondAttribute="leading" id="eV5-RL-miL"/>
<constraint firstAttribute="trailing" secondItem="vUM-ac-164" secondAttribute="trailing" id="u5q-oF-oPt"/>
</constraints>
<variation key="default">
<mask key="subviews">
<exclude reference="qBe-Jw-QUx"/>
</mask>
</variation>
</stackView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="active_code_logo" translatesAutoresizingMaskIntoConstraints="NO" id="xwu-AC-ij3">
<rect key="frame" x="294" y="10" width="80" height="80"/>
......@@ -1191,9 +1224,13 @@
</constraints>
</view>
<connections>
<outlet property="activeCodeContentView" destination="Cjr-c8-pL3" id="KXI-Mq-PWS"/>
<outlet property="activeCodeContentViewHeight" destination="eQ1-yY-Dk0" id="J69-Hr-XD3"/>
<outlet property="activeCodeExpirationLabel" destination="qL0-3b-eqA" id="XjP-lI-UtJ"/>
<outlet property="activeCodeImage" destination="xwu-AC-ij3" id="iU8-rU-Q07"/>
<outlet property="activeCodeLabel" destination="qBe-Jw-QUx" id="mlj-zT-T0Z"/>
<outlet property="activeCodeScrollView" destination="vUM-ac-164" id="kIA-4v-lGx"/>
<outlet property="activeCodeScrollViewHeight" destination="zkI-mG-qPM" id="hXL-Rp-DQz"/>
<outlet property="activeCodeView" destination="zFT-By-XHL" id="M0w-Ln-iC9"/>
<outlet property="activeCodeViewHeight" destination="7r0-fu-7H9" id="nDr-bk-ViP"/>
<outlet property="activeCodesCountLabel" destination="ucC-u4-AQL" id="BCn-Ul-WqA"/>
......
......@@ -40,6 +40,10 @@ import SwiftEventBus
@IBOutlet weak var emptyView: UIView!
@IBOutlet weak var emptyImage: UIImageView!
@IBOutlet weak var emptyLabel: UILabel!
@IBOutlet weak var activeCodeScrollView: UIScrollView!
@IBOutlet weak var activeCodeScrollViewHeight: NSLayoutConstraint!
@IBOutlet weak var activeCodeContentView: UIView!
@IBOutlet weak var activeCodeContentViewHeight: NSLayoutConstraint!
public var coupons:Array<swiftApi.CouponItemModel> = swiftApi().getCouponList()
public var dfyCoupons:Array<swiftApi.ActiveDFYCouponModel> = swiftApi().getActiveDFYCoupons()
......@@ -237,7 +241,21 @@ import SwiftEventBus
}
activeCodesCountLabel.text = "Ενεργός κωδικός:"
activeCodeLabel.text = dfyCoupons[0]._code
// activeCodeLabel.text = dfyCoupons[0]._code
let newLabel = CopyableLabel()
newLabel.text = String(dfyCoupons[0]._code)
newLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 19)
newLabel.textColor = UIColor(rgb: 0x3C5365)
newLabel.frame.size.width = newLabel.intrinsicContentSize.width
newLabel.frame.size.height = newLabel.intrinsicContentSize.height // tagHeight
activeCodeContentView.addSubview(newLabel)
// set the btn frame origin
newLabel.frame.origin.x = 0
newLabel.frame.origin.y = 0
let scrollHeight = newLabel.intrinsicContentSize.height
activeCodeContentViewHeight.constant = scrollHeight
activeCodeScrollViewHeight.constant = scrollHeight
activeCodeExpirationLabel.isHidden = false
if (daysFromNow == "1") {
activeCodeExpirationLabel.text = "Λήγει σε " + daysFromNow + " ημέρα"
......@@ -246,19 +264,61 @@ import SwiftEventBus
}
} else {
var couponCodesString = ""
var tagHeight:CGFloat = 30
let tagPadding: CGFloat = 0
let tagSpacingX: CGFloat = 0
let tagSpacingY: CGFloat = 2
let containerWidth = activeCodeContentView.frame.size.width
var currentOriginX: CGFloat = 0
var currentOriginY: CGFloat = 0
// var couponCodesString = ""
for (index, item) in dfyCoupons.enumerated() {
let newLabel = CopyableLabel()
newLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 19)
newLabel.textColor = UIColor(rgb: 0x3C5365)
if (index == (dfyCoupons.endIndex - 1)) {
couponCodesString += String(item._code)
// couponCodesString += String(item._code)
newLabel.text = String(item._code)
} else {
couponCodesString += String(item._code) + ", "
// couponCodesString += String(item._code) + ", "
newLabel.text = String(item._code) + ", "
}
newLabel.frame.size.width = newLabel.intrinsicContentSize.width + tagPadding
newLabel.frame.size.height = newLabel.intrinsicContentSize.height // tagHeight
tagHeight = newLabel.intrinsicContentSize.height
activeCodeContentView.addSubview(newLabel)
// if current X + label width will be greater than container view width
// "move to next row"
if currentOriginX + newLabel.frame.width > containerWidth {
currentOriginX = 0
currentOriginY += tagHeight + tagSpacingY
}
// set the btn frame origin
newLabel.frame.origin.x = currentOriginX
newLabel.frame.origin.y = currentOriginY
// increment current X by btn width + spacing
currentOriginX += newLabel.frame.width + tagSpacingX
}
activeCodesCountLabel.text = String(dfyCoupons.count) + " Ενεργοί κωδικοί:"
activeCodeLabel.text = couponCodesString
// activeCodeLabel.text = couponCodesString
activeCodeExpirationLabel.isHidden = true
// update container view height
activeCodeContentViewHeight.constant = currentOriginY + tagHeight
if ((currentOriginY + tagHeight) <= (2 * tagHeight + tagSpacingY)) {
activeCodeScrollViewHeight.constant = currentOriginY + tagHeight
} else {
activeCodeScrollViewHeight.constant = 2 * tagHeight + tagSpacingY
}
}
} else {
activeCodeLabel.text = "-"
......