Changed preview concept (new vc) and added dialogs bar. Is correctly working in coordinators system. Btw wish General were a channel...

This commit is contained in:
Darya Rednikina 2019-05-01 14:29:32 +03:00
parent d782405160
commit 2c1cb56a14
9 changed files with 250 additions and 15 deletions

View File

@ -19,6 +19,8 @@
1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */; };
1291BE342221569B009D3F23 /* TabbarCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */; };
1291BE3622218DBF009D3F23 /* LogInCoordinator1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE3522218DBF009D3F23 /* LogInCoordinator1.swift */; };
129320042279B4270035C7B3 /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320032279B4270035C7B3 /* MessagesViewController.swift */; };
129320072279B5690035C7B3 /* MessagesCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320062279B5690035C7B3 /* MessagesCoordinator.swift */; };
12BA4B9B224101A400DF93D7 /* ApplicationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */; };
12BA4B9D224101E700DF93D7 /* BaseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */; };
12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */; };
@ -101,6 +103,8 @@
1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelsCoordinator.swift; sourceTree = "<group>"; };
1291BE332221569B009D3F23 /* TabbarCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabbarCoordinator.swift; sourceTree = "<group>"; };
1291BE3522218DBF009D3F23 /* LogInCoordinator1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInCoordinator1.swift; sourceTree = "<group>"; };
129320032279B4270035C7B3 /* MessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = "<group>"; };
129320062279B5690035C7B3 /* MessagesCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesCoordinator.swift; sourceTree = "<group>"; };
12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationCoordinator.swift; sourceTree = "<group>"; };
12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCoordinator.swift; sourceTree = "<group>"; };
12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInCoordinator.swift; sourceTree = "<group>"; };
@ -177,6 +181,7 @@
isa = PBXGroup;
children = (
12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */,
129320062279B5690035C7B3 /* MessagesCoordinator.swift */,
12F3D6AF224106F700A69214 /* TabbarController.swift */,
12F3D6B12241097B00A69214 /* ProfileCoordinator.swift */,
12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */,
@ -196,6 +201,14 @@
path = "Log In";
sourceTree = "<group>";
};
129320052279B4300035C7B3 /* Messages */ = {
isa = PBXGroup;
children = (
129320032279B4270035C7B3 /* MessagesViewController.swift */,
);
path = Messages;
sourceTree = "<group>";
};
12E36D8F221424EA006FCDD7 = {
isa = PBXGroup;
children = (
@ -264,6 +277,7 @@
isa = PBXGroup;
children = (
1291BE32222154C3009D3F23 /* Coordinators */,
129320052279B4300035C7B3 /* Messages */,
1291BE3722218DC4009D3F23 /* Log In */,
1288B5CC221F0EFE002BE6B1 /* Profile */,
12E36DD322156519006FCDD7 /* News and channels */,
@ -371,6 +385,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
129320072279B5690035C7B3 /* MessagesCoordinator.swift in Sources */,
124CC7032221C00C009DF531 /* Model.swift in Sources */,
12F3D6B0224106F700A69214 /* TabbarController.swift in Sources */,
12E36DD522156559006FCDD7 /* MyStackView.swift in Sources */,
@ -391,6 +406,7 @@
12BA4B9B224101A400DF93D7 /* ApplicationCoordinator.swift in Sources */,
1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */,
12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */,
129320042279B4270035C7B3 /* MessagesViewController.swift in Sources */,
1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */,
12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */,
12F3D6B22241097B00A69214 /* ProfileCoordinator.swift in Sources */,

View File

@ -11,6 +11,20 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Item-->
<scene sceneID="bZ2-fw-XBE">
<objects>
<navigationController id="gt4-mD-66Q" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Item" id="ZPm-j1-3dy"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="XiY-wd-750">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4yT-77-90q" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1089" y="481"/>
</scene>
<!--Profile View Controller-->
<scene sceneID="rQ6-TM-V7T">
<objects>
@ -131,7 +145,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="sap-zV-B7l" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2013.5999999999999" y="957.57121439280365"/>
<point key="canvasLocation" x="1884" y="1216"/>
</scene>
<!--Settings View Controller-->
<scene sceneID="WVn-Qy-9tO">
@ -168,7 +182,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="xdg-ZK-4Jv" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1986" y="1756"/>
<point key="canvasLocation" x="1980" y="1979"/>
</scene>
<!--Invite View Controller-->
<scene sceneID="DcO-6Y-Iko">
@ -212,7 +226,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="t8a-Sv-mbh" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2803" y="1756"/>
<point key="canvasLocation" x="2799" y="1979"/>
</scene>
<!--Simplified Channels List-->
<scene sceneID="gAa-jy-vpG">
@ -416,9 +430,38 @@
</objects>
<point key="canvasLocation" x="3444" y="129.98500749625188"/>
</scene>
<!--Messages View Controller-->
<scene sceneID="WSW-fr-Vf8">
<objects>
<tableViewController storyboardIdentifier="MessagesViewController" id="KLf-CK-diQ" customClass="MessagesViewController" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="13B-QX-K78">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="67C-fT-WEV">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="67C-fT-WEV" id="O3b-Xv-UNk">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="KLf-CK-diQ" id="LjF-Uw-Xhq"/>
<outlet property="delegate" destination="KLf-CK-diQ" id="yJZ-wH-O3v"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="fu3-z4-EY7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2798" y="932"/>
</scene>
<!--Posts-->
<scene sceneID="RSd-UJ-34B">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="POV-5T-jeQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController storyboardIdentifier="navChannels" automaticallyAdjustsScrollViewInsets="NO" id="NuV-ZG-ld2" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Posts" image="5" selectedImage="5" id="dH2-sL-YsR"/>
<toolbarItems/>
@ -428,9 +471,8 @@
</navigationBar>
<nil name="viewControllers"/>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="POV-5T-jeQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1088.8" y="132.68365817091455"/>
<point key="canvasLocation" x="1089" y="-306"/>
</scene>
<!--Profile-->
<scene sceneID="dJj-Hp-Wa9">
@ -446,7 +488,7 @@
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Fvm-qf-2Ve" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1089" y="958"/>
<point key="canvasLocation" x="1015" y="1216"/>
</scene>
<!--Tabbar Controller-->
<scene sceneID="HCR-WO-p7g">
@ -460,6 +502,7 @@
</tabBar>
<connections>
<segue destination="NuV-ZG-ld2" kind="relationship" relationship="viewControllers" id="XuX-8s-fZU"/>
<segue destination="gt4-mD-66Q" kind="relationship" relationship="viewControllers" id="QM3-FF-LMu"/>
<segue destination="tae-5q-wvT" kind="relationship" relationship="viewControllers" id="wCJ-4N-lfC"/>
</connections>
</tabBarController>

View File

@ -43,6 +43,9 @@ let newsController = "NewsController"
/// constant for switching to view controller for log in app
let logInController = "LogInController"
// constant for getting to messages
let messagesViewControllerId = "MessagesViewController"
let profileViewController = "ProfileViewController"

View File

@ -33,6 +33,9 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
var activeDataSource: ActiveTable = .people
// func to show preview of the current channel
var onShowingPreview: ((Model.Channels)->())?
@IBOutlet weak var viewww: UIView!
@IBOutlet weak var textField: UITextField!
@ -61,16 +64,33 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
// TODO: update channel
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if let _ = channel?.id { print("update")
Model.updateChannel(with: channel!)
} else { print("create")
Model.createChannel(with: channel!)
defer {
super.viewWillDisappear(animated)
}
guard let _ = self.navigationController?.viewControllers.lastIndex(of: self) else {
if let _ = channel?.id { print("update")
Model.updateChannel(with: channel!)
} else { print("create")
Model.createChannel(with: channel!)
}
return
}
// nou
}
@objc func showPreview(){
if let channel = channel {
onShowingPreview?(channel)
}
}
func setUpController(){
// setting up the preview button for the editing or created channel
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Preview", style: .done, target: self, action: #selector(showPreview))
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: itemCellId)

View File

@ -33,7 +33,7 @@ class ChannelsCoordinator: BaseCoordinator{
}
channels.onEditingModeBegins = { [unowned self] (channel, indexPath) in
let vc = self.presentNewsController(with: channel)
let vc = self.presentChannelController(with: channel)
self.navigationController?.pushViewController(vc, animated: true)
vc.tabBarController?.tabBar.isHidden = true
}
@ -42,11 +42,26 @@ class ChannelsCoordinator: BaseCoordinator{
navigationController?.setViewControllers([channels, nc], animated: false)
}
func presentNewsController(with channel: Model.Channels? = nil) -> NewsController {
/// Function that presents channel controller
///
/// - Parameter channel: channel that needs to be displayed
func presentChannelController(with channel: Model.Channels? = nil) -> ChannelController {
let mainContentVC = storyboard.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
// to show preview we need to instantiate newsController but with different functionality
mainContentVC.onShowingPreview = { [weak mainContentVC, unowned self] ch in
let vc = self.presentNewsController(with: ch, previewMode: true)
mainContentVC?.navigationController?.pushViewController(vc, animated: true)
}
mainContentVC.channel = channel
return mainContentVC
}
func presentNewsController(with channel: Model.Channels? = nil, previewMode: Bool = false) -> NewsController {
let mainContentVC = storyboard.instantiateViewController(withIdentifier: newsController) as! NewsController
mainContentVC.channel = channel
if channel == nil || channel?.id == -1 {
if !previewMode {
mainContentVC.news.onFullPost = {
[weak self] (type,post) in

View File

@ -0,0 +1,32 @@
//
// MessagesCoordinator.swift
// GDproject
//
// Created by cstore on 01/05/2019.
// Copyright © 2019 drHSE. All rights reserved.
//
import Foundation
import UIKit
class MessagesCoordinator: BaseCoordinator {
var didEndSession: (()->())?
let storyboard = UIStoryboard(name: "Main", bundle: nil)
private weak var navigationController: UINavigationController?
init(nc: UINavigationController) {
self.navigationController = nc
}
override func start() {
show()
}
private func show(){
let vc = storyboard.instantiateViewController(withIdentifier: messagesViewControllerId) as! MessagesViewController
navigationController?.viewControllers = [vc]
}
}

View File

@ -12,6 +12,7 @@ import UIKit
protocol TabbarView: class {
var onChannelsFlowSelect: ((UINavigationController) -> ())? { get set }
var onProfileFlowSelect: ((UINavigationController) -> ())? { get set }
var onMessagesFlowSelect: ((UINavigationController) -> ())? { get set }
var onViewDidLoad: ((UINavigationController) -> ())? { get set }
}
@ -20,6 +21,8 @@ final class TabbarController: UITabBarController, UITabBarControllerDelegate, Ta
var onChannelsFlowSelect: ((UINavigationController) -> ())?
var onProfileFlowSelect: ((UINavigationController) -> ())?
var onMessagesFlowSelect: ((UINavigationController) -> ())?
var onViewDidLoad: ((UINavigationController) -> ())?
override func viewDidLoad() {
@ -38,8 +41,10 @@ final class TabbarController: UITabBarController, UITabBarControllerDelegate, Ta
if selectedIndex == 0 {
onChannelsFlowSelect?(controller)
} else {
} else if selectedIndex == 2 {
onProfileFlowSelect?(controller)
} else {
onMessagesFlowSelect?(controller)
}
}
}

View File

@ -26,6 +26,7 @@ class TabBarCoordinator: BaseCoordinator {
tabbarView.onViewDidLoad = runChannelsFlow()
tabbarView.onChannelsFlowSelect = runChannelsFlow()
tabbarView.onProfileFlowSelect = runProfileFlow()
tabbarView.onMessagesFlowSelect = runMessagesFlow()
window?.rootViewController = tabbarView as! TabbarController
}
@ -40,6 +41,16 @@ class TabBarCoordinator: BaseCoordinator {
}
}
private func runMessagesFlow() -> ((UINavigationController) -> ()){
return { [unowned self] navController in
if navController.viewControllers.isEmpty == true {
let messagesCoordinator = MessagesCoordinator(nc: navController)
self.addDependency(messagesCoordinator)
messagesCoordinator.start()
}
}
}
private func runProfileFlow() -> ((UINavigationController) -> ())
{
return { [unowned self] navController in

View File

@ -0,0 +1,90 @@
//
// MessagesViewController.swift
// GDproject
//
// Created by cstore on 01/05/2019.
// Copyright © 2019 drHSE. All rights reserved.
//
import UIKit
class MessagesViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
/*
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Configure the cell...
return cell
}
*/
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// 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.
}
*/
}