git.iko.soy/dashared/GDproject
on master help sign in
Seach is added!!! CompletionTree algorithm's being used! Slowly moving towards only Model.GetAnonymousChannel instead of every other request (getLast, getUser..)
commit8f02f3af4a9cc3b8d2d9e69afe6dbba4c5962cd7 authorDarya Rednikina <rednikina.com@yandex.ru> dateSat 4 May 2019, 16:48 (7 years ago) parenta32c342
8 files changed+156−41
GDproject.xcodeproj/project.pbxproj+4−4 GDproject/Base.lproj/Main.storyboard+37 GDproject/Constants.swift+2 GDproject/Controller/ News and channels/AnonimousChannelController.swift−18 GDproject/Controller/ News and channels/NewsController.swift+48−8 GDproject/Controller/ News and channels/NewsVC.swift+9−9 GDproject/Controller/ News and channels/TagsSuggestionController.swift+52 GDproject/Simple model/Model.swift+4−2
GDproject.xcodeproj/project.pbxproj+4−4
@@ -8,7 +8,7 @@
88
99/* Begin PBXBuildFile section */
1010 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */; };
11− 121A8972226B1EAC005EE599 /* AnonimousChannelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 121A8971226B1EAC005EE599 /* AnonimousChannelController.swift */; };
11+ 121A8972226B1EAC005EE599 /* TagsSuggestionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 121A8971226B1EAC005EE599 /* TagsSuggestionController.swift */; };
1212 1220FF94227C41270092C6BC /* TaggsSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1220FF93227C41270092C6BC /* TaggsSelectionViewController.swift */; };
1313 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; };
1414 123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; };
@@ -102,7 +102,7 @@
102102
103103/* Begin PBXFileReference section */
104104 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedChannelsList.swift; sourceTree = "<group>"; };
105− 121A8971226B1EAC005EE599 /* AnonimousChannelController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnonimousChannelController.swift; sourceTree = "<group>"; };
105+ 121A8971226B1EAC005EE599 /* TagsSuggestionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsSuggestionController.swift; sourceTree = "<group>"; };
106106 1220FF93227C41270092C6BC /* TaggsSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaggsSelectionViewController.swift; sourceTree = "<group>"; };
107107 123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = "<group>"; };
108108 123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = "<group>"; };
@@ -316,7 +316,7 @@
316316 1220FF93227C41270092C6BC /* TaggsSelectionViewController.swift */,
317317 1261BB94227B3991003898CF /* AddToChannelVC.swift */,
318318 12D7D134221C42B700B35452 /* ChannelController.swift */,
319− 121A8971226B1EAC005EE599 /* AnonimousChannelController.swift */,
319+ 121A8971226B1EAC005EE599 /* TagsSuggestionController.swift */,
320320 12D7D132221C321600B35452 /* ChannelListController.swift */,
321321 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */,
322322 12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
@@ -423,7 +423,7 @@
423423 125BD5812217314A008A3575 /* NewsVC.swift in Sources */,
424424 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
425425 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
426− 121A8972226B1EAC005EE599 /* AnonimousChannelController.swift in Sources */,
426+ 121A8972226B1EAC005EE599 /* TagsSuggestionController.swift in Sources */,
427427 1293200D2279D7310035C7B3 /* CompletionTree.swift in Sources */,
428428 1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */,
429429 12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */,
GDproject/Base.lproj/Main.storyboard+37
@@ -729,6 +729,43 @@
729729 </objects>
730730 <point key="canvasLocation" x="5057" y="938"/>
731731 </scene>
732+ <!--Tags Suggestion Controller-->
733+ <scene sceneID="gfS-IA-vBj">
734+ <objects>
735+ <tableViewController storyboardIdentifier="TagsSuggestionController" id="shX-JH-apo" customClass="TagsSuggestionController" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
736+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="jTj-mU-lli">
737+ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
738+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
739+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
740+ <prototypes>
741+ <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="cell" textLabel="Lbu-Z7-fTN" style="IBUITableViewCellStyleDefault" id="pnl-jg-9DL">
742+ <rect key="frame" x="0.0" y="28" width="375" height="44"/>
743+ <autoresizingMask key="autoresizingMask"/>
744+ <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="pnl-jg-9DL" id="Vsm-Ic-k7e">
745+ <rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
746+ <autoresizingMask key="autoresizingMask"/>
747+ <subviews>
748+ <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Lbu-Z7-fTN">
749+ <rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
750+ <autoresizingMask key="autoresizingMask"/>
751+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
752+ <nil key="textColor"/>
753+ <nil key="highlightedColor"/>
754+ </label>
755+ </subviews>
756+ </tableViewCellContentView>
757+ </tableViewCell>
758+ </prototypes>
759+ <connections>
760+ <outlet property="dataSource" destination="shX-JH-apo" id="a9b-xm-VIg"/>
761+ <outlet property="delegate" destination="shX-JH-apo" id="Cg4-aC-E7h"/>
762+ </connections>
763+ </tableView>
764+ </tableViewController>
765+ <placeholder placeholderIdentifier="IBFirstResponder" id="RsJ-xx-GJW" userLabel="First Responder" sceneMemberID="firstResponder"/>
766+ </objects>
767+ <point key="canvasLocation" x="5925" y="1339"/>
768+ </scene>
732769 <!--Channel View Controller-->
733770 <scene sceneID="myW-UY-uGB">
734771 <objects>
GDproject/Constants.swift+2
@@ -63,5 +63,7 @@ let taggsSelectionViewController = "TaggsSelectionViewController"
6363
6464let dialogViewController = "DialogViewController"
6565
66+let tagsSuggestionController = "TagsSuggestionController"
67+
6668let blueSystemColor = UIColor(red: 0, green: 137/255, blue: 249/255, alpha: 0.5)
6769
GDproject/Controller/ News and channels/AnonimousChannelController.swiftdeleted−18
@@ -1,18 +0,0 @@
1−//
2−// AnonimousChannelController.swift
3−// GDproject
4−//
5−// Created by cstore on 20/04/2019.
6−// Copyright © 2019 drHSE. All rights reserved.
7−//
8−
9−import UIKit
10−
11−class AnonimousChannelController: UITableViewController {
12−
13− override func viewDidLoad() {
14− super.viewDidLoad()
15− }
16−
17−
18−}
GDproject/Controller/ News and channels/NewsController.swift+48−8
@@ -12,6 +12,7 @@ import Cartography
1212
1313protocol UpdateableWithChannel: class {
1414 var channel: Model.Channels? { get set }
15+ func updateChannel(on channel: Model.Channels)
1516}
1617
1718protocol UpdateableWithUser: class {
@@ -19,8 +20,14 @@ protocol UpdateableWithUser: class {
1920}
2021// MARK:- Controller with posts and channels availiable.
2122// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
22−class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWithChannel
23+class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWithChannel, UISearchResultsUpdating
2324{
25+ func updateChannel(on channel: Model.Channels) {
26+ self.channel = channel
27+ news.currChannel = channel
28+ decideWhatChannelDisplay()
29+ }
30+
2431 var changedChannelName: ((String)->())?
2532
2633 @IBOutlet weak var tableView: UITableView!
@@ -31,7 +38,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
3138 // MARK: - Output -
3239 var onSelectChannel: (() -> Void)?
3340
34− var searchController = UISearchController(searchResultsController: nil)
41+ var searchController: UISearchController?
3542
3643 var news = NewsVC()
3744 var type: HeaderType? = .NEWS
@@ -41,6 +48,11 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
4148 override func viewDidLoad()
4249 {
4350 super.viewDidLoad()
51+
52+ let updater = TagsSuggestionController()
53+ updater.delegate = self
54+ searchController = UISearchController(searchResultsController: updater)
55+
4456 navigationItem.title = "Loading ..."
4557 tableView.refreshControl = refreshContr
4658 // Configure Refresh Control
@@ -49,8 +61,9 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
4961 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
5062 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
5163
52− // setUpSearchContr()
64+ setUpSearchContr()
5365
66+ // navigationItem.
5467 news.viewController = self
5568 news.type = type == .NEWS ? .NEWS : type!
5669 news.currChannel = channel
@@ -59,11 +72,12 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
5972 }
6073
6174 func setUpSearchContr(){
62− searchController.delegate = self
63− searchController.obscuresBackgroundDuringPresentation = false
75+ searchController?.delegate = self
76+ searchController?.obscuresBackgroundDuringPresentation = false
6477 navigationItem.searchController = searchController
6578 definesPresentationContext = true
66− searchController.searchBar.placeholder = "Search anything"
79+ searchController?.searchResultsUpdater = self
80+ searchController?.searchBar.placeholder = "Search tags"
6781 }
6882
6983 @objc func refreshPostsData( _ ff: UIRefreshControl){
@@ -76,7 +90,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
7690
7791 override func viewWillAppear(_ animated: Bool) {
7892 super.viewWillAppear(animated)
79− searchController.isActive = false
93+ searchController?.isActive = false
8094 // TODO:- display something if no posts are availiable
8195
8296 decideWhatChannelDisplay()
@@ -85,16 +99,18 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
8599 }
86100
87101 func decideWhatChannelDisplay(){
102+
88103 switch type! {
89104 case .NEWS, .NONE:
90105 if let channel = channel, let id = channel.id, id != -1 {
91106
92− Model.getChannel(with: id) { [weak self] in
107+ Model.getAnonymousChannel(by: channel) { [weak self] in
93108 self?.news.dataSourse = $0.posts
94109 self?.news.dictionary = $0.users
95110 self?.refreshContr.endRefreshing()
96111 self?.changedChannelName?(channel.name)
97112 }
113+
98114 } else {
99115 Model.getLast { [weak self] in
100116 self?.news.dataSourse = $0.posts
@@ -110,6 +126,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
110126 changedChannelName?("Anonymous")
111127 }
112128 }
129+
113130 }
114131
115132 func setUpNavigationItemsforPosts(){
@@ -117,4 +134,27 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
117134 tableView.dataSource = news
118135 tableView.reloadData()
119136 }
137+
138+ func updateSearchResults(for searchController: UISearchController)
139+ {
140+ let filteredData = CompletionTree.getCompletion(tree: Model.hashTagTree!, word: searchController.searchBar.text?.lowercased() ?? "")
141+
142+ // Apply the filtered results to the search results table.
143+ if let resultsController = searchController.searchResultsController as? TagsSuggestionController {
144+ resultsController.suggestions = filteredData
145+ resultsController.tableView.reloadData()
146+ }
147+ }
148+
149+ func willPresentSearchController(_ searchController: UISearchController) {
150+ searchController.searchResultsController?.view.isHidden = false;
151+ }
152+
153+ func didPresentSearchController(_ searchController: UISearchController) {
154+ searchController.searchResultsController?.view.isHidden = false;
155+ }
156+
157+ func didDismissSearchController(_ searchController: UISearchController) {
158+ searchController.searchBar.text = ""
159+ }
120160}
GDproject/Controller/ News and channels/NewsVC.swift+9−9
@@ -91,12 +91,12 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
9191 }
9292 }
9393
94− cell.onAnonymousChannelDisplay = {
95− [weak self] (tag) in
96− Model.getAnonymousChannel(by: Model.AnonymousChannel(people: [], tags: [tag]),
97− completion: { (tuple) in self?.onChannelDidChange?(tuple) }
98− )
99− }
94+// cell.onAnonymousChannelDisplay = {
95+// [weak self] (tag) in
96+// Model.getAnonymousChannel(by: Model.AnonymousChannel(people: [], tags: [tag]),
97+// completion: { (tuple) in self?.onChannelDidChange?(tuple) }
98+// )
99+// }
100100
101101 cell.selectionStyle = .none
102102 return cell
@@ -117,13 +117,13 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
117117 // pagination
118118 if indexPath.row == cellDataSourse.count - 1 && prevLast != indexPath.row
119119 {
120− if let ch = currChannel, let id = ch.id, ch.id != -1{
120+ if let ch = currChannel, let id = ch.id, id != -1 {
121121 // check this!
122− Model.getChannel(with: id, on: 10, from: dataSourse.last?.id )
123− { [weak self] in
122+ Model.getAnonymousChannel(by: ch, exclusiveFrom: dataSourse.last?.id) { [weak self] in
124123 self?.dataSourse.append(contentsOf: $0.posts)
125124 $0.users.forEach { self?.dictionary[$0.key] = $0.value }
126125 }
126+
127127 } else {
128128 // check this!
129129 Model.getLast(on: 10, from: dataSourse.last?.id )
GDproject/Controller/ News and channels/TagsSuggestionController.swiftnew file+52
@@ -0,0 +1,52 @@
1+//
2+// AnonimousChannelController.swift
3+// GDproject
4+//
5+// Created by cstore on 20/04/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class TagsSuggestionController: UITableViewController
12+{
13+ weak var delegate: UpdateableWithChannel?
14+
15+ var suggestions = [String]()
16+ var channel: Model.Channels?
17+
18+ override func viewDidLoad()
19+ {
20+ super.viewDidLoad()
21+ if let tree = Model.hashTagTree {
22+ suggestions = CompletionTree.getCompletion(tree: tree, word: "")
23+ print(suggestions)
24+ }
25+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
26+ tableView.reloadData()
27+ }
28+
29+ override func numberOfSections(in tableView: UITableView) -> Int {
30+ return 1
31+ }
32+
33+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
34+ return suggestions.count
35+ }
36+
37+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
38+ {
39+ let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
40+ cell.textLabel?.text = suggestions[indexPath.row]
41+
42+ return cell
43+ }
44+
45+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
46+ {
47+ channel = Model.Channels(people: [], name: "\(self.suggestions[indexPath.row])", id: 0, tags: [self.suggestions[indexPath.row]])
48+
49+ delegate?.updateChannel(on: channel!)
50+ self.dismiss(animated: true)
51+ }
52+}
GDproject/Simple model/Model.swift+4−2
@@ -525,11 +525,13 @@ class Model{
525525 }
526526 }
527527 */
528− static func getAnonymousChannel(by anonymousChannel: Model.AnonymousChannel, completion: @escaping (((users:[Int: Users], posts:[Posts]))->())){
528+ static func getAnonymousChannel(by anonymousChannel: Model.Channels, exclusiveFrom: Int? = nil, completion: @escaping (((users:[Int: Users], posts:[Posts]))->())){
529529
530+ let req = GeneralRequest<Model.Channels>(limit: 10, exclusiveFrom: exclusiveFrom, request: anonymousChannel)
531+
530532 var request = URLRequest(url: channelsGetAnonURL)
531533 request.httpMethod = "POST"
532− request.httpBody = try? JSONEncoder().encode(anonymousChannel)
534+ request.httpBody = try? JSONEncoder().encode(req)
533535
534536 request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
535537 AF.request(request).response {