-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #492 from vickcoo/currency-symbol-selection
Make the keyboard able to replace currency symbols
- Loading branch information
Showing
14 changed files
with
1,553 additions
and
811 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
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 | ||
} | ||
} |
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 |
---|---|---|
@@ -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]] | ||
} |
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
Oops, something went wrong.