Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achievement popup AB #420

Merged
merged 16 commits into from
Dec 3, 2018
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
4 changes: 4 additions & 0 deletions Stepic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,7 @@
2C4F3407210A177100E259FE /* NotificationsBadgesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C4F3406210A177100E259FE /* NotificationsBadgesManager.swift */; };
2C558780217521E8009E1BDE /* LocalNotificationsMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C55877F217521E8009E1BDE /* LocalNotificationsMigrator.swift */; };
2C570A63212FD61B00B56AD9 /* TopologicalSortTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C570A62212FD61B00B56AD9 /* TopologicalSortTests.swift */; };
2C5A791021B19B6400909C04 /* AchievementPopupSplitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C5A790F21B19B6400909C04 /* AchievementPopupSplitTest.swift */; };
2C5D51592024653B00B9D932 /* BaseCardsStepsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C5D51582024653B00B9D932 /* BaseCardsStepsViewController.swift */; };
2C5D515A202468CE00B9D932 /* AchievementNotificationView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C3DA0031F3C68B700D74968 /* AchievementNotificationView.xib */; };
2C5D515B202468D100B9D932 /* AchievementNotificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C2544081F3480BE004DB3D9 /* AchievementNotificationView.swift */; };
Expand Down Expand Up @@ -5651,6 +5652,7 @@
2C59F03A20EB8ACA00666EE0 /* ExamEGERussianTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExamEGERussianTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
2C59F04020EB8ACA00666EE0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2C59F06620EBA2EE00666EE0 /* UserRegistrationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRegistrationService.swift; sourceTree = "<group>"; };
2C5A790F21B19B6400909C04 /* AchievementPopupSplitTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AchievementPopupSplitTest.swift; sourceTree = "<group>"; };
2C5D51582024653B00B9D932 /* BaseCardsStepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCardsStepsViewController.swift; sourceTree = "<group>"; };
2C5DF1381FEBDC8C003B1177 /* CardsStepsPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardsStepsPresenter.swift; sourceTree = "<group>"; };
2C5DF13A1FEC0534003B1177 /* CardsStepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardsStepsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9043,6 +9045,7 @@
children = (
08421BCA21764FC400E8A81B /* ActiveSplitTestsContainer.swift */,
62E988F198B6ED19738CB0B5 /* SubscribeNotificationsOnLaunchSplitTest.swift */,
2C5A790F21B19B6400909C04 /* AchievementPopupSplitTest.swift */,
);
path = ActiveTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -15038,6 +15041,7 @@
62E982769C19C7852BCD59C4 /* TooltipStorageManager.swift in Sources */,
62E985DD90444821A835C02F /* CourseListsCollectionSkeletonView.swift in Sources */,
62E98A53567525055BCCA089 /* AppDelegate.swift in Sources */,
2C5A791021B19B6400909C04 /* AchievementPopupSplitTest.swift in Sources */,
62E982C316E409B90DC3AA21 /* SubscribeNotificationsOnLaunchSplitTest.swift in Sources */,
62E9874D1EAE49639F81C916 /* URL+AppendQueryParameters.swift in Sources */,
);
Expand Down
39 changes: 24 additions & 15 deletions Stepic/AchievementBadgeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
import UIKit

struct AchievementViewData {
let id: String

let title: String
let description: String

let badge: UIImage

let completedLevel: Int
let maxLevel: Int
let score: Int
let maxScore: Int
let completedLevel: Int?
let maxLevel: Int?
let score: Int?
let maxScore: Int?

var isLocked: Bool {
return completedLevel == 0
Expand Down Expand Up @@ -186,19 +188,26 @@ class AchievementBadgeView: UIView {
}

private func updateProgress() {
if let data = data {
if data.isLocked {
circleView.alpha = 0.3
circleViewGradientLayer?.isHidden = true
} else {
circleView.alpha = 1.0
circleViewGradientLayer?.isHidden = false
}
guard let data = self.data,
let score = data.score,
let maxScore = data.maxScore,
let completedLevel = data.completedLevel,
let maxLevel = data.maxLevel else {
return
}

initStageProgress(value: Float(data.score) / Float(data.maxScore))
badgeImageView.image = data.badge
initLevelProgress(completedLevel: data.completedLevel, maxLevel: data.maxLevel)
if data.isLocked {
circleView.alpha = 0.3
circleViewGradientLayer?.isHidden = true
} else {
circleView.alpha = 1.0
circleViewGradientLayer?.isHidden = false
}

self.initStageProgress(value: Float(score) / Float(maxScore))
self.badgeImageView.image = data.badge
self.initLevelProgress(completedLevel: completedLevel, maxLevel: maxLevel)

}

override func layoutSubviews() {
Expand Down
23 changes: 21 additions & 2 deletions Stepic/AchievementPopupAlertManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,27 @@
import Foundation
import Presentr

class AchievementPopupAlertManager: AlertManager {
final class AchievementPopupAlertManager: AlertManager {
private let source: AchievementPopupViewController.Source

init(source: AchievementPopupViewController.Source) {
self.source = source
}

func present(alert: UIViewController, inController controller: UIViewController) {
controller.customPresentViewController(presentr, viewController: alert, animated: true, completion: nil)
if let alert = alert as? AchievementPopupViewController, let data = alert.data {
AmplitudeAnalyticsEvents.Achievements.popupOpened(
source: self.source.rawValue,
kind: data.id,
level: data.completedLevel
).send()
}

controller.customPresentViewController(
self.presentr,
viewController: alert,
animated: true
)
}

let presentr: Presentr = {
Expand All @@ -24,6 +42,7 @@ class AchievementPopupAlertManager: AlertManager {
let alert = AchievementPopupViewController(nibName: "AchievementPopupViewController", bundle: nil)
alert.data = data
alert.canShare = canShare
alert.source = self.source
return alert
}
}
35 changes: 26 additions & 9 deletions Stepic/AchievementPopupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@
import UIKit
import SnapKit

class AchievementPopupViewController: UIViewController {
final class AchievementPopupViewController: UIViewController {
@IBOutlet weak var achievementNameLabel: UILabel!
@IBOutlet weak var achievementDescriptionLabel: UILabel!
@IBOutlet weak var achievementBadgeImageView: UIImageView!
@IBOutlet weak var levelLabel: UILabel!
@IBOutlet weak var progressLabel: UILabel!
@IBOutlet weak var shareButton: StepikButton!
@IBOutlet weak var closeButton: UIButton!
@IBOutlet weak var separatorView: UIView!

var widthConstraint: NSLayoutConstraint?

var data: AchievementViewData?
var canShare: Bool = true
var source: Source = .notification

@IBAction func onShareButtonClick(_ sender: Any) {
guard let data = data else {
return
}

AmplitudeAnalyticsEvents.Achievements.popupShared(
source: self.source.rawValue, kind: data.id, level: data.completedLevel
).send()

let activityVC = UIActivityViewController(activityItems: [String(format: NSLocalizedString("AchievementsShareText", comment: ""), "\(data.title)")], applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityType.airDrop]
activityVC.popoverPresentationController?.sourceView = shareButton
Expand Down Expand Up @@ -56,20 +62,31 @@ class AchievementPopupViewController: UIViewController {
}

private func update(with data: AchievementViewData) {
achievementNameLabel.text = data.title
achievementDescriptionLabel.text = data.description
achievementBadgeImageView.image = data.badge
self.achievementNameLabel.text = data.title
self.achievementDescriptionLabel.text = data.description
self.achievementBadgeImageView.image = data.badge

if data.completedLevel == data.maxLevel {
progressLabel.alpha = 0.0
} else {
progressLabel.text = String(format: NSLocalizedString("AchievementsNextLevel", comment: ""), "\(data.maxScore - data.score)")
self.progressLabel.alpha = 0.0
} else if let maxScore = data.maxScore, let score = data.score {
self.progressLabel.text = String(format: NSLocalizedString("AchievementsNextLevel", comment: ""), "\(maxScore - score)")
}

if data.isLocked {
levelLabel.text = NSLocalizedString("AchievementsLevelNotObtained", comment: "")
self.levelLabel.text = NSLocalizedString("AchievementsLevelNotObtained", comment: "")
} else if let completedLevel = data.completedLevel, let maxLevel = data.maxLevel {
self.levelLabel.text = String(format: NSLocalizedString("AchievementsLevel", comment: ""), "\(completedLevel)", "\(maxLevel)")
} else {
levelLabel.text = String(format: NSLocalizedString("AchievementsLevel", comment: ""), "\(data.completedLevel)", "\(data.maxLevel)")
self.levelLabel.alpha = 0.0
}

self.separatorView.alpha = self.progressLabel.alpha == 0
&& self.levelLabel.alpha == 0 ? 0 : 1
}

enum Source: String {
case profile
case achievementList = "achievement-list"
case notification
}
}
11 changes: 5 additions & 6 deletions Stepic/AchievementPopupViewController.xib
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -19,6 +17,7 @@
<outlet property="closeButton" destination="GNE-1D-jyB" id="Yg2-jb-PPj"/>
<outlet property="levelLabel" destination="MV4-yl-m9w" id="LKQ-Rs-mTo"/>
<outlet property="progressLabel" destination="6sQ-Ho-7JX" id="B8G-6A-EB7"/>
<outlet property="separatorView" destination="TNE-Xw-Np9" id="vDw-r2-9jo"/>
<outlet property="shareButton" destination="Xnp-fU-oIh" id="5ps-Dg-XRT"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
Expand All @@ -29,13 +28,13 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" image="achievement-1-4" translatesAutoresizingMaskIntoConstraints="NO" id="tg6-q5-mG8">
<rect key="frame" x="127.5" y="16" width="120.5" height="120"/>
<rect key="frame" x="127.5" y="16" width="120" height="120"/>
<constraints>
<constraint firstAttribute="width" secondItem="tg6-q5-mG8" secondAttribute="height" multiplier="1:1" id="N9t-GY-OtX"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" text="Длинное название бейджа" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="15" translatesAutoresizingMaskIntoConstraints="NO" id="Gck-yv-Go7">
<rect key="frame" x="59.5" y="138" width="257.5" height="21.5"/>
<rect key="frame" x="59" y="138" width="257.5" height="21.5"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="18"/>
<color key="textColor" red="0.32549019610000002" green="0.32549019610000002" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
Expand Down
11 changes: 7 additions & 4 deletions Stepic/AchievementsListPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ class AchievementsListPresenter {
return nil
}

return AchievementViewData(title: kindDescription.getName(),
return AchievementViewData(
id: kindDescription.rawValue,
title: kindDescription.getName(),
description: kindDescription.getDescription(for: data.maxScore),
badge: kindDescription.getBadge(for: data.currentLevel),
completedLevel: data.currentLevel,
maxLevel: data.maxLevel,
score: data.currentScore,
maxScore: data.maxScore)
maxScore: data.maxScore
)
}

self?.view?.set(achievements: viewData.sorted(by: { a, b in
let aScore = !a.isLocked ? 1 : (a.score > 0 ? 2 : 3)
let bScore = !b.isLocked ? 1 : (b.score > 0 ? 2 : 3)
let aScore = !a.isLocked ? 1 : (a.score ?? 0 > 0 ? 2 : 3)
let bScore = !b.isLocked ? 1 : (b.score ?? 0 > 0 ? 2 : 3)
return aScore < bScore
}))
}.catch { [weak self] error in
Expand Down
2 changes: 1 addition & 1 deletion Stepic/AchievementsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AchievementsListViewController: UIViewController, AchievementsListView, Co
}

func showAchievementInfo(viewData: AchievementViewData, canShare: Bool) {
let alertManager = AchievementPopupAlertManager()
let alertManager = AchievementPopupAlertManager(source: .achievementList)
let vc = alertManager.construct(with: viewData, canShare: canShare)
alertManager.present(alert: vc, inController: self)
}
Expand Down
24 changes: 24 additions & 0 deletions Stepic/Analytics/AmplitudeAnalyticsEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,30 @@ struct AmplitudeAnalyticsEvents {
]
)
}

static func popupOpened(source: String, kind: String, level: Int? = nil) -> AnalyticsEvent {
return popupEvent(name: "Achievement popup opened", source: source, kind: kind, level: level)
}

static func popupShared(source: String, kind: String, level: Int? = nil) -> AnalyticsEvent {
return popupEvent(name: "Achievement share pressed", source: source, kind: kind, level: level)
}

private static func popupEvent(
name: String,
source: String,
kind: String,
level: Int? = nil
) -> AnalyticsEvent {
return AnalyticsEvent(
name: name,
parameters: [
"source": source,
"achievement_kind": kind,
"achievement_level": level as Any
]
)
}
}

struct Settings {
Expand Down
7 changes: 5 additions & 2 deletions Stepic/ProfileAchievementsPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ class ProfileAchievementsPresenter {
return nil
}

return AchievementViewData(title: kindDescription.getName(),
return AchievementViewData(
id: kindDescription.rawValue,
title: kindDescription.getName(),
description: kindDescription.getDescription(for: data.maxScore),
badge: kindDescription.getBadge(for: data.currentLevel),
completedLevel: data.currentLevel,
maxLevel: data.maxLevel,
score: data.currentScore,
maxScore: data.maxScore)
maxScore: data.maxScore
)
}
self?.view?.set(achievements: viewData)
}.catch { [weak self] error in
Expand Down
2 changes: 1 addition & 1 deletion Stepic/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ProfileViewController: MenuViewController, ProfileView, ControllerWithStep
}

func showAchievementInfo(viewData: AchievementViewData, canShare: Bool) {
let alertManager = AchievementPopupAlertManager()
let alertManager = AchievementPopupAlertManager(source: .profile)
let vc = alertManager.construct(with: viewData, canShare: canShare)
alertManager.present(alert: vc, inController: self)
}
Expand Down
Loading