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

Handle discussions deep-links #555

Merged
merged 11 commits into from
Nov 9, 2019
102 changes: 51 additions & 51 deletions Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Stepic/AdaptiveRatingsPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ struct ScoreboardViewData {
final class AdaptiveRatingsPresenter {
weak var view: AdaptiveRatingsView?

fileprivate var ratingsAPI: AdaptiveRatingsAPI
fileprivate var usersAPI: UsersAPI
fileprivate var ratingManager: AdaptiveRatingManager
private var ratingsAPI: AdaptiveRatingsAPI
private var usersAPI: UsersAPI
private var ratingManager: AdaptiveRatingManager

private var scoreboard: [Int: ScoreboardViewData] = [:]

Expand Down Expand Up @@ -81,7 +81,7 @@ final class AdaptiveRatingsPresenter {
AmplitudeAnalyticsEvents.AdaptiveRating.opened(course: ratingManager.courseId).send()
}

fileprivate func reloadRating(days: Int? = nil, force: Bool = false) -> Promise<ScoreboardViewData> {
private func reloadRating(days: Int? = nil, force: Bool = false) -> Promise<ScoreboardViewData> {
return Promise { seal in
let currentUser = AuthInfo.shared.userId
var usersForDeanonIds = [Int]()
Expand Down Expand Up @@ -123,7 +123,7 @@ final class AdaptiveRatingsPresenter {
}
}

fileprivate func loadNamesFromFiles() {
private func loadNamesFromFiles() {
func readFile(name: String) -> [String] {
if let path = Bundle.main.path(forResource: name, ofType: "plist"),
let words = NSArray(contentsOfFile: path) as? [String] {
Expand All @@ -140,7 +140,7 @@ final class AdaptiveRatingsPresenter {
assert(adjs.count % 2 == 0)
}

fileprivate func generateNameBy(userId: Int) -> String {
private func generateNameBy(userId: Int) -> String {
func hash(_ id: Int) -> Int {
var x = id
x = ((x >> 16) ^ x) &* 0x45d9f3b
Expand Down
10 changes: 5 additions & 5 deletions Stepic/AdaptiveRatingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class AdaptiveRatingsViewController: UIViewController {
case normal(message: String?)
}

fileprivate var state: State = .loading {
private var state: State = .loading {
didSet {
switch state {
case .loading:
Expand Down Expand Up @@ -50,7 +50,7 @@ final class AdaptiveRatingsViewController: UIViewController {

@IBOutlet weak var ratingSegmentedControl: UISegmentedControl!

fileprivate var data: [Any]?
private var data: [Any]?

@IBAction func onRatingSegmentedControlValueChanged(_ sender: Any) {
let sections: [Int: Int?] = [
Expand All @@ -77,12 +77,12 @@ final class AdaptiveRatingsViewController: UIViewController {
presenter?.sendOpenedAnalytics()
}

fileprivate func colorize() {
private func colorize() {
loadingIndicator.color = UIColor.mainDark
ratingSegmentedControl.tintColor = UIColor.mainDark
}

fileprivate func localize() {
private func localize() {
ratingSegmentedControl.setTitle(NSLocalizedString("AdaptiveAllTime", comment: ""), forSegmentAt: 0)
ratingSegmentedControl.setTitle(NSLocalizedString("Adaptive7Days", comment: ""), forSegmentAt: 1)
ratingSegmentedControl.setTitle(NSLocalizedString("AdaptiveToday", comment: ""), forSegmentAt: 2)
Expand Down Expand Up @@ -116,7 +116,7 @@ final class AdaptiveRatingsViewController: UIViewController {
}
}

fileprivate func setUpTable() {
private func setUpTable() {
tableView.delegate = self
tableView.dataSource = self

Expand Down
2 changes: 1 addition & 1 deletion Stepic/AdaptiveStatsPagerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class AdaptiveStatsPagerViewController: PagerController {
setUpTabs()
}

fileprivate func setUpTabs() {
private func setUpTabs() {
tabHeight = 44.0
indicatorHeight = 1.5
centerCurrentTab = true
Expand Down
4 changes: 2 additions & 2 deletions Stepic/AdaptiveStatsPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct WeekProgressViewData {
final class AdaptiveStatsPresenter {
weak var view: AdaptiveStatsView?

fileprivate var ratingManager: AdaptiveRatingManager
fileprivate var statsManager: AdaptiveStatsManager
private var ratingManager: AdaptiveRatingManager
private var statsManager: AdaptiveStatsManager

private var progressByWeek: [WeekProgressViewData]?

Expand Down
14 changes: 7 additions & 7 deletions Stepic/AdaptiveStatsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AdaptiveStatsViewController: UIViewController {
case normal(message: String?)
}

fileprivate var state: State = .loading {
private var state: State = .loading {
didSet {
switch state {
case .loading:
Expand Down Expand Up @@ -58,7 +58,7 @@ final class AdaptiveStatsViewController: UIViewController {
@IBOutlet weak var xpPer7DaysTitleLabel: UILabel!
@IBOutlet weak var last7DaysTitleLabel: UILabel!

fileprivate var data: [Any]?
private var data: [Any]?

@IBAction func onCancelButtonClick(_ sender: Any) {
dismiss(animated: true, completion: nil)
Expand All @@ -81,7 +81,7 @@ final class AdaptiveStatsViewController: UIViewController {
presenter?.reloadData(force: data == nil)
}

fileprivate func colorize() {
private func colorize() {
currentWeekXPLabel.textColor = UIColor.mainDark
bestStreakLabel.textColor = UIColor.mainDark
currentLevelLabel.textColor = UIColor.mainDark
Expand Down Expand Up @@ -123,7 +123,7 @@ final class AdaptiveStatsViewController: UIViewController {
}
}

fileprivate func valuesToDataEntries(values: [Int]) -> [ChartDataEntry] {
private func valuesToDataEntries(values: [Int]) -> [ChartDataEntry] {
var dataEntries: [ChartDataEntry] = []

for i in 0..<values.count {
Expand All @@ -134,7 +134,7 @@ final class AdaptiveStatsViewController: UIViewController {
return dataEntries
}

fileprivate func setUpTable() {
private func setUpTable() {
tableView.delegate = self
tableView.dataSource = self

Expand All @@ -144,7 +144,7 @@ final class AdaptiveStatsViewController: UIViewController {
tableView.register(UINib(nibName: "ProgressTableViewCell", bundle: nil), forCellReuseIdentifier: ProgressTableViewCell.reuseId)
}

fileprivate func setUpChart() {
private func setUpChart() {
progressChart.chartDescription?.enabled = false
progressChart.isUserInteractionEnabled = false
progressChart.setScaleEnabled(false)
Expand All @@ -157,7 +157,7 @@ final class AdaptiveStatsViewController: UIViewController {
progressChart.legend.enabled = false
}

fileprivate func updateDataSet(_ dataSet: LineChartDataSet) -> LineChartDataSet {
private func updateDataSet(_ dataSet: LineChartDataSet) -> LineChartDataSet {
dataSet.setColor(UIColor.mainDark)
dataSet.mode = .horizontalBezier
dataSet.cubicIntensity = 0.2
Expand Down
15 changes: 14 additions & 1 deletion Stepic/Analytics/AmplitudeAnalyticsEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,20 @@ struct AmplitudeAnalyticsEvents {
}

struct Discussions {
static var opened = AnalyticsEvent(name: "Discussions screen opened")
enum DiscussionsSource: String {
case discussion
case reply
case `default`
}

static func opened(source: DiscussionsSource) -> AnalyticsEvent {
return AnalyticsEvent(
name: "Discussions screen opened",
parameters: [
"source": source.rawValue
]
)
}
}

struct Stories {
Expand Down
2 changes: 1 addition & 1 deletion Stepic/ApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final class ApiRequestPerformer {
}
}

fileprivate static func performRequestWithAuthorizationCheck(_ completion: @escaping (() -> Void), error errorHandler: ((PerformRequestError) -> Void)? = nil) {
private static func performRequestWithAuthorizationCheck(_ completion: @escaping (() -> Void), error errorHandler: ((PerformRequestError) -> Void)? = nil) {
// if let user = AuthInfo.shared.user {
// print("performing request with user \(user.id)")
if !AuthInfo.shared.isAuthorized && Session.needsRefresh {
Expand Down
2 changes: 1 addition & 1 deletion Stepic/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
ConnectionHelper.shared.instantiate()
self.alamofireRequestsLogger.startIfDebug()

if !AudioManager.sharedManager.initAudioSession() {
if !AudioManager.shared.initAudioSession() {
print("Could not initialize audio session")
}

Expand Down
2 changes: 1 addition & 1 deletion Stepic/Attempt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class Attempt: JSONSerializable {
]
}

fileprivate func getDatasetFromJSON(_ json: JSON, stepName: String) -> Dataset? {
private func getDatasetFromJSON(_ json: JSON, stepName: String) -> Dataset? {
switch stepName {
case "choice" :
return ChoiceDataset(json: json)
Expand Down
16 changes: 9 additions & 7 deletions Stepic/AudioManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ import AVFoundation
import UIKit

final class AudioManager: NSObject {
override fileprivate init() { super.init() }
static let sharedManager = AudioManager()
static let shared = AudioManager()

var ignoreMuteSwitch: Bool {
get {
let currentCategory = AVAudioSession.sharedInstance().category
print("in isIgnoring, current category = \(currentCategory))")
return currentCategory == .playback
}

set(ignore) {
set {
do {
print("setting ignore status to \(ignore)")
print("setting ignore status to \(newValue)")
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default)
try AVAudioSession.sharedInstance().setActive(!ignore)
try AVAudioSession.sharedInstance().setActive(!newValue)
} catch {
print("Error while setting ignore mute switch")
}
}
}

private override init() {
super.init()
}

func initAudioSession() -> Bool {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default)
Expand All @@ -40,7 +42,7 @@ final class AudioManager: NSObject {
}
}

fileprivate func changeMuteIgnoreStatusTo(ignore: Bool) -> Bool {
private func changeMuteIgnoreStatusTo(ignore: Bool) -> Bool {
do {
try AVAudioSession.sharedInstance().setActive(!ignore)
return true
Expand Down
6 changes: 3 additions & 3 deletions Stepic/AuthInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ extension Foundation.Notification.Name {
final class AuthInfo: NSObject {
static var shared = AuthInfo()

fileprivate let defaults = UserDefaults.standard
private let defaults = UserDefaults.standard

override fileprivate init() {
private override init() {
super.init()

print("initializing AuthInfo with userId \(String(describing: userId))")
Expand All @@ -33,7 +33,7 @@ final class AuthInfo: NSObject {
}
}

fileprivate func setTokenValue(_ newToken: StepicToken?) {
private func setTokenValue(_ newToken: StepicToken?) {
defaults.setValue(newToken?.accessToken, forKey: "access_token")
defaults.setValue(newToken?.refreshToken, forKey: "refresh_token")
defaults.setValue(newToken?.tokenType, forKey: "token_type")
Expand Down
2 changes: 1 addition & 1 deletion Stepic/BaseCardsStepsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class BaseCardsStepsViewController: CardsStepsViewController {
@IBOutlet weak var backButton: UIButton!
@IBOutlet weak var shadowView: UIView!

fileprivate var statusBarPad: UIView?
private var statusBarPad: UIView?
private var shouldToggleNavigationBar = true

// For init View-Presenter via view creating
Expand Down
12 changes: 6 additions & 6 deletions Stepic/CardsStepsPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ final class BaseCardsStepsPresenter: CardsStepsPresenter, StepCardViewDelegate {
func logout() {
}

fileprivate func loadRecommendations(for course: Course, count: Int) -> Promise<[Lesson]> {
private func loadRecommendations(for course: Course, count: Int) -> Promise<[Lesson]> {
return Promise { seal in
self.recommendationsAPI.retrieve(course: course.id, count: count).then { lessonsIds -> Promise<[Lesson]> in
guard !lessonsIds.isEmpty else {
Expand All @@ -332,7 +332,7 @@ final class BaseCardsStepsPresenter: CardsStepsPresenter, StepCardViewDelegate {
}
}

fileprivate func getStep(for lesson: Lesson, index: Int = 0) -> Promise<Step> {
private func getStep(for lesson: Lesson, index: Int = 0) -> Promise<Step> {
return Promise { seal in
guard lesson.stepsArray.count > index else {
throw CardsStepsError.noStepsInLesson
Expand All @@ -354,7 +354,7 @@ final class BaseCardsStepsPresenter: CardsStepsPresenter, StepCardViewDelegate {
}
}

fileprivate func getNewRecommendation(for course: Course) -> Promise<Lesson> {
private func getNewRecommendation(for course: Course) -> Promise<Lesson> {
print("cards steps: preloaded lessons = \(cachedRecommendedLessons.map { $0.id })")

return Promise { seal in
Expand Down Expand Up @@ -404,7 +404,7 @@ final class BaseCardsStepsPresenter: CardsStepsPresenter, StepCardViewDelegate {
}
}

fileprivate func sendView(step: Step) -> Promise<Void> {
private func sendView(step: Step) -> Promise<Void> {
return Promise { seal in
guard let lesson = step.lesson else {
throw CardsStepsError.viewNotSent
Expand All @@ -425,7 +425,7 @@ final class BaseCardsStepsPresenter: CardsStepsPresenter, StepCardViewDelegate {
}
}

fileprivate func sendReaction(_ reaction: Reaction, for lesson: Lesson, user: User) -> Promise<Void> {
private func sendReaction(_ reaction: Reaction, for lesson: Lesson, user: User) -> Promise<Void> {
return Promise { seal in
self.recommendationsAPI.sendReaction(user: user.id, lesson: lesson.id, reaction: reaction).done { _ in
if let curState = self.currentStepPresenter?.state {
Expand All @@ -452,7 +452,7 @@ final class BaseCardsStepsPresenter: CardsStepsPresenter, StepCardViewDelegate {
}
}

fileprivate func syncRatingAndStreak(for course: Course) -> Guarantee<Void> {
private func syncRatingAndStreak(for course: Course) -> Guarantee<Void> {
return Guarantee { seal in
self.ratingsAPI.restore(courseId: course.id).done { exp, streak in
self.rating = max(self.rating, exp)
Expand Down
6 changes: 3 additions & 3 deletions Stepic/CardsStepsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class CardsStepsViewController: UIViewController, CardsStepsView, ControllerWith

var canSwipeCurrentCardUp = false

fileprivate var topCard: StepCardView?
fileprivate var currentStepViewController: CardStepViewController?
private var topCard: StepCardView?
private var currentStepViewController: CardStepViewController?

var state: CardsStepsViewState = .normal {
didSet {
Expand Down Expand Up @@ -100,7 +100,7 @@ class CardsStepsViewController: UIViewController, CardsStepsView, ControllerWith
}

func presentDiscussions(stepId: Int, discussionProxyId: String) {
let assembly = NewDiscussionsAssembly(discussionProxyID: discussionProxyId, stepID: stepId)
let assembly = DiscussionsAssembly(discussionProxyID: discussionProxyId, stepID: stepId)
self.push(module: assembly.makeModule())
}

Expand Down
4 changes: 2 additions & 2 deletions Stepic/CertificatesPresentationContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import Foundation

final class CertificatesPresentationContainer {
fileprivate let defaults = UserDefaults.standard
private let defaults = UserDefaults.standard

fileprivate let certificatesStoredKey = "certificatesStoredIdsKey"
private let certificatesStoredKey = "certificatesStoredIdsKey"

var certificatesIds: [Int] {
get {
Expand Down
4 changes: 2 additions & 2 deletions Stepic/ChoiceQuizViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class ChoiceQuizViewController: QuizViewController {
tableView.register(UINib(nibName: "ChoiceQuizTableViewCell", bundle: nil), forCellReuseIdentifier: "ChoiceQuizTableViewCell")
}

fileprivate func hasTagsInDataset(dataset: ChoiceDataset) -> Bool {
private func hasTagsInDataset(dataset: ChoiceDataset) -> Bool {
for option in dataset.options {
if TagDetectionUtil.isWebViewSupportNeeded(option) {
return true
Expand Down Expand Up @@ -151,7 +151,7 @@ extension ChoiceQuizViewController: UITableViewDelegate {
reactOnSelection(tableView, didSelectRowAtIndexPath: indexPath)
}

fileprivate func reactOnSelection(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
private func reactOnSelection(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? ChoiceQuizTableViewCell {
if let dataset = dataset {
if dataset.isMultipleChoice {
Expand Down
Loading