Skip to content

Commit

Permalink
- добавлена оплата по карте через API сбербанка
Browse files Browse the repository at this point in the history
- добавлены Web-контроллеры, которые позволяют динамически добавлять в интерфейс приложения новый функционал или менять его, без необходимости обновления нативного приложения
(в частности, мы у себя реализовали на web-контроллере механизм работы с бонусами: просмотр и обмен на рубли)
  • Loading branch information
sbca68 committed Mar 18, 2022
1 parent ee97b31 commit d8891f8
Show file tree
Hide file tree
Showing 61 changed files with 2,317 additions and 187 deletions.
164 changes: 140 additions & 24 deletions SmartYard.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions SmartYard/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// обрабатываем только url вида https://demo.lanta.me/0123456789 для подтверждения адреса
if components.host == "demo.lanta.me",
components.scheme == "https",
let path = components.path,
path.matches(pattern: "/[0-9]{10}") {
appCoordinator.trigger(.registerQRCode(code: incomingURL.absoluteString))
let path = components.path {
if path.matches(pattern: "/[0-9]{10}") {
appCoordinator.trigger(.registerQRCode(code: incomingURL.absoluteString))
}
if path == "/open_app.html" {
NotificationCenter.default.post(name: .refreshVisibleWebVC, object: nil)
}
} else
// в противном случае даём OS обработать это событие самостоятельно
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class SwipeInteractionController: UIPercentDrivenInteractiveTransition {

private weak var viewController: UIViewController?

private weak var scrollView: UIScrollView?

private var initialOffset: CGPoint = .zero

/// Показывает, на сколько пикселей animatedView.bottom находится ниже superview.bottom
var animatedViewBottomOffset: CGFloat = 0

Expand All @@ -21,14 +25,59 @@ class SwipeInteractionController: UIPercentDrivenInteractiveTransition {
/// Устанавливает порог максимальной скорости свайпа, после которого вьюха будет автоматически закрываться
var velocityThreshold: CGFloat?

init(viewController: UIViewController, animatedView: UIView) {
init(viewController: UIViewController, animatedView: UIView, scrollView: UIScrollView? = nil) {
super.init()

self.viewController = viewController
self.scrollView = scrollView

animatedView.addGestureRecognizer(
UIPanGestureRecognizer(target: self, action: #selector(handleGesture(_:)))
)

scrollView?.panGestureRecognizer.addTarget(self, action: #selector(handleScrollViewGestureRecognizer(_:)))
}

@objc private func handleScrollViewGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer) {
switch gestureRecognizer.state {
case .began:
// сохраняем смещение контента в скролл-вью в момент начала жеста
initialOffset = scrollView?.contentOffset ?? .zero
// пробрасываем жест для обработчика родительского вью
handleGesture(gestureRecognizer)
case .changed:
// если скролл-вью не на верхней точке, то дальше не пробрасываем обработку жеста, тем самым
// даём возможность работать только стандартному обработчику scrollView.
// Но если мы уже на верхней точке в скролл-вью, то мы также пробрасываем событие жеста
// для родительской вьюхи.
if scrollView?.contentOffset.y == 0 {
// сохраняем состояние смещения.
let originalTranslation = gestureRecognizer.translation(in: scrollView)

// модифицируем смещение с учётом initialOffset (смещения скролл-вью в начале жеста),
// чтобы родительская вьюха получила только часть смещения, без учёта "пробега" от скрола.
gestureRecognizer.setTranslation(
originalTranslation.applying(
CGAffineTransform(translationX: -initialOffset.x, y: -initialOffset.y)
),
in: scrollView
)
/* gestureRecognizer.setTranslation(
CGPoint(x: originalTranslation.x - initialOffset.x, y: originalTranslation.y - initialOffset.y),
in: scrollView
)
*/

// обрабатываем смещение родительской вьюхой.
handleGesture(gestureRecognizer)

// восстанавливаем исходное состояние смещения для корректной работы скролл-вью
gestureRecognizer.setTranslation(originalTranslation, in: scrollView)
}
case .ended, .cancelled:
handleGesture(gestureRecognizer)
default: break
}
}

@objc private func handleGesture(_ gestureRecognizer: UIPanGestureRecognizer) {
Expand Down
5 changes: 5 additions & 0 deletions SmartYard/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ enum Constants {
static let yandexApiKey = "YOU_NEED_TO_CHANGE_THIS"
static let defaultBackendURL = "YOU_NEED_TO_CHANGE_THIS"
static let mapBoxPublicKey = "YOU_NEED_TO_CHANGE_THIS"
static let sberbankAPILogin = "YOU_NEED_TO_CHANGE_THIS"
static let sberbankAPIPassword = "YOU_NEED_TO_CHANGE_THIS"
static let sberbankSuccessReturnURL = "YOU_NEED_TO_CHANGE_THIS"
static let sberbankFailureReturnURL = "YOU_NEED_TO_CHANGE_THIS"


enum Chat {
static let token = "YOU_NEED_TO_CHANGE_THIS"
Expand Down
2 changes: 2 additions & 0 deletions SmartYard/Extensions/NotificationName+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ extension Notification.Name {

static let updateFaces = Notification.Name("UpdateFaces")
static let updateEvent = Notification.Name("UpdateEvent")

static let refreshVisibleWebVC = Notification.Name("RefreshVisibleWebVC")
}
21 changes: 11 additions & 10 deletions SmartYard/Extensions/UIImage+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ extension UIImage {

public convenience init?(base64URLString: String) {
let previewURL = base64URLString.replacingOccurrences(of: "\\/", with: "/")
let pattern = "^data:image\\/.*;base64,"
guard let regex = try? NSRegularExpression(
pattern: pattern,
options: []
) else {
return nil
}
let range = NSRange(location: 0, length: previewURL.count)
let base64Data = regex.stringByReplacingMatches(in: previewURL, options: [], range: range, withTemplate: "")

if previewURL.hasPrefix("data:image/jpeg;base64,") {
let base64Data = previewURL.removingPrefix("data:image/jpeg;base64,")

guard let data = Data(base64Encoded: base64Data, options: .ignoreUnknownCharacters) else {
return nil
}

self.init(data: data)

} else {
guard let data = Data(base64Encoded: base64Data, options: .ignoreUnknownCharacters) else {
return nil
}
self.init(data: data)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MainMenuItem: UICollectionViewCell {
layer.borderColor = UIColor.SmartYard.grayBorder.cgColor
}

func configure(name: String?, iconName: String?) {
func configure(name: String?, iconName: String? = nil, icon: UIImage? = nil) {
contentView.removeSubviews()
mainContainer.removeSubviews()

Expand All @@ -80,8 +80,15 @@ class MainMenuItem: UICollectionViewCell {
}

arrowImageView.image = UIImage(named: "RightArrowIcon")
iconImageView.image = UIImage(named: iconName ?? "PublicCamsMenuIcon")
iconImageView.contentMode = .center

if icon != nil {
iconImageView.image = icon?.withRenderingMode(.alwaysTemplate)
} else {
iconImageView.image = UIImage(named: iconName ?? "PublicCamsMenuIcon")
}

iconImageView.contentMode = .scaleAspectFit
iconImageView.tintColor = UIColor.SmartYard.gray

mainContainer.addSubview(iconImageView)
mainContainer.addSubview(arrowImageView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import UIKit
import RxSwift
import RxCocoa
import JGProgressHUD

class MainMenuViewController: BaseViewController {

class MainMenuViewController: BaseViewController, LoaderPresentable {
var loader: JGProgressHUD?
private let viewModel: MainMenuViewModel
private let itemsProxy = BehaviorSubject<[MenuItemsList]>(value: [])
private let itemsProxy = BehaviorSubject<[MenuListItem]>(value: [])
private let callSupportTrigger = PublishSubject<Void>()
private let itemSelected = PublishSubject<IndexPath>()

@IBOutlet private weak var mainContainerView: UIView!
@IBOutlet private weak var skeletonContainer: UIView!
@IBOutlet private weak var collectionView: UICollectionView!

init(viewModel: MainMenuViewModel) {
Expand Down Expand Up @@ -72,6 +75,32 @@ class MainMenuViewController: BaseViewController {
}
)
.disposed(by: disposeBag)

output.isLoading
.debounce(.milliseconds(25))
.drive(
onNext: { [weak self] isLoading in
if isLoading {
self?.view.endEditing(true)
}

self?.updateLoader(isEnabled: isLoading, detailText: nil)
}
)
.disposed(by: disposeBag)

output.shouldBlockInteraction
.drive(
onNext: { [weak self] shouldBlockInteraction in
self?.collectionView.isHidden = shouldBlockInteraction
self?.skeletonContainer.isHidden = !shouldBlockInteraction

shouldBlockInteraction ?
self?.skeletonContainer.showSkeletonAsynchronously() :
self?.skeletonContainer.hideSkeleton()
}
)
.disposed(by: disposeBag)
}

private func configureTableView() {
Expand Down Expand Up @@ -172,7 +201,14 @@ extension MainMenuViewController: UICollectionViewDataSource {
switch indexPath.section {
case 0:
let cell = collectionView.dequeueReusableCell(withClass: MainMenuItem.self, for: indexPath)
cell.configure(name: data[safe: indexPath.row]?.label, iconName: data[safe: indexPath.row]?.iconName)
guard let item = data[safe: indexPath.row] else {
return cell
}
if item.icon != nil {
cell.configure(name: item.label, icon: item.icon)
} else {
cell.configure(name: item.label, iconName: item.iconName)
}
return cell
default:
let bottomCell = collectionView.dequeueReusableCell(withClass: BottomCell.self, for: indexPath)
Expand Down

0 comments on commit d8891f8

Please sign in to comment.