-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#330] Add description texts to cells #384
Changes from all commits
0f38536
2bed3f1
26a22b8
040dbd0
ac0979f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,171 @@ | ||
// | ||
// AboutViewController.swift | ||
// Copyright (C) 2023 Scribe | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you suggest putting this copyright notice at the head of each file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the project is based on the GNU license, it is advised by the license itself to add this header on top of each code file. I'm adding it to new files and files I'm refactoring only, doing a complete pass would add nothing and generate extra commit noise, it can be done over time instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll make an issue for this, @damien-rivet! Thanks for bringing this to my attention :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #391 😊 |
||
// | ||
// 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" | ||
title = NSLocalizedString("about.title", comment: "The title of the about tab") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really beautiful stuff, and great that you jumped into already using the naming conventions we're planning on 🙌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks 😉 A good thing with this system is that the naming can be changed and it will update the catalog with the new keys (not sure it will move the values accordingly though 🤔 ). |
||
|
||
tableView.register(UINib(nibName: "AboutTableViewCell", bundle: nil), forCellReuseIdentifier: AboutTableViewCell.reuseIdentifier) | ||
} | ||
} | ||
|
||
// MARK: UITableViewDataSource | ||
|
||
extension AboutViewController { | ||
|
||
let nib = UINib(nibName: "ParentTableViewCell", bundle: nil) | ||
outerTable.register(nib, forCellReuseIdentifier: "ParentTableViewCell") | ||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: AboutTableViewCell.reuseIdentifier, for: indexPath) as! AboutTableViewCell | ||
|
||
outerTable.dataSource = self | ||
outerTable.delegate = self | ||
cell.configureCell(for: dataSet[indexPath.section].section[indexPath.row]) | ||
|
||
outerTable.separatorStyle = .none | ||
outerTable.backgroundColor = .clear | ||
return cell | ||
} | ||
} | ||
|
||
// MARK: UITableViewDataSource | ||
// MARK: 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() | ||
|
||
/// Function implementation conforming to the UITableViewDataSource protocol. | ||
extension AboutViewController: UITableViewDataSource { | ||
func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int { | ||
return tableData.count | ||
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) | ||
} | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "ParentTableViewCell", for: indexPath) as! ParentTableViewCell | ||
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) | ||
} | ||
} | ||
|
||
cell.configureCell(for: tableData[indexPath.row]) | ||
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) | ||
} | ||
} | ||
|
||
cell.backgroundColor = .clear | ||
cell.selectionStyle = .none | ||
private func openScribeAppStore(alert _: UIAlertAction) { | ||
openURLString(urlString: "itms-apps: //itunes.apple.com/app/id1596613886", withEncoding: true) | ||
} | ||
|
||
return cell | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for nit for period that I can add :) |
||
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: UITableViewDelegate | ||
// MARK: - MFMailComposeViewControllerDelegate | ||
|
||
extension AboutViewController: MFMailComposeViewControllerDelegate { | ||
|
||
/// Function implementation conforming to the UITableViewDelegate protocol. | ||
extension AboutViewController: UITableViewDelegate {} | ||
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith _: MFMailComposeResult, error _: Error?) { | ||
controller.dismiss(animated: true, completion: nil) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching it to nested navigation as a check makes a lot more sense, @damien-rivet :)