Skip to content

Commit

Permalink
Course revenue tab monthly (#1009)
Browse files Browse the repository at this point in the history
* Generate module

* Add PaginationState struct

* Implement provider

* Implement UI

* Fix monthName

* Add gradient layer

* Add skeleton
  • Loading branch information
ivan-magda authored Jul 12, 2021
1 parent a5a03db commit 5334533
Show file tree
Hide file tree
Showing 30 changed files with 2,138 additions and 14 deletions.
104 changes: 103 additions & 1 deletion Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ extension CourseBenefitByMonth {
@NSManaged var managedYearNumber: NSNumber?
@NSManaged var managedMonthNumber: NSNumber?
@NSManaged var managedCountPayments: NSNumber?
@NSManaged var managedCountCoursePayments: NSNumber?
@NSManaged var managedCountInvoicePayments: NSNumber?
@NSManaged var managedCountZPayments: NSNumber?
@NSManaged var managedCountNonZPayments: NSNumber?
@NSManaged var managedCountRefunds: NSNumber?
@NSManaged var managedCurrencyCode: String?
@NSManaged var managedTotalTurnover: NSNumber?
@NSManaged var managedTotalUserIncome: NSNumber?
@NSManaged var managedTotalRefunds: NSNumber?

@NSManaged var managedUser: User?
@NSManaged var managedCourse: Course?
Expand Down Expand Up @@ -88,6 +91,24 @@ extension CourseBenefitByMonth {
}
}

var countCoursePayments: Int {
get {
self.managedCountCoursePayments?.intValue ?? 0
}
set {
self.managedCountCoursePayments = NSNumber(value: newValue)
}
}

var countInvoicePayments: Int {
get {
self.managedCountInvoicePayments?.intValue ?? 0
}
set {
self.managedCountInvoicePayments = NSNumber(value: newValue)
}
}

var countZPayments: Int {
get {
self.managedCountZPayments?.intValue ?? 0
Expand Down Expand Up @@ -142,6 +163,15 @@ extension CourseBenefitByMonth {
}
}

var totalRefunds: Float {
get {
self.managedTotalRefunds?.floatValue ?? 0
}
set {
self.managedTotalRefunds = NSNumber(value: newValue)
}
}

var user: User? {
get {
self.managedUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class CourseBenefitByMonth: NSManagedObject, JSONSerializable {
typealias IdType = String

var date: DateInRegion? {
self.dateString.toISODate()
self.dateString.toISODate(region: Date.europeMoscowRegion)
}

required convenience init(json: JSON) {
Expand All @@ -22,12 +22,15 @@ final class CourseBenefitByMonth: NSManagedObject, JSONSerializable {
self.yearNumber = json[JSONKey.year.rawValue].intValue
self.monthNumber = json[JSONKey.month.rawValue].intValue
self.countPayments = json[JSONKey.countPayments.rawValue].intValue
self.countCoursePayments = json[JSONKey.countCoursePayments.rawValue].intValue
self.countInvoicePayments = json[JSONKey.countInvoicePayments.rawValue].intValue
self.countZPayments = json[JSONKey.countZPayments.rawValue].intValue
self.countNonZPayments = json[JSONKey.countNonZPayments.rawValue].intValue
self.countRefunds = json[JSONKey.countRefunds.rawValue].intValue
self.currencyCode = json[JSONKey.currencyCode.rawValue].stringValue
self.totalTurnover = json[JSONKey.totalTurnover.rawValue].floatValue
self.totalUserIncome = json[JSONKey.totalUserIncome.rawValue].floatValue
self.totalRefunds = json[JSONKey.totalRefunds.rawValue].floatValue
}

enum JSONKey: String {
Expand All @@ -37,11 +40,14 @@ final class CourseBenefitByMonth: NSManagedObject, JSONSerializable {
case year
case month
case countPayments = "count_payments"
case countCoursePayments = "count_course_payments"
case countInvoicePayments = "count_invoice_payments"
case countZPayments = "count_z_payments"
case countNonZPayments = "count_non_z_payments"
case countRefunds = "count_refunds"
case currencyCode = "currency_code"
case totalTurnover = "total_turnover"
case totalUserIncome = "total_user_income"
case totalRefunds = "total_refunds"
}
}
2 changes: 1 addition & 1 deletion Stepic/Legacy/Model/Model.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Model_course_benefit_by_month_v83.xcdatamodel</string>
<string>Model_course_benefit_by_month_refunds_v84.xcdatamodel</string>
</dict>
</plist>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@
<element name="CodeTemplate" positionX="-492.8984375" positionY="-359.9921875" width="128" height="105"/>
<element name="Course" positionX="-594.50390625" positionY="49.8359375" width="128" height="1004"/>
<element name="CourseBenefit" positionX="-450" positionY="-234" width="128" height="239"/>
<element name="CourseBenefitByMonth" positionX="-450" positionY="-234" width="128" height="239"/>
<element name="CourseBenefitSummary" positionX="-450" positionY="-234" width="128" height="194"/>
<element name="CourseList" positionX="-14.1953125" positionY="793.859375" width="128" height="149"/>
<element name="CoursePurchase" positionX="-450" positionY="-234" width="128" height="133"/>
Expand Down Expand Up @@ -540,6 +541,5 @@
<element name="UserCourse" positionX="-450" positionY="-234" width="128" height="178"/>
<element name="Video" positionX="259.9609375" positionY="505.1015625" width="128" height="165"/>
<element name="VideoURL" positionX="445.92578125" positionY="580.05078125" width="128" height="90"/>
<element name="CourseBenefitByMonth" positionX="-450" positionY="-234" width="128" height="239"/>
</elements>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import SnapKit
import UIKit

extension CourseRevenueTabMonthlyCellSkeletonView {
struct Appearance {
let insets = LayoutInsets.default

let totalViewHeight: CGFloat = 44
let totalViewCornerRadius: CGFloat = 6
let totalViewInsets = LayoutInsets.default

let logoIconSize = CGSize(width: 24, height: 24)

let labelsHeight: CGFloat = 17
let labelsCornerRadius: CGFloat = 5
let labelsInsets = LayoutInsets(top: 16, left: 32, bottom: 16, right: 32)
}
}

final class CourseRevenueTabMonthlyCellSkeletonView: UIView {
let appearance: Appearance

private lazy var totalView = UIView()

private lazy var firstTitleView = UIView()
private lazy var firstSubtitleView = UIView()

private lazy var secondTitleView = UIView()
private lazy var secondSubtitleView = UIView()

private lazy var thirdTitleView = UIView()
private lazy var thirdSubtitleView = UIView()

private lazy var fourthLogoIconView = UIView()
private lazy var fourthTitleView = UIView()
private lazy var fourthSubtitleView = UIView()

private lazy var fifthLogoIconView = UIView()
private lazy var fifthTitleView = UIView()
private lazy var fifthSubtitleView = UIView()

init(
frame: CGRect = .zero,
appearance: Appearance = Appearance()
) {
self.appearance = appearance
super.init(frame: frame)

self.setupView()
self.addSubviews()
self.makeConstraints()
}

@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension CourseRevenueTabMonthlyCellSkeletonView: ProgrammaticallyInitializableViewProtocol {
func setupView() {
self.totalView.clipsToBounds = true
self.totalView.layer.cornerRadius = self.appearance.totalViewCornerRadius

[
self.firstTitleView,
self.firstSubtitleView,
self.secondTitleView,
self.secondSubtitleView,
self.thirdTitleView,
self.thirdSubtitleView,
self.fourthTitleView,
self.fourthSubtitleView,
self.fifthTitleView,
self.fifthSubtitleView
].forEach { view in
view.clipsToBounds = true
view.layer.cornerRadius = self.appearance.labelsCornerRadius
}

[
self.fourthLogoIconView,
self.fifthLogoIconView
].forEach { view in
view.clipsToBounds = true
view.layer.cornerRadius = self.appearance.logoIconSize.height / 2
}
}

func addSubviews() {
self.addSubview(self.totalView)
self.addSubview(self.firstTitleView)
self.addSubview(self.firstSubtitleView)
self.addSubview(self.secondTitleView)
self.addSubview(self.secondSubtitleView)
self.addSubview(self.thirdTitleView)
self.addSubview(self.thirdSubtitleView)
self.addSubview(self.fourthLogoIconView)
self.addSubview(self.fourthTitleView)
self.addSubview(self.fourthSubtitleView)
self.addSubview(self.fifthLogoIconView)
self.addSubview(self.fifthTitleView)
self.addSubview(self.fifthSubtitleView)
}

func makeConstraints() {
self.totalView.translatesAutoresizingMaskIntoConstraints = false
self.totalView.snp.makeConstraints { make in
make.top.leading.trailing.equalToSuperview().inset(self.appearance.totalViewInsets.edgeInsets)
make.height.equalTo(self.appearance.totalViewHeight)
}

self.firstTitleView.translatesAutoresizingMaskIntoConstraints = false
self.firstTitleView.snp.makeConstraints { make in
make.top.equalTo(self.totalView.snp.bottom).offset(self.appearance.labelsInsets.top)
make.leading.equalToSuperview().offset(self.appearance.labelsInsets.left)
make.height.equalTo(self.appearance.labelsHeight)
make.width.equalToSuperview().multipliedBy(0.15)
}

self.firstSubtitleView.translatesAutoresizingMaskIntoConstraints = false
self.firstSubtitleView.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-self.appearance.labelsInsets.right)
make.height.equalTo(self.appearance.labelsHeight)
make.centerY.equalTo(self.firstTitleView.snp.centerY)
make.width.equalToSuperview().multipliedBy(0.25)
}

self.secondTitleView.translatesAutoresizingMaskIntoConstraints = false
self.secondTitleView.snp.makeConstraints { make in
make.top.equalTo(self.firstTitleView.snp.bottom).offset(self.appearance.labelsInsets.top)
make.leading.equalToSuperview().offset(self.appearance.labelsInsets.left)
make.height.equalTo(self.appearance.labelsHeight)
make.width.equalToSuperview().multipliedBy(0.2)
}

self.secondSubtitleView.translatesAutoresizingMaskIntoConstraints = false
self.secondSubtitleView.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-self.appearance.labelsInsets.right)
make.height.equalTo(self.appearance.labelsHeight)
make.centerY.equalTo(self.secondTitleView.snp.centerY)
make.width.equalToSuperview().multipliedBy(0.2)
}

self.thirdTitleView.translatesAutoresizingMaskIntoConstraints = false
self.thirdTitleView.snp.makeConstraints { make in
make.top.equalTo(self.secondTitleView.snp.bottom).offset(self.appearance.labelsInsets.top)
make.leading.equalToSuperview().offset(self.appearance.labelsInsets.left)
make.height.equalTo(self.appearance.labelsHeight)
make.width.equalToSuperview().multipliedBy(0.25)
}

self.thirdSubtitleView.translatesAutoresizingMaskIntoConstraints = false
self.thirdSubtitleView.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-self.appearance.labelsInsets.right)
make.height.equalTo(self.appearance.labelsHeight)
make.centerY.equalTo(self.thirdTitleView.snp.centerY)
make.width.equalToSuperview().multipliedBy(0.15)
}

self.fourthLogoIconView.translatesAutoresizingMaskIntoConstraints = false
self.fourthLogoIconView.snp.makeConstraints { make in
make.top.equalTo(self.thirdTitleView.snp.bottom).offset(self.appearance.labelsInsets.top)
make.leading.equalToSuperview().offset(self.appearance.labelsInsets.left)
make.size.equalTo(self.appearance.logoIconSize)
}

self.fourthTitleView.translatesAutoresizingMaskIntoConstraints = false
self.fourthTitleView.snp.makeConstraints { make in
make.leading.equalTo(self.fourthLogoIconView.snp.trailing).offset(self.appearance.insets.left / 2)
make.centerY.equalTo(self.fourthLogoIconView.snp.centerY)
make.height.equalTo(self.appearance.labelsHeight)
make.width.equalToSuperview().multipliedBy(0.4)
}

self.fourthSubtitleView.translatesAutoresizingMaskIntoConstraints = false
self.fourthSubtitleView.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-self.appearance.labelsInsets.right)
make.height.equalTo(self.appearance.labelsHeight)
make.centerY.equalTo(self.fourthTitleView.snp.centerY)
make.width.equalToSuperview().multipliedBy(0.15)
}

self.fifthLogoIconView.translatesAutoresizingMaskIntoConstraints = false
self.fifthLogoIconView.snp.makeConstraints { make in
make.top.equalTo(self.fourthLogoIconView.snp.bottom).offset(self.appearance.labelsInsets.top)
make.leading.equalToSuperview().offset(self.appearance.labelsInsets.left)
make.bottom.equalToSuperview().offset(-self.appearance.labelsInsets.bottom)
make.size.equalTo(self.appearance.logoIconSize)
}

self.fifthTitleView.translatesAutoresizingMaskIntoConstraints = false
self.fifthTitleView.snp.makeConstraints { make in
make.leading.equalTo(self.fifthLogoIconView.snp.trailing).offset(self.appearance.insets.left / 2)
make.centerY.equalTo(self.fifthLogoIconView.snp.centerY)
make.height.equalTo(self.appearance.labelsHeight)
make.width.equalToSuperview().multipliedBy(0.45)
}

self.fifthSubtitleView.translatesAutoresizingMaskIntoConstraints = false
self.fifthSubtitleView.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-self.appearance.labelsInsets.right)
make.height.equalTo(self.appearance.labelsHeight)
make.centerY.equalTo(self.fifthTitleView.snp.centerY)
make.width.equalToSuperview().multipliedBy(0.15)
}
}
}
11 changes: 11 additions & 0 deletions Stepic/Sources/Model/PaginationState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

struct PaginationState {
let page: Int
let hasNext: Bool

init(page: Int = 1, hasNext: Bool = false) {
self.page = page
self.hasNext = hasNext
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ protocol CourseInfoTabReviewsInteractorProtocol: AnyObject {
}

final class CourseInfoTabReviewsInteractor: CourseInfoTabReviewsInteractorProtocol {
typealias PaginationState = (page: Int, hasNext: Bool)

private let presenter: CourseInfoTabReviewsPresenterProtocol
private let provider: CourseInfoTabReviewsProviderProtocol
private let analytics: Analytics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ protocol CourseListInteractorProtocol: AnyObject {
}

final class CourseListInteractor: CourseListInteractorProtocol {
typealias PaginationState = (page: Int, hasNext: Bool)

// We should be able to set uid cause we want to manage
// which course list module called module output methods
var moduleIdentifier: UniqueIdentifierType?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ final class CourseRevenueViewController: UIViewController, ControllerWithStepikP
controller = assembly.makeModule()
moduleInput = assembly.moduleInput
case .monthly:
controller = UIViewController()
moduleInput = nil
let assembly = CourseRevenueTabMonthlyAssembly()
controller = assembly.makeModule()
moduleInput = assembly.moduleInput
}

self.submodulesControllers[index] = controller
Expand Down
Loading

0 comments on commit 5334533

Please sign in to comment.