|
@@ -54,48 +54,9 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
return navBarView
|
|
|
}()
|
|
|
|
|
|
- // ###################################### cusStackView ######################################
|
|
|
- lazy var cusStackView: TSCustomStackView = {
|
|
|
- let cusStackView = TSCustomStackView(axis: .vertical, spacing: 0)
|
|
|
- cusStackView.scrollView.isScrollEnabled = true
|
|
|
- return cusStackView
|
|
|
- }()
|
|
|
-
|
|
|
- // ###################################### 上传图片 ######################################
|
|
|
- lazy var uploadView: TSPTPUploadView = {
|
|
|
- let uploadView = TSPTPUploadView()
|
|
|
- uploadView.clickHandel = { [weak self] index in
|
|
|
- guard let self = self else { return }
|
|
|
|
|
|
- if index == 0 { // 删除
|
|
|
- viewModel.upLoadImage = nil
|
|
|
- uploadView.upLoadImage = nil
|
|
|
- } else { // 添加
|
|
|
- if TSAIListHintBaseVC.isShowUploadImageHint {
|
|
|
- TSAIListHintBaseVC.isShowUploadImageHint = false
|
|
|
- presentModalHintVC()
|
|
|
- } else {
|
|
|
- pickSinglePhoto()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return uploadView
|
|
|
- }()
|
|
|
-
|
|
|
- func pickSinglePhoto() {
|
|
|
- photoPickerManager.pickCustomSinglePhoto { [weak self] image, errorString in
|
|
|
- guard let self = self else { return }
|
|
|
- if let errorString = errorString {
|
|
|
- TSToastShared.showToast(text: errorString)
|
|
|
- } else {
|
|
|
- viewModel.upLoadImage = image
|
|
|
- uploadView.upLoadImage = image
|
|
|
- }
|
|
|
- kDelayMainShort {
|
|
|
- self.photoPickerManager.dismissPageVC()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ lazy var cusStackView: TSCustomStackView = creatStackView()
|
|
|
+ lazy var uploadView: TSPTPUploadView = creatUploadView()//上传图片
|
|
|
|
|
|
// ###################################### 选择风格 ######################################
|
|
|
lazy var selectStyleView: TSPTPSelectStyleView = {
|
|
@@ -113,144 +74,15 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
}()
|
|
|
|
|
|
// ###################################### 输入框 ######################################
|
|
|
- lazy var customTextView: TSPlaceholderTextView = {
|
|
|
- let customTextView = TSPlaceholderTextView(
|
|
|
- placeholder: "Describe how you want to transform".localized,
|
|
|
- text: "",
|
|
|
- font: .font(size: 14),
|
|
|
- textColor: .white,
|
|
|
- backgroundColor: .clear
|
|
|
- )
|
|
|
- customTextView.delegate = self
|
|
|
- customTextView.returnKeyType = .done
|
|
|
- return customTextView
|
|
|
- }()
|
|
|
-
|
|
|
- lazy var clearBtn: TSUIExpandedTouchButton = {
|
|
|
- let clearBtn = TSUIExpandedTouchButton()
|
|
|
- clearBtn.setUpButton(
|
|
|
- image: UIImage(named: "clear_text")
|
|
|
- ) { [weak self] in
|
|
|
- guard let self = self else { return }
|
|
|
- customTextView.text = ""
|
|
|
- textViewDidChange(customTextView)
|
|
|
- }
|
|
|
- clearBtn.isHidden = true
|
|
|
- return clearBtn
|
|
|
- }()
|
|
|
-
|
|
|
+ lazy var customTextView: TSPlaceholderTextView = creatCustomTextView()
|
|
|
+ lazy var clearBtn: TSUIExpandedTouchButton = creatClearBtn()
|
|
|
var promptTextViewH: CGFloat = 96.0
|
|
|
- lazy var promptTextView: UIView = {
|
|
|
- let promptTextView = UIView()
|
|
|
- promptTextView.isHidden = true
|
|
|
- promptTextView.clipsToBounds = true
|
|
|
- let bgView = UIView()
|
|
|
- bgView.backgroundColor = "#333333".uiColor
|
|
|
- bgView.cornerRadius = 16.0
|
|
|
- promptTextView.addSubview(bgView)
|
|
|
- bgView.snp.makeConstraints { make in
|
|
|
- make.edges.equalTo(UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16))
|
|
|
- }
|
|
|
-
|
|
|
- bgView.addSubview(customTextView)
|
|
|
- bgView.addSubview(clearBtn)
|
|
|
-
|
|
|
- customTextView.snp.makeConstraints { make in
|
|
|
- make.centerY.equalToSuperview()
|
|
|
- make.leading.equalTo(12.0)
|
|
|
- make.top.equalTo(12.0)
|
|
|
- make.bottom.equalTo(-12.0)
|
|
|
- make.trailing.equalTo(-20)
|
|
|
- }
|
|
|
-
|
|
|
- clearBtn.snp.makeConstraints { make in
|
|
|
- make.width.height.equalTo(16.0)
|
|
|
- make.trailing.equalTo(-12)
|
|
|
- make.bottom.equalTo(-12.0)
|
|
|
- }
|
|
|
-
|
|
|
- return promptTextView
|
|
|
- }()
|
|
|
+ lazy var promptTextView: UIView = creatPromptTextView()
|
|
|
|
|
|
// ###################################### 集合视图 ######################################
|
|
|
private var collectionViewObserver: CollectionViewObserver!
|
|
|
let collectionViewBtootm: CGFloat = 80
|
|
|
- lazy var collectionComponent: TSCollectionViewComponent = {
|
|
|
- let layout = UICollectionViewFlowLayout()
|
|
|
- let cp = TSCollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [:])
|
|
|
- cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: collectionViewBtootm, right: 0)
|
|
|
- cp.collectionView.isScrollEnabled = false
|
|
|
-
|
|
|
- // 禁用自动 contentInset 调整
|
|
|
- if #available(iOS 11.0, *) {
|
|
|
- cp.collectionView.contentInsetAdjustmentBehavior = .never
|
|
|
- } else {
|
|
|
- automaticallyAdjustsScrollViewInsets = false
|
|
|
- }
|
|
|
-
|
|
|
- cp.sectionActionHandler = { [weak self] cellCp, _ in
|
|
|
- guard let self = self else { return }
|
|
|
- if let cmd = cellCp as? String {
|
|
|
- if cmd == "delete" {
|
|
|
- showCustomAlert(message: "Are you sure to delete all histories?".localized, rightActionString: "Delete All".localized , deleteHandler: {
|
|
|
- self.viewModel.removeAllHistoryList()
|
|
|
- self.updataCollectionView()
|
|
|
- })
|
|
|
- } else if cmd == "more" {
|
|
|
- let historyVC = TSPTPHistoryVC(style: .ptp)
|
|
|
- kPushVC(target: self, modelVC: historyVC)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- cp.itemActionHandler = { [weak self] object, indexPath in
|
|
|
- guard let self = self else { return }
|
|
|
- // 删除过期的任务
|
|
|
- if let cmd = object as? String{
|
|
|
- if cmd == "delete_task_expired" {
|
|
|
- if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel,
|
|
|
- let currentActionInfoModel = sections.items.safeObj(At: indexPath.item) {
|
|
|
- TSRMShared.ptpDBHistory.deleteListModel(id: currentActionInfoModel.dataModel.id)
|
|
|
- updataCollectionView()
|
|
|
- }
|
|
|
- }else if cmd == "delete_task_sensitive" {
|
|
|
- showDeleteErrorAlert(message: "Delete this error history?".localized, deleteHandler: { [weak self] in
|
|
|
- guard let self = self else { return }
|
|
|
- if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel,
|
|
|
- let currentActionInfoModel = sections.items.safeObj(At: indexPath.item) {
|
|
|
- TSRMShared.ptpDBHistory.deleteListModel(id: currentActionInfoModel.dataModel.id)
|
|
|
- updataCollectionView()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- cp.itemDidSelectedHandler = { [weak self] _, indexPath in
|
|
|
- guard let self = self else { return }
|
|
|
- if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel,
|
|
|
- let dataModel = sections.items.safeObj(At: indexPath.item)?.dataModel {
|
|
|
- var dataModelArray: [TSActionInfoModel] = []
|
|
|
- for itemModel in sections.items {
|
|
|
- if itemModel.dataModel.status == "success" || itemModel.dataModel.modelType == .example {
|
|
|
- dataModelArray.append(itemModel.dataModel)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let browseVC = TSAIPhotoBrowseVC()
|
|
|
- browseVC.dataModelArray = dataModelArray
|
|
|
- browseVC.currentIndex = dataModelArray.firstIndex(of: dataModel) ?? 0
|
|
|
- browseVC.deleteComplete = { [weak self] deleteModel in
|
|
|
- guard let self = self else { return }
|
|
|
- TSRMShared.ptpDBHistory.deleteListModel(id: deleteModel.id)
|
|
|
- updataCollectionView()
|
|
|
- }
|
|
|
- kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
|
|
|
- }
|
|
|
- }
|
|
|
- cp.collectionView.keyboardDismissMode = .interactive
|
|
|
- return cp
|
|
|
- }()
|
|
|
+ lazy var collectionComponent: TSCollectionViewComponent = creatCollectionComponent()
|
|
|
|
|
|
// ###################################### Button ######################################
|
|
|
lazy var creatBtnView: TSAppBtnView = {
|
|
@@ -362,108 +194,8 @@ class TSPTPInputVC: TSBaseVC {
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(autoSelectImageToImageStyle(notify:)), name: .schemeImageToImageStylePick, object: nil)
|
|
|
}
|
|
|
-
|
|
|
- func updataCollectionView() {
|
|
|
- viewModel.updateRecentData()
|
|
|
- collectionComponent.clear()
|
|
|
- collectionComponent.reloadView(with: viewModel.colDataArray)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
-extension TSPTPInputVC {
|
|
|
- func presentModalHintVC() {
|
|
|
- hintBaseVC = TSAIListHintBaseVC(config: .defaultConfig) { [weak self] image in
|
|
|
- guard let self = self else { return }
|
|
|
- viewModel.upLoadImage = image
|
|
|
- uploadView.upLoadImage = image
|
|
|
- hintBaseVC.dismissPageVC()
|
|
|
- }
|
|
|
- kPresentModalVC(target: self, modelVC: hintBaseVC, transitionStyle: .crossDissolve)
|
|
|
- }
|
|
|
-
|
|
|
- func setUpCusStackView() {
|
|
|
-// let uploadPhotoTitleView = TSTitleView.creatTitleView(title: "Upload Photo".localized, subTitle: "")
|
|
|
-// cusStackView.addSubviewToStack(uploadPhotoTitleView)
|
|
|
-// uploadPhotoTitleView.snp.makeConstraints { make in
|
|
|
-// make.height.equalTo(uploadPhotoTitleView.viewH)
|
|
|
-// make.width.equalTo(k_ScreenWidth)
|
|
|
-// }
|
|
|
-//
|
|
|
-// let hintBtn = TSUIExpandedTouchButton()
|
|
|
-// hintBtn.setUpButton(image: UIImage(named: "ptp_hint")) { [weak self] in
|
|
|
-// guard let self = self else { return }
|
|
|
-// presentModalHintVC()
|
|
|
-// }
|
|
|
-// uploadPhotoTitleView.contentView.addSubview(hintBtn)
|
|
|
-// hintBtn.snp.makeConstraints { make in
|
|
|
-// make.centerY.equalToSuperview().offset(kSectionTitleViewCenterYOffset)
|
|
|
-// make.trailing.equalTo(-16)
|
|
|
-// make.width.height.equalTo(16)
|
|
|
-// }
|
|
|
-
|
|
|
- cusStackView.addSpacing(length: 10)
|
|
|
- cusStackView.addSubviewToStack(uploadView)
|
|
|
- uploadView.snp.makeConstraints { make in
|
|
|
- make.height.equalTo(uploadView.viewH)
|
|
|
- make.width.equalTo(k_ScreenWidth)
|
|
|
- }
|
|
|
-
|
|
|
- let selectStyleTitleView = TSTitleMoreView()
|
|
|
- selectStyleTitleView.setTitle(title: "Select Style".localized) { [weak self] in
|
|
|
- guard let self = self else { return }
|
|
|
- let selectStyleVC = TSGennertatorSelectStyleVC()
|
|
|
- selectStyleVC.currentIndexPath = IndexPath(item: viewModel.selectedStyleIndex, section: 0)
|
|
|
- selectStyleVC.dataArray = viewModel.ptpStyleModels
|
|
|
- selectStyleVC.selectedValueBlock = { [weak self] indexPath, _ in
|
|
|
- guard let self = self else { return }
|
|
|
- selectStyleView.collectionView(selectStyleView.styleCollectionView, didSelectItemAt: indexPath)
|
|
|
- }
|
|
|
- kPresentModalVC(target: self, modelVC: selectStyleVC, transitionStyle: .coverVertical)
|
|
|
- }
|
|
|
- cusStackView.addSubviewToStack(selectStyleTitleView)
|
|
|
- selectStyleTitleView.snp.makeConstraints { make in
|
|
|
- make.height.equalTo(selectStyleTitleView.viewH)
|
|
|
- make.width.equalTo(k_ScreenWidth)
|
|
|
- }
|
|
|
-
|
|
|
- cusStackView.addSubviewToStack(selectStyleView)
|
|
|
- selectStyleView.snp.makeConstraints { make in
|
|
|
- make.height.equalTo(selectStyleView.viewH)
|
|
|
- make.width.equalTo(k_ScreenWidth)
|
|
|
- }
|
|
|
-
|
|
|
- cusStackView.addSubviewToStack(promptTextView, length: promptTextViewH)
|
|
|
-
|
|
|
- promptTextView.isHidden = !viewModel.selectedPTPStyleModel.input
|
|
|
-
|
|
|
- cusStackView.addSubviewToStack(collectionComponent.collectionView)
|
|
|
- collectionComponent.collectionView.snp.makeConstraints { make in
|
|
|
- make.height.equalTo(0)
|
|
|
- make.width.equalTo(k_ScreenWidth)
|
|
|
- }
|
|
|
-
|
|
|
- cusStackView.addSpacing(length: collectionViewBtootm)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension TSPTPInputVC: UITextViewDelegate {
|
|
|
- // 实现 UITextViewDelegate 协议方法,控制 return 键行为
|
|
|
- func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
|
|
- if text == "\n" {
|
|
|
- // 当输入为换行符(即按下 return 键)时,执行相应操作
|
|
|
- // sendBolck?(textView.text)
|
|
|
- clickView()
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- func textViewDidChange(_ textView: UITextView) {
|
|
|
- clearBtn.isHidden = textView.text.count <= 0
|
|
|
- viewModel.selectedPTPStyleModel.inputText = textView.text
|
|
|
- viewModel.gennerateChange()
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
extension TSPTPInputVC {
|
|
|
@objc func vipInfoChanged() {
|
|
@@ -531,37 +263,7 @@ extension TSPTPInputVC {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-extension TSPTPInputVC {
|
|
|
- @objc func keyboardWillShow(_ notification: Notification) {
|
|
|
- guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
|
|
|
- let scrollView = cusStackView.scrollView
|
|
|
- let keyboardHeight = keyboardFrame.height - view.safeAreaInsets.bottom
|
|
|
- let textViewFrame = scrollView.convert(customTextView.frame, from: customTextView.superview)
|
|
|
- let scrollDistance = textViewFrame.maxY - (scrollView.bounds.height - keyboardHeight)
|
|
|
- let y = scrollDistance
|
|
|
- scrollView.setContentOffset(CGPoint(x: 0, y: y), animated: true)
|
|
|
- }
|
|
|
-
|
|
|
- // MARK: - 键盘隐藏时恢复
|
|
|
|
|
|
- @objc private func keyboardWillHide(_ notification: Notification) {
|
|
|
- cusStackView.scrollView.contentOffset = CGPoint(x: 0, y: 0)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension TSPTPInputVC {
|
|
|
- func updateTextFiledView() {
|
|
|
- if viewModel.selectedPTPStyleModel.input {
|
|
|
- promptTextView.isHidden = false
|
|
|
- } else {
|
|
|
- promptTextView.isHidden = true
|
|
|
- }
|
|
|
-
|
|
|
- UIView.animate(withDuration: 0.3) {
|
|
|
- self.cusStackView.layoutIfNeeded()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
extension TSPTPInputVC {
|
|
|
@objc func autoSelectImageToImageStyle(notify: Notification) {
|