-
Notifications
You must be signed in to change notification settings - Fork 74
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 #384 from damien-rivet/feature/330-add-settings-op…
…tions-information-tooltips [#330] Add description texts to cells
- Loading branch information
Showing
21 changed files
with
908 additions
and
598 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,51 +1,171 @@ | ||
// | ||
// 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" | ||
title = NSLocalizedString("about.title", comment: "The title of the about tab") | ||
|
||
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 | ||
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) | ||
} | ||
} |
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.