mirror of
https://github.com/dashared/GDproject.git
synced 2024-11-25 11:43:58 +03:00
channels: attempt2
This commit is contained in:
parent
333da2671a
commit
49bc15b3b2
@ -7,6 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */; };
|
||||
123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; };
|
||||
123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; };
|
||||
124CC7032221C00C009DF531 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124CC7022221C00C009DF531 /* Model.swift */; };
|
||||
@ -72,6 +73,7 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
1210A0BA223940310080686D /* SimplifiedChannelsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedChannelsList.swift; sourceTree = "<group>"; };
|
||||
123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = "<group>"; };
|
||||
123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = "<group>"; };
|
||||
124CC7022221C00C009DF531 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
|
||||
@ -238,6 +240,7 @@
|
||||
children = (
|
||||
12D7D134221C42B700B35452 /* ChannelController.swift */,
|
||||
12D7D132221C321600B35452 /* ChannelListController.swift */,
|
||||
1210A0BA223940310080686D /* SimplifiedChannelsList.swift */,
|
||||
12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
|
||||
12E36DD022148122006FCDD7 /* FullPostController.swift */,
|
||||
12E36D9D221424EA006FCDD7 /* NewsController.swift */,
|
||||
@ -332,6 +335,7 @@
|
||||
12D7D137221D78E800B35452 /* Channel.swift in Sources */,
|
||||
1291BE3622218DBF009D3F23 /* LogInCoordinator.swift in Sources */,
|
||||
12E36DB922144016006FCDD7 /* User.swift in Sources */,
|
||||
1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */,
|
||||
125BD5812217314A008A3575 /* NewsVC.swift in Sources */,
|
||||
12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
|
||||
12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
|
||||
|
@ -214,6 +214,50 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="2803" y="1756"/>
|
||||
</scene>
|
||||
<!--Simplified Channels List-->
|
||||
<scene sceneID="gAa-jy-vpG">
|
||||
<objects>
|
||||
<tableViewController storyboardIdentifier="SimplifiedChannelsList" id="pgD-Fz-bkD" customClass="SimplifiedChannelsList" 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="Onz-Ne-JgO">
|
||||
<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" restorationIdentifier="cell" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="cell" textLabel="mZB-IA-VFq" detailTextLabel="6A8-yj-Eqe" style="IBUITableViewCellStyleSubtitle" id="6dT-km-gZC">
|
||||
<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="6dT-km-gZC" id="h7U-va-4PX">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="mZB-IA-VFq">
|
||||
<rect key="frame" x="16" y="5" width="33.5" height="20.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Subtitle" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="6A8-yj-Eqe">
|
||||
<rect key="frame" x="16" y="25.5" width="44" height="14.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="12"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="pgD-Fz-bkD" id="V4y-ql-GOS"/>
|
||||
<outlet property="delegate" destination="pgD-Fz-bkD" id="Avz-4G-8j6"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="731-nV-bC3" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="4445.6000000000004" y="-598.65067466266873"/>
|
||||
</scene>
|
||||
<!--Channel List Controller-->
|
||||
<scene sceneID="4eb-Jz-gcx">
|
||||
<objects>
|
||||
|
@ -44,3 +44,5 @@ let logInController = "LogInController"
|
||||
|
||||
|
||||
let profileViewController = "ProfileViewController"
|
||||
|
||||
let simplifiedChannelsList = "SimplifiedChannelsList"
|
||||
|
@ -198,7 +198,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
|
||||
|
||||
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
|
||||
if searchText.isEmpty {
|
||||
switch activeDataSource{
|
||||
switch activeDataSource {
|
||||
case .people:
|
||||
dataSourcePeople = fullPeople
|
||||
case .tags:
|
||||
@ -235,6 +235,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
|
||||
dataSourceTags = fullTags
|
||||
dataSourcePeople = []
|
||||
}
|
||||
print("\(searchBar.selectedScopeButtonIndex)")
|
||||
activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
|
||||
if (!(searchBar.text?.isEmpty ?? true))
|
||||
{
|
||||
@ -250,6 +251,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
|
||||
dataSourceTags = channel!.tags
|
||||
dataSourcePeople = []
|
||||
}
|
||||
print(" not active \(searchBar.selectedScopeButtonIndex)")
|
||||
activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
@ -70,16 +70,25 @@ class ChannelListController: UITableViewController, DataDelegate {
|
||||
navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool)
|
||||
override func viewDidAppear(_ animated: Bool)
|
||||
{
|
||||
super.viewWillAppear(animated)
|
||||
super.viewDidAppear(animated)
|
||||
searchController.isActive = false
|
||||
askForUpdates()
|
||||
}
|
||||
|
||||
private func askForUpdates(){
|
||||
Model.channelsList { [weak self] (channels) in
|
||||
self?.dataSource = [ChannelListController.generalChannel] + channels
|
||||
self?.toReload = true
|
||||
}
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(true)
|
||||
askForUpdates()
|
||||
}
|
||||
|
||||
@objc func addChannel()
|
||||
{
|
||||
// editing mode is on automatically
|
||||
@ -157,6 +166,7 @@ class ChannelListController: UITableViewController, DataDelegate {
|
||||
self?.tableView.deleteRows(at: [indexPath], with: .none)
|
||||
self?.tableView.endUpdates()
|
||||
}
|
||||
|
||||
deleteButton.backgroundColor = .red
|
||||
|
||||
return [editButton, deleteButton]
|
||||
|
@ -32,14 +32,19 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
|
||||
}
|
||||
|
||||
var dictionary: [Int: Model.Users]? {
|
||||
didSet{
|
||||
didSet {
|
||||
|
||||
var newPosts: [Model.Posts] = []
|
||||
|
||||
posts!.forEach({ (post) in
|
||||
|
||||
newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: dictionary![post.authorId]!, date: post.updated, tags: post.tags))
|
||||
|
||||
post.tags.forEach { Model.Channels.fullTags.insert($0) }
|
||||
|
||||
})
|
||||
|
||||
|
||||
news.dataSourse = newPosts
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
@ -142,7 +142,13 @@ class PostViewCell: UITableViewCell
|
||||
contentView.addSubview(mainView)
|
||||
mainView.edgesToSuperview(excluding: [.top, .bottom])
|
||||
mainView.topToBottom(of: nameStackView, offset: 5)
|
||||
mainView.height(30)
|
||||
|
||||
// TODO:- change!!!!!!!!!!!!
|
||||
if hashtags.isEmpty{
|
||||
mainView.height(0)
|
||||
} else {
|
||||
mainView.height(30)
|
||||
}
|
||||
|
||||
let stackView = MyStackView(arrangedSubviews: views)
|
||||
stackView.isFull = full
|
||||
|
@ -0,0 +1,81 @@
|
||||
//
|
||||
// SimplifiedChannelsList.swift
|
||||
// GDproject
|
||||
//
|
||||
// Created by cstore on 13/03/2019.
|
||||
// Copyright © 2019 drHSE. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
/// class for ADDing person to existing (or new) channel: like playlist in itunes
|
||||
import UIKit
|
||||
|
||||
class SimplifiedChannelsList: UITableViewController {
|
||||
|
||||
var user: Model.Users?
|
||||
|
||||
var dataSource: [Model.Channels]?{
|
||||
didSet{
|
||||
tableView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setUpNavigationButtons()
|
||||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
Model.channelsList { [weak self] (channels) in
|
||||
self?.dataSource = channels
|
||||
}
|
||||
}
|
||||
|
||||
func setUpNavigationButtons(){
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelAction))
|
||||
}
|
||||
|
||||
func completedActions(with channel: Model.Channels){
|
||||
Model.updateChannel(with: channel)
|
||||
cancelAction()
|
||||
}
|
||||
|
||||
@objc func cancelAction(){
|
||||
let transition = CATransition()
|
||||
transition.duration = 0.5
|
||||
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
transition.type = CATransitionType.reveal
|
||||
transition.subtype = CATransitionSubtype.fromBottom
|
||||
navigationController?.view.layer.add(transition, forKey: nil)
|
||||
navigationController?.popViewController(animated: false)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
||||
let viewHeader = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30))
|
||||
return viewHeader
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
||||
return 30
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return dataSource?.count ?? 0
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
var channel = dataSource![indexPath.row]
|
||||
channel.people.append(user!.id)
|
||||
completedActions(with: channel)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
||||
|
||||
cell.textLabel?.text = dataSource![indexPath.row].name
|
||||
cell.detailTextLabel?.text = "\(dataSource![indexPath.row].id!)"
|
||||
|
||||
return cell
|
||||
}
|
||||
}
|
@ -47,6 +47,9 @@ class ProfileViewController: UIViewController
|
||||
var user: Model.Users? {
|
||||
didSet {
|
||||
self.fill(with: user!)
|
||||
Model.getPostsForUser(with: user!.id) { [weak self] (posts) in
|
||||
self?.dataSourse = posts
|
||||
}
|
||||
navigationItem.title = "\(user?.id ?? 0)"
|
||||
}
|
||||
}
|
||||
@ -108,9 +111,7 @@ class ProfileViewController: UIViewController
|
||||
}
|
||||
}
|
||||
|
||||
Model.getPostsForUser(with: id) { [weak self] (posts) in
|
||||
self?.dataSourse = posts
|
||||
}
|
||||
// requst for postsforuser was here. moved because of concrr
|
||||
}
|
||||
|
||||
setUpNavigarionBar()
|
||||
@ -136,7 +137,21 @@ class ProfileViewController: UIViewController
|
||||
// saved
|
||||
|
||||
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
let editAction = UIAlertAction(title: "Edit profile", style: .default)
|
||||
let channelAction = UIAlertAction(title: "Add to the channel", style: .default){
|
||||
[weak self] (_) in
|
||||
|
||||
let vc = self?.storyboard?.instantiateViewController(withIdentifier: simplifiedChannelsList) as! SimplifiedChannelsList
|
||||
|
||||
vc.user = self?.user!
|
||||
|
||||
let transition = CATransition()
|
||||
transition.duration = 0.5
|
||||
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
||||
transition.type = CATransitionType.moveIn
|
||||
transition.subtype = CATransitionSubtype.fromTop
|
||||
self?.navigationController?.view.layer.add(transition, forKey: nil)
|
||||
self?.navigationController?.pushViewController(vc, animated: false)
|
||||
}
|
||||
let settingsAction = UIAlertAction(title: "Setting", style: .default)
|
||||
{ [weak self] (_) in
|
||||
|
||||
@ -151,7 +166,7 @@ class ProfileViewController: UIViewController
|
||||
DataStorage.standard.setIsLoggedIn(value: false, with: 0)
|
||||
}
|
||||
|
||||
optionMenu.addAction(editAction)
|
||||
optionMenu.addAction(channelAction)
|
||||
optionMenu.addAction(settingsAction)
|
||||
optionMenu.addAction(copyLink)
|
||||
optionMenu.addAction(logoutAction)
|
||||
|
@ -124,18 +124,14 @@ class Model{
|
||||
|
||||
struct Channels: Codable {
|
||||
|
||||
static var fullTags = Set<String>()
|
||||
static var fullPeople = [Int:Users]()
|
||||
|
||||
var people: [Int]
|
||||
var name: String
|
||||
var id: Int?
|
||||
var tags: [String]
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case people
|
||||
case name
|
||||
case id
|
||||
case tags
|
||||
}
|
||||
|
||||
init(people: [Int], name: String, id: Int, tags: [String]) {
|
||||
self.id = id
|
||||
self.people = people
|
||||
@ -149,6 +145,13 @@ class Model{
|
||||
self.name = name
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case people
|
||||
case name
|
||||
case id
|
||||
case tags
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(people, forKey: .people)
|
||||
|
Loading…
Reference in New Issue
Block a user