INRecorderController.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. //
  2. // INRecorderController.swift
  3. // Introduce
  4. //
  5. // Created by 胡志强 on 2021/11/29.
  6. // 首页
  7. import BFMaterialKit
  8. import BFRecordScreenKit
  9. import BFUIKit
  10. import Foundation
  11. import UIKit
  12. import TYAttributedLabel
  13. import BFCommonKit
  14. import BFAnalyzeKit
  15. import Photos
  16. import AppTrackingTransparency
  17. class INRecorderController: BFBaseViewController {
  18. lazy var titleL : UILabel = {
  19. let l = UILabel()
  20. l.text = "home_title".BFLocale
  21. l.textAlignment = .center
  22. l.textColor = .white
  23. l.font = UIFont.systemFont(ofSize: 36)
  24. return l
  25. }()
  26. var cUserProtocol:String = "https://weapppiccdn.yishihui.com/resources/agreements/shishuo/videoservice_\( BFLocalizedUtil.currentLanguage()).html"
  27. var cPrivacy:String = "https://weapppiccdn.yishihui.com/resources/agreements/shishuo/videoagreement_\( BFLocalizedUtil.currentLanguage()).html"
  28. lazy var camaraBtn: UIButton = {
  29. let btn = UIButton(type: .custom)
  30. btn.setImage(UIImage(named: "shot"), for: .normal)
  31. btn.setTitle("home_shoot".BFLocale, for: .normal)
  32. btn.setTitleColor(UIColor.init(white: 1, alpha: 0.5), for: .normal)
  33. btn.titleLabel?.font = UIFont.systemFont(ofSize: 17)
  34. btn.addTarget(self, action: #selector(cameraBtnAction), for: .touchUpInside)
  35. btn.eventInterval = 1
  36. return btn
  37. }()
  38. lazy var photoBtn: UIButton = {
  39. let btn = UIButton(type: .custom)
  40. btn.setImage(UIImage(named: "import"), for: .normal)
  41. btn.setTitle("home_choose".BFLocale, for: .normal)
  42. btn.setTitleColor(UIColor.init(white: 1, alpha: 0.5), for: .normal)
  43. btn.titleLabel?.font = UIFont.systemFont(ofSize: 17)
  44. btn.addTarget(self, action: #selector(addVideo), for: .touchUpInside)
  45. btn.eventInterval = 1
  46. return btn
  47. }()
  48. lazy var bgView:UIImageView = {
  49. let bgView = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
  50. bgView.contentMode = .scaleAspectFill
  51. bgView.image = UIImage(named: "homebg")
  52. return bgView
  53. }()
  54. //欢迎界面
  55. lazy var centerView:UIView = {
  56. let view = UIView.init()
  57. return view
  58. }()
  59. //欢迎界面
  60. lazy var welcomeView:UIView = {
  61. let view = UIView.init()
  62. view.backgroundColor = .white
  63. view.addCorner(corner:17)
  64. return view
  65. }()
  66. //欢迎界面背景
  67. lazy var welcomeBackView:UIView = {
  68. let view = UIView.init(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
  69. view.backgroundColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.6)
  70. return view
  71. }()
  72. lazy var welcomeTitle:UILabel = {
  73. let l = UILabel()
  74. l.text = "home_agreement_tittle".BFLocale
  75. l.textColor = .black
  76. l.font = UIFont.boldSystemFont(ofSize: 22)
  77. l.textAlignment = .center
  78. view.addSubview(l)
  79. return l
  80. }()
  81. //显示编译时间
  82. lazy var buildTimeLabel:UILabel = {
  83. let l = UILabel.init(frame: CGRect.init(x: 0, y: 120, width: cScreenWidth, height: 20))
  84. l.text = "打包时间:" + PQENVUtil.shared.ENBuildTime
  85. l.textColor = .white
  86. l.font = UIFont.boldSystemFont(ofSize: 18)
  87. l.textAlignment = .left
  88. return l
  89. }()
  90. lazy var protocolLab: TYAttributedLabel = {
  91. let protocolLab = TYAttributedLabel()
  92. protocolLab.highlightedLinkBackgroundColor = UIColor.clear
  93. protocolLab.backgroundColor = UIColor.clear
  94. protocolLab.numberOfLines = 0
  95. protocolLab.delegate = self
  96. protocolLab.font = UIFont.systemFont(ofSize: 14)
  97. protocolLab.text = "home_agreement_begin".BFLocale
  98. protocolLab.textColor = UIColor(red: 0.262, green: 0.262, blue: 0.262, alpha: 1)
  99. protocolLab.appendLink(withText: "home_agreement_service".BFLocale, linkFont: UIFont.systemFont(ofSize: 14), linkColor: UIColor.hexColor(hexadecimal: "#90a9d2"), underLineStyle:CTUnderlineStyle(), linkData: cUserProtocol)
  100. protocolLab.appendLink(withText: "home_agreement_privacy".BFLocale, linkFont: UIFont.systemFont(ofSize: 14), linkColor: UIColor.hexColor(hexadecimal: "#90a9d2"), underLineStyle:CTUnderlineStyle(), linkData: cPrivacy)
  101. protocolLab.appendLink(withText: "\("home_agreement_remarks".BFLocale)\n\n", linkFont: UIFont.systemFont(ofSize: 14), linkColor: UIColor.hexColor(hexadecimal: "#434343"), underLineStyle: CTUnderlineStyle(), linkData: nil)
  102. protocolLab.appendLink(withText: "home_agreement_prompt".BFLocale, linkFont: UIFont.systemFont(ofSize: 14), linkColor: UIColor(red: 0.262, green: 0.262, blue: 0.262, alpha: 1), underLineStyle: CTUnderlineStyle(), linkData: nil)
  103. protocolLab.textAlignment = CTTextAlignment.left
  104. return protocolLab
  105. }()
  106. lazy var doneBtn:UIButton = {
  107. let doneBtn = UIButton()
  108. doneBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#389AFF")
  109. doneBtn.setTitle("option_accept".BFLocale, for: .normal)
  110. doneBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
  111. doneBtn.addTarget(self, action: #selector(doneAction), for: .touchUpInside)
  112. doneBtn.addCorner(corner: 4)
  113. return doneBtn
  114. }()
  115. lazy var cancleBtn:UIButton = {
  116. let cancleBtn = UIButton()
  117. cancleBtn.backgroundColor = UIColor.clear
  118. cancleBtn.setTitle("option_refuse".BFLocale, for: .normal)
  119. cancleBtn.setTitleColor( UIColor(red: 0.262, green: 0.262, blue: 0.262, alpha: 1), for: .normal)
  120. cancleBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
  121. cancleBtn.addTarget(self, action: #selector(cancleAction), for: .touchUpInside)
  122. cancleBtn.addCorner(corner: 4)
  123. return cancleBtn
  124. }()
  125. lazy var settingBtn: UIButton = {
  126. let btn = UIButton(type: .custom)
  127. btn.setImage(UIImage(named: "set"), for: .normal)
  128. btn.addTarget(self, action: #selector(settingBtnAction), for: .touchUpInside)
  129. return btn
  130. }()
  131. override func viewWillAppear(_ animated: Bool) {
  132. super.viewWillAppear(animated)
  133. hiddenNavigation()
  134. // 曝光上报
  135. BFEventTrackAdaptor.baseReportUpload(businessType: .bt_pageView, objectType: nil, pageSource: .sp_homePage, commonParams: commonParams())
  136. }
  137. // MARK: - 生命周期
  138. override func viewDidAppear(_ animated: Bool) {
  139. super.viewDidAppear(animated)
  140. // 清理cache文件
  141. clearCacheFile(at: exportVideosDirectory)
  142. clearCacheFile(at: exportAudiosDirectory)
  143. clearCacheFile(at: recordVideosDirectory)
  144. }
  145. override func viewDidLoad() {
  146. super.viewDidLoad()
  147. view.backgroundColor = .black
  148. view.addSubview(bgView)
  149. if(PQENVUtil.shared.channel == "Development"){
  150. view.addSubview(buildTimeLabel)
  151. }
  152. view.addSubview(centerView)
  153. view.addSubview(settingBtn)
  154. centerView.snp.makeConstraints { make in
  155. make.width.equalToSuperview()
  156. make.height.equalTo(209)
  157. make.center.equalToSuperview()
  158. }
  159. settingBtn.snp.makeConstraints { make in
  160. make.width.height.equalTo(40)
  161. make.right.equalToSuperview().offset(-10)
  162. make.top.equalToSuperview().offset(51)
  163. }
  164. centerView.addSubview(titleL)
  165. centerView.addSubview(camaraBtn)
  166. centerView.addSubview(photoBtn)
  167. camaraBtn.snp.makeConstraints { make in
  168. make.width.equalTo(130)
  169. make.height.equalTo(180)
  170. make.centerX.equalToSuperview().offset(-80)
  171. make.centerY.equalToSuperview()
  172. }
  173. photoBtn.snp.makeConstraints { make in
  174. make.left.equalTo(camaraBtn.snp.right).offset(30)
  175. make.width.height.centerY.equalTo(camaraBtn)
  176. }
  177. titleL.snp.makeConstraints { make in
  178. make.bottom.equalTo(photoBtn.snp.top).offset(-80)
  179. make.centerX.equalToSuperview()
  180. make.width.equalTo(cScreenWidth)
  181. make.height.equalTo(40)
  182. }
  183. //欢迎界面
  184. if(getUserDefaults(key: "welcomeViewisshow") == nil){
  185. view.addSubview(welcomeBackView)
  186. welcomeBackView.addSubview(welcomeView)
  187. welcomeView.addSubview(protocolLab)
  188. welcomeView.addSubview(welcomeTitle)
  189. welcomeView.addSubview(doneBtn)
  190. welcomeView.addSubview(cancleBtn)
  191. welcomeView.snp.makeConstraints{ make in
  192. make.center.equalToSuperview()
  193. make.width.equalTo(280)
  194. make.height.equalTo(350)
  195. }
  196. welcomeTitle.snp.makeConstraints{ make in
  197. make.centerX.equalToSuperview()
  198. make.width.equalToSuperview()
  199. make.top.equalToSuperview().offset(30)
  200. make.height.equalTo(31)
  201. }
  202. protocolLab.snp.makeConstraints{ make in
  203. make.centerX.equalToSuperview()
  204. make.width.equalTo(230)
  205. make.top.equalTo(welcomeTitle.snp.bottom).offset(16)
  206. make.height.equalTo(140)
  207. }
  208. doneBtn.snp.makeConstraints { make in
  209. make.centerX.equalToSuperview()
  210. make.width.equalTo(230)
  211. make.height.equalTo(47)
  212. make.top.equalTo(protocolLab.snp.bottom).offset(30)
  213. }
  214. cancleBtn.snp.makeConstraints { make in
  215. make.centerX.equalToSuperview()
  216. make.width.equalTo(230)
  217. make.height.equalTo(20)
  218. make.top.equalTo(doneBtn.snp.bottom).offset(17)
  219. }
  220. }
  221. // add by ak 取 nsl token
  222. BFRecordScreenViewModel.getNlsAccessToken { [weak self] token, appkey in
  223. BFLog(message: "提前取一次nls appkey is \(appkey), token is \(token)")
  224. }
  225. }
  226. override func viewDidLayoutSubviews() {
  227. var btn = camaraBtn
  228. btn.imageEdgeInsets = UIEdgeInsets(top: -btn.titleLabel!.height - 2, left: 0, bottom: 0, right: -btn.titleLabel!.width)
  229. btn.titleEdgeInsets = UIEdgeInsets(top: btn.imageView!.height + 40, left: -btn.imageView!.width, bottom: 0, right: 0)
  230. btn = photoBtn
  231. btn.imageEdgeInsets = UIEdgeInsets(top: -btn.titleLabel!.height - 2, left: 0, bottom: 0, right: -btn.titleLabel!.width)
  232. btn.titleEdgeInsets = UIEdgeInsets(top: btn.imageView!.height + 40, left: -btn.imageView!.width, bottom: 0, right: 0)
  233. }
  234. @objc func doneAction() {
  235. welcomeBackView.isHidden = true
  236. saveUserDefaults(key: "welcomeViewisshow", value: "true")
  237. }
  238. @objc func cancleAction() {
  239. welcomeBackView.isHidden = true
  240. exit(-1)
  241. }
  242. override func didReceiveMemoryWarning() {
  243. super.didReceiveMemoryWarning()
  244. // Dispose of any resources that can be recreated.
  245. }
  246. @objc func addVideo() {
  247. if (getUserDefaults(key: "welcomeViewisshow") == nil) {
  248. welcomeBackView.isHidden = false
  249. }else{
  250. let vc = INPhotoVideosController()
  251. vc.hidesBottomBarWhenPushed = true
  252. navigationController?.pushViewController(vc, animated: true)
  253. // 按钮点击
  254. BFEventTrackAdaptor.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_addVideoButton, pageSource: .sp_homePage,extParams:nil,commonParams: commonParams())
  255. }
  256. }
  257. @objc func cameraBtnAction() {
  258. if chechCameraPromission() {
  259. let vc = INIntroduceController()
  260. let ass = PHAsset()
  261. ass.title = "record.camera"
  262. vc.assets = [ass]
  263. navigationController?.pushViewController(vc, animated: true)
  264. }
  265. BFEventTrackAdaptor.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shootVideoButton, pageSource: .sp_homePage,extParams:nil,commonParams: commonParams())
  266. }
  267. @objc func settingBtnAction() {
  268. let vc = INRecorderSetting()
  269. navigationController?.pushViewController(vc, animated: true)
  270. }
  271. func chechCameraPromission() -> Bool{
  272. if AVCaptureDevice.authorizationStatus(for: AVMediaType.video) != AVAuthorizationStatus.denied {
  273. return true
  274. }else {
  275. cShowHUB(superView: nil, msg: "record_fail_camera".BFLocale)
  276. return false
  277. }
  278. }
  279. @objc func protocolClick(sender:UIButton) {
  280. var link: String?
  281. if sender.tag == 1 {
  282. link = cUserProtocol
  283. } else {
  284. link = cPrivacy
  285. }
  286. if link != nil, (link?.count ?? 0) > 0 {
  287. let detail = BFBaseWebViewController()
  288. detail.baseUrl = link
  289. self.navigationController?.pushViewController(detail, animated: true)
  290. }
  291. }
  292. //
  293. func clearCacheFile(at folderPath: String) {
  294. if let files = try? FileManager.default.contentsOfDirectory(atPath: folderPath) {
  295. for file in files {
  296. do {
  297. try FileManager.default.removeItem(at: URL(fileURLWithPath: folderPath).appendingPathComponent(file))
  298. } catch {
  299. BFLog(1, message: "\(error), \(file)")
  300. }
  301. }
  302. }
  303. }
  304. }
  305. //点击超链接回调
  306. extension INRecorderController: TYAttributedLabelDelegate {
  307. func attributedLabel(_: TYAttributedLabel!, textStorageClicked textStorage: TYTextStorageProtocol!, at _: CGPoint) {
  308. let link: String? = (textStorage as? TYLinkTextStorage)?.linkData as? String ?? ""
  309. if link != nil, (link?.count ?? 0) > 0 {
  310. let detail = BFBaseWebViewController()
  311. detail.baseUrl = link
  312. self.navigationController?.pushViewController(detail, animated: true)
  313. }
  314. }
  315. }