Skip to content

Commit

Permalink
Merge pull request #2 from mitsuaki1229/develop
Browse files Browse the repository at this point in the history
Add pop tips.
  • Loading branch information
mitsuaki1229 authored Mar 18, 2018
2 parents bf7b810 + c794159 commit c921534
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 21 deletions.
26 changes: 24 additions & 2 deletions BeaconDetection.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
2C87A178205DF94900379FD4 /* DescriptionViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C87A177205DF94900379FD4 /* DescriptionViewModelSpec.swift */; };
2C87A17A205DF97700379FD4 /* SettingViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C87A179205DF97700379FD4 /* SettingViewModelSpec.swift */; };
2C87A17C205DF9EF00379FD4 /* DetectionViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C87A17B205DF9EF00379FD4 /* DetectionViewModelSpec.swift */; };
2C87A17E205E21BC00379FD4 /* AMPopTip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C87A17D205E21BC00379FD4 /* AMPopTip.framework */; };
2C87A184205E90CC00379FD4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2C87A186205E90CC00379FD4 /* Localizable.strings */; };
2CA179BF1F7F0D960086BADF /* SimulatorViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA179BE1F7F0D960086BADF /* SimulatorViewModelSpec.swift */; };
2CB89EE91BEE567C002A4EC7 /* Const.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB89EE81BEE567C002A4EC7 /* Const.swift */; };
2CCCF0881F6FFEE000B5B560 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CCCF0871F6FFEE000B5B560 /* TabBarController.swift */; };
Expand Down Expand Up @@ -87,6 +89,9 @@
2C87A177205DF94900379FD4 /* DescriptionViewModelSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DescriptionViewModelSpec.swift; sourceTree = "<group>"; };
2C87A179205DF97700379FD4 /* SettingViewModelSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewModelSpec.swift; sourceTree = "<group>"; };
2C87A17B205DF9EF00379FD4 /* DetectionViewModelSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetectionViewModelSpec.swift; sourceTree = "<group>"; };
2C87A17D205E21BC00379FD4 /* AMPopTip.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AMPopTip.framework; path = Carthage/Build/iOS/AMPopTip.framework; sourceTree = "<group>"; };
2C87A185205E90CC00379FD4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
2C87A187205E90E300379FD4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
2CA179BE1F7F0D960086BADF /* SimulatorViewModelSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorViewModelSpec.swift; sourceTree = "<group>"; };
2CB89EE51BEE4F7C002A4EC7 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
2CB89EE81BEE567C002A4EC7 /* Const.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Const.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -114,6 +119,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2C87A17E205E21BC00379FD4 /* AMPopTip.framework in Frameworks */,
2C3F00851F2C58C40086076D /* SnapKit.framework in Frameworks */,
2C4D4AA91F486F690050CB14 /* MMMarkdown.framework in Frameworks */,
2CDDF20D1F35474100101FD7 /* RxDataSources.framework in Frameworks */,
Expand Down Expand Up @@ -146,6 +152,7 @@
08E2F86F4D9CD7C0F52361CF /* Frameworks */ = {
isa = PBXGroup;
children = (
2C87A17D205E21BC00379FD4 /* AMPopTip.framework */,
2C7B486B1F52F7F9008616CD /* Nimble.framework */,
2C7B486D1F52F7F9008616CD /* Quick.framework */,
2C4D4AA81F486F690050CB14 /* MMMarkdown.framework */,
Expand Down Expand Up @@ -241,6 +248,7 @@
6E7CADCA1BEC95D70046E77B /* LaunchScreen.storyboard */,
6E7CADCD1BEC95D70046E77B /* Info.plist */,
2C21D5A21F75C9C3000E481C /* Settings.bundle */,
2C87A186205E90CC00379FD4 /* Localizable.strings */,
);
path = BeaconDetection;
sourceTree = "<group>";
Expand Down Expand Up @@ -361,6 +369,7 @@
knownRegions = (
en,
Base,
ja,
);
mainGroup = 6E7CADB51BEC95D70046E77B;
productRefGroup = 6E7CADBF1BEC95D70046E77B /* Products */;
Expand All @@ -382,6 +391,7 @@
2CE891551F4B04D80046EC73 /* LICENSE.md in Resources */,
2C4D4AA71F486D620050CB14 /* README.md in Resources */,
2C21D5A31F75C9C3000E481C /* Settings.bundle in Resources */,
2C87A184205E90CC00379FD4 /* Localizable.strings in Resources */,
6E7CADCC1BEC95D70046E77B /* LaunchScreen.storyboard in Resources */,
6E7CADC91BEC95D70046E77B /* Assets.xcassets in Resources */,
2C87A176205D3FDE00379FD4 /* [email protected] in Resources */,
Expand Down Expand Up @@ -446,6 +456,7 @@
"$(SRCROOT)/Carthage/Build/iOS/RxSwift.framework",
"$(SRCROOT)/Carthage/Build/iOS/RxDataSources.framework",
"$(SRCROOT)/Carthage/Build/iOS/MMMarkdown.framework",
"$(SRCROOT)/Carthage/Build/iOS/AMPopTip.framework",
);
outputPaths = (
);
Expand Down Expand Up @@ -515,6 +526,15 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
2C87A186205E90CC00379FD4 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
2C87A185205E90CC00379FD4 /* en */,
2C87A187205E90E300379FD4 /* ja */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
6E7CADCA1BEC95D70046E77B /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -572,7 +592,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3.5;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -620,7 +640,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3.5;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -641,6 +661,7 @@
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = BeaconDetection/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mitsuaki1229.BeaconDetection;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -664,6 +685,7 @@
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = BeaconDetection/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mitsuaki1229.BeaconDetection;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
25 changes: 12 additions & 13 deletions BeaconDetection/Detection/DetectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import UIKit

class DetectionView: UIView, CustomView {

let detectionInfoTableView = UITableView()

let statusLabel = UILabel()
let proximityUUIDInputTextField = UITextField()
let majorInputTextField = UITextField()
let minorInputTextField = UITextField()

let statusLabel = UILabel()
let detectionInfoTableView = UITableView()

private var tabBarHeight: CGFloat {
return UITabBarController().tabBar.frame.size.height
}
Expand All @@ -38,23 +38,22 @@ class DetectionView: UIView, CustomView {

func addSubviews() {

addSubview(statusLabel)
addSubview(proximityUUIDInputTextField)
addSubview(majorInputTextField)
addSubview(minorInputTextField)
addSubview(statusLabel)
addSubview(detectionInfoTableView)
}

func addOptionalParameters() {

proximityUUIDInputTextField.placeholder = "proximityUUID"
majorInputTextField.placeholder = "major"
minorInputTextField.placeholder = "minor"

setInputTextFieldOption(textField: proximityUUIDInputTextField)
proximityUUIDInputTextField.keyboardType = .asciiCapable
majorInputTextField.placeholder = "major"
setInputTextFieldOption(textField: majorInputTextField)
majorInputTextField.keyboardType = .numberPad
minorInputTextField.placeholder = "minor"
setInputTextFieldOption(textField: minorInputTextField)
minorInputTextField.keyboardType = .numberPad

Expand All @@ -64,26 +63,26 @@ class DetectionView: UIView, CustomView {

func installConstraints() {

statusLabel.snp.makeConstraints { make in
proximityUUIDInputTextField.snp.makeConstraints { make in
make.top.equalToSuperview().offset(30)
make.left.equalToSuperview().offset(20)
make.right.equalTo(majorInputTextField.snp.left).offset(-20)
make.height.equalTo(30)
}

proximityUUIDInputTextField.snp.makeConstraints { make in
make.top.equalTo(statusLabel.snp.bottom).offset(10)
make.left.right.equalTo(statusLabel)
statusLabel.snp.makeConstraints { make in
make.top.equalTo(proximityUUIDInputTextField.snp.bottom).offset(10)
make.left.right.equalTo(proximityUUIDInputTextField)
}

majorInputTextField.snp.makeConstraints { make in
make.top.equalTo(statusLabel)
make.top.equalTo(proximityUUIDInputTextField)
make.right.equalToSuperview().offset(-10)
make.width.equalToSuperview().multipliedBy(0.2)
}

minorInputTextField.snp.makeConstraints { make in
make.top.equalTo(proximityUUIDInputTextField)
make.top.equalTo(statusLabel)
make.left.right.equalTo(majorInputTextField)
}

Expand Down
68 changes: 68 additions & 0 deletions BeaconDetection/Detection/DetectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2017年 Mitsuaki Ihara. All rights reserved.
//

import AMPopTip
import RxCocoa
import RxSwift
import UIKit
Expand All @@ -29,6 +30,18 @@ class DetectionViewController: UIViewController {
viewModel.updateProximityUUIDToDefault()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

setUpPopTip()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

removePopTips(view: view)
}

override var canBecomeFirstResponder: Bool {
return true
}
Expand Down Expand Up @@ -133,6 +146,61 @@ class DetectionViewController: UIViewController {
view.majorInputTextField.inputAccessoryView = numberPadToolbar
view.minorInputTextField.inputAccessoryView = numberPadToolbar
}

private func setUpPopTip() {
let checkedTips = UserDefaults().integer(forKey: Const.kCheckedTipsUserDefaultKey)
popTipChain(nextTips: (checkedTips + 1))
}

private func popTipChain(pt: PopTip = PopTip(), nextTips: Int, completion: (() -> Void)? = nil) {

guard nextTips >= 1,
nextTips < 8 else { return }

let view = self.view as! DetectionView
popTipDisplayPosition(tips: nextTips) { (direction, frame) in
pt.show(text: ("CheckedTips" + nextTips.description).localized, direction: direction, maxWidth: 200, in: view, from: frame)
}

let ptNext = PopTip()
pt.dismissHandler = { [unowned self] _ in
UserDefaults().set(nextTips, forKey: Const.kCheckedTipsUserDefaultKey)
self.popTipChain(pt: ptNext, nextTips: (nextTips + 1), completion: {
if let completion = completion {
completion()
}
})
}
}

private func popTipDisplayPosition(tips: Int, position: (_ direction: PopTipDirection, _ frame: CGRect) -> Void) {
let view = self.view as! DetectionView
switch tips {
case 1:
position(.down, view.proximityUUIDInputTextField.frame)
case 2:
position(.down, view.proximityUUIDInputTextField.frame)
case 3:
position(.left, view.majorInputTextField.frame)
case 4:
position(.down, view.statusLabel.frame)
case 5:
position(.down, view.statusLabel.frame)
case 6:
position(.none, view.detectionInfoTableView.frame)
case 7:
position(.none, view.frame)
default:
assert(false, "Implementation error")
}
}

private func removePopTips(view: UIView) {
for subview in view.subviews {
guard let subview = subview as? PopTip else { continue }
subview.removeFromSuperview()
}
}
}

extension DetectionViewController: UITableViewDelegate {
Expand Down
11 changes: 10 additions & 1 deletion BeaconDetection/Setting/SettingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SettingViewController: UIViewController {
super.viewDidLoad()

navigationController?.navigationBar.isTranslucent = false
navigationItem.title = "Description"
navigationItem.title = "Setting"

let view = self.view as! SettingView
view.listTableView.rx.setDelegate(self)
Expand All @@ -34,6 +34,15 @@ class SettingViewController: UIViewController {
return (ip, self?.viewModel.dataSource[ip])
}
.subscribe(onNext: { [weak self] ip, _ in

if ip.row == 3 {
self?.viewModel.clearCheckedTips()
let alert = UIAlertController(title: "Info", message: "Clear Checked Tips.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self?.rootViewController().present(alert, animated: false, completion: nil)
return
}

guard let type = DescriptionFileType(rawValue: ip.row),
type != .none else { return }
let descriptionViewController = DescriptionViewController(type: type)
Expand Down
16 changes: 11 additions & 5 deletions BeaconDetection/Setting/SettingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class SettingViewModel: NSObject {
SectionSettingListData(header: "", items: [
SettinglistData(title: "README"),
SettinglistData(title: "LICENSE"),
SettinglistData(title: "Version:" + version)
SettinglistData(title: "Version:" + version),
SettinglistData(title: "Clear Checked Tips")
])
]
}
Expand All @@ -52,12 +53,13 @@ class SettingViewModel: NSObject {
?? UITableViewCell(style: .default, reuseIdentifier: "Cell")
cell.textLabel?.text = item.title

if DescriptionFileType(rawValue: ip.row) == DescriptionFileType.none {
cell.selectionStyle = .none
cell.accessoryType = .none
} else {
if DescriptionFileType(rawValue: ip.row) == .readme ||
DescriptionFileType(rawValue: ip.row) == .license {
cell.selectionStyle = .default
cell.accessoryType = .disclosureIndicator
} else {
cell.selectionStyle = .none
cell.accessoryType = .none
}

return cell
Expand All @@ -67,4 +69,8 @@ class SettingViewModel: NSObject {
ds.sectionModels[index].header
}
}

func clearCheckedTips() {
UserDefaults().set(0, forKey: Const.kCheckedTipsUserDefaultKey)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: AMPopTip, nameSpecified: , owner: andreamazz, version: 3.2.1

name: MMMarkdown, nameSpecified: , owner: mdiep, version: 0.5.5

name: Nimble, nameSpecified: , owner: Quick, version: v7.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>File</key>
<string>com.mono0926.LicensePlist/AMPopTip</string>
<key>Title</key>
<string>AMPopTip</string>
<key>Type</key>
<string>PSChildPaneSpecifier</string>
</dict>
<dict>
<key>File</key>
<string>com.mono0926.LicensePlist/MMMarkdown</string>
Expand Down
Loading

0 comments on commit c921534

Please sign in to comment.