spiegel-keyman/ios/engine/KMEI/KeymanEngine/Classes/SpacebarTextViewController.swift
Marc Durdin 073ca98e2e feat(ios): add spacebar text controls
Relates to #949.

Mirror of #5349 (Android), for iOS.

* Adds setSpacebarText() API to Keyman Engine for iOS
* Adds displayName API to Keyman Engine for iOS
* Adds Preference for spacebar text to Keyman Engine for iOS
* Sets default spacebar text to keyboard name for FirstVoices Keyboards
2021-06-25 11:44:09 +10:00

83 lines
2.5 KiB
Swift

//
// SpacebarTextViewController.swift
// KeymanEngine
//
// Created by Marc Durdin on 24/6/21.
// Copyright © 2021 SIL International. All rights reserved.
//
import UIKit
open class SpacebarTextViewController: UITableViewController {
let items: [String] = [
"menu-settings-spacebar-item-language",
"menu-settings-spacebar-item-keyboard",
"menu-settings-spacebar-item-languageKeyboard",
"menu-settings-spacebar-item-blank"
]
let itemValues: [SpacebarText] = [
SpacebarText.LANGUAGE,
SpacebarText.KEYBOARD,
SpacebarText.LANGUAGE_KEYBOARD,
SpacebarText.BLANK
]
let cellIdentifier = "spacebarTextCell"
var selection: Int
override open func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override open func viewDidLoad() {
super.viewDidLoad()
title = NSLocalizedString("menu-settings-spacebar-title", bundle: engineBundle, comment: "")
navigationItem.setHidesBackButton(false, animated: true)
navigationItem.leftBarButtonItem?.isEnabled = true
navigationController?.toolbar?.barTintColor = Colors.statusToolbar
}
public init() {
switch Manager.shared.spacebarText {
case SpacebarText.LANGUAGE:
selection = 0
case SpacebarText.KEYBOARD:
selection = 1
case SpacebarText.LANGUAGE_KEYBOARD:
selection = 2
case SpacebarText.BLANK:
selection = 3
}
super.init(nibName: nil, bundle: nil)
_ = view
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Table view data source
override open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count
}
override public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell
if let reusedCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) {
cell = reusedCell
} else {
cell = UITableViewCell(style: .default, reuseIdentifier: cellIdentifier)
}
cell.accessoryType = self.selection == indexPath.row ? .checkmark : .none
cell.textLabel?.text = NSLocalizedString(items[indexPath.row], bundle: engineBundle, comment: "")
return cell
}
override public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Manager.shared.spacebarText = self.itemValues[indexPath.row]
navigationController?.popViewController(animated: true)
}
}