From fa14ae0bd0718dd5c70c9a645c57d72a357f7c57 Mon Sep 17 00:00:00 2001 From: Jag-Marcel Date: Mon, 24 Jun 2024 18:21:16 +0200 Subject: [PATCH] Added right-hand label to InfoChildTableCell (#469) - Minor refactor to code for the button - Reworked how the chevron is displayed on the button - Added a label to the left of the chevron - Resized elements of the button to be centred instead of slightly lower than the centre - Added a button to language settings for picking a translation language - Created temporary value to store currently selected translation language, the plan is for every keyboard to have one of these --- .../KeyboardsBase/InterfaceVariables.swift | 12 ++++ .../InfoChildTableViewCell.swift | 49 ++++++++++----- .../InfoChildTableViewCell.xib | 62 ++++++++++++++++--- Scribe/ParentTableCellModel.swift | 3 +- Scribe/SettingsTab/SettingsTableData.swift | 11 +++- .../SettingsTab/SettingsViewController.swift | 10 +-- 6 files changed, 115 insertions(+), 32 deletions(-) diff --git a/Keyboards/KeyboardsBase/InterfaceVariables.swift b/Keyboards/KeyboardsBase/InterfaceVariables.swift index 09e8fea9..6dca4ed9 100644 --- a/Keyboards/KeyboardsBase/InterfaceVariables.swift +++ b/Keyboards/KeyboardsBase/InterfaceVariables.swift @@ -132,6 +132,17 @@ enum ConjViewShiftButtonsState { case rightInactive } +enum TranslateLanguage: String { + case english + case french + case german + case italian + case portuguese + case russian + case spanish + case swedish +} + // Baseline state variables. var keyboardState: KeyboardState = .letters var shiftButtonState: ShiftButtonState = .normal @@ -139,6 +150,7 @@ var capsLockButtonState: CapsLockButtonState = .normal var commandState: CommandState = .idle var autoActionState: AutoActionState = .suggest var conjViewShiftButtonsState: ConjViewShiftButtonsState = .bothInactive +var translateLanguage: TranslateLanguage = .english // Variables and functions to determine display parameters. enum DeviceType { diff --git a/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.swift b/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.swift index a6332e56..3ecb9aaf 100644 --- a/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.swift +++ b/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.swift @@ -31,6 +31,14 @@ final class InfoChildTableViewCell: UITableViewCell { @IBOutlet var titleLabelPad: UILabel! var titleLabel: UILabel! + @IBOutlet var subLabelPhone: UILabel! + @IBOutlet var subLabelPad: UILabel! + var subLabel: UILabel! + + @IBOutlet var iconImageViewPhone: UIImageView! + @IBOutlet var iconImageViewPad: UIImageView! + var iconImageView: UIImageView! + @IBOutlet var toggleSwitchPhone: UISwitch! @IBOutlet var toggleSwitchPad: UISwitch! var toggleSwitch: UISwitch! @@ -45,18 +53,26 @@ final class InfoChildTableViewCell: UITableViewCell { func setTableView() { if DeviceType.isPad { titleLabel = titleLabelPad + subLabel = subLabelPad + iconImageView = iconImageViewPad toggleSwitch = toggleSwitchPad descriptionLabel = descriptionLabelPad titleLabelPhone.removeFromSuperview() + subLabelPhone.removeFromSuperview() + iconImageViewPhone.removeFromSuperview() toggleSwitchPhone.removeFromSuperview() descriptionLabelPhone.removeFromSuperview() } else { titleLabel = titleLabelPhone + subLabel = subLabelPhone + iconImageView = iconImageViewPhone toggleSwitch = toggleSwitchPhone descriptionLabel = descriptionLabelPhone titleLabelPad.removeFromSuperview() + subLabelPad.removeFromSuperview() + iconImageViewPad.removeFromSuperview() toggleSwitchPad.removeFromSuperview() descriptionLabelPad.removeFromSuperview() } @@ -96,26 +112,27 @@ final class InfoChildTableViewCell: UITableViewCell { descriptionLabel.removeFromSuperview() } - if !section.hasToggle { - let disclosureIcon = UIImage(systemName: "chevron.right") - let accessory = UIImageView( - frame: CGRect( - x: 0, y: 0, width: (disclosureIcon?.size.width)!, height: (disclosureIcon?.size.height)! - ) - ) - accessory.image = disclosureIcon - accessory.tintColor = menuOptionColor - accessoryView = accessory - toggleSwitch.isHidden = true - } else { + if section.hasToggle { accessoryType = .none toggleSwitch.isHidden = false - } - fetchSwitchStateForCell() + fetchSwitchStateForCell() - toggleSwitch.onTintColor = .init(ScribeColor.scribeCTA).withAlphaComponent(0.4) - toggleSwitch.thumbTintColor = toggleSwitch.isOn ? .init(.scribeCTA) : .lightGray + toggleSwitch.onTintColor = .init(ScribeColor.scribeCTA).withAlphaComponent(0.4) + toggleSwitch.thumbTintColor = toggleSwitch.isOn ? .init(.scribeCTA) : .lightGray + } else { + iconImageView.image = UIImage(systemName: "chevron.right") + iconImageView.tintColor = menuOptionColor + toggleSwitch.isHidden = true + } + + if section.sectionState == .translateLang { + let currentLang = "_global.\(translateLanguage.rawValue)" + subLabel.text = NSLocalizedString(currentLang, value: translateLanguage.rawValue.capitalized, comment: "") + subLabel.textColor = menuOptionColor + } else { + subLabel.removeFromSuperview() + } } @IBAction func switchDidChange(_: UISwitch) { diff --git a/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.xib b/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.xib index 51c84a4c..86400be2 100644 --- a/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.xib +++ b/Scribe/Components/InfoChildTableViewCell/InfoChildTableViewCell.xib @@ -3,7 +3,7 @@ - + @@ -20,16 +20,23 @@ + + + + + + + - + @@ -38,7 +45,7 @@ + + + + + + + + - + @@ -65,7 +88,7 @@ + + + + + + + + + + + + + diff --git a/Scribe/ParentTableCellModel.swift b/Scribe/ParentTableCellModel.swift index fefcc23c..556a4604 100644 --- a/Scribe/ParentTableCellModel.swift +++ b/Scribe/ParentTableCellModel.swift @@ -69,8 +69,9 @@ enum SectionState: Equatable { case licenses case appLang case specificLang(String) - case none(UserInteractiveState) + case translateLang case externalLink + case none(UserInteractiveState) } enum UserInteractiveState { diff --git a/Scribe/SettingsTab/SettingsTableData.swift b/Scribe/SettingsTab/SettingsTableData.swift index 99b269e9..a14177ba 100644 --- a/Scribe/SettingsTab/SettingsTableData.swift +++ b/Scribe/SettingsTab/SettingsTableData.swift @@ -26,7 +26,6 @@ enum SettingsTableData { section: [ Section( sectionTitle: NSLocalizedString("settings.appSettings.appLanguage", value: "App language", comment: ""), - hasToggle: false, sectionState: .appLang ) ], @@ -42,6 +41,16 @@ enum SettingsTableData { ] static let languageSettingsData: [ParentTableCellModel] = [ + ParentTableCellModel( + headingTitle: NSLocalizedString("app.settings.translateLang", value: "Translation language", comment: ""), + section: [ + Section( + sectionTitle: NSLocalizedString("app.settings.translateLang", value: "Translation language", comment: ""), + sectionState: .translateLang + ) + ], + hasDynamicData: nil + ), ParentTableCellModel( headingTitle: NSLocalizedString("settings.layout", value: "Layout", comment: ""), section: [ diff --git a/Scribe/SettingsTab/SettingsViewController.swift b/Scribe/SettingsTab/SettingsViewController.swift index b8379726..8537ae9c 100644 --- a/Scribe/SettingsTab/SettingsViewController.swift +++ b/Scribe/SettingsTab/SettingsViewController.swift @@ -169,27 +169,27 @@ extension SettingsViewController: UITableViewDelegate { var data = SettingsTableData.languageSettingsData // Check if the device is an iPad to determine period and comma on the ABC characters option. - let periodCommaOptionIndex = SettingsTableData.languageSettingsData[0].section.firstIndex(where: { s in + let periodCommaOptionIndex = data[1].section.firstIndex(where: { s in s.sectionTitle.elementsEqual(NSLocalizedString("settings.layout.periodAndComma", value: "Period and comma on ABC", comment: "")) }) ?? -1 if DeviceType.isPad { - let periodCommaSettings = data[0].section.remove(at: periodCommaOptionIndex) + let periodCommaSettings = data[1].section.remove(at: periodCommaOptionIndex) print(periodCommaSettings) } // Languages where we can disable accent keys. let accentKeyLanguages: [String] = ["Swedish", "German", "Spanish"] - let accentKeyOptionIndex = SettingsTableData.languageSettingsData[0].section.firstIndex(where: { s in + let accentKeyOptionIndex = data[1].section.firstIndex(where: { s in s.sectionTitle.elementsEqual(NSLocalizedString("settings.layout.disableAccentCharacters", value: "Disable accent characters", comment: "")) }) ?? -1 if accentKeyLanguages.firstIndex(of: section.sectionTitle) == nil && accentKeyOptionIndex != -1 { // As there are no accent keys we can remove the `Disable accent characters` option. - let accentKeySettings = data[0].section.remove(at: accentKeyOptionIndex) + let accentKeySettings = data[1].section.remove(at: accentKeyOptionIndex) print(accentKeySettings) } else if accentKeyLanguages.firstIndex(of: section.sectionTitle) != nil && accentKeyOptionIndex == -1 { - data[0].section.insert( + data[1].section.insert( Section( sectionTitle: NSLocalizedString("settings.layout.disableAccentCharacters", value: "Disable accent characters", comment: ""), imageString: "info.circle",