Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def all_pods
pod 'Atributika', '~> 4.0'
pod 'DeviceKit', '~> 1.0'
pod 'lottie-ios'
pod 'EasyTipView', :git => 'https://github.com/igorkislyuk/EasyTipView.git'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему какой-то форк юзаем? Swift 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да

end

def testing_pods
Expand Down
98 changes: 98 additions & 0 deletions Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<key>StepikTV.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>90</integer>
<integer>92</integer>
</dict>
<key>StickerPackExtension.xcscheme</key>
<dict>
Expand Down
5 changes: 3 additions & 2 deletions Stepic/CourseListPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class CourseListPresenter {
[weak self]
course -> Void in
self?.view?.finishProgressHUD(success: true, message: "")
if let controller = self?.getSectionsController(for: course) {
if let controller = self?.getSectionsController(for: course, didSubscribe: true) {
self?.view?.show(controller: controller)
}
}.catch {
Expand Down Expand Up @@ -536,12 +536,13 @@ class CourseListPresenter {
}
}

private func getSectionsController(for course: Course, sourceView: UIView? = nil) -> UIViewController? {
private func getSectionsController(for course: Course, sourceView: UIView? = nil, didSubscribe: Bool = false) -> UIViewController? {
guard let courseVC = ControllerHelper.instantiateViewController(identifier: "SectionsViewController") as? SectionsViewController else {
return nil
}
AnalyticsReporter.reportEvent(AnalyticsEvents.PeekNPop.Course.peeked)
courseVC.course = course
courseVC.shouldShowShareTooltip = didSubscribe
courseVC.parentShareBlock = {
[weak self]
shareVC in
Expand Down
1 change: 1 addition & 0 deletions Stepic/CoursePreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class CoursePreviewViewController: UIViewController, ShareableController {
if segue.identifier == "showSections" {
let dvc = segue.destination as! SectionsViewController
dvc.course = course
dvc.shouldShowShareTooltip = true
}
}

Expand Down
1 change: 0 additions & 1 deletion Stepic/CourseSubscriptionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CourseSubscriptionManager: NSObject {
let courseUnsubscribedNotificationName = NSNotification.Name(rawValue: "CourseUnsubscribedNotification")

var handleUpdatesBlock: (() -> Void)?

override init() {}

func startObservingOtherSubscriptionManagers() {
Expand Down
19 changes: 17 additions & 2 deletions Stepic/HomeScreenViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class HomeScreenViewController: UIViewController, HomeScreenView {
private let streaksWidgetBackgroundView = UIView()
private var streaksWidgetView: UserActivityHomeView?

private var continueLearningTooltip: Tooltip?

override func viewDidLoad() {
super.viewDidLoad()
self.presenter = HomeScreenPresenter(view: self, userActivitiesAPI: UserActivitiesAPI())
Expand All @@ -42,6 +44,11 @@ class HomeScreenViewController: UIViewController, HomeScreenView {
presenter?.checkStreaks()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
continueLearningTooltip?.dismiss()
}

private func setupStackView() {
scrollView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(scrollView)
Expand Down Expand Up @@ -143,9 +150,16 @@ class HomeScreenViewController: UIViewController, HomeScreenView {
stackView.insertArrangedSubview(widgetBackgroundView, at: streaksWidgetView == nil ? 0 : 1)
widgetBackgroundView.alignLeading("0", trailing: "0", toView: self.view)

UIView.animate(withDuration: 0.15) {
UIView.animate(withDuration: 0.15, animations: {
self.widgetBackgroundView.isHidden = false
}
}, completion: {
_ in
if TooltipDefaultsManager.shared.shouldShowOnHomeContinueLearning {
self.continueLearningTooltip = TooltipFactory.continueLearningWidget
self.continueLearningTooltip?.show(direction: .up, in: nil, from: self.continueLearningWidget.continueLearningButton)
TooltipDefaultsManager.shared.didShowOnHomeContinueLearning = true
}
})

if !isContinueLearningWidgetPresented {
isContinueLearningWidgetPresented = true
Expand All @@ -155,6 +169,7 @@ class HomeScreenViewController: UIViewController, HomeScreenView {
func hideCountinueLearningWidget() {
isContinueLearningWidgetPresented = false
stackView.removeArrangedSubview(widgetBackgroundView)
continueLearningTooltip?.dismiss()
UIView.animate(withDuration: 0.15) {
self.widgetBackgroundView.isHidden = true
}
Expand Down
6 changes: 6 additions & 0 deletions Stepic/Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class Menu {
self.blocks = blocks
}

func getBlockIndex(id: String) -> Int? {
return blocks.index(where: {
$0.id == id
})
}

func getBlock(id: String) -> MenuBlock? {
return blocks.first(where: {
$0.id == id
Expand Down
2 changes: 1 addition & 1 deletion Stepic/ProfilePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ProfilePresenter {

// MARK: - Menu initialization

private let notificationsSwitchBlockId = "notifications_switch"
let notificationsSwitchBlockId = "notifications_switch"
private let notificationsTimeSelectionBlockId = "notifications_time_selection"
private let infoBlockId = "info"
private let settingsBlockId = "settings"
Expand Down
39 changes: 39 additions & 0 deletions Stepic/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,42 @@ class ProfileViewController: MenuViewController, ProfileView {
self.streaks = streaks
}

var streaksTooltip: Tooltip?

func set(menu: Menu) {
self.menu = menu

guard let presenter = presenter else {
return
}

guard let blockIndex = menu.getBlockIndex(id: presenter.notificationsSwitchBlockId),
let block = menu.getBlock(id: presenter.notificationsSwitchBlockId) as? SwitchMenuBlock else {
return
}

if TooltipDefaultsManager.shared.shouldShowOnStreaksSwitchInProfile {
delay(0.1) {
[weak self] in
guard let s = self else {
return
}
if let cell = s.tableView.cellForRow(at: IndexPath(row: blockIndex, section: 0)) as? SwitchMenuBlockTableViewCell {
if !cell.blockSwitch.isOn {
let oldOnSwitch = block.onSwitch
block.onSwitch = {
[weak self]
isOn in
self?.streaksTooltip?.dismiss()
oldOnSwitch?(isOn)
}
s.streaksTooltip = TooltipFactory.streaksTooltip
s.streaksTooltip?.show(direction: .up, in: s.tableView, from: cell.blockSwitch)
TooltipDefaultsManager.shared.didShowOnStreaksSwitchInProfile = true
}
}
}
}
}

func showNotificationSettingsAlert(completion: (() -> Void)?) {
Expand Down Expand Up @@ -164,6 +198,11 @@ class ProfileViewController: MenuViewController, ProfileView {
super.viewWillAppear(animated)
onAppear()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
streaksTooltip?.dismiss()
}
}

extension ProfileViewController : DZNEmptyDataSetDelegate {
Expand Down
22 changes: 19 additions & 3 deletions Stepic/SectionsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class SectionsViewController: UIViewController, ShareableController, UIViewContr
let refreshControl = UIRefreshControl()
var didRefresh = false
var course: Course!

var moduleId: Int?
var parentShareBlock: ((UIActivityViewController) -> Void)?
private var shareBarButtonItem: UIBarButtonItem!
private var shareTooltip: Tooltip?
var shouldShowShareTooltip: Bool = false

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -30,7 +32,7 @@ class SectionsViewController: UIViewController, ShareableController, UIViewContr
tableView.tableFooterView = UIView()
self.navigationItem.backBarButtonItem?.title = " "

let shareBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target: self, action: #selector(SectionsViewController.shareButtonPressed(_:)))
shareBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target: self, action: #selector(SectionsViewController.shareButtonPressed(_:)))
let infoBtn = UIButton(type: UIButtonType.infoDark)
infoBtn.addTarget(self, action: #selector(SectionsViewController.infoButtonPressed(_:)), for: UIControlEvents.touchUpInside)
let infoBarButtonItem = UIBarButtonItem(customView: infoBtn)
Expand Down Expand Up @@ -97,6 +99,20 @@ class SectionsViewController: UIViewController, ShareableController, UIViewContr
}
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if shouldShowShareTooltip {
shareTooltip = TooltipFactory.streaksTooltip
shareTooltip?.show(direction: .up, in: nil, from: shareBarButtonItem)
shouldShowShareTooltip = false
}
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
shareTooltip?.dismiss()
}

var emptyDatasetState: EmptyDatasetState = .empty {
didSet {
UIThread.performUI {
Expand Down Expand Up @@ -201,7 +217,7 @@ class SectionsViewController: UIViewController, ShareableController, UIViewContr
AnalyticsReporter.reportEvent(AnalyticsEvents.Syllabus.shared, parameters: nil)
let shareBlock: ((UIActivityViewController) -> Void)? = parentShareBlock
let url = self.url

shareTooltip?.dismiss()
DispatchQueue.global(qos: .background).async {
[weak self] in

Expand Down
122 changes: 122 additions & 0 deletions Stepic/Tooltip.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// Tooltip.swift
// Stepic
//
// Created by Ostrenkiy on 19.01.2018.
// Copyright © 2018 Alex Karpov. All rights reserved.
//

import Foundation
import EasyTipView

protocol Tooltip {
init(text: String, shouldDismissAfterTime: Bool, color: TooltipColor)
func show(direction: TooltipDirection, in inView: UIView?, from fromView: UIView)
func show(direction: TooltipDirection, in inView: UIView?, from fromItem: UIBarButtonItem)
func dismiss()
}

enum TooltipColor {
case light, dark, standard

var textColor: UIColor {
switch self {
case .light:
return UIColor.mainDark
case .dark:
return UIColor.mainLight
case .standard:
return UIColor.white
}
}

var borderColor: UIColor {
switch self {
case .light:
return UIColor.mainDark
case .dark:
return UIColor.mainLight
case .standard:
return UIColor.thirdColor
}
}

var backgroundColor: UIColor {
switch self {
case .light:
return UIColor.mainLight
case .dark:
return UIColor.mainDark
case .standard:
return UIColor.thirdColor
}
}
}

class EasyTipTooltip: Tooltip {
private var easyTip: EasyTipView = EasyTipView(text: "")
private var preferences: EasyTipView.Preferences
let dismissesAfter: TimeInterval = 7.5

var text: String
var shouldDismissAfterTime: Bool

private func easyTipDirectionFromTooltipDirection(direction: TooltipDirection) -> EasyTipView.ArrowPosition {
switch direction {
case .up:
return EasyTipView.ArrowPosition.top
case .left:
return EasyTipView.ArrowPosition.left
case .right:
return EasyTipView.ArrowPosition.right
case .down:
return EasyTipView.ArrowPosition.bottom
}
}

required init(text: String, shouldDismissAfterTime: Bool, color: TooltipColor) {
self.text = text
self.shouldDismissAfterTime = shouldDismissAfterTime
preferences = EasyTipView.Preferences()
preferences.drawing.font = UIFont.systemFont(ofSize: 14)
preferences.drawing.foregroundColor = color.textColor
preferences.drawing.backgroundColor = color.backgroundColor
preferences.drawing.borderWidth = 1.0
preferences.drawing.borderColor = color.borderColor
}

private func setupTooltip(direction: TooltipDirection) {
preferences.drawing.arrowPosition = easyTipDirectionFromTooltipDirection(direction: direction)
easyTip = EasyTipView(text: text, preferences: preferences, delegate: nil)
}

private func setupDisappear() {
guard shouldDismissAfterTime else {
return
}
delay(dismissesAfter) {
[weak self] in
self?.dismiss()
}
}

func show(direction: TooltipDirection, in inView: UIView?, from fromView: UIView) {
setupTooltip(direction: direction)
easyTip.show(forView: fromView, withinSuperview: inView)
setupDisappear()
}

func show(direction: TooltipDirection, in inView: UIView?, from fromItem: UIBarButtonItem) {
setupTooltip(direction: direction)
easyTip.show(forItem: fromItem, withinSuperView: inView)
setupDisappear()
}

func dismiss() {
easyTip.dismiss()
}
}

enum TooltipDirection {
case left, up, right, down
}
Loading