Skip to content

Commit

Permalink
Added Rate Base Value realtime change
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayer committed Dec 8, 2019
1 parent 352e6c2 commit 6b0ffef
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15400" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15400"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SafariExtensionViewController" customModule="CurrencyConverter_Extension" customModuleProvider="target">
<connections>
<outlet property="baseRateValueField" destination="FYs-pI-VQX" id="NOa-uU-9pB"/>
<outlet property="convertListBtn" destination="O6F-e9-S0S" id="WaW-Xm-HQp"/>
<outlet property="convertToListBtn" destination="oft-bR-MYa" id="uf9-pk-FaF"/>
<outlet property="formatterListBtn" destination="qtJ-F7-RwH" id="HzF-yz-5hW"/>
Expand All @@ -21,31 +22,31 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe">
<rect key="frame" x="0.0" y="0.0" width="386" height="183"/>
<rect key="frame" x="0.0" y="0.0" width="425" height="142"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="10" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fGs-PP-re3">
<rect key="frame" x="10" y="15" width="366" height="153"/>
<rect key="frame" x="10" y="15" width="405" height="112"/>
<subviews>
<stackView distribution="fill" orientation="horizontal" alignment="centerY" spacing="10" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kRc-jp-qL9">
<rect key="frame" x="0.0" y="137" width="366" height="16"/>
<rect key="frame" x="0.0" y="91" width="405" height="21"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2Eb-xW-tdx">
<rect key="frame" x="-2" y="0.0" width="53" height="16"/>
<rect key="frame" x="-2" y="3" width="53" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Convert" id="1aJ-XB-fks">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton identifier="convertTo" horizontalHuggingPriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="O6F-e9-S0S">
<rect key="frame" x="57" y="-2" width="151" height="20"/>
<rect key="frame" x="57" y="1" width="140" height="20"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="70" id="oQu-Ja-vNm"/>
</constraints>
<popUpButtonCell key="cell" type="check" title="Loading..." bezelStyle="regularSquare" imagePosition="left" lineBreakMode="truncatingTail" state="on" borderStyle="bezel" inset="2" selectedItem="7iB-GU-NXP" id="05m-Qp-gkt">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="system"/>
<menu key="menu" title="Loading" id="7en-Qr-0vp">
<items>
<menuItem title="Loading..." state="on" id="7iB-GU-NXP"/>
Expand All @@ -59,21 +60,21 @@
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="oKH-gt-BLV">
<rect key="frame" x="214" y="0.0" width="19" height="16"/>
<rect key="frame" x="203" y="3" width="19" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="To" id="V75-Um-qfu">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="oft-bR-MYa">
<rect key="frame" x="239" y="-2" width="84" height="20"/>
<rect key="frame" x="228" y="1" width="84" height="20"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="70" id="bD1-DS-XIs"/>
</constraints>
<popUpButtonCell key="cell" type="check" title="Loading..." bezelStyle="regularSquare" imagePosition="left" lineBreakMode="truncatingTail" state="on" borderStyle="bezel" inset="2" selectedItem="sqG-R2-WNo" id="wfy-Rk-GRs">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="system"/>
<menu key="menu" title="Loading" id="TnW-gn-x6r">
<items>
<menuItem title="Loading..." state="on" id="sqG-R2-WNo"/>
Expand All @@ -86,8 +87,23 @@
<action selector="OnConvertToClicked:" target="-2" id="MIA-T0-vBY"/>
</connections>
</popUpButton>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="FYs-pI-VQX">
<rect key="frame" x="320" y="0.0" width="40" height="21"/>
<constraints>
<constraint firstAttribute="width" constant="40" id="c8O-4e-QNT"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="agm-Wd-4vR">
<numberFormatter key="formatter" formatterBehavior="default10_4" numberStyle="decimal" formatWidth="-1" minimumIntegerDigits="1" maximumIntegerDigits="2000000000" maximumFractionDigits="3" id="DUn-Il-YkY"/>
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="OnBaseRateValueChanged:" target="-2" id="pds-vE-ERh"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TyX-ll-gIp">
<rect key="frame" x="329" y="0.0" width="39" height="16"/>
<rect key="frame" x="368" y="3" width="39" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Rates" id="iZu-Mz-CQl">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -98,24 +114,28 @@
<constraints>
<constraint firstItem="oKH-gt-BLV" firstAttribute="leading" secondItem="O6F-e9-S0S" secondAttribute="trailing" constant="10" id="4FH-BC-fEs"/>
<constraint firstItem="oft-bR-MYa" firstAttribute="leading" secondItem="oKH-gt-BLV" secondAttribute="trailing" constant="10" id="QYp-ZM-dvX"/>
<constraint firstItem="FYs-pI-VQX" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="oft-bR-MYa" secondAttribute="trailing" constant="10" id="bwc-fl-8Dc"/>
<constraint firstItem="TyX-ll-gIp" firstAttribute="leading" relation="lessThanOrEqual" secondItem="FYs-pI-VQX" secondAttribute="trailing" multiplier="2" constant="3" id="r5T-3D-BmZ"/>
</constraints>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<stackView distribution="fill" orientation="vertical" alignment="centerX" spacing="10" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gaL-NW-C6N">
<rect key="frame" x="0.0" y="85" width="347" height="42"/>
<rect key="frame" x="0.0" y="39" width="347" height="42"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gvL-DV-pOX">
<rect key="frame" x="-2" y="26" width="351" height="16"/>
Expand Down Expand Up @@ -184,24 +204,24 @@
</customSpacing>
</stackView>
<stackView distribution="fill" orientation="horizontal" alignment="firstBaseline" spacing="10" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Uuk-Yp-v7x">
<rect key="frame" x="0.0" y="0.0" width="211" height="75"/>
<rect key="frame" x="0.0" y="0.0" width="211" height="29"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZQ6-Cb-hfO">
<rect key="frame" x="-2" y="59" width="85" height="16"/>
<rect key="frame" x="-2" y="13" width="85" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Paste Format" id="SWx-gV-TgK">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="qtJ-F7-RwH">
<rect key="frame" x="89" y="57" width="124" height="20"/>
<rect key="frame" x="89" y="11" width="124" height="20"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="120" id="56X-bX-hLi"/>
</constraints>
<popUpButtonCell key="cell" type="check" title="Loading" bezelStyle="regularSquare" imagePosition="left" lineBreakMode="truncatingTail" state="on" borderStyle="bezel" inset="2" selectedItem="G2X-eD-aCr" id="zke-wh-lxC">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="system"/>
<menu key="menu" id="rUi-G2-qot">
<items>
<menuItem title="Loading" state="on" id="G2X-eD-aCr"/>
Expand Down Expand Up @@ -246,7 +266,7 @@
<constraint firstAttribute="bottom" secondItem="fGs-PP-re3" secondAttribute="bottom" constant="15" id="n9a-WP-n3f"/>
<constraint firstItem="fGs-PP-re3" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="10" id="pP1-vE-s5v"/>
</constraints>
<point key="canvasLocation" x="-41" y="105.5"/>
<point key="canvasLocation" x="-41.5" y="85"/>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="ZiD-3V-OX3">
<rect key="frame" x="0.0" y="0.0" width="37" height="16"/>
Expand Down
6 changes: 3 additions & 3 deletions CurrencyConverter Extension/ConvertPasteboardFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ConvertPasteboardFormatter {
let ToSymbolPH = "${to_symbol}"
let FromSymbolPH = "${from_symbol}"

static let formatterString : [String] = [
static let defaultFormattingString : [String] = [
"${to_amount} ${to_symbol}",
"${to_amount}",
"${from_amount} ${from_symbol} => ${to_amount} ${to_symbol}",
Expand All @@ -34,7 +34,7 @@ class ConvertPasteboardFormatter {
}

func getFormattedString(formatIndex: Int) -> String{
var ret = ConvertPasteboardFormatter.formatterString[formatIndex]
var ret = ConvertPasteboardFormatter.defaultFormattingString[formatIndex]
ret = ret.replacingOccurrences(of: FromSymbolPH, with: self.fromSymbol)
ret = ret.replacingOccurrences(of: ToSymbolPH, with: self.toSymbol)

Expand All @@ -47,7 +47,7 @@ class ConvertPasteboardFormatter {

func getAllFormattedStrings() -> [String] {
var ret : [String] = []
for x in 0...(ConvertPasteboardFormatter.formatterString.count - 1) {
for x in 0...(ConvertPasteboardFormatter.defaultFormattingString.count - 1) {
ret.insert(getFormattedString(formatIndex: x), at: x)
}
return ret
Expand Down
12 changes: 10 additions & 2 deletions CurrencyConverter Extension/SafariExtensionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController {
@IBOutlet weak var fxRateBtn0: NSButton!
@IBOutlet weak var fxRateBtn15: NSButton!
@IBOutlet weak var fxRateBtn2: NSButton!
@IBOutlet weak var baseRateValueField: NSTextField!

var fxRateBtnList : [NSButton] = []

Expand All @@ -56,10 +57,17 @@ class SafariExtensionViewController: SFSafariExtensionViewController {
self.convertToSym = UserDefaults.standard.value(forKey: "convertToSym") as! String? ?? "TWD"
self.convertListBtn.selectItem(at: self.symbols!.firstIndex(of: self.convertFromSym ?? "USD") ?? 0)
self.convertToListBtn.selectItem(at: self.symbols!.firstIndex(of: self.convertToSym ?? "TWD") ?? 0)
self.baseRateValueField.floatValue = UserDefaults.standard.value(forKey: "baseRateValue") as! Float32? ?? 1.0
self.UpdateFormatters()
self.UpdateRates()
}
}

@IBAction func OnBaseRateValueChanged(_ sender: NSTextField) {
let baseRateValue = sender.floatValue
UserDefaults.standard.set(baseRateValue as Float32, forKey: "baseRateValue")
UpdateRates()
}

@IBAction func OnConvertFromClicked(_ sender: NSPopUpButton) {
let selected = symbols![sender.indexOfSelectedItem]
Expand Down Expand Up @@ -91,9 +99,9 @@ class SafariExtensionViewController: SFSafariExtensionViewController {

func UpdateRates() {
let cc = CurrencyConverter.shared
cc.convert(from: convertFromSym!, to: convertToSym!, unit: 1.0) { (result, error) in
cc.convert(from: convertFromSym!, to: convertToSym!, unit: baseRateValueField.floatValue) { (result, error) in
let resultFixed = String(format: "%.4f", result)
self.ratesText.stringValue = "1:\(resultFixed)"
self.ratesText.stringValue = ":\(resultFixed)"
}
}

Expand Down
2 changes: 2 additions & 0 deletions CurrencyConverter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = CurrencyConverter/CurrencyConverter.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = J9849FB53X;
Expand All @@ -661,6 +662,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = CurrencyConverter/CurrencyConverter.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = J9849FB53X;
Expand Down

0 comments on commit 6b0ffef

Please sign in to comment.