Skip to content

Commit

Permalink
Merge pull request #492 from vickcoo/currency-symbol-selection
Browse files Browse the repository at this point in the history
Make the keyboard able to replace currency symbols
  • Loading branch information
andrewtavis authored Aug 24, 2024
2 parents 55ed33d + 88c1ee3 commit 6e72d7f
Show file tree
Hide file tree
Showing 14 changed files with 1,553 additions and 811 deletions.
56 changes: 56 additions & 0 deletions Keyboards/KeyboardBuilder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Building a keyboard layout using a builder pattern.
*
* Copyright (C) 2024 Scribe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import Foundation

protocol KeyboardBuilderProtocol {
func addRow(_ row: [String]) -> KeyboardBuilder
func build() -> [[String]]
func replaceKey(row: Int, column: Int, to newKey: String) -> KeyboardBuilder
func replaceKey(form oldKey: String, to newKey: String) -> KeyboardBuilder
}

class KeyboardBuilder: KeyboardBuilderProtocol {
private var rows: [[String]] = []

func addRow(_ row: [String]) -> KeyboardBuilder {
rows.append(row)
return self
}

func build() -> [[String]] {
return rows
}

func replaceKey(row: Int, column: Int, to newKey: String) -> KeyboardBuilder {
guard row < rows.count && column < rows[row].count else { return self }
rows[row][column] = newKey

return self
}

func replaceKey(form oldKey: String, to newKey: String) -> KeyboardBuilder {
for (rowIndex, row) in rows.enumerated() {
if let symbolIndex = row.firstIndex(of: oldKey) {
rows[rowIndex][symbolIndex] = newKey
}
}
return self
}
}
39 changes: 39 additions & 0 deletions Keyboards/KeyboardProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Define protocol for keyboard provider.
*
* Copyright (C) 2024 Scribe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import Foundation

protocol KeyboardProviderProtocol {
static func genPhoneLetterKeys() -> [[String]]
static func genPhoneNumberKeys(currencyKey: String) -> [[String]]
static func genPhoneSymbolKeys(currencyKeys: [String]) -> [[String]]

static func genPadLetterKeys() -> [[String]]
static func genPadNumberKeys(currencyKey: String) -> [[String]]
static func genPadSymbolKeys(currencyKeys: [String]) -> [[String]]

static func genPadExpandedLetterKeys() -> [[String]]
static func genPadExpandedSymbolKeys() -> [[String]]
}

protocol KeyboardProviderDisableAccentsProtocol {
static func genPhoneDisableAccentsLetterKeys() -> [[String]]
static func genPadDisableAccentsLetterKeys() -> [[String]]
static func genPadExpandedDisableAccentsLetterKeys() -> [[String]]
}
163 changes: 102 additions & 61 deletions Keyboards/LanguageKeyboards/Danish/DAInterfaceVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,8 @@
import UIKit

public enum DanishKeyboardConstants {
// iPhone keyboard layouts.
static let letterKeysPhone = [
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "å"],
["a", "s", "d", "f", "g", "h", "j", "k", "l", "æ", "ø"],
["shift", "z", "x", "c", "v", "b", "n", "m", "delete"],
["123", "selectKeyboard", "space", "return"] // "undo"
]

static let numberKeysPhone = [
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
["-", "/", ":", ";", "(", ")", "", "&", "@", "\""],
["#+=", ".", ",", "?", "!", "'", "delete"],
["ABC", "selectKeyboard", "space", "return"] // "undo"
]

static let symbolKeysPhone = [
["[", "]", "{", "}", "#", "%", "^", "*", "+", "="],
["_", "\\", "|", "~", "<", ">", "", "£", "¥", "·"],
["123", ".", ",", "?", "!", "'", "delete"],
["ABC", "selectKeyboard", "space", "return"] // "undo"
]

// iPad keyboard layouts.
static let letterKeysPad = [
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "+"],
["q", "w", "e", "r", "t", "y", "u", "i", "o", "æ", "ø", "delete"],
["a", "s", "d", "f", "g", "h", "j", "k", "l", "ö", "ä", "return"],
["shift", "z", "x", "c", "v", "b", "n", "m", ",", ".", "-", "shift"],
["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"] // "undo"
]

static let numberKeysPad = [
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "`", "delete"],
["@", "#", "kr", "&", "*", "(", ")", "'", "\"", "+", "·", "return"],
["#+=", "%", "_", "-", "=", "/", ";", ":", ",", ".", "?", "#+="],
["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"] // "undo"
]

static let symbolKeysPad = [
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "'", "delete"],
["", "$", "£", "^", "[", "]", "{", "}", "", "", "...", "return"],
["123", "§", "|", "~", "", "", "\\", "<", ">", "!", "?", "123"],
["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"] // "undo"
]

// Expanded iPad keyboard layouts for wider devices.
static let letterKeysPadExpanded = [
["kr", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "+", "´", "delete"],
[SpecialKeys.indent, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "å", "@", "¨"],
[SpecialKeys.capsLock, "a", "s", "d", "f", "g", "h", "j", "k", "l", "æ", "ø", "'", "return"],
["shift", "*", "z", "x", "c", "v", "b", "n", "m", ",", ".", "-", "shift"],
["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"] // "microphone", "scribble"
]

static let symbolKeysPadExpanded = [
["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<", ">", "delete"],
[SpecialKeys.indent, "[", "]", "{", "}", "#", "%", "^", "*", "+", "=", "\"", "|", ""],
[SpecialKeys.capsLock, "°", "/", ":", ";", "(", ")", "$", "&", "@", "£", "¥", "~", "return"], // "undo"
["shift", "", "?", "!", "", "'", "\"", "_", "", ",", ".", "-", "shift"], // "redo"
["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"] // "microphone", "scribble"
]
static let defaultCurrencyKey = "kr"
static let currencyKeys = ["kr", "", "$", "£", "¥"]

// Alternate key vars.
static let keysWithAlternates = ["a", "e", "i", "o", "u", "y", "æ", "ø", "d", "l", "n", "s"]
Expand All @@ -101,6 +42,106 @@ public enum DanishKeyboardConstants {
static let sAlternateKeys = ["ß", "ś", "š"]
}

struct DanishKeyboardProvider: KeyboardProviderProtocol {
// iPhone keyboard layouts.
static func genPhoneLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "å"])
.addRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", "æ", "ø"])
.addRow(["shift", "z", "x", "c", "v", "b", "n", "m", "delete"])
.addRow(["123", "selectKeyboard", "space", "return"]) // "undo"
.build()
}

static func genPhoneNumberKeys(currencyKey: String) -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"])
.addRow(["-", "/", ":", ";", "(", ")", "kr", "&", "@", "\""])
.addRow( ["#+=", ".", ",", "?", "!", "'", "delete"])
.addRow(["ABC", "selectKeyboard", "space", "return"]) // "undo"
.replaceKey(row: 1, column: 6, to: currencyKey)
.build()
}

static func genPhoneSymbolKeys(currencyKeys: [String]) -> [[String]] {
let keyboardBuilder = KeyboardBuilder()
.addRow(["[", "]", "{", "}", "#", "%", "^", "*", "+", "="])
.addRow(["_", "\\", "|", "~", "<", ">", "", "£", "¥", "·"])
.addRow(["123", ".", ",", "?", "!", "'", "delete"])
.addRow(["ABC", "selectKeyboard", "space", "return"]) // "undo"

if currencyKeys.count < 3 {
return keyboardBuilder.build()
} else {
return keyboardBuilder
.replaceKey(row: 1, column: 6, to: currencyKeys[0])
.replaceKey(row: 1, column: 7, to: currencyKeys[1])
.replaceKey(row: 1, column: 8, to: currencyKeys[2])
.build()
}
}

// iPad keyboard layouts.
static func genPadLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "+"])
.addRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "æ", "ø", "delete"])
.addRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", "ö", "ä", "return"])
.addRow(["shift", "z", "x", "c", "v", "b", "n", "m", ",", ".", "-", "shift"])
.addRow(["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"]) // "undo"
.build()
}

static func genPadNumberKeys(currencyKey: String) -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "`", "delete"])
.addRow(["@", "#", "kr", "&", "*", "(", ")", "'", "\"", "+", "·", "return"])
.addRow(["#+=", "%", "_", "-", "=", "/", ";", ":", ",", ".", "?", "#+="])
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"]) // "undo"
.replaceKey(row: 1, column: 2, to: currencyKey)
.build()
}

static func genPadSymbolKeys(currencyKeys: [String]) -> [[String]] {
let keyboardBuilder = KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "'", "delete"])
.addRow(["", "$", "£", "^", "[", "]", "{", "}", "", "", "...", "return"])
.addRow(["123", "§", "|", "~", "", "", "\\", "<", ">", "!", "?", "123"])
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"]) // "undo"

if currencyKeys.count < 3 {
return keyboardBuilder.build()
} else {
return keyboardBuilder
.replaceKey(row: 1, column: 0, to: currencyKeys[0])
.replaceKey(row: 1, column: 1, to: currencyKeys[1])
.replaceKey(row: 1, column: 2, to: currencyKeys[2])
.build()
}
}

// Expanded iPad keyboard layouts for wider devices.
static func genPadExpandedLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["kr", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "+", "´", "delete"])
.addRow([SpecialKeys.indent, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "å", "@", "¨"])
.addRow([SpecialKeys.capsLock, "a", "s", "d", "f", "g", "h", "j", "k", "l", "æ", "ø", "'", "return"])
.addRow(["shift", "*", "z", "x", "c", "v", "b", "n", "m", ",", ".", "-", "shift"])
.addRow(["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"]) // "microphone", "scribble"
.build()
}

static func genPadExpandedSymbolKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<", ">", "delete"])
.addRow([SpecialKeys.indent, "[", "]", "{", "}", "#", "%", "^", "*", "+", "=", "\"", "|", ""])
.addRow([SpecialKeys.capsLock, "°", "/", ":", ";", "(", ")", "$", "&", "@", "£", "¥", "~", "return"]) // "undo"
.addRow(["shift", "", "?", "!", "", "'", "\"", "_", "", ",", ".", "-", "shift"]) // "redo"
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"]) // "microphone", "scribble"
.build()
}
}

/// Gets the keys for the Danish keyboard.
func getDAKeys() {}

Expand Down
Loading

0 comments on commit 6e72d7f

Please sign in to comment.