Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.

Commit cbe119c

Browse files
Merge pull request #5 from ciaranmul/custom_server_selection_cleanup
Tidying Up Custom Server Selection
2 parents ab8352f + 05a93a4 commit cbe119c

File tree

4 files changed

+97
-42
lines changed

4 files changed

+97
-42
lines changed

Jellyfin Player.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
35F763A622A19F8300018AB2 /* UserProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F763A522A19F8300018AB2 /* UserProfileViewController.swift */; };
102102
35F763A822A19FF400018AB2 /* UserProfileStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35F763A722A19FF400018AB2 /* UserProfileStore.swift */; };
103103
485D3C875F9CF93AFE4C26C9 /* Pods_Jellyfin_PlayerUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 750445B871A56DC5558172D2 /* Pods_Jellyfin_PlayerUITests.framework */; };
104+
8F8236DB2499694F00CAEBF8 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F8236DA2499694F00CAEBF8 /* StringExtension.swift */; };
104105
B8F8DAFD9BC332389EFFB38F /* Pods_Jellyfin_Player.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B1799B14B665EACDC88A913A /* Pods_Jellyfin_Player.framework */; };
105106
/* End PBXBuildFile section */
106107

@@ -226,6 +227,7 @@
226227
44CC976103F2E07BB47587C0 /* Pods-Jellyfin Player.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Jellyfin Player.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Jellyfin Player/Pods-Jellyfin Player.debug.xcconfig"; sourceTree = "<group>"; };
227228
48D0C8A94A643FC8E967A534 /* Pods-Jellyfin Player.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Jellyfin Player.release.xcconfig"; path = "Pods/Target Support Files/Pods-Jellyfin Player/Pods-Jellyfin Player.release.xcconfig"; sourceTree = "<group>"; };
228229
750445B871A56DC5558172D2 /* Pods_Jellyfin_PlayerUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Jellyfin_PlayerUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
230+
8F8236DA2499694F00CAEBF8 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
229231
B1799B14B665EACDC88A913A /* Pods_Jellyfin_Player.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Jellyfin_Player.framework; sourceTree = BUILT_PRODUCTS_DIR; };
230232
E33F5BE93C32C14CD853811C /* Pods_Jellyfin_PlayerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Jellyfin_PlayerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
231233
/* End PBXFileReference section */
@@ -414,6 +416,7 @@
414416
352B5F26213165A300E346C6 /* Jellyfin Player */ = {
415417
isa = PBXGroup;
416418
children = (
419+
8F8236D92499693700CAEBF8 /* Extensions */,
417420
351ECB16215CE2F8003020C4 /* README.md */,
418421
35E9BB6B21ED2DB400E609FD /* Utilities */,
419422
351CFF1021621F27005743CE /* AppCache.swift */,
@@ -685,6 +688,14 @@
685688
name = Frameworks;
686689
sourceTree = "<group>";
687690
};
691+
8F8236D92499693700CAEBF8 /* Extensions */ = {
692+
isa = PBXGroup;
693+
children = (
694+
8F8236DA2499694F00CAEBF8 /* StringExtension.swift */,
695+
);
696+
path = Extensions;
697+
sourceTree = "<group>";
698+
};
688699
BB7494443E19B4D84EB4B173 /* Pods */ = {
689700
isa = PBXGroup;
690701
children = (
@@ -971,6 +982,7 @@
971982
351A81052146FA370028AC73 /* SingleItemOfflineFetcher.swift in Sources */,
972983
35F59673215E2B1700E3117D /* OngoingDownloadTableViewCell.swift in Sources */,
973984
357428352141174500713FC5 /* VideoInformationViewController.swift in Sources */,
985+
8F8236DB2499694F00CAEBF8 /* StringExtension.swift in Sources */,
974986
351CFF14216227B5005743CE /* ItemActionsViewController.swift in Sources */,
975987
351A80F221454C8C0028AC73 /* SubtitleViewController.swift in Sources */,
976988
35667BF32136F9EF000A20A0 /* ImageLoaderViewController.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
5+
// StringExtension.swift
6+
// Jellyfin Player
7+
//
8+
// Created by Ciarán Mulholland on 16/06/2020.
9+
// Copyright © 2020 Mats Mollestad. All rights reserved.
10+
//
11+
12+
import Foundation
13+
14+
extension String {
15+
var isNotBlankOrEmpty: Bool {
16+
return !self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
17+
}
18+
}

Jellyfin Player/Server Selection/Custom Server Selection/CustomServerSelectionCoordinator.swift

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class CustomServerSelectionCoordinator: Coordinating, CustomServerSelectionViewC
2323

2424
func start() {
2525
selectionController.delegate = self
26-
selectionController.errorTextLabel.isHidden = true
2726
presenter.setViewControllers([selectionController], animated: false)
2827
// presenter.pushViewController(selectionController, animated: true)
2928
}

Jellyfin Player/Server Selection/Custom Server Selection/CustomServerSelectionViewController.swift

+67-41
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ protocol CustomServerSelectionViewControllerDelegate: class {
2323
class CustomServerSelectionViewController: UIViewController {
2424

2525
private struct Strings {
26-
static let missingIPTitle = "Missing IP Address"
27-
static let invalidPortTitle = "Invalid Server Port"
28-
static let serverAddressLabel = "Server address"
26+
static let missingIPTitle = "Missing IP Address"
27+
static let invalidPortTitle = "Invalid Server Port"
28+
static let serverAddressLabel = "Server address"
2929
static let serverAddressPlaceholder = "https://your-server.com"
30-
static let serverPortLabel = "Server Port"
31-
static let serverPortPlaceholder = "8096"
32-
static let connectTitle = "Connect to Server"
33-
30+
static let serverPortLabel = "Server Port"
31+
static let serverPortPlaceholder = "8096"
32+
static let connectTitle = "Connect to Server"
3433
}
3534

3635
enum Errors: LocalizedError {
@@ -39,62 +38,83 @@ class CustomServerSelectionViewController: UIViewController {
3938

4039
public var errorDescription: String? {
4140
switch self {
42-
case .missingIP: return Strings.missingIPTitle
43-
case .invalidServerPort: return Strings.invalidPortTitle
41+
case .missingIP:
42+
return Strings.missingIPTitle
43+
case .invalidServerPort:
44+
return Strings.invalidPortTitle
4445
}
4546
}
4647
}
4748

48-
lazy var scrollView: UIScrollView = ViewBuilder.scrollView(subview: self.contentView)
49-
lazy var contentView: UIStackView = ViewBuilder.stackView(arrangedSubviews: [self.serverIPLabel,
50-
self.serverIPField,
51-
self.serverPortLabel,
52-
self.serverPortField,
53-
self.errorTextLabel,
54-
self.connectButton],
55-
layoutMargins: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20))
56-
57-
lazy var serverIPLabel = ViewBuilder.textLabel(font: .title3,
58-
text: Strings.serverAddressLabel)
59-
lazy var serverIPField: UITextField = ViewBuilder.textField(placeholder: Strings.serverAddressPlaceholder,
60-
text: "",
61-
keybordType: .URL)
62-
63-
lazy var serverPortLabel = ViewBuilder.textLabel(font: .title3,
64-
text: Strings.serverPortLabel)
65-
lazy var serverPortField: UITextField = ViewBuilder.textField(placeholder: Strings.serverPortPlaceholder,
66-
keybordType: .numberPad)
67-
68-
lazy var errorTextLabel: UILabel = ViewBuilder.textLabel(textColor: .red,
69-
font: .callout,
70-
isHidden: true)
71-
72-
lazy var connectButton: UIButton = ViewBuilder.button(title: Strings.connectTitle,
73-
color: UIColor(red: 20/255, green: 200/255, blue: 20/255, alpha: 1),
74-
target: self,
75-
selector: #selector(self.connectButtonWasTapped))
49+
lazy private var serverIPField: UITextField = ViewBuilder.textField(placeholder: Strings.serverAddressPlaceholder,
50+
text: "", keybordType: .URL)
51+
52+
lazy private var serverPortField: UITextField = ViewBuilder.textField(placeholder: Strings.serverPortPlaceholder,
53+
keybordType: .numberPad)
54+
55+
lazy private var errorTextLabel: UILabel = ViewBuilder.textLabel(textColor: .red,
56+
font: .callout,
57+
isHidden: true)
58+
59+
lazy private var connectButton: UIButton = ViewBuilder.button(title: Strings.connectTitle,
60+
color: UIColor(red: 20/255, green: 200/255, blue: 20/255, alpha: 1),
61+
target: self,
62+
selector: #selector(self.connectButtonWasTapped))
7663

7764
weak var delegate: CustomServerSelectionViewControllerDelegate?
7865

7966
override func viewDidLoad() {
8067
setupViewController()
8168
}
8269

70+
override func viewDidDisappear(_ animated: Bool) {
71+
resetViewController()
72+
}
73+
8374
private func setupViewController() {
75+
let serverIPLabel: UILabel = ViewBuilder.textLabel(font: .title3, text: Strings.serverAddressLabel)
76+
let serverPortLabel: UILabel = ViewBuilder.textLabel(font: .title3, text: Strings.serverPortLabel)
77+
8478
title = "Custom Connection"
8579
view.backgroundColor = .black
80+
81+
let views = [serverIPLabel,
82+
serverIPField,
83+
serverPortLabel,
84+
serverPortField,
85+
errorTextLabel,
86+
connectButton]
87+
88+
let contentView: UIStackView = ViewBuilder.stackView(arrangedSubviews: views,
89+
layoutMargins: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20))
90+
91+
let scrollView: UIScrollView = ViewBuilder.scrollView(subview: contentView)
92+
8693
view.addSubview(scrollView)
8794
scrollView.fillSuperView()
95+
96+
serverIPField.autocapitalizationType = .none
97+
}
98+
99+
private func resetViewController() {
100+
resetError()
88101
}
89102

90103
private func getServerConnection() throws -> ServerConnection {
91104

92-
guard var ipAddress = serverIPField.text,
93-
!ipAddress.isEmpty else { throw Errors.missingIP }
105+
guard var ipAddress = serverIPField.text, ipAddress.isNotBlankOrEmpty else { throw Errors.missingIP }
106+
94107
if !ipAddress.contains(":") {
95108
ipAddress = "http://" + ipAddress
96109
}
97-
let portString = serverPortField.text?.isEmpty == true ? Strings.serverPortPlaceholder : serverPortField.text!
110+
111+
let portString: String
112+
if let userDefinedPort = serverPortField.text {
113+
portString = userDefinedPort.isNotBlankOrEmpty ? userDefinedPort : Strings.serverPortPlaceholder
114+
} else {
115+
portString = Strings.serverPortPlaceholder
116+
}
117+
98118
guard let port = Int(portString) else { throw Errors.invalidServerPort }
99119

100120
return ServerConnection(ipAddress: ipAddress, port: port)
@@ -105,9 +125,15 @@ class CustomServerSelectionViewController: UIViewController {
105125
errorTextLabel.isHidden = false
106126
}
107127

128+
private func resetError() {
129+
errorTextLabel.text = ""
130+
errorTextLabel.isHidden = true
131+
}
132+
108133
@objc
109-
func connectButtonWasTapped() {
134+
private func connectButtonWasTapped() {
110135
do {
136+
resetError()
111137
let connection = try getServerConnection()
112138
delegate?.connectToServer(connection)
113139
} catch {

0 commit comments

Comments
 (0)