Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Fixes Reaction emoji updates on split view #2359

Merged
merged 2 commits into from
Oct 28, 2018
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
8 changes: 8 additions & 0 deletions Classes/Settings/DefaultReactionDetailController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import UIKit

protocol DefaultReactionDelegate: class {
func didUpdateDefaultReaction()
}

class DefaultReactionDetailController: UITableViewController {

@IBOutlet var thumbsUpCell: UITableViewCell!
Expand All @@ -18,6 +22,8 @@ class DefaultReactionDetailController: UITableViewController {
@IBOutlet var heartCell: UITableViewCell!
@IBOutlet var enabledSwitch: UISwitch!

weak var delegate: DefaultReactionDelegate?

override func viewDidLoad() {
super.viewDidLoad()
checkCurrentDefault()
Expand Down Expand Up @@ -95,10 +101,12 @@ class DefaultReactionDetailController: UITableViewController {
private func updateDefault(reaction: ReactionContent) {
UserDefaults.standard.setDefault(reaction: reaction)
checkCurrentDefault()
delegate?.didUpdateDefaultReaction()
}

private func disableReaction() {
UserDefaults.standard.disableReaction()
delegate?.didUpdateDefaultReaction()
}

private func updateSections() {
Expand Down
23 changes: 1 addition & 22 deletions Classes/Settings/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@
</subviews>
</tableViewCellContentView>
<inset key="separatorInset" minX="16" minY="0.0" maxX="0.0" maxY="0.0"/>
<connections>
<segue destination="zTX-UL-vjU" kind="showDetail" id="t7M-y6-pfg"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="pnm-5p-yC5" customClass="StyledTableCell" customModule="Freetime" customModuleProvider="target">
<rect key="frame" x="0.0" y="375.5" width="375" height="44"/>
Expand Down Expand Up @@ -454,7 +451,7 @@
<!--Double Tap Reaction-->
<scene sceneID="7SH-vC-PA6">
<objects>
<tableViewController id="D6n-Kh-ydE" customClass="DefaultReactionDetailController" customModule="Freetime" customModuleProvider="target" sceneMemberID="viewController">
<tableViewController storyboardIdentifier="DefaultReactionDetailController" id="D6n-Kh-ydE" customClass="DefaultReactionDetailController" customModule="Freetime" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="bOV-gp-5Q9">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -703,24 +700,6 @@
</objects>
<point key="canvasLocation" x="1552.8" y="-132.68365817091455"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="Gqm-gt-Lcu">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="zTX-UL-vjU" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Z7d-Gy-h3x">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="D6n-Kh-ydE" kind="relationship" relationship="rootViewController" id="WFW-pz-Za9"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="kTW-nS-mww" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-108" y="-132.68365817091455"/>
</scene>
</scenes>
<resources>
<image name="link-external" width="19" height="25"/>
Expand Down
24 changes: 20 additions & 4 deletions Classes/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import GitHubSession
import Squawk

final class SettingsViewController: UITableViewController,
NewIssueTableViewControllerDelegate {
NewIssueTableViewControllerDelegate, DefaultReactionDelegate {

// must be injected
var sessionManager: GitHubSessionManager!
Expand Down Expand Up @@ -62,8 +62,7 @@ NewIssueTableViewControllerDelegate {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

defaultReactionLabel.text = ReactionContent.defaultReaction?.emoji
?? NSLocalizedString("Off", comment: "")
updateDefaultReaction()

rz_smoothlyDeselectRows(tableView: tableView)
accountsCell.detailTextLabel?.text = sessionManager.focusedUserSession?.username ?? Constants.Strings.unknown
Expand Down Expand Up @@ -126,6 +125,11 @@ NewIssueTableViewControllerDelegate {

// MARK: Private API

func updateDefaultReaction() {
defaultReactionLabel.text = ReactionContent.defaultReaction?.emoji
?? NSLocalizedString("Off", comment: "")
}

func onReviewAccess() {
guard let url = URL(string: "https://github.com/settings/connections/applications/\(Secrets.GitHub.clientId)")
else { fatalError("Should always create GitHub issue URL") }
Expand Down Expand Up @@ -191,7 +195,13 @@ NewIssueTableViewControllerDelegate {
}

func onSetDefaultReaction() {
//showDefaultReactionMenu()
let storyboard = UIStoryboard(name: "Settings", bundle: nil)
guard let viewController = storyboard.instantiateViewController(withIdentifier: "DefaultReactionDetailController") as? DefaultReactionDetailController else {
fatalError("Cannot instantiate DefaultReactionDetailController instance")
}
viewController.delegate = self
let navController = UINavigationController(rootViewController: viewController)
showDetailViewController(navController, sender: self)
}

func onTryTestFlightBeta() {
Expand Down Expand Up @@ -288,4 +298,10 @@ NewIssueTableViewControllerDelegate {
let navigation = UINavigationController(rootViewController: issuesViewController)
showDetailViewController(navigation, sender: nil)
}

// MARK: DefaultReactionDelegate

func didUpdateDefaultReaction() {
updateDefaultReaction()
}
}