Skip to content

Commit

Permalink
Added right-hand label to InfoChildTableCell (scribe-org#469)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Jag-Marcel committed Jun 24, 2024
1 parent 1fc7bee commit e878c50
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 32 deletions.
12 changes: 12 additions & 0 deletions Keyboards/KeyboardsBase/InterfaceVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,25 @@ 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
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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()
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand All @@ -20,16 +20,23 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XI7-83-3eC" userLabel="TitleLabelPad">
<rect key="frame" x="24.000000000000004" y="12" width="58.333333333333343" height="48"/>
<rect key="frame" x="24.000000000000004" y="12" width="58.333333333333343" height="42"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="trX-iS-h3L"/>
<constraint firstAttribute="height" constant="42" id="trX-iS-h3L"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="24"/>
<color key="textColor" name="keyChar"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="clp-Yj-pdj" userLabel="IconImageViewPad">
<rect key="frame" x="382" y="18" width="18" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="Wph-jk-pH6"/>
<constraint firstAttribute="width" constant="18" id="bkB-2m-7Ka"/>
</constraints>
</imageView>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FbK-yb-cab" userLabel="ToggleSwitchPad">
<rect key="frame" x="351" y="20.666666666666671" width="51" height="31"/>
<rect key="frame" x="351" y="17.666666666666671" width="51" height="31"/>
<constraints>
<constraint firstAttribute="width" constant="49" id="TLe-pF-eis"/>
</constraints>
Expand All @@ -38,7 +45,7 @@
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LZg-In-Sru" userLabel="DescriptionLabelPad">
<rect key="frame" x="24" y="68" width="376" height="64"/>
<rect key="frame" x="24" y="62" width="376" height="70"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="21" id="h5P-Y8-JKH"/>
</constraints>
Expand All @@ -47,16 +54,32 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Y7l-w6-QQi" userLabel="TitleLabelPhone">
<rect key="frame" x="15.999999999999996" y="8" width="40.666666666666657" height="32"/>
<rect key="frame" x="15.999999999999996" y="8" width="40.666666666666657" height="28"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="FRe-ww-FJ2"/>
<constraint firstAttribute="height" constant="28" id="FRe-ww-FJ2"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<color key="textColor" name="keyChar"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="right" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jzv-r8-6Ur" userLabel="SubLabelPhone">
<rect key="frame" x="352" y="6" width="36" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="2Ry-o6-qVG"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="SWG-JP-Qz7" userLabel="IconImageViewPhone">
<rect key="frame" x="396" y="12" width="12" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="12" id="Y1S-pW-XVz"/>
<constraint firstAttribute="height" constant="20" id="dJC-Kw-e1b"/>
</constraints>
</imageView>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iEK-aH-VJH" userLabel="ToggleSwitchPhone">
<rect key="frame" x="359" y="8.6666666666666643" width="51" height="31"/>
<rect key="frame" x="359" y="6.6666666666666679" width="51" height="31.000000000000004"/>
<constraints>
<constraint firstAttribute="width" constant="49" id="Khi-vw-oTT"/>
</constraints>
Expand All @@ -65,39 +88,60 @@
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Z37-gs-N4L" userLabel="DescriptionLabelPhone">
<rect key="frame" x="16" y="48" width="392" height="84"/>
<rect key="frame" x="16" y="44" width="392" height="88"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="21" id="ynu-Q0-G95"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="right" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Pub-0x-feK" userLabel="SubLabelPad">
<rect key="frame" x="326" y="9" width="48" height="48"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="YTm-od-kA1"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="SWG-JP-Qz7" firstAttribute="centerY" secondItem="Y7l-w6-QQi" secondAttribute="centerY" id="18U-Wx-tNI"/>
<constraint firstAttribute="trailing" secondItem="LZg-In-Sru" secondAttribute="trailing" constant="24" id="2Qt-oK-abA"/>
<constraint firstAttribute="bottom" secondItem="LZg-In-Sru" secondAttribute="bottom" constant="16" id="3Bx-Zf-41Z"/>
<constraint firstItem="LZg-In-Sru" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="24" id="5iP-HO-wDD"/>
<constraint firstItem="jzv-r8-6Ur" firstAttribute="centerY" secondItem="Y7l-w6-QQi" secondAttribute="centerY" id="8r0-iD-8to"/>
<constraint firstItem="XI7-83-3eC" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="24" id="AFt-39-OV3"/>
<constraint firstItem="FbK-yb-cab" firstAttribute="centerY" secondItem="XI7-83-3eC" secondAttribute="centerY" id="IRH-3q-9RQ"/>
<constraint firstItem="Pub-0x-feK" firstAttribute="centerY" secondItem="XI7-83-3eC" secondAttribute="centerY" id="MfM-OH-gno"/>
<constraint firstAttribute="trailing" secondItem="FbK-yb-cab" secondAttribute="trailing" constant="24" id="NSu-Bi-Rs7"/>
<constraint firstItem="Z37-gs-N4L" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="NUc-eT-51z"/>
<constraint firstAttribute="bottom" secondItem="Z37-gs-N4L" secondAttribute="bottom" constant="16" id="NVO-sx-oET"/>
<constraint firstItem="SWG-JP-Qz7" firstAttribute="leading" secondItem="jzv-r8-6Ur" secondAttribute="trailing" constant="8" id="Pjt-0b-ip5"/>
<constraint firstItem="LZg-In-Sru" firstAttribute="top" secondItem="XI7-83-3eC" secondAttribute="bottom" constant="8" id="YPZ-4h-YkG"/>
<constraint firstAttribute="trailing" secondItem="clp-Yj-pdj" secondAttribute="trailing" constant="24" id="blK-K8-o1U"/>
<constraint firstItem="Z37-gs-N4L" firstAttribute="top" secondItem="Y7l-w6-QQi" secondAttribute="bottom" constant="8" id="cYT-7r-iva"/>
<constraint firstItem="XI7-83-3eC" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="12" id="da5-Mw-d8e"/>
<constraint firstItem="Y7l-w6-QQi" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="8" id="j7R-Wb-Bf1"/>
<constraint firstItem="clp-Yj-pdj" firstAttribute="leading" secondItem="Pub-0x-feK" secondAttribute="trailing" constant="8" id="jl5-7e-VdG"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="XI7-83-3eC" secondAttribute="bottom" constant="12" id="lu1-D7-DGx"/>
<constraint firstAttribute="trailing" secondItem="iEK-aH-VJH" secondAttribute="trailing" constant="16" id="n4G-Lb-Cpd"/>
<constraint firstItem="clp-Yj-pdj" firstAttribute="centerY" secondItem="XI7-83-3eC" secondAttribute="centerY" id="n6t-Z4-pIB"/>
<constraint firstItem="Y7l-w6-QQi" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="pKu-Re-d4D"/>
<constraint firstItem="iEK-aH-VJH" firstAttribute="centerY" secondItem="Y7l-w6-QQi" secondAttribute="centerY" id="pgQ-hV-7VG"/>
<constraint firstAttribute="trailing" secondItem="Z37-gs-N4L" secondAttribute="trailing" constant="16" id="v6o-1J-9JP"/>
<constraint firstAttribute="trailing" secondItem="SWG-JP-Qz7" secondAttribute="trailing" constant="16" id="vSZ-Y9-0VH"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections>
<outlet property="descriptionLabelPad" destination="LZg-In-Sru" id="pqa-F0-8gX"/>
<outlet property="descriptionLabelPhone" destination="Z37-gs-N4L" id="QWf-la-nC2"/>
<outlet property="iconImageViewPad" destination="clp-Yj-pdj" id="7ql-KU-skf"/>
<outlet property="iconImageViewPhone" destination="SWG-JP-Qz7" id="Z1C-uf-OPJ"/>
<outlet property="subLabelPad" destination="Pub-0x-feK" id="jTs-UX-Dxz"/>
<outlet property="subLabelPhone" destination="jzv-r8-6Ur" id="ktg-zl-PaB"/>
<outlet property="titleLabelPad" destination="XI7-83-3eC" id="Ux1-cE-hdw"/>
<outlet property="titleLabelPhone" destination="Y7l-w6-QQi" id="Azb-9B-TQa"/>
<outlet property="toggleSwitchPad" destination="FbK-yb-cab" id="jdx-46-rpt"/>
Expand Down
3 changes: 2 additions & 1 deletion Scribe/ParentTableCellModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion Scribe/SettingsTab/SettingsTableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ enum SettingsTableData {
section: [
Section(
sectionTitle: NSLocalizedString("settings.appSettings.appLanguage", value: "App language", comment: ""),
hasToggle: false,
sectionState: .appLang
)
],
Expand All @@ -42,6 +41,16 @@ enum SettingsTableData {
]

static let languageSettingsData: [ParentTableCellModel] = [
ParentTableCellModel(
headingTitle: NSLocalizedString("settings.tlLang", 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: [
Expand Down
Loading

0 comments on commit e878c50

Please sign in to comment.