Skip to content

Commit

Permalink
[scribe-org#330] Refactor cells and tableviews
Browse files Browse the repository at this point in the history
Add a base table view controller to implement similar logic between screens.
  • Loading branch information
damien-rivet authored and SaurabhJamadagni committed Apr 18, 2024
1 parent 93ddb18 commit 6987fc8
Show file tree
Hide file tree
Showing 13 changed files with 550 additions and 276 deletions.
62 changes: 29 additions & 33 deletions Scribe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
140158992A430DD000D14E52 /* ENThirdPartyLicenses.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140158982A430DD000D14E52 /* ENThirdPartyLicenses.swift */; };
1401589B2A45A07200D14E52 /* ENWikimediaAndScribe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1401589A2A45A07200D14E52 /* ENWikimediaAndScribe.swift */; };
140158A22A4EDB2200D14E52 /* TableViewTemplateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140158A12A4EDB2200D14E52 /* TableViewTemplateViewController.swift */; };
140158A42A4F06CA00D14E52 /* CustomChildTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 140158A32A4F06CA00D14E52 /* CustomChildTableView.swift */; };
1406B7872A2DFCDD001DF45B /* AboutTableData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1406B7862A2DFCDD001DF45B /* AboutTableData.swift */; };
1406B78C2A3209CF001DF45B /* AppExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1406B78B2A3209CF001DF45B /* AppExtensions.swift */; };
146B70BD2A853A3800710BD4 /* SwipeableTabBarController in Frameworks */ = {isa = PBXBuildFile; productRef = 146B70BC2A853A3800710BD4 /* SwipeableTabBarController */; };
147797AC2A2CD2F70044A53E /* ParentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 147797AA2A2CD2F70044A53E /* ParentTableViewCell.swift */; };
147797AD2A2CD2F70044A53E /* ParentTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 147797AB2A2CD2F70044A53E /* ParentTableViewCell.xib */; };
147797B02A2CD3370044A53E /* InfoChildTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 147797AE2A2CD3370044A53E /* InfoChildTableViewCell.swift */; };
147797B12A2CD3370044A53E /* InfoChildTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 147797AF2A2CD3370044A53E /* InfoChildTableViewCell.xib */; };
147797B32A2CD5AB0044A53E /* ParentTableCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 147797B22A2CD5AB0044A53E /* ParentTableCellModel.swift */; };
Expand Down Expand Up @@ -741,6 +738,8 @@
D1F0367327AAE1B400CD7921 /* CommandVariables.swift in Sources */ = {isa = PBXBuildFile; fileRef = D190B2462741B24F00705659 /* CommandVariables.swift */; };
EA536F182AF9B4CB00795DA3 /* DownloadDataTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA536F162AF9B4CB00795DA3 /* DownloadDataTable.swift */; };
EA536F192AF9B4CB00795DA3 /* DownloadDataVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA536F172AF9B4CB00795DA3 /* DownloadDataVC.swift */; };
EDB4601B2AF9FD8200BEA967 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = EDB4601A2AF9FD8200BEA967 /* Localizable.xcstrings */; };
EDB460212B03B3E400BEA967 /* BaseTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB460202B03B3E400BEA967 /* BaseTableViewController.swift */; };
EDC364692AE408F20001E456 /* InterfaceConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC364682AE408F20001E456 /* InterfaceConstants.swift */; };
EDC3646A2AE408FA0001E456 /* InterfaceConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC364682AE408F20001E456 /* InterfaceConstants.swift */; };
EDC3646B2AE408FC0001E456 /* InterfaceConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC364682AE408F20001E456 /* InterfaceConstants.swift */; };
Expand Down Expand Up @@ -859,12 +858,9 @@
140158982A430DD000D14E52 /* ENThirdPartyLicenses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENThirdPartyLicenses.swift; sourceTree = "<group>"; };
1401589A2A45A07200D14E52 /* ENWikimediaAndScribe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENWikimediaAndScribe.swift; sourceTree = "<group>"; };
140158A12A4EDB2200D14E52 /* TableViewTemplateViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewTemplateViewController.swift; sourceTree = "<group>"; };
140158A32A4F06CA00D14E52 /* CustomChildTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomChildTableView.swift; sourceTree = "<group>"; };
1406B7862A2DFCDD001DF45B /* AboutTableData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutTableData.swift; sourceTree = "<group>"; };
1406B78B2A3209CF001DF45B /* AppExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppExtensions.swift; sourceTree = "<group>"; };
144B56F22A568AC200C2F447 /* Scribe.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Scribe.entitlements; sourceTree = "<group>"; };
147797AA2A2CD2F70044A53E /* ParentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParentTableViewCell.swift; sourceTree = "<group>"; };
147797AB2A2CD2F70044A53E /* ParentTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ParentTableViewCell.xib; sourceTree = "<group>"; };
147797AE2A2CD3370044A53E /* InfoChildTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoChildTableViewCell.swift; sourceTree = "<group>"; };
147797AF2A2CD3370044A53E /* InfoChildTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = InfoChildTableViewCell.xib; sourceTree = "<group>"; };
147797B22A2CD5AB0044A53E /* ParentTableCellModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParentTableCellModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -990,6 +986,10 @@
D1D8B23D2AE408C50070B817 /* French.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = French.entitlements; sourceTree = "<group>"; };
EA536F162AF9B4CB00795DA3 /* DownloadDataTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadDataTable.swift; sourceTree = "<group>"; };
EA536F172AF9B4CB00795DA3 /* DownloadDataVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadDataVC.swift; sourceTree = "<group>"; };
EDB4601A2AF9FD8200BEA967 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
EDB4601C2AF9FDD600BEA967 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/AppScreen.strings; sourceTree = "<group>"; };
EDB4601D2AF9FDD600BEA967 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
EDB460202B03B3E400BEA967 /* BaseTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTableViewController.swift; sourceTree = "<group>"; };
EDC364682AE408F20001E456 /* InterfaceConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterfaceConstants.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -1110,27 +1110,16 @@
isa = PBXGroup;
children = (
1406B7852A2DFCBE001DF45B /* InfoChildTableViewCell */,
1406B7842A2DFCAB001DF45B /* ParentTableViewCell */,
140158A12A4EDB2200D14E52 /* TableViewTemplateViewController.swift */,
);
path = Components;
sourceTree = "<group>";
};
1406B7842A2DFCAB001DF45B /* ParentTableViewCell */ = {
isa = PBXGroup;
children = (
147797AA2A2CD2F70044A53E /* ParentTableViewCell.swift */,
147797AB2A2CD2F70044A53E /* ParentTableViewCell.xib */,
);
path = ParentTableViewCell;
sourceTree = "<group>";
};
1406B7852A2DFCBE001DF45B /* InfoChildTableViewCell */ = {
isa = PBXGroup;
children = (
147797AE2A2CD3370044A53E /* InfoChildTableViewCell.swift */,
147797AF2A2CD3370044A53E /* InfoChildTableViewCell.xib */,
140158A32A4F06CA00D14E52 /* CustomChildTableView.swift */,
);
path = InfoChildTableViewCell;
sourceTree = "<group>";
Expand Down Expand Up @@ -1232,23 +1221,23 @@
38BD213222D5907F00C6795D /* Scribe */ = {
isa = PBXGroup;
children = (
EDB4601E2AF9FFAA00BEA967 /* Utils */,
144B56F22A568AC200C2F447 /* Scribe.entitlements */,
1406B7882A2DFE4C001DF45B /* InstallationTab */,
147797B62A2CFB560044A53E /* SettingsTab */,
147797A92A2CD2B50044A53E /* AboutTab */,
D1A2DCAF27AD378F0057A10D /* AppTexts */,
1406B7832A2DFCA2001DF45B /* Components */,
147797B22A2CD5AB0044A53E /* ParentTableCellModel.swift */,
38BD213322D5907F00C6795D /* AppDelegate.swift */,
D17193C327AEAD7D0038660B /* AppStyling.swift */,
D1A2DCB327AD3EB50057A10D /* AppUISymbols.swift */,
1406B78B2A3209CF001DF45B /* AppExtensions.swift */,
38BD213722D5907F00C6795D /* AppScreen.storyboard */,
38BD213F22D5908100C6795D /* LaunchScreen.storyboard */,
D17193C327AEAD7D0038660B /* AppStyling.swift */,
D1A2DCAF27AD378F0057A10D /* AppTexts */,
D1A2DCB327AD3EB50057A10D /* AppUISymbols.swift */,
38BD213D22D5908100C6795D /* Assets.xcassets */,
1406B7832A2DFCA2001DF45B /* Components */,
38BD214222D5908100C6795D /* Info.plist */,
EDB4601A2AF9FD8200BEA967 /* Localizable.xcstrings */,
1406B7882A2DFE4C001DF45B /* InstallationTab */,
38BD213F22D5908100C6795D /* LaunchScreen.storyboard */,
147797B22A2CD5AB0044A53E /* ParentTableCellModel.swift */,
EDB460222B03BF7000BEA967 /* Resources */,
144B56F22A568AC200C2F447 /* Scribe.entitlements */,
147797B62A2CFB560044A53E /* SettingsTab */,
EDB4601F2B03B3B400BEA967 /* Views */,
);
path = Scribe;
sourceTree = "<group>";
Expand Down Expand Up @@ -1499,11 +1488,20 @@
path = Keyboards;
sourceTree = "<group>";
};
EDB4601E2AF9FFAA00BEA967 /* Utils */ = {
EDB4601F2B03B3B400BEA967 /* Views */ = {
isa = PBXGroup;
children = (
EDB460202B03B3E400BEA967 /* BaseTableViewController.swift */,
);
path = Views;
sourceTree = "<group>";
};
EDB460222B03BF7000BEA967 /* Resources */ = {
isa = PBXGroup;
children = (
EDB4601A2AF9FD8200BEA967 /* Localizable.xcstrings */,
);
path = Utils;
path = Resources;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -1857,7 +1855,6 @@
147797B12A2CD3370044A53E /* InfoChildTableViewCell.xib in Resources */,
EDB4601B2AF9FD8200BEA967 /* Localizable.xcstrings in Resources */,
38BD213922D5907F00C6795D /* AppScreen.storyboard in Resources */,
147797AD2A2CD2F70044A53E /* ParentTableViewCell.xib in Resources */,
38BD213E22D5908100C6795D /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -2034,12 +2031,12 @@
D1CDED792A859FB600098546 /* ENCommandVariables.swift in Sources */,
140158A22A4EDB2200D14E52 /* TableViewTemplateViewController.swift in Sources */,
D1CDED7F2A85A05C00098546 /* HECommandVariables.swift in Sources */,
147797AC2A2CD2F70044A53E /* ParentTableViewCell.swift in Sources */,
38BD213422D5907F00C6795D /* AppDelegate.swift in Sources */,
30489C1E2936DAB700B59393 /* ToolTipView.swift in Sources */,
3045396F293B9DF2003AE55B /* ToolTipViewTheme.swift in Sources */,
D1F0367327AAE1B400CD7921 /* CommandVariables.swift in Sources */,
D16DD3A529E78A1500FB9022 /* Utilities.swift in Sources */,
EDB460212B03B3E400BEA967 /* BaseTableViewController.swift in Sources */,
D1CDED752A859DDD00098546 /* DAInterfaceVariables.swift in Sources */,
D17193E827AECAE60038660B /* ESInterfaceVariables.swift in Sources */,
D156BC0929CCDBE8007E7362 /* DEAppText.swift in Sources */,
Expand All @@ -2061,7 +2058,6 @@
D171944927AEF7290038660B /* KeyboardKeys.swift in Sources */,
147797B32A2CD5AB0044A53E /* ParentTableCellModel.swift in Sources */,
1401589B2A45A07200D14E52 /* ENWikimediaAndScribe.swift in Sources */,
140158A42A4F06CA00D14E52 /* CustomChildTableView.swift in Sources */,
3045396B293B9DC9003AE55B /* ToolTipViewDatasourceable.swift in Sources */,
D156BC0829CCDBE8007E7362 /* DEPrivacyPolicy.swift in Sources */,
D1B071A027C6A1AA00FD7DBD /* KeyAltChars.swift in Sources */,
Expand Down
167 changes: 144 additions & 23 deletions Scribe/AboutTab/AboutViewController.swift
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
//
// AboutViewController.swift
// Copyright (C) 2023 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 UIKit
import MessageUI
import StoreKit

class AboutViewController: UIViewController {
@IBOutlet var outerTable: UITableView!
final class AboutViewController: BaseTableViewController {

let tableData = AboutTableData.aboutTableData
override var dataSet: [ParentTableCellModel] {
AboutTableData.aboutTableData
}

override func viewDidLoad() {
super.viewDidLoad()

title = "About"

let nib = UINib(nibName: "ParentTableViewCell", bundle: nil)
outerTable.register(nib, forCellReuseIdentifier: "ParentTableViewCell")

outerTable.dataSource = self
outerTable.delegate = self

outerTable.separatorStyle = .none
outerTable.backgroundColor = .clear
}
}

// MARK: UITableViewDataSource

/// Function implementation conforming to the UITableViewDataSource protocol.
extension AboutViewController: UITableViewDataSource {
func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
return tableData.count
}
extension AboutViewController {

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ParentTableViewCell", for: indexPath) as! ParentTableViewCell
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: InfoChildTableViewCell.reuseIdentifier, for: indexPath) as! InfoChildTableViewCell

cell.configureCell(for: tableData[indexPath.row])
cell.configureCell(for: dataSet[indexPath.section].section[indexPath.row])

cell.backgroundColor = .clear
cell.selectionStyle = .none
Expand All @@ -47,5 +50,123 @@ extension AboutViewController: UITableViewDataSource {

// MARK: UITableViewDelegate

/// Function implementation conforming to the UITableViewDelegate protocol.
extension AboutViewController: UITableViewDelegate {}
extension AboutViewController {

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let tableSection = dataSet[indexPath.section]
let section = tableSection.section[indexPath.row]

switch section.sectionState {
case .github:
openURLString(urlString: "https://github.com/scribe-org/Scribe-iOS", withEncoding: false)

case .matrix:
openURLString(urlString: "https://matrix.to/#/#scribe_community:matrix.org", withEncoding: true)

case .wikimedia:
if let viewController = storyboard?.instantiateViewController(identifier: "InformationScreenVC") as? InformationScreenVC {
navigationController?.pushViewController(viewController, animated: true)
viewController.section = .wikimedia
}

case .shareScribe:
showShareSheet()

case .rateScribe:
showRateScribeUI()

case .bugReport:
openURLString(urlString: "https://github.com/scribe-org/Scribe-iOS/issues", withEncoding: false)

case .email:
showEmailUI()

// case .appHints:
// // reset functionality
// print("Resets app hints")

case .privacyPolicy:
if let viewController = storyboard?.instantiateViewController(identifier: "InformationScreenVC") as? InformationScreenVC {
navigationController?.pushViewController(viewController, animated: true)
viewController.section = .privacyPolicy
}

case .licenses:
if let viewController = storyboard?.instantiateViewController(identifier: "InformationScreenVC") as? InformationScreenVC {
navigationController?.pushViewController(viewController, animated: true)
viewController.section = .licenses
}

case .appLang: break
case .none: break
case .specificLang(_): break
}


if let selectedIndexPath = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: selectedIndexPath, animated: false)
}
}

private func openURLString(urlString: String, withEncoding: Bool) {
if withEncoding {
let encodedString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
guard let encodedURLString = encodedString, let url = URL(string: encodedURLString) else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
guard let url = URL(string: urlString) else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}

private func showRateScribeUI() {
if #available(iOS 14.0, *) {
guard let scene = UIApplication.shared.foregroundActiveScene else { return }
SKStoreReviewController.requestReview(in: scene)
} else {
let alert = UIAlertController(title: "Enjoying Scribe?", message: "Rate Scribe on the App Store.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Continue", style: .default, handler: openScribeAppStore(alert:)))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true)
}
}

private func openScribeAppStore(alert _: UIAlertAction) {
openURLString(urlString: "itms-apps: //itunes.apple.com/app/id1596613886", withEncoding: true)
}

private func showEmailUI() {
if MFMailComposeViewController.canSendMail() {
let mailComposeViewController = MFMailComposeViewController()
mailComposeViewController.mailComposeDelegate = self
mailComposeViewController.setToRecipients(["[email protected]"])
mailComposeViewController.setSubject("Hey Scribe!")

present(mailComposeViewController, animated: true, completion: nil)
} else {
/// Show alert mentioning the email address
let alert = UIAlertController(title: "Send us an email?", message: "Reach out to us at [email protected]", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true)
}
}

private func showShareSheet() {
let urlString = "itms-apps: //itunes.apple.com/app/id1596613886"
let encodedString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
guard let encodedURLString = encodedString, let url = URL(string: encodedURLString) else { return }

let shareSheetVC = UIActivityViewController(activityItems: [url], applicationActivities: nil)

present(shareSheetVC, animated: true, completion: nil)
}
}

// MARK: - MFMailComposeViewControllerDelegate

extension AboutViewController: MFMailComposeViewControllerDelegate {

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith _: MFMailComposeResult, error _: Error?) {
controller.dismiss(animated: true, completion: nil)
}
}
Loading

0 comments on commit 6987fc8

Please sign in to comment.