Skip to content

Commit e41ec77

Browse files
baquerchashmeetsingh
authored andcommitted
Feat: Share Skill Feature on Skill Detail View Controller (#488)
* Share Skill Feature * Show skill options * remove reportskill and shareskill button * Fix termination * Changes Done
1 parent d150cb2 commit e41ec77

File tree

8 files changed

+101
-25
lines changed

8 files changed

+101
-25
lines changed

Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ target 'Susi' do
2525
pod 'ReachabilitySwift'
2626
pod 'Localize-Swift'
2727
pod 'paper-onboarding'
28+
pod 'FTPopOverMenu_Swift', '~> 0.1.3'
2829
shared_pods
2930
end
3031

Podfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PODS:
22
- Alamofire (4.7.2)
33
- BouncyLayout (2.1.0)
44
- Fakery (3.3.0)
5+
- FTPopOverMenu_Swift (0.1.3)
56
- Ji (2.1.0):
67
- Ji/Ji (= 2.1.0)
78
- Ji/Ji (2.1.0):
@@ -37,6 +38,7 @@ DEPENDENCIES:
3738
- Alamofire (~> 4.7)
3839
- BouncyLayout
3940
- Fakery (~> 3.3.0)
41+
- FTPopOverMenu_Swift (~> 0.1.3)
4042
- Kingfisher (~> 4.10.0)
4143
- Localize-Swift
4244
- M13Checkbox (from `https://github.com/Marxon13/M13Checkbox.git`, branch `swift_4_2`)
@@ -56,6 +58,7 @@ SPEC REPOS:
5658
- Alamofire
5759
- BouncyLayout
5860
- Fakery
61+
- FTPopOverMenu_Swift
5962
- Ji
6063
- Kingfisher
6164
- Localize-Swift
@@ -95,6 +98,7 @@ SPEC CHECKSUMS:
9598
Alamofire: e4fa87002c137ba2d8d634d2c51fabcda0d5c223
9699
BouncyLayout: a7955879861375cc4e88bb64d42bcf622cd2694c
97100
Fakery: 3aae11a87721c807c18c6456500d088c1230d3e5
101+
FTPopOverMenu_Swift: f67e0af3935485c1cbcc44b5c92ed530ee32d21d
98102
Ji: 21946da4e13425485ddd424edfaeeced0d80ad28
99103
Kingfisher: c148cd7b47ebde9989f6bc7c27dcaa79d81279a0
100104
Localize-Swift: c798ec9286494866f7068f85f7c71283ac5bdab4
@@ -111,6 +115,6 @@ SPEC CHECKSUMS:
111115
SwiftValidators: 660ce9ef3f0358c25c3a6154f7edc02c7d4a0578
112116
Toast-Swift: 594b5c5e5129f15438e410207e43287f027b3c00
113117

114-
PODFILE CHECKSUM: f180a406836915113d97ddd3ea7f6a12c9f36cb2
118+
PODFILE CHECKSUM: e5b547ed712df64379156640ae0c63d2467d7609
115119

116120
COCOAPODS: 1.5.3

Susi.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@
896896
"${SRCROOT}/Pods/Target Support Files/Pods-Susi/Pods-Susi-frameworks.sh",
897897
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
898898
"${BUILT_PRODUCTS_DIR}/BouncyLayout/BouncyLayout.framework",
899+
"${BUILT_PRODUCTS_DIR}/FTPopOverMenu_Swift/FTPopOverMenu_Swift.framework",
899900
"${BUILT_PRODUCTS_DIR}/Fakery/Fakery.framework",
900901
"${BUILT_PRODUCTS_DIR}/Ji/Ji.framework",
901902
"${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework",
@@ -917,6 +918,7 @@
917918
outputPaths = (
918919
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
919920
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/BouncyLayout.framework",
921+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FTPopOverMenu_Swift.framework",
920922
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Fakery.framework",
921923
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Ji.framework",
922924
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kingfisher.framework",

Susi/Controllers/SkillDetailViewController/SkillDetailVCMethods.swift

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import UIKit
1010
import Toast_Swift
11+
import FTPopOverMenu_Swift
1112

1213
extension SkillDetailViewController {
1314

@@ -130,19 +131,7 @@ extension SkillDetailViewController {
130131
}
131132

132133
}
133-
134-
func setupReportSkillButton() {
135-
if let delegate = UIApplication.shared.delegate as? AppDelegate, let _ = delegate.currentUser {
136-
view.addSubview(reportSkillButton)
137-
reportSkillButton.widthAnchor.constraint(equalToConstant: 140).isActive = true
138-
reportSkillButton.heightAnchor.constraint(equalToConstant: 32).isActive = true
139-
reportSkillButton.leftAnchor.constraint(equalTo: contentType.leftAnchor).isActive = true
140-
reportSkillButton.topAnchor.constraint(equalTo: contentType.bottomAnchor, constant: 8).isActive = true
141-
142-
reportSkillButton.addTarget(self, action: #selector(reportSkillAction), for: .touchUpInside)
143-
}
144-
}
145-
134+
146135
@objc func reportSkillAction() {
147136
let reportSkillAlert = UIAlertController(title: "Report Skill", message: "Flag as inappropriate", preferredStyle: .alert)
148137
reportSkillAlert.addTextField(configurationHandler: { (textfield: UITextField) in
@@ -186,6 +175,58 @@ extension SkillDetailViewController {
186175
}
187176
}
188177
}
178+
179+
// Share Skill Action
180+
@objc func shareSkillAction() {
181+
let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: [ControllerConstants.ShareSkill.message, URL(string: getSkillURL(Client.APIURLs.SkillURL,(skill?.group)!,(skill?.skillName)!,(skill?.language)!)) as Any], applicationActivities: nil)
182+
// For overcoming the crash in iPad
183+
activityViewController.popoverPresentationController?.sourceView = self.view
184+
activityViewController.excludedActivityTypes = [
185+
UIActivity.ActivityType.airDrop,
186+
UIActivity.ActivityType.saveToCameraRoll,
187+
UIActivity.ActivityType.openInIBooks,
188+
UIActivity.ActivityType.markupAsPDF]
189+
self.present(activityViewController, animated: true, completion: nil)
190+
191+
}
192+
193+
func skillOptionBarButton() {
194+
navigationItem.rightViews = [skillOptionButton]
195+
}
196+
197+
func ftConfig() {
198+
let config = FTConfiguration.shared
199+
config.backgoundTintColor = .white
200+
config.borderColor = .lightGray
201+
config.menuWidth = 150
202+
config.menuSeparatorColor = .lightGray
203+
config.menuRowHeight = 44
204+
config.cornerRadius = 10
205+
206+
}
207+
208+
@objc func barButtonAction(_ sender: UIBarButtonItem, event: UIEvent) {
209+
let user = UserDefaults.standard.dictionary(forKey: ControllerConstants.UserDefaultsKeys.user)
210+
if user != nil {
211+
ftConfig()
212+
let cellConfis = Array(repeating: cellConfiguration, count: menuOptionsAfterLogin.count)
213+
FTPopOverMenu.showForEvent(event: event, with: menuOptionsAfterLogin, menuImageArray: nil, cellConfigurationArray: cellConfis, done: { (selectedIndex) in
214+
if selectedIndex == 0 {
215+
self.shareSkillAction()
216+
} else {
217+
self.reportSkillAction()
218+
}
219+
})
220+
} else {
221+
ftConfig()
222+
let cellConfis = Array(repeating: cellConfiguration, count: menuOptionsBeforeLogin.count)
223+
FTPopOverMenu.showForEvent(event: event, with: menuOptionsBeforeLogin, menuImageArray: nil, cellConfigurationArray: cellConfis, done: { (selectedIndex) in
224+
if selectedIndex == 0 {
225+
self.shareSkillAction()
226+
}
227+
})
228+
}
229+
}
189230

190231
func setupFeedbackTextField() {
191232
skillFeedbackTextField.placeholderActiveColor = UIColor.skillFeedbackColor()

Susi/Controllers/SkillDetailViewController/SkillDetailViewController.swift

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import UIKit
1010
import Kingfisher
1111
import Material
12+
import FTPopOverMenu_Swift
1213

1314
class SkillDetailViewController: GeneralViewController {
1415

@@ -30,16 +31,23 @@ class SkillDetailViewController: GeneralViewController {
3031
return label
3132
}()
3233

33-
let reportSkillButton: UIButton = {
34-
let button = UIButton(type: .system)
35-
button.contentHorizontalAlignment = .left
36-
button.setTitle("Report Skill", for: .normal)
37-
button.setTitleColor(UIColor.iOSGray(), for: .normal)
38-
button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
39-
button.translatesAutoresizingMaskIntoConstraints = false
40-
41-
return button
34+
lazy var skillOptionButton: IconButton = {
35+
let sb = IconButton()
36+
sb.image = Icon.moreVertical
37+
sb.tintColor = .white
38+
sb.layer.cornerRadius = 18.0
39+
sb.addTarget(self, action: #selector(barButtonAction(_:event:)), for: .touchUpInside)
40+
return sb
41+
}()
42+
43+
lazy var cellConfiguration: FTCellConfiguration = {
44+
let cellConfig = FTCellConfiguration()
45+
cellConfig.textColor = .darkGray
46+
cellConfig.textAlignment = .left
47+
cellConfig.textFont = .systemFont(ofSize: 17)
48+
return cellConfig
4249
}()
50+
4351
var isOpenThroughShortcut = false
4452
var skill: Skill?
4553
var chatViewController: ChatViewController?
@@ -104,6 +112,13 @@ class SkillDetailViewController: GeneralViewController {
104112
UIColor.twoStarRating(),
105113
UIColor.oneStarRating()
106114
]
115+
116+
var menuOptionsAfterLogin: [String] {
117+
return ["Share Skill","Report Skill"]
118+
}
119+
var menuOptionsBeforeLogin: [String] {
120+
return ["Share Skill"]
121+
}
107122

108123
override func viewDidLoad() {
109124
super.viewDidLoad()
@@ -118,13 +133,13 @@ class SkillDetailViewController: GeneralViewController {
118133
setupFiveStarData()
119134
setupBarChart()
120135
addContentType()
121-
setupReportSkillButton()
122136
setupFeedbackTextField()
123137
}
124138

125139
override func viewWillAppear(_ animated: Bool) {
126140
super.viewWillAppear(animated)
127141
registerKeyboardNotifications()
142+
skillOptionBarButton()
128143
}
129144

130145
override func viewWillDisappear(_ animated: Bool) {
@@ -152,5 +167,9 @@ class SkillDetailViewController: GeneralViewController {
152167
ratingBackView.layer.cornerRadius = 8.0
153168
postButton.layer.cornerRadius = 4.0
154169
}
170+
171+
func getSkillURL(_ skillURL: String, _ group: String, _ skillName: String, _ language:String) -> String {
172+
return "\(skillURL)/\(group)/\(skillName)/\(language)"
173+
}
155174

156175
}

Susi/Helpers/ControllerConstants.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,17 @@ class ControllerConstants {
273273
static let reportIssueURL = "https://github.com/fossasia/susi_iOS/issues"
274274
static let licenseURL = "https://github.com/fossasia/susi_iOS/blob/master/LICENSE"
275275
}
276+
277+
struct ShareSkill {
278+
static let message = "Hey! checkout this worderful Susi Skill "
279+
}
276280

277281
struct Logout {
278282
static let title = "Logout"
279283
static let message = "Are you sure, you want to log out?"
280284
static let cancel = "Cancel"
281285
static let confirm = "Confirm"
282286
}
283-
284287
}
288+
289+

Susi/Model/Client/Constants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extension Client {
1414
static let YoutubeSearch = "https://www.googleapis.com/youtube/v3/search"
1515
static let SnowboyTrain = "https://snowboy.kitt.ai/api/v1/train/"
1616
static let SpeakerBaseURL = "http://10.0.0.1:5000"
17+
static let SkillURL = "https://skills.susi.ai"
1718
}
1819

1920
struct Methods {

Susi/Model/Skill.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class Skill: NSObject {
4444
var skillKeyName: String = ""
4545
var model: String = ""
4646
var group: String = ""
47+
var language: String = ""
48+
4749

4850
init(dictionary: [String: AnyObject], skillKey: String) {
4951
super.init()
@@ -66,6 +68,7 @@ class Skill: NSObject {
6668
skillKeyName = skillKey
6769
model = dictionary[Client.SkillListing.model] as? String ?? ""
6870
group = dictionary[Client.SkillListing.group] as? String ?? ""
71+
language = dictionary[Client.SkillListing.language] as? String ?? ""
6972
}
7073

7174
static func getAllSkill(_ skills: [String: AnyObject], _ model: String, _ group: String, _ language: String) -> [Skill] {

0 commit comments

Comments
 (0)