ios added phone/card switch

This commit is contained in:
Semyon Babushkin
2017-11-23 16:46:40 +03:00
parent 1f6fe22b82
commit 857154faf8
21 changed files with 168 additions and 89 deletions

View File

@@ -31,7 +31,7 @@
@"appTitle" : @"Dinect",
@"showBonus" : @YES,
},
@"com.dinect.develop" : @{
@"com.dinect.develop-iOS" : @{
@"locale" : @"ru",
@"flavor" : @"autobonus",
@"currency" : @643,

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Icon-20.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Icon-40.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Icon-60.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

View File

@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Icon-20.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Icon-40.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Icon-60.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -19,9 +19,47 @@ extension ZBarSymbolSet: Sequence {
}
@objc class ScannerViewController: UIViewController, ZBarReaderDelegate, UITextFieldDelegate {
enum ButtonState {
case card
case phone
var icon: UIImage {
switch self {
case .card: return UIImage(named: "card")!
case .phone: return UIImage(named: "phone")!
}
}
var inputText: String {
switch self {
case .card: return "Enter the barcode manualy"
case .phone: return "Enter the phone manualy"
}
}
var errorText: String {
switch self {
case .card: return "User with card number %@ not found"
case .phone: return "User with phone number %@ not found"
}
}
var searchType: String {
switch self {
case .card: return "card"
case .phone: return "phone"
}
}
}
var buttonState: ButtonState = .card
var platformChannel: FlutterMethodChannel?
let readerViewController = ZBarReaderViewController()
//Вьюшка для верхнего меню
let topView = UIView()
@@ -49,12 +87,15 @@ extension ZBarSymbolSet: Sequence {
topView.addSubview(settingButton)
textField.delegate = self
textField.keyboardType = .numberPad
//textField.keyboardType = .numberPad
//Looks for single or multiple taps.
let tap = UITapGestureRecognizer(target: self, action: #selector(ScannerViewController.hideKeyboard))
readerViewController.view.addGestureRecognizer(tap)
settingButton.setImage(self.buttonState.icon, for: .normal)
textField.placeholder = self.buttonState.inputText
}
func hideKeyboard() {
@@ -63,8 +104,12 @@ extension ZBarSymbolSet: Sequence {
func buttonTouch(){
sendResult(textField.text!)
switch self.buttonState {
case .card: self.buttonState = .phone
case .phone: self.buttonState = .card
}
settingButton.setImage(self.buttonState.icon, for: .normal)
textField.placeholder = self.buttonState.inputText
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
@@ -75,9 +120,9 @@ extension ZBarSymbolSet: Sequence {
}
func sendResult(_ str: String) {
platformChannel?.invokeMethod("findUserAndPurchase", arguments: [str], result: { (result: Any?) in
platformChannel?.invokeMethod("findUserAndPurchase", arguments: [str, buttonState.searchType], result: { (result: Any?) in
if result is FlutterError {
self.showErrorAlert()
self.showErrorAlert(str)
} else {
self.presentingViewController?.dismiss(animated: false, completion: { self.dismiss(animated: true) })
}
@@ -86,9 +131,12 @@ extension ZBarSymbolSet: Sequence {
}
func showErrorAlert() {
let alertController = UIAlertController(title: "Error", message:
"Wrong code", preferredStyle: UIAlertControllerStyle.alert)
func showErrorAlert(_ str: String) {
let alertController = UIAlertController(
title: "Error",
message: String(format: buttonState.errorText, str),
preferredStyle: UIAlertControllerStyle.alert
)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
@@ -96,14 +144,8 @@ extension ZBarSymbolSet: Sequence {
}
override func viewWillAppear(_ animated: Bool) {
topView.backgroundColor = UIColor.white
settingButton.setTitle("+", for: .normal)
textField.placeholder = "Enter code"
textField.borderStyle = .roundedRect
//self.present(readerViewController, animated: true)
super.viewWillAppear(animated)
}
@@ -115,8 +157,8 @@ extension ZBarSymbolSet: Sequence {
readerViewController.view.frame = view.bounds
topView.frame = CGRect(x: 0, y: 0, width: readerViewController.view.frame.size.width, height: 40)
textField.frame = CGRect(x: 8, y: 5, width: readerViewController.view.frame.size.width - 50, height: 30)
settingButton.frame = CGRect(x: textField.frame.maxX + 8, y: 10, width: 20, height: 20)
textField.frame = CGRect(x: settingButton.frame.maxX + 8, y: 5, width: readerViewController.view.frame.size.width - 50, height: 30)
settingButton.frame = CGRect(x: 8, y: 10, width: 20, height: 20)
}
@@ -127,32 +169,9 @@ extension ZBarSymbolSet: Sequence {
if let symbol = symbol as? ZBarSymbol, let data = symbol.data {
sendResult(data)
/*
if let platformChannel = self.platformChannel {
// self.dismiss(animated: true, completion: {
// self.presentingViewController?.dismiss(animated: true, completion: {
platformChannel.invokeMethod("findUserAndPurchase", arguments: [data], result: { (result: Any?) in
print("result: \(result ?? "")")
self.presentingViewController?.dismiss(animated: false, completion: { self.dismiss(animated: true) })
})
// })
// })
// let result = platformChannel.invokeMethod("getUserByCode", arguments: [data], handleResult(result: FlutterResult))
// print(result);
}
/*
let toast = UIAlertController()
toast.message = data
toast.add
toast.show()
*/
//navigationController?.popViewController(animated: true)
*/
}
}
//navigationController?.popViewController(animated: true)
}