Skip to content
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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 69 additions & 30 deletions Scribe.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Scribe/AboutTab/AboutTableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ struct AboutTableData {
ParentTableCellModel(
headingTitle: "Community",
section: [
Section(sectionTitle: "See the code on GitHub", imageString: "github", hasToggle: false, sectionState: .github),
Section(sectionTitle: "Chat with the team on Matrix", imageString: "matrix", hasToggle: false, sectionState: .matrix),
Section(sectionTitle: "Wikimedia and Scribe", imageString: "wikimedia", hasToggle: false, sectionState: .wikimedia),
Section(sectionTitle: "Share Scribe", imageString: "square.and.arrow.up", hasToggle: false, sectionState: .shareScribe),
Section(sectionTitle: "See the code on GitHub", imageString: "github", sectionState: .github),
Section(sectionTitle: "Chat with the team on Matrix", imageString: "matrix", sectionState: .matrix),
Section(sectionTitle: "Wikimedia and Scribe", imageString: "wikimedia", sectionState: .wikimedia),
Section(sectionTitle: "Share Scribe", imageString: "square.and.arrow.up", sectionState: .shareScribe),
],
hasDynamicData: nil
),
ParentTableCellModel(
headingTitle: "Feedback and support",
section: [
Section(sectionTitle: "Rate Scribe", imageString: "star", hasToggle: false, sectionState: .rateScribe),
Section(sectionTitle: "Report a bug", imageString: "ant", hasToggle: false, sectionState: .bugReport),
Section(sectionTitle: "Send us an email", imageString: "envelope", hasToggle: false, sectionState: .email),
// Section(sectionTitle: "Reset app hints", imageString: "lightbulb", hasToggle: false, sectionState: .appHints)
Section(sectionTitle: "Rate Scribe", imageString: "star", sectionState: .rateScribe),
Section(sectionTitle: "Report a bug", imageString: "ant", sectionState: .bugReport),
Section(sectionTitle: "Send us an email", imageString: "envelope", sectionState: .email),
// Section(sectionTitle: "Reset app hints", imageString: "lightbulb", sectionState: .appHints)
],
hasDynamicData: nil
),
ParentTableCellModel(
headingTitle: "Legal",
section: [
Section(sectionTitle: "Privacy policy", imageString: "lock.shield", hasToggle: false, sectionState: .privacyPolicy),
Section(sectionTitle: "Third-party licenses", imageString: "thirdPartyLicenses", hasToggle: false, sectionState: .licenses),
Section(sectionTitle: "Privacy policy", imageString: "lock.shield", hasNestedNavigation: true, sectionState: .privacyPolicy),
Copy link
Member

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 :)

Section(sectionTitle: "Third-party licenses", imageString: "thirdPartyLicenses", hasNestedNavigation: true, sectionState: .licenses),
],
hasDynamicData: nil
),
Expand Down
170 changes: 145 additions & 25 deletions Scribe/AboutTab/AboutViewController.swift
Original file line number Diff line number Diff line change
@@ -1,51 +1,171 @@
//
// AboutViewController.swift
// Copyright (C) 2023 Scribe
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@damien-rivet damien-rivet Dec 15, 2023

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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 :)

Copy link
Member

Choose a reason for hiding this comment

The 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")
Copy link
Member

Choose a reason for hiding this comment

The 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 🙌

Copy link
Contributor Author

@damien-rivet damien-rivet Dec 15, 2023

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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)
}
}
1 change: 0 additions & 1 deletion Scribe/AboutTab/InformationScreenVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class InformationScreenVC: UIViewController {
@IBOutlet var iconImageView: UIImageView!

var text: String = ""
var screenTitle: String = ""
var section: SectionState = .privacyPolicy

override func viewDidLoad() {
Expand Down
Loading