-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d21b69a
commit 1cbda70
Showing
6 changed files
with
96 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters