Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.
Closed
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
17 changes: 12 additions & 5 deletions Classes/Issues/Comments/IssueCommentBaseCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {

contentView.clipsToBounds = true

doubleTapGesture.addTarget(self, action: #selector(onDoubleTap))
doubleTapGesture.numberOfTapsRequired = 2
doubleTapGesture.delegate = self
addGestureRecognizer(doubleTapGesture)

setUpDoubleTapIfNeeded()
collapseLayer.isHidden = true
collapseLayer.colors = [
UIColor(white: 1, alpha: 0).cgColor,
Expand Down Expand Up @@ -96,6 +92,17 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {
collapseButton.isHidden = true
}

private func setUpDoubleTapIfNeeded()
{
// If reaction is set to none, no need for the double-tap
if ReactionContent.defaultReaction == .__unknown("Disabled") { return }

doubleTapGesture.addTarget(self, action: #selector(onDoubleTap))
doubleTapGesture.numberOfTapsRequired = 2
doubleTapGesture.delegate = self
addGestureRecognizer(doubleTapGesture)
}

// MARK: Private API

@objc private func onDoubleTap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ final class IssueCommentSectionController:
// MARK: IssueCommentDoubleTapDelegate

func didDoubleTap(cell: IssueCommentBaseCell) {
let reaction = ReactionContent.thumbsUp
let reaction = ReactionContent.defaultReaction
guard let reactions = reactionMutation ?? self.object?.reactions,
!reactions.viewerDidReact(reaction: reaction)
else { return }
Expand Down
25 changes: 25 additions & 0 deletions Classes/Issues/Comments/Reactions/Defaults+Reaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Defaults+Reaction.swift
// Freetime
//
// Created by Ehud Adler on 7/30/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//

extension UserDefaults {
// Stores ReactionContent in string form but
// accepts and returns in original form
static func setDefault(reaction: ReactionContent)
{
standard.set(reaction.emoji, forKey: "default.reaction")
}

static var getDefaultReaction: ReactionContent
{
guard let reactionAsString = standard.string(forKey: "default.reaction")
else { return ReactionContent.thumbsUp}
let reaction = reactionAsString.reaction
return reaction
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ extension ReactionContent {
case .thumbsDown: return "👎"
}
}

static var defaultReaction: ReactionContent {
return UserDefaults.getDefaultReaction
}
}

extension String {
var reaction: ReactionContent {
switch self {
case "😕": return .confused
case "❤️": return .heart
case "🎉": return .hooray
case "😄": return .laugh
case "👍": return .thumbsUp
case "👎": return .thumbsDown
default: return .__unknown(self)
}
}
}
33 changes: 30 additions & 3 deletions Classes/Settings/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<color key="separatorColor" red="0.73725490196078436" green="0.73333333333333328" blue="0.75686274509803919" alpha="1" colorSpace="calibratedRGB"/>
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
<view key="tableFooterView" contentMode="scaleToFill" id="jkq-3p-p02">
<rect key="frame" x="0.0" y="605.5" width="375" height="44"/>
<rect key="frame" x="0.0" y="649.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Version 1.4.0 (1207)" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2bb-Lj-p2k" customClass="SettingsLabel" customModule="Freetime" customModuleProvider="target">
Expand Down Expand Up @@ -260,9 +260,34 @@
</tableViewCellContentView>
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="Z8j-JQ-qiy" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="wm1-n0-0PA" detailTextLabel="UHH-lU-DUe" style="IBUITableViewCellStyleValue1" id="gjX-57-UIr" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
<rect key="frame" x="0.0" y="463.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="gjX-57-UIr" id="RUD-Yw-Zkq">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Set Default Reaction" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="wm1-n0-0PA">
<rect key="frame" x="16" y="12" width="156.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.14117647059999999" green="0.16078431369999999" blue="0.18039215689999999" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="UHH-lU-DUe">
<rect key="frame" x="315" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="Z8j-JQ-qiy" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
<rect key="frame" x="0.0" y="507.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Z8j-JQ-qiy" id="uAb-lB-GZA">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -292,7 +317,7 @@
<tableViewSection id="GTg-1u-cvV">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="ku5-ZI-OG9" style="IBUITableViewCellStyleDefault" id="Y2k-Zq-AUW" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
<rect key="frame" x="0.0" y="543.5" width="375" height="44"/>
<rect key="frame" x="0.0" y="587.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Y2k-Zq-AUW" id="XiT-sq-B22">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
Expand Down Expand Up @@ -324,12 +349,14 @@
<outlet property="apiStatusView" destination="1mP-Dr-7rt" id="f66-HG-AkG"/>
<outlet property="backgroundFetchSwitch" destination="FvK-93-raA" id="Huy-vc-MoM"/>
<outlet property="badgeCell" destination="pnm-5p-yC5" id="hdC-aO-QSy"/>
<outlet property="defaultReactionLabel" destination="UHH-lU-DUe" id="ew2-Hr-5UH"/>
<outlet property="githubStatusCell" destination="x9n-2O-buf" id="xc3-W3-bZW"/>
<outlet property="markReadSwitch" destination="8dQ-YU-Yuw" id="5jz-5d-osk"/>
<outlet property="openSettingsButton" destination="36B-Ge-m5V" id="tsc-wS-3vb"/>
<outlet property="reportBugCell" destination="WwO-m1-s3q" id="nCb-BL-DRJ"/>
<outlet property="reviewAccessCell" destination="TXs-sw-hO1" id="10W-u8-ofC"/>
<outlet property="reviewOnAppStoreCell" destination="Z8j-JQ-qiy" id="QRZ-5e-WQi"/>
<outlet property="setDefaultReaction" destination="gjX-57-UIr" id="aCf-HJ-KKS"/>
<outlet property="signOutCell" destination="Y2k-Zq-AUW" id="QIk-J0-zqg"/>
<outlet property="signatureSwitch" destination="ZWv-km-fU1" id="pf4-kH-RIp"/>
<outlet property="versionLabel" destination="2bb-Lj-p2k" id="qDb-KP-pnk"/>
Expand Down
87 changes: 85 additions & 2 deletions Classes/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ NewIssueTableViewControllerDelegate {
@IBOutlet weak var reviewOnAppStoreCell: StyledTableCell!
@IBOutlet weak var reportBugCell: StyledTableCell!
@IBOutlet weak var viewSourceCell: StyledTableCell!
@IBOutlet weak var setDefaultReaction: StyledTableCell!
@IBOutlet weak var signOutCell: StyledTableCell!
@IBOutlet weak var backgroundFetchSwitch: UISwitch!
@IBOutlet weak var openSettingsButton: UIButton!
Expand All @@ -36,14 +37,16 @@ NewIssueTableViewControllerDelegate {
@IBOutlet weak var apiStatusLabel: UILabel!
@IBOutlet weak var apiStatusView: UIView!
@IBOutlet weak var signatureSwitch: UISwitch!

override func viewDidLoad() {
@IBOutlet weak var defaultReactionLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

versionLabel.text = Bundle.main.prettyVersionString
markReadSwitch.isOn = NotificationModelController.readOnOpen
apiStatusView.layer.cornerRadius = 7
signatureSwitch.isOn = Signature.enabled
defaultReactionLabel.text = ReactionContent.defaultReaction.emoji

updateBadge()
style()
Expand Down Expand Up @@ -108,6 +111,8 @@ NewIssueTableViewControllerDelegate {
onReportBug()
} else if cell === viewSourceCell {
onViewSource()
} else if cell === setDefaultReaction {
onSetDefaultReaction()
} else if cell === signOutCell {
onSignOut()
}
Expand Down Expand Up @@ -178,6 +183,10 @@ NewIssueTableViewControllerDelegate {
let repoViewController = RepositoryViewController(client: client, repo: repo)
navigationController?.showDetailViewController(repoViewController, sender: self)
}

func onSetDefaultReaction() {
showDefaultReactionMenu()
}

func onSignOut() {
let title = NSLocalizedString("Are you sure?", comment: "")
Expand Down Expand Up @@ -259,3 +268,77 @@ NewIssueTableViewControllerDelegate {
showDetailViewController(navigation, sender: nil)
}
}

extension SettingsViewController {
// Default Reaction + MenuController

private func showDefaultReactionMenu() {

setDefaultReaction.becomeFirstResponder() // Required

let actions = [
(ReactionContent.thumbsUp.emoji, #selector(SettingsViewController.onThumbsUp)),
(ReactionContent.thumbsDown.emoji, #selector(SettingsViewController.onThumbsDown)),
(ReactionContent.laugh.emoji, #selector(SettingsViewController.onLaugh)),
(ReactionContent.hooray.emoji, #selector(SettingsViewController.onHooray)),
(ReactionContent.confused.emoji, #selector(SettingsViewController.onConfused)),
(ReactionContent.heart.emoji, #selector(SettingsViewController.onHeart)),
("Disable", #selector(SettingsViewController.onDisabled))
]

let menu = UIMenuController.shared
menu.menuItems = actions.map { UIMenuItem(title: $0.0, action: $0.1) }
menu.setTargetRect(defaultReactionLabel.frame, in: setDefaultReaction)
menu.setMenuVisible(true, animated: trueUnlessReduceMotionEnabled)
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
switch action {
case #selector(SettingsViewController.onThumbsUp),
#selector(SettingsViewController.onThumbsDown),
#selector(SettingsViewController.onLaugh),
#selector(SettingsViewController.onHooray),
#selector(SettingsViewController.onConfused),
#selector(SettingsViewController.onHeart),
#selector(SettingsViewController.onDisabled):
return true
default: return false
}
}

@objc private func onThumbsUp() {
updateDefaultReaction(.thumbsUp)
}

@objc private func onThumbsDown() {
updateDefaultReaction(.thumbsDown)
}

@objc private func onLaugh() {
updateDefaultReaction( .laugh)
}

@objc private func onHooray() {
updateDefaultReaction(.hooray)
}

@objc private func onConfused() {
updateDefaultReaction(.confused)
}

@objc private func onHeart() {
updateDefaultReaction(.heart)
}

@objc private func onDisabled() {
updateDefaultReaction(.__unknown("Disabled"))
}

func updateDefaultReaction(_ reaction: ReactionContent)
{
UserDefaults.setDefault(reaction: reaction)
defaultReactionLabel.text = reaction == .__unknown("Disabled")
? "Disabled"
: reaction.emoji
}
}
5 changes: 4 additions & 1 deletion Classes/Views/StyledTableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ class StyledTableCell: UITableViewCell {
background.backgroundColor = Styles.Colors.Gray.alphaLighter
selectedBackgroundView = background
}


override var canBecomeFirstResponder: Bool {
return true
}
}