mirror of
https://github.com/dashared/GDproject.git
synced 2024-11-25 11:43:58 +03:00
Changed creation of new channels A LOT. But still search inside people and hashtags is left (and also preview - make get Anon channel). Fixed pagination and something else.
This commit is contained in:
parent
659507bde9
commit
caebb61779
@ -15,6 +15,8 @@
|
||||
125BD57D22171D2A008A3575 /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125BD57C22171D2A008A3575 /* ProfileViewController.swift */; };
|
||||
125BD57F22171D73008A3575 /* Extentions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125BD57E22171D73008A3575 /* Extentions.swift */; };
|
||||
125BD5812217314A008A3575 /* NewsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125BD5802217314A008A3575 /* NewsVC.swift */; };
|
||||
1261BB93227B364C003898CF /* ChannelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1261BB92227B364C003898CF /* ChannelViewController.swift */; };
|
||||
1261BB95227B3991003898CF /* AddToChannelVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1261BB94227B3991003898CF /* AddToChannelVC.swift */; };
|
||||
1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1288B5CD221F1158002BE6B1 /* DataStorage.swift */; };
|
||||
1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */; };
|
||||
1291BE342221569B009D3F23 /* TabbarCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */; };
|
||||
@ -102,6 +104,8 @@
|
||||
125BD57C22171D2A008A3575 /* ProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewController.swift; sourceTree = "<group>"; };
|
||||
125BD57E22171D73008A3575 /* Extentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extentions.swift; sourceTree = "<group>"; };
|
||||
125BD5802217314A008A3575 /* NewsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsVC.swift; sourceTree = "<group>"; };
|
||||
1261BB92227B364C003898CF /* ChannelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelViewController.swift; sourceTree = "<group>"; };
|
||||
1261BB94227B3991003898CF /* AddToChannelVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToChannelVC.swift; sourceTree = "<group>"; };
|
||||
1288B5CD221F1158002BE6B1 /* DataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStorage.swift; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
@ -297,6 +301,8 @@
|
||||
12E36DD322156519006FCDD7 /* News and channels */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1261BB92227B364C003898CF /* ChannelViewController.swift */,
|
||||
1261BB94227B3991003898CF /* AddToChannelVC.swift */,
|
||||
12D7D134221C42B700B35452 /* ChannelController.swift */,
|
||||
121A8971226B1EAC005EE599 /* AnonimousChannelController.swift */,
|
||||
12D7D132221C321600B35452 /* ChannelListController.swift */,
|
||||
@ -423,8 +429,10 @@
|
||||
12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */,
|
||||
12F3D6B22241097B00A69214 /* ProfileCoordinator.swift in Sources */,
|
||||
125BD57D22171D2A008A3575 /* ProfileViewController.swift in Sources */,
|
||||
1261BB95227B3991003898CF /* AddToChannelVC.swift in Sources */,
|
||||
12DB7FDB2218590C0096878E /* InfoCell.swift in Sources */,
|
||||
12DB7FD922181E660096878E /* BasicInfoCell.swift in Sources */,
|
||||
1261BB93227B364C003898CF /* ChannelViewController.swift in Sources */,
|
||||
12D7D135221C42B700B35452 /* ChannelController.swift in Sources */,
|
||||
12E36D9C221424EA006FCDD7 /* AppDelegate.swift in Sources */,
|
||||
12BA4B9D224101E700DF93D7 /* BaseCoordinator.swift in Sources */,
|
||||
|
@ -546,10 +546,86 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="4336" y="937"/>
|
||||
</scene>
|
||||
<!--Channel View Controller-->
|
||||
<scene sceneID="myW-UY-uGB">
|
||||
<objects>
|
||||
<tableViewController storyboardIdentifier="ChannelViewController" id="M45-Em-JMM" customClass="ChannelViewController" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="poy-7L-m8s">
|
||||
<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"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="titleCell" id="x0n-Is-bsF" customClass="TitleCell" customModule="GDproject" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="55.5" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="x0n-Is-bsF" id="5aI-NN-BRQ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Name the channel" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="jTk-cs-cpn">
|
||||
<rect key="frame" x="16" y="7" width="343" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="30" id="ZDL-Wx-W4e"/>
|
||||
</constraints>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="jTk-cs-cpn" secondAttribute="trailing" constant="16" id="KLT-Mg-Igg"/>
|
||||
<constraint firstAttribute="bottom" secondItem="jTk-cs-cpn" secondAttribute="bottom" constant="6.5" id="Yuh-81-wLm"/>
|
||||
<constraint firstItem="jTk-cs-cpn" firstAttribute="leading" secondItem="5aI-NN-BRQ" secondAttribute="leading" constant="16" id="tx2-BD-LW1"/>
|
||||
<constraint firstItem="jTk-cs-cpn" firstAttribute="top" secondItem="5aI-NN-BRQ" secondAttribute="top" constant="7" id="ufD-Sr-H0c"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="titleLabel" destination="jTk-cs-cpn" id="ysU-SK-thv"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
<sections/>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="M45-Em-JMM" id="zIt-LL-u3B"/>
|
||||
<outlet property="delegate" destination="M45-Em-JMM" id="8oD-9d-gx0"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="W3K-lW-jpq" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="5531" y="656"/>
|
||||
</scene>
|
||||
<!--Add To ChannelVC-->
|
||||
<scene sceneID="Qir-mq-wma">
|
||||
<objects>
|
||||
<tableViewController storyboardIdentifier="AddToChannelVC" id="sZD-zJ-IzQ" customClass="AddToChannelVC" 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="yj4-wM-mw1">
|
||||
<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="none" indentationWidth="10" id="xMi-Gz-AGg">
|
||||
<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="xMi-Gz-AGg" id="Lj0-2E-Ai9">
|
||||
<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="sZD-zJ-IzQ" id="RJA-hG-8Bd"/>
|
||||
<outlet property="delegate" destination="sZD-zJ-IzQ" id="zlr-yK-CDk"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="kT3-kK-tSX" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="6287" y="653"/>
|
||||
</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/>
|
||||
@ -559,6 +635,7 @@
|
||||
</navigationBar>
|
||||
<nil name="viewControllers"/>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="POV-5T-jeQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1089" y="-306"/>
|
||||
</scene>
|
||||
|
@ -55,5 +55,9 @@ let profileViewController = "ProfileViewController"
|
||||
|
||||
let simplifiedChannelsList = "SimplifiedChannelsList"
|
||||
|
||||
let channelViewControllerId = "ChannelViewController"
|
||||
|
||||
let addToChannelVCId = "AddToChannelVC"
|
||||
|
||||
let blueSystemColor = UIColor(red: 0, green: 137/255, blue: 249/255, alpha: 0.5)
|
||||
|
||||
|
117
GDproject/Controller/ News and channels/AddToChannelVC.swift
Normal file
117
GDproject/Controller/ News and channels/AddToChannelVC.swift
Normal file
@ -0,0 +1,117 @@
|
||||
//
|
||||
// AddToChannelVC.swift
|
||||
// GDproject
|
||||
//
|
||||
// Created by cstore on 02/05/2019.
|
||||
// Copyright © 2019 drHSE. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
enum DataSourse{
|
||||
case people, tags
|
||||
}
|
||||
|
||||
class AddToChannelVC: UITableViewController {
|
||||
|
||||
var channel: Model.Channels?
|
||||
var dataSourse: DataSourse = .people
|
||||
weak var update: UpdatableChannel?
|
||||
|
||||
// data sources for people and hashtags
|
||||
var dataSourcePeople: [Model.Users] = Model.Channels.fullPeople
|
||||
var fullTags: [String] = CompletionTree.getCompletion(tree: Model.hashTagTree!, word: "")
|
||||
|
||||
|
||||
var reloadtable: Bool = false {
|
||||
didSet{
|
||||
tableView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
let searchC = UISearchController(searchResultsController: nil)
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
|
||||
self.navigationItem.searchController = searchC
|
||||
navigationItem.largeTitleDisplayMode = .never
|
||||
self.navigationItem.hidesSearchBarWhenScrolling = false
|
||||
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
|
||||
update?.updateChannel(with: channel!)
|
||||
}
|
||||
// MARK: - Table view data source
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
switch dataSourse {
|
||||
case .people:
|
||||
return dataSourcePeople.count
|
||||
default:
|
||||
return fullTags.count
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
|
||||
{
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
||||
|
||||
switch dataSourse {
|
||||
case .people:
|
||||
cell.textLabel?.text = dataSourcePeople[indexPath.row].fullName()
|
||||
if channel!.people.contains(dataSourcePeople[indexPath.row].id) {
|
||||
cell.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
|
||||
} else {
|
||||
cell.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
|
||||
}
|
||||
default:
|
||||
cell.textLabel?.text = "# \(fullTags[indexPath.row])"
|
||||
if channel!.tags.contains(fullTags[indexPath.row]) {
|
||||
cell.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
|
||||
} else {
|
||||
cell.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
|
||||
}
|
||||
}
|
||||
|
||||
cell.selectionStyle = .none
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
if let cell = tableView.cellForRow(at: indexPath) {
|
||||
switch dataSourse {
|
||||
case .people:
|
||||
if cell.backgroundColor == #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1) {
|
||||
let filtered = channel!.people.filter{ $0 != dataSourcePeople[indexPath.row].id }
|
||||
channel?.people = filtered
|
||||
cell.backgroundColor = #colorLiteral(red: 0.9999960065, green: 1, blue: 1, alpha: 1)
|
||||
} else {
|
||||
channel?.people.append(dataSourcePeople[indexPath.row].id)
|
||||
cell.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
|
||||
}
|
||||
default: //tags
|
||||
if cell.backgroundColor == #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1) {
|
||||
let filtered = channel!.tags.filter{
|
||||
!fullTags[indexPath.row].contains($0)
|
||||
}
|
||||
channel?.tags = filtered
|
||||
cell.backgroundColor = #colorLiteral(red: 0.9999960065, green: 1, blue: 1, alpha: 1)
|
||||
} else {
|
||||
channel?.tags.append(fullTags[indexPath.row])
|
||||
cell.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -84,7 +84,7 @@ class ChannelListController: UITableViewController {
|
||||
askForUpdates()
|
||||
}
|
||||
|
||||
private func askForUpdates(){
|
||||
func askForUpdates(){
|
||||
Model.channelsList { [weak self] (channels) in
|
||||
self?.dataSource = [ChannelListController.generalChannel] + channels
|
||||
self?.toReload = true
|
||||
|
@ -0,0 +1,195 @@
|
||||
//
|
||||
// ChannelViewController.swift
|
||||
// MessageApp
|
||||
//
|
||||
// Created by cstore on 02/05/2019.
|
||||
// Copyright © 2019 drHSE. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol UpdatableName: class{
|
||||
func updateName(with name: String)
|
||||
}
|
||||
|
||||
protocol UpdatableChannel: class{
|
||||
func updateChannel(with channel: Model.Channels)
|
||||
}
|
||||
|
||||
class ChannelViewController: UITableViewController, UpdatableName, UpdatableChannel {
|
||||
|
||||
func updateName(with name: String){
|
||||
channel?.name = name
|
||||
}
|
||||
|
||||
func updateChannel(with channel: Model.Channels) {
|
||||
self.channel = channel
|
||||
}
|
||||
|
||||
var channel: Model.Channels?
|
||||
|
||||
// func to show preview of the current channel
|
||||
var onShowingPreview: ((Model.Channels)->())?
|
||||
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
|
||||
navigationItem.rightBarButtonItems = [ UIBarButtonItem(barButtonSystemItem: .play, target: self, action: #selector(showPreview)), self.editButtonItem]
|
||||
navigationItem.largeTitleDisplayMode = .never
|
||||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
|
||||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "searchCell")
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
tableView.reloadData()
|
||||
}
|
||||
// TODO: update channel
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
|
||||
defer {
|
||||
super.viewWillDisappear(animated)
|
||||
}
|
||||
|
||||
guard let _ = self.navigationController?.viewControllers.lastIndex(of: self) else {
|
||||
if let _ = channel?.id
|
||||
{
|
||||
Model.updateChannel(with: channel!)
|
||||
} else {
|
||||
Model.createChannel(with: channel!)
|
||||
}
|
||||
return
|
||||
}
|
||||
// nou
|
||||
}
|
||||
|
||||
@objc func showPreview(){
|
||||
if let channel = channel {
|
||||
onShowingPreview?(channel)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Table view data source
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 3
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
switch section {
|
||||
case 1:
|
||||
return (channel?.people.count ?? 0) + 1
|
||||
case 2:
|
||||
return (channel?.tags.count ?? 0) + 1
|
||||
default:
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
switch section {
|
||||
case 1:
|
||||
return "People"
|
||||
case 2:
|
||||
return "Tags"
|
||||
default:
|
||||
return "Title"
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
|
||||
switch indexPath.section{
|
||||
case 1 , 2:
|
||||
return whichCell(tableView, cellForRowAt: indexPath)
|
||||
default:
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "titleCell") as! TitleCell
|
||||
|
||||
cell.fill(title: channel?.name)
|
||||
cell.update = self
|
||||
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
||||
private func whichCell(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
|
||||
{
|
||||
let row = indexPath.row
|
||||
let section = indexPath.section
|
||||
|
||||
if row == 0
|
||||
{
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "searchCell")!
|
||||
cell.textLabel?.text = "Add more"
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
return cell
|
||||
}
|
||||
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
||||
|
||||
if section == 1 {
|
||||
cell.textLabel?.text = Model.Channels.fullPeopleDict[channel?.people[row-1] ?? 0]?.fullName()
|
||||
} else {
|
||||
cell.textLabel?.text = "# \(channel!.tags[row-1])"
|
||||
}
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
|
||||
{
|
||||
if editingStyle == UITableViewCell.EditingStyle.delete {
|
||||
if indexPath.section == 1 {
|
||||
channel?.people.remove(at: indexPath.row-1)
|
||||
} else {
|
||||
channel?.tags.remove(at: indexPath.row-1)
|
||||
}
|
||||
}
|
||||
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
||||
if indexPath.row == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
|
||||
{
|
||||
if indexPath.row == 0 && indexPath.section != 0
|
||||
{
|
||||
let vc = storyboard?.instantiateViewController(withIdentifier: addToChannelVCId) as! AddToChannelVC
|
||||
|
||||
vc.dataSourse = indexPath.section == 1 ? .people : .tags
|
||||
vc.channel = channel
|
||||
vc.update = self
|
||||
|
||||
navigationController?.pushViewController(vc, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TitleCell: UITableViewCell, UITextFieldDelegate {
|
||||
|
||||
@IBOutlet weak var titleLabel: UITextField!
|
||||
|
||||
weak var update: UpdatableName?
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
}
|
||||
|
||||
func fill(title: String?){
|
||||
titleLabel.text = title
|
||||
titleLabel.addTarget(self, action: #selector(changedText(_:)), for: .editingChanged)
|
||||
}
|
||||
|
||||
@objc func changedText(_ textField: UITextField){
|
||||
update?.updateName(with: textField.text!)
|
||||
}
|
||||
}
|
@ -53,10 +53,9 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
|
||||
|
||||
news.viewController = self
|
||||
news.type = type == .NEWS ? .NEWS : type!
|
||||
news.currChannel = channel
|
||||
|
||||
setUpNavigationItemsforPosts()
|
||||
|
||||
//setUpBanner()
|
||||
}
|
||||
|
||||
func setUpSearchContr(){
|
||||
|
@ -45,6 +45,8 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
var currChannel : Model.Channels?
|
||||
|
||||
var dataSourse: [Model.Posts] = [] {
|
||||
didSet {
|
||||
cellDataSourse = dataSourse.map { PostCellData(attributedData: PostCellData.create(with: $0.body)) }
|
||||
@ -115,11 +117,20 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
||||
// pagination
|
||||
if indexPath.row == cellDataSourse.count - 1 && prevLast != indexPath.row
|
||||
{
|
||||
// check this!
|
||||
Model.getLast(on: 10, from: dataSourse.last?.id )
|
||||
{ [weak self] in
|
||||
self?.dataSourse.append(contentsOf: $0.posts)
|
||||
$0.users.forEach { self?.dictionary[$0.key] = $0.value }
|
||||
if let ch = currChannel, let id = ch.id, ch.id != -1{
|
||||
// check this!
|
||||
Model.getChannel(with: id, on: 10, from: dataSourse.last?.id )
|
||||
{ [weak self] in
|
||||
self?.dataSourse.append(contentsOf: $0.posts)
|
||||
$0.users.forEach { self?.dictionary[$0.key] = $0.value }
|
||||
}
|
||||
} else {
|
||||
// check this!
|
||||
Model.getLast(on: 10, from: dataSourse.last?.id )
|
||||
{ [weak self] in
|
||||
self?.dataSourse.append(contentsOf: $0.posts)
|
||||
$0.users.forEach { self?.dictionary[$0.key] = $0.value }
|
||||
}
|
||||
}
|
||||
|
||||
prevLast = indexPath.row
|
||||
|
@ -32,6 +32,8 @@ class ChannelsCoordinator: BaseCoordinator{
|
||||
self.navigationController?.pushViewController(self.presentNewsController(with: channel), animated: true)
|
||||
}
|
||||
|
||||
channels.askForUpdates()
|
||||
|
||||
channels.onEditingModeBegins = { [unowned self] (channel, indexPath) in
|
||||
let vc = self.presentChannelController(with: channel)
|
||||
self.navigationController?.pushViewController(vc, animated: true)
|
||||
@ -45,8 +47,8 @@ class ChannelsCoordinator: BaseCoordinator{
|
||||
/// 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
|
||||
func presentChannelController(with channel: Model.Channels? = nil) -> ChannelViewController {
|
||||
let mainContentVC = storyboard.instantiateViewController(withIdentifier: channelViewControllerId) as! ChannelViewController
|
||||
|
||||
// to show preview we need to instantiate newsController but with different functionality
|
||||
mainContentVC.onShowingPreview = { [weak mainContentVC, unowned self] ch in
|
||||
@ -57,7 +59,8 @@ class ChannelsCoordinator: BaseCoordinator{
|
||||
return mainContentVC
|
||||
}
|
||||
|
||||
func presentNewsController(with channel: Model.Channels? = nil, previewMode: Bool = false) -> NewsController {
|
||||
func presentNewsController(with channel: Model.Channels? = nil, previewMode: Bool = false) -> NewsController
|
||||
{
|
||||
let mainContentVC = storyboard.instantiateViewController(withIdentifier: newsController) as! NewsController
|
||||
mainContentVC.channel = channel
|
||||
|
||||
@ -75,14 +78,14 @@ class ChannelsCoordinator: BaseCoordinator{
|
||||
print("anon with \($0.0.count) users")
|
||||
}
|
||||
|
||||
mainContentVC.changedChannelName = {
|
||||
[weak mainContentVC] (title) in mainContentVC?.navigationItem.title = title
|
||||
}
|
||||
|
||||
mainContentVC.navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(writePost(_:)))
|
||||
]
|
||||
}
|
||||
|
||||
mainContentVC.changedChannelName = {
|
||||
[weak mainContentVC] (title) in mainContentVC?.navigationItem.title = title
|
||||
}
|
||||
|
||||
return mainContentVC
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,9 @@ class Model{
|
||||
var firstName: String
|
||||
var id: Int
|
||||
|
||||
func fullName() -> String {
|
||||
return "\(firstName) \(lastName)"
|
||||
}
|
||||
}
|
||||
|
||||
struct Attachments: Codable {
|
||||
@ -209,10 +212,10 @@ class Model{
|
||||
}
|
||||
}
|
||||
|
||||
struct PostsLastRequest: Codable {
|
||||
struct PostsLastRequest<T: Codable>: Codable {
|
||||
var limit: Int
|
||||
var exclusiveFrom: Int?
|
||||
var request: [Int] = []
|
||||
var request: T
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case limit
|
||||
@ -230,7 +233,7 @@ class Model{
|
||||
|
||||
static func getLast(on limit: Int = 10, from pointInTime: Int? = nil, completion: @escaping (((users:[Int: Users], posts:[Posts]))->()))
|
||||
{
|
||||
let postRequest = PostsLastRequest(limit: limit, exclusiveFrom: pointInTime, request: [])
|
||||
let postRequest = PostsLastRequest<[Int]>(limit: limit, exclusiveFrom: pointInTime, request: [])
|
||||
|
||||
var request = URLRequest(url: postsLastURL)
|
||||
request.httpBody = try? JSONEncoder().encode(postRequest)
|
||||
@ -333,13 +336,10 @@ class Model{
|
||||
}
|
||||
|
||||
// get channel (with id): in responce -- PostQuery
|
||||
static func getChannel(with channelId: Int, completion: @escaping (((users:[Int: Users], posts:[Posts]))->())){
|
||||
let json = [
|
||||
"request" : channelId,
|
||||
"limit": 10
|
||||
]
|
||||
|
||||
let jsonData = try? JSONSerialization.data(withJSONObject: json)
|
||||
static func getChannel(with channelId: Int, on limit: Int = 10, from pointInTime: Int? = nil, completion: @escaping (((users:[Int: Users], posts:[Posts]))->()))
|
||||
{
|
||||
let postRequest = PostsLastRequest<Int>(limit: limit, exclusiveFrom: pointInTime, request: channelId)
|
||||
let jsonData = try? JSONEncoder().encode(postRequest)
|
||||
|
||||
var request = URLRequest(url: channelsGetURL)
|
||||
request.httpMethod = "POST"
|
||||
|
Loading…
Reference in New Issue
Block a user