Start preferences

This commit is contained in:
Shadowfacts 2018-08-28 19:16:17 -04:00
parent 41fddd8bd2
commit 7448c6a09e
8 changed files with 202 additions and 2 deletions

View File

@ -16,6 +16,10 @@
D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64D0AB02128D9AE005A6F37 /* OnboardingViewController.swift */; };
D663625D2135C74800C9CBA2 /* ConversationMainStatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D663625C2135C74800C9CBA2 /* ConversationMainStatusTableViewCell.xib */; };
D663625F2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663625E2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift */; };
D663626221360B1900C9CBA2 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626121360B1900C9CBA2 /* Preferences.swift */; };
D663626421360D2300C9CBA2 /* AvatarStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626321360D2300C9CBA2 /* AvatarStyle.swift */; };
D663626621360DD700C9CBA2 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D663626521360DD700C9CBA2 /* Preferences.storyboard */; };
D663626821360E2C00C9CBA2 /* PreferencesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */; };
D667E5E12134937B0057A976 /* StatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E02134937B0057A976 /* StatusTableViewCell.xib */; };
D667E5E3213499F70057A976 /* Profile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E2213499F70057A976 /* Profile.storyboard */; };
D667E5E721349D4C0057A976 /* ProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */; };
@ -84,6 +88,10 @@
D64D0AB02128D9AE005A6F37 /* OnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewController.swift; sourceTree = "<group>"; };
D663625C2135C74800C9CBA2 /* ConversationMainStatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConversationMainStatusTableViewCell.xib; sourceTree = "<group>"; };
D663625E2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationMainStatusTableViewCell.swift; sourceTree = "<group>"; };
D663626121360B1900C9CBA2 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
D663626321360D2300C9CBA2 /* AvatarStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarStyle.swift; sourceTree = "<group>"; };
D663626521360DD700C9CBA2 /* Preferences.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Preferences.storyboard; sourceTree = "<group>"; };
D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesTableViewController.swift; sourceTree = "<group>"; };
D667E5E02134937B0057A976 /* StatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusTableViewCell.xib; sourceTree = "<group>"; };
D667E5E2213499F70057A976 /* Profile.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Profile.storyboard; sourceTree = "<group>"; };
D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTableViewController.swift; sourceTree = "<group>"; };
@ -141,6 +149,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
D663626021360A9600C9CBA2 /* Preferences */ = {
isa = PBXGroup;
children = (
D663626121360B1900C9CBA2 /* Preferences.swift */,
D663626321360D2300C9CBA2 /* AvatarStyle.swift */,
);
path = Preferences;
sourceTree = "<group>";
};
D667E5F62135C2ED0057A976 /* Extensions */ = {
isa = PBXGroup;
children = (
@ -194,6 +211,7 @@
04DACE89212CA6B7009840C4 /* Timeline.swift */,
D64D0AAC2128D88B005A6F37 /* LocalData.swift */,
04DACE8D212CC7CC009840C4 /* AvatarCache.swift */,
D663626021360A9600C9CBA2 /* Preferences */,
D667E5F62135C2ED0057A976 /* Extensions */,
D6F953F121251A2F00CF0F2B /* Controllers */,
D6F953E9212519B800CF0F2B /* View Controllers */,
@ -232,6 +250,7 @@
04DACE8B212CB14B009840C4 /* MainTabBarViewController.swift */,
D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */,
D667E5F42135BCD50057A976 /* ConversationViewController.swift */,
D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */,
);
path = "View Controllers";
sourceTree = "<group>";
@ -244,6 +263,7 @@
D64D0AAE2128D954005A6F37 /* Onboarding.storyboard */,
D667E5E2213499F70057A976 /* Profile.storyboard */,
D667E5F22135BC260057A976 /* Conversation.storyboard */,
D663626521360DD700C9CBA2 /* Preferences.storyboard */,
);
path = Storyboards;
sourceTree = "<group>";
@ -370,6 +390,7 @@
D6F953EE21251A0700CF0F2B /* Timeline.storyboard in Resources */,
D6D4DDD5212518A000E1C4BB /* Main.storyboard in Resources */,
D667E5E3213499F70057A976 /* Profile.storyboard in Resources */,
D663626621360DD700C9CBA2 /* Preferences.storyboard in Resources */,
D667E5E12134937B0057A976 /* StatusTableViewCell.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -401,10 +422,13 @@
D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */,
D667E5F82135C3040057A976 /* Mastodon+Equatable.swift in Sources */,
04DACE8E212CC7CC009840C4 /* AvatarCache.swift in Sources */,
D663626421360D2300C9CBA2 /* AvatarStyle.swift in Sources */,
D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */,
D64D0AAD2128D88B005A6F37 /* LocalData.swift in Sources */,
D663626221360B1900C9CBA2 /* Preferences.swift in Sources */,
D667E5EF2134C39F0057A976 /* StatusContentLabel.swift in Sources */,
D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */,
D663626821360E2C00C9CBA2 /* PreferencesTableViewController.swift in Sources */,
D6F953EC212519E700CF0F2B /* TimelineTableViewController.swift in Sources */,
D667E5EB21349EF80057A976 /* ProfileHeaderTableViewCell.swift in Sources */,
D64A0CD32132153900640E3B /* HTMLContentLabel.swift in Sources */,

View File

@ -33,6 +33,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
Preferences.save()
}
func applicationWillEnterForeground(_ application: UIApplication) {

View File

@ -0,0 +1,13 @@
//
// AvatarStyle.swift
// Tusker
//
// Created by Shadowfacts on 8/28/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import Foundation
enum AvatarStyle: String, Codable {
case roundRect, circle
}

View File

@ -0,0 +1,35 @@
//
// Preferences.swift
// Tusker
//
// Created by Shadowfacts on 8/28/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import Foundation
class Preferences: Codable {
private(set) static var shared: Preferences = load()
private static var documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
private static var archiveURL = Preferences.documentsDirectory.appendingPathComponent("preferences").appendingPathExtension("plist")
static func save() {
let encoder = PropertyListEncoder()
let data = try? encoder.encode(shared)
try? data?.write(to: Preferences.archiveURL, options: .noFileProtection)
}
static func load() -> Preferences {
let decoder = PropertyListDecoder()
if let data = try? Data(contentsOf: Preferences.archiveURL),
let preferences = try? decoder.decode(Preferences.self, from: data) {
return preferences
}
return Preferences()
}
var showRepliesInProfiles = false
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.13.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="VJJ-jC-9g8">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.9"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Preferences-->
<scene sceneID="PD7-d3-cFe">
<objects>
<tableViewController id="ArB-e7-yko" customClass="PreferencesTableViewController" customModule="Tusker" 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="JGC-f9-j7V">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections>
<tableViewSection id="9cB-GR-Pdp">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="ffB-1O-bFL">
<rect key="frame" x="0.0" y="35" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ffB-1O-bFL" id="PFp-4A-2ka">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Show Replies in Profiles" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DkZ-zq-Q4w">
<rect key="frame" x="16" y="11.5" width="182" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iCG-F0-6ZK">
<rect key="frame" x="310" y="6.5" width="51" height="31"/>
<connections>
<action selector="showRepliesInProfilesChanged:" destination="ArB-e7-yko" eventType="valueChanged" id="viU-pi-47n"/>
</connections>
</switch>
</subviews>
<constraints>
<constraint firstItem="iCG-F0-6ZK" firstAttribute="centerY" secondItem="PFp-4A-2ka" secondAttribute="centerY" id="7aD-RX-CTV"/>
<constraint firstAttribute="trailing" secondItem="iCG-F0-6ZK" secondAttribute="trailing" constant="16" id="Vns-XW-ptr"/>
<constraint firstItem="DkZ-zq-Q4w" firstAttribute="centerY" secondItem="PFp-4A-2ka" secondAttribute="centerY" id="lGl-bs-NXC"/>
<constraint firstItem="DkZ-zq-Q4w" firstAttribute="leading" secondItem="PFp-4A-2ka" secondAttribute="leadingMargin" id="s8Y-iu-VJ6"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="ArB-e7-yko" id="Kxa-qc-mae"/>
<outlet property="delegate" destination="ArB-e7-yko" id="BFj-a8-oE6"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Preferences" id="dN7-yl-voz"/>
<connections>
<outlet property="showRepliesInProfilesSwitch" destination="iCG-F0-6ZK" id="p5E-oK-ZYl"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="GBL-Cz-yNZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="826" y="-234"/>
</scene>
<!--Preferences-->
<scene sceneID="3UV-H1-kd4">
<objects>
<navigationController id="VJJ-jC-9g8" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Preferences" id="Glr-Fd-5tZ"/>
<simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="YW6-8Y-aXt">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="ArB-e7-yko" kind="relationship" relationship="rootViewController" id="iO7-5u-D0i"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Otz-oe-r9y" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-126" y="-234"/>
</scene>
</scenes>
</document>

View File

@ -16,7 +16,8 @@ class MainTabBarViewController: UITabBarController {
viewControllers = [
TimelineTableViewController.create(for: .home),
TimelineTableViewController.create(for: .federated),
TimelineTableViewController.create(for: .local)
TimelineTableViewController.create(for: .local),
PreferencesTableViewController.create()
]
}

View File

@ -0,0 +1,40 @@
//
// PreferencesTableViewController.swift
// Tusker
//
// Created by Shadowfacts on 8/28/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
class PreferencesTableViewController: UITableViewController {
static func create() -> UIViewController {
guard let navigationController = UIStoryboard(name: "Preferences", bundle: nil).instantiateInitialViewController() as? UINavigationController else { fatalError() }
return navigationController
}
@IBOutlet weak var showRepliesInProfilesSwitch: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
showRepliesInProfilesSwitch.setOn(Preferences.shared.showRepliesInProfiles, animated: false)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
@IBAction func showRepliesInProfilesChanged(_ sender: Any) {
Preferences.shared.showRepliesInProfiles = showRepliesInProfilesSwitch.isOn
}
}

View File

@ -33,7 +33,7 @@ class ProfileTableViewController: UITableViewController {
func request(for range: RequestRange? = .default) -> Request<[Status]> {
let range = range ?? .default
return Accounts.statuses(id: account.id, mediaOnly: false, pinnedOnly: false, excludeReplies: true, range: range)
return Accounts.statuses(id: account.id, mediaOnly: false, pinnedOnly: false, excludeReplies: !Preferences.shared.showRepliesInProfiles, range: range)
}
override func viewDidLoad() {