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

// MARK: Private API

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)
}
@objc private func onDoubleTap() {
doubleTapDelegate?.didDoubleTap(cell: self)
}
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
24 changes: 24 additions & 0 deletions Classes/Issues/Comments/Reactions/Defaults+Reaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// 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 @@ -15,8 +15,26 @@ extension ReactionContent {
case .heart: return "❤️"
case .hooray: return "🎉"
case .laugh: return "😄"
case .__unknown("Disabled"): return "Disabled"
case .thumbsUp, .__unknown: return "👍"
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)
}
}
}
118 changes: 118 additions & 0 deletions Classes/Settings/DefaultReactionDetailController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// DefaultReactionSubController.swift
// Freetime
//
// Created by Ehud Adler on 8/5/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//

import UIKit

class DefaultReactionDetailController: UITableViewController {

@IBOutlet var thumbsUpCell: UITableViewCell!
@IBOutlet var thumbsDownCell: UITableViewCell!
@IBOutlet var laughCell: UITableViewCell!
@IBOutlet var hoorayCell: UITableViewCell!
@IBOutlet var confusedCell: UITableViewCell!
@IBOutlet var heartCell: UITableViewCell!
@IBOutlet var enabledSwitch: UISwitch!

override func viewDidLoad() {
super.viewDidLoad()
checkCurrentDefault()
tableView.reloadData()
}

override func numberOfSections(in tableView: UITableView) -> Int {
return enabledSwitch.isOn ? 2 : 1
}

private func checkCurrentDefault() {
switch (ReactionContent.defaultReaction)
{
case ReactionContent.thumbsUp:
updateCells(cell: thumbsUpCell)
case ReactionContent.thumbsDown:
updateCells(cell: thumbsDownCell)
case ReactionContent.laugh:
updateCells(cell: laughCell)
case ReactionContent.hooray:
updateCells(cell: hoorayCell)
case ReactionContent.confused:
updateCells(cell: confusedCell)
case ReactionContent.heart:
updateCells(cell: heartCell)
case ReactionContent.__unknown("Disabled"):
enabledSwitch.isOn = false
default:
updateCells(cell: thumbsUpCell)
}

}

private func updateCells(cell: UITableViewCell) {

rz_smoothlyDeselectRows(tableView: self.tableView)

// Reset all to none
thumbsUpCell.accessoryType = .none
thumbsDownCell.accessoryType = .none
laughCell.accessoryType = .none
hoorayCell.accessoryType = .none
confusedCell.accessoryType = .none
heartCell.accessoryType = .none

// Set proper cell to check
cell.accessoryType = .checkmark

}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

tableView.deselectRow(at: indexPath, animated: trueUnlessReduceMotionEnabled)
let cell = tableView.cellForRow(at: indexPath)

switch cell {
case thumbsUpCell:
updateDefaultReaction(.thumbsUp)
case thumbsDownCell:
updateDefaultReaction(.thumbsDown)
case laughCell:
updateDefaultReaction(.laugh)
case hoorayCell:
updateDefaultReaction(.hooray)
case confusedCell:
updateDefaultReaction(.confused)
case heartCell:
updateDefaultReaction(.heart)
default:
break
}
}

@IBAction func toggleDefaultReaction(_ sender: Any) {
if(enabledSwitch.isOn) {
updateDefaultReaction(.thumbsUp)
} else {
updateDefaultReaction(.__unknown("Disabled"))
}
updateSections()
}

private func updateDefaultReaction(_ reaction: ReactionContent) {
UserDefaults.setDefault(reaction: reaction)
checkCurrentDefault()
}

private func updateSections() {
tableView.performBatchUpdates({
if(enabledSwitch.isOn) {
self.tableView.insertSections(IndexSet(integer: 1), with: .top)
} else {
self.tableView.deleteSections(IndexSet(integer: 1), with: .top)
}
}, completion: nil)
}
}

Loading