INRecorderController.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. lazy var addwxBtn: UIButton = {
  132. let btn = UIButton(type: .custom)
  133. btn.setImage(UIImage(named: "addwx"), for: .normal)
  134. btn.addTarget(self, action: #selector(addwxAction), for: .touchUpInside)
  135. return btn
  136. }()
  137. override func viewWillAppear(_ animated: Bool) {
  138. super.viewWillAppear(animated)
  139. hiddenNavigation()
  140. // 曝光上报
  141. BFEventTrackAdaptor.baseReportUpload(businessType: .bt_pageView, objectType: nil, pageSource: .sp_homePage, commonParams: commonParams())
  142. }
  143. // MARK: - 生命周期
  144. override func viewDidAppear(_ animated: Bool) {
  145. super.viewDidAppear(animated)
  146. // 清理cache文件
  147. clearCacheFile(at: exportVideosDirectory)
  148. clearCacheFile(at: exportAudiosDirectory)
  149. clearCacheFile(at: recordVideosDirectory)
  150. }
  151. override func viewDidLoad() {
  152. super.viewDidLoad()
  153. view.backgroundColor = .black
  154. view.addSubview(bgView)
  155. if(PQENVUtil.shared.channel == "Development"){
  156. view.addSubview(buildTimeLabel)
  157. }
  158. view.addSubview(centerView)
  159. view.addSubview(addwxBtn)
  160. view.addSubview(settingBtn)
  161. centerView.snp.makeConstraints { make in
  162. make.width.equalToSuperview()
  163. make.height.equalTo(209)
  164. make.center.equalToSuperview()
  165. }
  166. addwxBtn.snp.makeConstraints { make in
  167. make.height.equalTo(40)
  168. make.width.equalTo(119)
  169. make.right.equalTo(-10)
  170. make.top.equalTo(51)
  171. }
  172. settingBtn.snp.makeConstraints { make in
  173. make.width.height.equalTo(40)
  174. make.left.equalTo(10)
  175. make.top.equalTo(51)
  176. }
  177. centerView.addSubview(titleL)
  178. centerView.addSubview(camaraBtn)
  179. centerView.addSubview(photoBtn)
  180. camaraBtn.snp.makeConstraints { make in
  181. make.width.equalTo(130)
  182. make.height.equalTo(180)
  183. make.centerX.equalToSuperview().offset(-80)
  184. make.centerY.equalToSuperview()
  185. }
  186. photoBtn.snp.makeConstraints { make in
  187. make.left.equalTo(camaraBtn.snp.right).offset(30)
  188. make.width.height.centerY.equalTo(camaraBtn)
  189. }
  190. titleL.snp.makeConstraints { make in
  191. make.bottom.equalTo(photoBtn.snp.top).offset(-80)
  192. make.centerX.equalToSuperview()
  193. make.width.equalTo(cScreenWidth)
  194. make.height.equalTo(40)
  195. }
  196. //欢迎界面
  197. if(getUserDefaults(key: "welcomeViewisshow") == nil){
  198. view.addSubview(welcomeBackView)
  199. welcomeBackView.addSubview(welcomeView)
  200. welcomeView.addSubview(protocolLab)
  201. welcomeView.addSubview(welcomeTitle)
  202. welcomeView.addSubview(doneBtn)
  203. welcomeView.addSubview(cancleBtn)
  204. welcomeView.snp.makeConstraints{ make in
  205. make.center.equalToSuperview()
  206. make.width.equalTo(280)
  207. make.height.equalTo(350)
  208. }
  209. welcomeTitle.snp.makeConstraints{ make in
  210. make.centerX.equalToSuperview()
  211. make.width.equalToSuperview()
  212. make.top.equalToSuperview().offset(30)
  213. make.height.equalTo(31)
  214. }
  215. protocolLab.snp.makeConstraints{ make in
  216. make.centerX.equalToSuperview()
  217. make.width.equalTo(230)
  218. make.top.equalTo(welcomeTitle.snp.bottom).offset(16)
  219. make.height.equalTo(140)
  220. }
  221. doneBtn.snp.makeConstraints { make in
  222. make.centerX.equalToSuperview()
  223. make.width.equalTo(230)
  224. make.height.equalTo(47)
  225. make.top.equalTo(protocolLab.snp.bottom).offset(30)
  226. }
  227. cancleBtn.snp.makeConstraints { make in
  228. make.centerX.equalToSuperview()
  229. make.width.equalTo(230)
  230. make.height.equalTo(20)
  231. make.top.equalTo(doneBtn.snp.bottom).offset(17)
  232. }
  233. }
  234. // add by ak 取 nsl token
  235. BFRecordScreenViewModel.getNlsAccessToken { [weak self] token, appkey in
  236. BFLog(message: "提前取一次nls appkey is \(appkey), token is \(token)")
  237. }
  238. }
  239. override func viewDidLayoutSubviews() {
  240. var btn = camaraBtn
  241. btn.imageEdgeInsets = UIEdgeInsets(top: -btn.titleLabel!.height - 2, left: 0, bottom: 0, right: -btn.titleLabel!.width)
  242. btn.titleEdgeInsets = UIEdgeInsets(top: btn.imageView!.height + 40, left: -btn.imageView!.width, bottom: 0, right: 0)
  243. btn = photoBtn
  244. btn.imageEdgeInsets = UIEdgeInsets(top: -btn.titleLabel!.height - 2, left: 0, bottom: 0, right: -btn.titleLabel!.width)
  245. btn.titleEdgeInsets = UIEdgeInsets(top: btn.imageView!.height + 40, left: -btn.imageView!.width, bottom: 0, right: 0)
  246. }
  247. @objc func doneAction() {
  248. welcomeBackView.isHidden = true
  249. saveUserDefaults(key: "welcomeViewisshow", value: "true")
  250. }
  251. @objc func cancleAction() {
  252. welcomeBackView.isHidden = true
  253. exit(-1)
  254. }
  255. override func didReceiveMemoryWarning() {
  256. super.didReceiveMemoryWarning()
  257. // Dispose of any resources that can be recreated.
  258. }
  259. @objc func addVideo() {
  260. if (getUserDefaults(key: "welcomeViewisshow") == nil) {
  261. welcomeBackView.isHidden = false
  262. }else{
  263. let vc = INPhotoVideosController()
  264. vc.hidesBottomBarWhenPushed = true
  265. navigationController?.pushViewController(vc, animated: true)
  266. // 按钮点击
  267. BFEventTrackAdaptor.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_addVideoButton, pageSource: .sp_homePage,extParams:nil,commonParams: commonParams())
  268. }
  269. }
  270. @objc func cameraBtnAction() {
  271. if chechCameraPromission() {
  272. let vc = INIntroduceController()
  273. let ass = PHAsset()
  274. ass.title = "record.camera"
  275. vc.assets = [ass]
  276. navigationController?.pushViewController(vc, animated: true)
  277. }
  278. BFEventTrackAdaptor.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shootVideoButton, pageSource: .sp_homePage,extParams:nil,commonParams: commonParams())
  279. }
  280. @objc func settingBtnAction() {
  281. let vc = INRecorderSetting()
  282. navigationController?.pushViewController(vc, animated: true)
  283. }
  284. @objc func addwxAction(){
  285. let alertv = UIAlertController(title: "添加微信好友", message: "\n遇到问题?功能建议?真诚期待和你聊天,请加微信 cjz_0216", preferredStyle: .alert)
  286. let sureAction = UIAlertAction(title: "复制微信号", style: .default, handler: { action in
  287. UIPasteboard.general.string = "cjz_0216"
  288. cShowHUB(superView: nil, msg: "已复制到剪切板")
  289. })
  290. sureAction.setValue(UIColor.hexColor(hexadecimal:"0x389AFF"), forKey: "_titleTextColor")
  291. alertv.addAction(sureAction)
  292. self.present(alertv, animated: true, completion: nil)
  293. }
  294. func chechCameraPromission() -> Bool{
  295. if AVCaptureDevice.authorizationStatus(for: AVMediaType.video) != AVAuthorizationStatus.denied {
  296. return true
  297. }else {
  298. cShowHUB(superView: nil, msg: "record_fail_camera".BFLocale)
  299. return false
  300. }
  301. }
  302. @objc func protocolClick(sender:UIButton) {
  303. var link: String?
  304. if sender.tag == 1 {
  305. link = cUserProtocol
  306. } else {
  307. link = cPrivacy
  308. }
  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. //
  316. func clearCacheFile(at folderPath: String) {
  317. if let files = try? FileManager.default.contentsOfDirectory(atPath: folderPath) {
  318. for file in files {
  319. do {
  320. try FileManager.default.removeItem(at: URL(fileURLWithPath: folderPath).appendingPathComponent(file))
  321. } catch {
  322. BFLog(1, message: "\(error), \(file)")
  323. }
  324. }
  325. }
  326. }
  327. }
  328. //点击超链接回调
  329. extension INRecorderController: TYAttributedLabelDelegate {
  330. func attributedLabel(_: TYAttributedLabel!, textStorageClicked textStorage: TYTextStorageProtocol!, at _: CGPoint) {
  331. let link: String? = (textStorage as? TYLinkTextStorage)?.linkData as? String ?? ""
  332. if link != nil, (link?.count ?? 0) > 0 {
  333. let detail = BFBaseWebViewController()
  334. detail.baseUrl = link
  335. self.navigationController?.pushViewController(detail, animated: true)
  336. }
  337. }
  338. }