Skip to content

Commit

Permalink
Add a menu for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrocaselani committed May 12, 2019
1 parent d21b69a commit 1cbda70
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CouchTrackerApp/AppFlow/AppFlowModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public enum AppFlowModule {
public static func setupModule() -> BaseView {
let userDefaults = Environment.instance.userDefaults

let dataSource = AppFlowiOSModuleDataSource()
let dataSource = AppFlowiOSModuleDataSource(buildConfig: Environment.instance.buildConfig)
let repository = AppFlowUserDefaultsRepository(userDefaults: userDefaults)
let presenter = AppFlowDefaultPresenter(repository: repository,
moduleDataSource: dataSource)
Expand Down
2 changes: 2 additions & 0 deletions CouchTrackerApp/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class Environment {
userDefaults = UserDefaults.standard
let schedulers = DefaultSchedulers.instance

DefaultBundleProvider.update(userDefaults: userDefaults)

let debug: Bool

let plugins = [PluginType]()
Expand Down
15 changes: 7 additions & 8 deletions CouchTrackerDebug/Menu/DebugMenuModule.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//
// DebugMenuModule.swift
// CouchTrackerDebug
//
// Created by Pietro Caselani on 12/05/19.
// Copyright © 2019 Pietro Caselani. All rights reserved.
//
import CouchTrackerCore

import Foundation
public enum DebugMenuModule {
public static func setupModule() -> BaseView {
// swiftlint:disable force_cast
return UINavigationController(rootViewController: DebugMenuViewController()) as! BaseView
}
}
86 changes: 77 additions & 9 deletions CouchTrackerDebug/Menu/DebugMenuViewController.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,77 @@
//
// DebugMenuViewController.swift
// CouchTrackerDebug
//
// Created by Pietro Caselani on 12/05/19.
// Copyright © 2019 Pietro Caselani. All rights reserved.
//

import Foundation
import CouchTrackerCore

final class DebugMenuViewController: UITableViewController {
private typealias S = DebugMenuViewController
private static let cellIdentifier = "DebugCellIdentifier"

private enum Settings: String, CaseIterable {
case language = "Language"
}

private var currentLanguageIndex = 0

override func viewDidLoad() {
super.viewDidLoad()

updateCurrentSettingsValues()

tableView.reloadData()
}

override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
return Settings.allCases.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = dequeueValidCell(tableView: tableView)

let settings = Settings.allCases[indexPath.row]

cell.textLabel?.text = settings.rawValue
cell.detailTextLabel?.text = currentValue(for: settings)

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

setNextValue(for: Settings.allCases[indexPath.row])

tableView.reloadData()
}

private func currentValue(for settings: Settings) -> String {
switch settings {
case .language: return DefaultBundleProvider.instance.currentLanguage.rawValue
}
}

private func setNextValue(for settings: Settings) {
switch settings {
case .language: updateLanguage()
}
}

private func updateLanguage() {
if currentLanguageIndex >= SupportedLanguages.allCases.count - 1 {
currentLanguageIndex = 0
} else {
currentLanguageIndex += 1
}

let nextLanguage = SupportedLanguages.allCases[currentLanguageIndex]

DefaultBundleProvider.update(language: nextLanguage)
}

private func updateCurrentSettingsValues() {
let currentLanguage = DefaultBundleProvider.instance.currentLanguage
currentLanguageIndex = SupportedLanguages.allCases.firstIndex(of: currentLanguage) ?? 0
}

private func dequeueValidCell(tableView: UITableView) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: S.cellIdentifier)
return cell ?? UITableViewCell(style: .subtitle, reuseIdentifier: S.cellIdentifier)
}
}
8 changes: 8 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ target 'CouchTracker' do

ios_pods
end

target 'CouchTrackerDebug' do
platform :ios, IOS_VERSION
use_frameworks!
inhibit_all_warnings!

pod 'SnapKit', SNAPKIT_VERSION
end
1 change: 1 addition & 0 deletions build_phases/swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ swiftformat --indent 2 CouchTrackerApp/
swiftformat --indent 2 CouchTrackerCore/
swiftformat --indent 2 CouchTrackerCoreTests/
swiftformat --indent 2 CouchTrackerPersistence/
swiftformat --indent 2 CouchTrackerDebug/

0 comments on commit 1cbda70

Please sign in to comment.