Browse Source

修改 bug 第一批 bug 清单

100Years 1 month ago
parent
commit
8d316850d9
17 changed files with 185 additions and 73 deletions
  1. BIN
      AIEmoji/Assets.xcassets/Tabbar/tabbar_unSelect_aichat.imageset/tabbar_unSelect_aichat@2x.png
  2. BIN
      AIEmoji/Assets.xcassets/Tabbar/tabbar_unSelect_aichat.imageset/tabbar_unSelect_aichat@3x.png
  3. BIN
      AIEmoji/Assets.xcassets/VIP/nav_vip.imageset/nav_vip@2x.png
  4. BIN
      AIEmoji/Assets.xcassets/VIP/nav_vip.imageset/nav_vip@3x.png
  5. 1 1
      AIEmoji/Business/AIChat/TSAIChatHistoryVC/TSAIChatHistoryVC.swift
  6. 45 12
      AIEmoji/Business/AIChat/TSChatViewController/TSChatInputBarVC/TSChatInputBarVC.swift
  7. 89 34
      AIEmoji/Business/AIChat/TSChatViewController/TSChatInputBarVC/TSChatInputFullScreenVC.swift
  8. 4 7
      AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController+Keyboard.swift
  9. 8 8
      AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController+SendMsg.swift
  10. 1 1
      AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController+VipView.swift
  11. 5 2
      AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController.swift
  12. 11 0
      AIEmoji/Business/AIChat/TSChatViewController/ViewModel/TSAIChatVM.swift
  13. 13 0
      AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/View/TSGenmojiGennerateCell.swift
  14. 2 2
      AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/View/TSGenmojiTextView.swift
  15. 2 2
      AIEmoji/Business/TSPurchaseMembershipVC/TSPurchaseVC.swift
  16. 1 1
      AIEmoji/Business/TSSetingVC/TSBusinessWebVC/TSBusinessWebVC.swift
  17. 3 3
      AIEmoji/Common/NetworkManager/TSNetWork/TSNetworkManager.swift

BIN
AIEmoji/Assets.xcassets/Tabbar/tabbar_unSelect_aichat.imageset/tabbar_unSelect_aichat@2x.png


BIN
AIEmoji/Assets.xcassets/Tabbar/tabbar_unSelect_aichat.imageset/tabbar_unSelect_aichat@3x.png


BIN
AIEmoji/Assets.xcassets/VIP/nav_vip.imageset/nav_vip@2x.png


BIN
AIEmoji/Assets.xcassets/VIP/nav_vip.imageset/nav_vip@3x.png


+ 1 - 1
AIEmoji/Business/AIChat/TSAIChatHistoryVC/TSAIChatHistoryVC.swift

@@ -209,7 +209,7 @@ class TSAIChatHistoryCell: SwipeCollectionViewCell {
     
     var model:TSDBAIChatList?{
         didSet{
-            if let dbMessage = model?.messages.first {
+            if let dbMessage = model?.messages.last {
                 titleLabel.text = dbMessage.kindValue
                 infoLabel.text = dbMessage.sentDate.dateTimeString
             }

+ 45 - 12
AIEmoji/Business/AIChat/TSChatViewController/TSChatInputBarVC/TSChatInputBarVC.swift

@@ -14,7 +14,7 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
     lazy var InputBarView:UIView = {
         let InputBarView = UIView()
         InputBarView.backgroundColor = "#222222".uiColor
-        InputBarView.cornerRadius = 16.0
+        InputBarView.cornerRadius = 28.0
         return InputBarView
     }()
     
@@ -24,10 +24,9 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
             if let string = textView.text {
                 sendComplete?([string])
             }
-            
-            textView.text = ""
-            textDidChange()
+            emptyInput()
         }
+        sendBtn.isEnabled = false
         return sendBtn
     }()
     
@@ -39,11 +38,13 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
             vc.sendComplete = { [weak self] date in
                 guard let self = self else { return }
                 sendComplete?(date)
+                emptyInput()
             }
             
             vc.closeComplete = { [weak self] text in
                 guard let self = self else { return }
                 textView.text = text
+                textDidChange()
                 scrollTextViewToBottom()
             }
             
@@ -53,10 +54,10 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
         return magnifyBtn
     }()
     
-    private let minHeight: CGFloat = 24
+    private let minHeight: CGFloat = 56//24
     private let maxHeight: CGFloat = 154
-    lazy var textView: UITextView = {
-        let textView = UITextView()
+    lazy var textView: TSCustomTextView = {
+        let textView = TSCustomTextView()
         textView.backgroundColor = .clear
         textView.textColor = .white
         textView.delegate = self
@@ -64,7 +65,11 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
         textView.clipsToBounds = true
         textView.isScrollEnabled = false
         textView.tintColor = .themeColor
-        textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
+        textView.returnKeyType = .send
+        textView.placeholder = "Type all necessary details".localized
+        textView.placeholderColor = .white.withAlphaComponent(0.4)
+        textView.placeholderLabel.font = .font(size: 16.0)
+        textView.textInsets = UIEdgeInsets(top: 18, left: 16, bottom: 14, right: 0)
         return textView
     }()
 
@@ -87,10 +92,10 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
         }
         
         textView.snp.makeConstraints { make in
-            make.leading.equalTo(16)
+            make.leading.equalTo(0)
             make.trailing.equalTo(-60)
-            make.top.equalTo(18)
-            make.bottom.equalTo(-14)
+            make.top.equalTo(0)
+            make.bottom.equalTo(0)
             make.height.equalTo(minHeight)
         }
         
@@ -122,6 +127,12 @@ class TSChatInputBarVC: TSBaseVC, UITextViewDelegate {
     }
 
     
+    func emptyInput() {
+        textView.text = ""
+        textDidChange()
+        magnifyBtn.isHidden = true
+    }
+    
     deinit {
         // 移除通知监听
         NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: textView)
@@ -138,8 +149,10 @@ extension TSChatInputBarVC {
 
         // 根据内容高度调整输入框的高度
         var newHeight = estimatedSize.height
-        if newHeight < minHeight {
+        if newHeight <= minHeight {
             newHeight = minHeight
+            textView.isScrollEnabled = false
+            magnifyBtn.isHidden = true
         } else if newHeight > maxHeight {
             newHeight = maxHeight
             textView.isScrollEnabled = true
@@ -148,6 +161,8 @@ extension TSChatInputBarVC {
             textView.isScrollEnabled = false
             magnifyBtn.isHidden = true
         }
+         
+        sendEnabled(enabled: textView.text.count > 0)
 
         // 更新输入框的高度
         textView.snp.updateConstraints { make in
@@ -161,3 +176,21 @@ extension TSChatInputBarVC {
     }
     
 }
+
+
+extension TSChatInputBarVC {
+    
+    // 实现 UITextViewDelegate 协议方法,控制 return 键行为
+    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
+        if text == "\n" {
+            // 当输入为换行符(即按下 return 键)时,执行相应操作
+            if let string = textView.text {
+                sendComplete?([string])
+            }
+            emptyInput()
+            textView.resignFirstResponder()
+            return false
+        }
+        return true
+    }
+}

+ 89 - 34
AIEmoji/Business/AIChat/TSChatViewController/TSChatInputBarVC/TSChatInputFullScreenVC.swift

@@ -16,7 +16,7 @@ class TSChatInputFullScreenVC: TSBaseVC, UITextViewDelegate {
     lazy var InputBarView:UIView = {
         let InputBarView = UIView()
         InputBarView.backgroundColor = "#222222".uiColor
-        InputBarView.cornerRadius = 16.0
+        InputBarView.cornerRadius = 28.0
         return InputBarView
     }()
     
@@ -27,6 +27,7 @@ class TSChatInputFullScreenVC: TSBaseVC, UITextViewDelegate {
                 sendComplete?([string])
             }
             textView.text = ""
+            dismiss(animated: true)
         }
         return sendBtn
     }()
@@ -42,19 +43,22 @@ class TSChatInputFullScreenVC: TSBaseVC, UITextViewDelegate {
     
     private let minHeight: CGFloat = 24
     private let maxHeight: CGFloat = 154
-    lazy var textView: UITextView = {
-        let textView = UITextView()
+    lazy var textView: TSCustomTextView = {
+        let textView = TSCustomTextView()
         textView.backgroundColor = .clear
         textView.textColor = .white
         textView.delegate = self
         textView.font = .font(size: 16)
         textView.clipsToBounds = true
-        textView.isScrollEnabled = true
+        textView.isScrollEnabled = false
         textView.tintColor = .themeColor
-        textView.textContainerInset = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 0)
+        textView.returnKeyType = .send
+        textView.placeholder = "Type all necessary details".localized
+        textView.placeholderColor = .white.withAlphaComponent(0.4)
+        textView.placeholderLabel.font = .font(size: 16.0)
+        textView.textInsets = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 0)
         return textView
     }()
-
   
     override func createView() {
         setNavBarViewHidden(true)
@@ -93,43 +97,94 @@ class TSChatInputFullScreenVC: TSBaseVC, UITextViewDelegate {
             make.width.equalTo(24)
             make.height.equalTo(24)
         }
-
     }
     
-    
+
     override func dealThings() {
-        // 监听文本变化事件
-//        NotificationCenter.default.addObserver(self, selector: #selector(textDidChange), name: UITextView.textDidChangeNotification, object: textView)
         textView.text = text
+        
+        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(clickView))
+        tapGesture.cancelsTouchesInView = false
+        InputBarView.addGestureRecognizer(tapGesture)
+        
+        // 监听文本变化事件
+        NotificationCenter.default.addObserver(self, selector: #selector(textDidChange), name: UITextView.textDidChangeNotification, object: textView)
+
+        // 监听键盘事件
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
     }
-//
-//
-//    @objc private func textDidChange() {
-//        // 计算输入框的内容高度
-//        let sizeToFit = CGSize(width: textView.bounds.width, height: .greatestFiniteMagnitude)
-//        let estimatedSize = textView.sizeThatFits(sizeToFit)
-//
-//        // 根据内容高度调整输入框的高度
-//        var newHeight = estimatedSize.height
-//        if newHeight < minHeight {
-//            newHeight = minHeight
-//        } else if newHeight > maxHeight {
-//            newHeight = maxHeight
-//            textView.isScrollEnabled = true
-//        } else {
-//            textView.isScrollEnabled = false
-//        }
-//
-//        // 更新输入框的高度
-//        textView.snp.updateConstraints { make in
-//            make.height.equalTo(newHeight)
-//        }
-//    }
 
+    @objc func clickView(){
+        view.endEditing(true)
+    }
+    
+    @objc private func textDidChange() {
+        sendEnabled(enabled: textView.text.count > 0)
+    }
+
+    func sendEnabled(enabled:Bool){
+        sendBtn.isEnabled = enabled
+    }
+    
+    @objc func keyboardWillShow(_ notification: Notification) {
+
+        guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect,
+              let animationDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval else {
+            return
+        }
+
+        let keyboardHeight = keyboardFrame.height
+        let contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardHeight, right: 0)
+
+        UIView.animate(withDuration: animationDuration) {
+            self.textView.contentInset = contentInset
+            self.textView.scrollIndicatorInsets = contentInset
+        }
+        
+        UIView.animate(withDuration: animationDuration+0.8) {
+            self.sendBtn.snp.updateConstraints { make in
+                make.bottom.equalTo(-keyboardHeight + k_Height_safeAreaInsetsBottom())
+            }
+        }
+    }
+
+    @objc func keyboardWillHide(_ notification: Notification) {
+        guard let animationDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval else {
+            return
+        }
+
+        let contentInset = UIEdgeInsets.zero
+        UIView.animate(withDuration: animationDuration) {
+            self.textView.contentInset = contentInset
+            self.textView.scrollIndicatorInsets = contentInset
+            
+            self.sendBtn.snp.updateConstraints { make in
+                make.bottom.equalTo(-16)
+            }
+        }
+    }
+    
     deinit {
         // 移除通知监听
         NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: textView)
     }
-    
+}
 
+extension TSChatInputFullScreenVC {
+    
+    // 实现 UITextViewDelegate 协议方法,控制 return 键行为
+    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
+        if text == "\n" {
+            // 当输入为换行符(即按下 return 键)时,执行相应操作
+            if let string = textView.text {
+                sendComplete?([string])
+            }
+            dismiss(animated: true)
+            textView.text = ""
+            textView.resignFirstResponder()
+            return false
+        }
+        return true
+    }
 }

+ 4 - 7
AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController+Keyboard.swift

@@ -23,8 +23,6 @@ extension TSChatViewController {
         return inputBarBgView
     }
     
-    
-    
     var creatScrollToBottomButton: UIButton{
         let backBottomBtn = UIButton.createButton(image: UIImage(named: "down_arrow_line")) { [weak self]  in
             guard let self = self else { return }
@@ -36,8 +34,6 @@ extension TSChatViewController {
         return backBottomBtn
     }
     
-    
-    
 }
 extension TSChatViewController{
     
@@ -54,6 +50,8 @@ extension TSChatViewController{
         } else {
             scrollToBottomButton.isHidden = false
         }
+        
+
     }
     
     
@@ -62,8 +60,7 @@ extension TSChatViewController{
 
 
 extension TSChatViewController{
-    
-    
+
     func configureMessageInputBar() {
         inputBarBgView.addSubview(inputBarTopView)
         inputBarTopView.snp.makeConstraints { make in
@@ -96,7 +93,7 @@ extension TSChatViewController{
             
             // 监听键盘事件
             NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
-            NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
+            NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
         }
     }
     

+ 8 - 8
AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController+SendMsg.swift

@@ -75,6 +75,13 @@ extension TSChatViewController {
             
             kExecuteOnMainThread {
                 self.inputBarVC.sendEnabled(enabled: true)
+                
+                //更新 Vip
+                if kPurchaseDefault.isVip == false{
+                    self.updateVipView()
+                }
+                
+//                self.messagesCollectionView.scrollToLastItem(animated: false)
             }
         }
     }
@@ -88,15 +95,8 @@ extension TSChatViewController {
             }else{
                 self.messagesCollectionView.reloadData()
             }
-
-            //更新 Vip
-            if kPurchaseDefault.isVip == false{
-                self.updateVipView()
-            }
-            
-            self.messagesCollectionView.scrollToLastItem(animated: false)
-            
         }
     }
     
+
 }

+ 1 - 1
AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController+VipView.swift

@@ -31,7 +31,7 @@ extension TSChatViewController {
         
         let label = UILabel.createLabel(
             text:"Free usage limit reached. Upgrade for unlimited chats.".localized,
-            font: .font(size: 14,weight: .bold),
+            font: .font(size: 14,weight: .medium),
             textColor: "#111111".uiColor,
             numberOfLines: 0
         )

+ 5 - 2
AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController/TSChatViewController.swift

@@ -88,8 +88,11 @@ class TSChatViewController: MessagesViewController, MessagesDataSource {
     }
 
     @objc func saveChatList() {
-        messageList.remove(at: 0)
-        viewModel.updateMessages(msgModels: messageList)
+        messageList.removeFirst()
+        if messageList.count > 0 {
+            //保存本次聊天记录
+            viewModel.updateMessages(msgModels: messageList)
+        }
     }
     
     func loadFirstMessages() {

+ 11 - 0
AIEmoji/Business/AIChat/TSChatViewController/ViewModel/TSAIChatVM.swift

@@ -63,6 +63,17 @@ extension TSAIChatVM {
         AiMDString = ""
         _ = TSNetworkShared.postStream(urlType: .chat,parameters: parameters) {[weak self] string in
             guard let self = self else { return }
+            
+            if AiMDString.count == 0 {
+                //{"code":500,"message":"Server Error"}
+                //如果错误,基本都是第一条就返回结果了,这里需要做下 code 判断,来确定接口
+                let dataDict = string.jsonDict()
+                if dataDict.safeInt(forKey: "code") != 200 {
+                    completion(nil,NSError(domain: dataDict.safeString(forKey: "message"), code: 0))
+                    return
+                }
+            }
+            
             AiMDString = AiMDString + string
             streamHandler(string)
         } completion: { result in

+ 13 - 0
AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/View/TSGenmojiGennerateCell.swift

@@ -22,6 +22,7 @@ class TSGenmojiGennerateCell : TSBaseCollectionCell{
         )
         customTextView.delegate = self
         customTextView.layer.cornerRadius = 12
+        customTextView.returnKeyType = .send
         return customTextView
     }()
     
@@ -81,4 +82,16 @@ extension TSGenmojiGennerateCell: UITextViewDelegate{
     func textViewDidChange(_ textView: UITextView) {
         submitBtn.isEnabled = textView.text.count > 0
     }
+    
+    // 实现 UITextViewDelegate 协议方法,控制 return 键行为
+    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
+        if text == "\n" {
+            // 当输入为换行符(即按下 return 键)时,执行相应操作
+            actionHandler(any: customTextView.text)
+            textView.text = ""
+            textView.resignFirstResponder()
+            return false
+        }
+        return true
+    }
 }

+ 2 - 2
AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/View/TSGenmojiTextView.swift

@@ -8,7 +8,7 @@
 class TSCustomTextView: UITextView {
     
     // Placeholder Label
-    private lazy var  placeholderLabel: TopLeftLabel = {
+    lazy var placeholderLabel: TopLeftLabel = {
         let placeholderLabel = TopLeftLabel()
         placeholderLabel.font = font
         placeholderLabel.textColor = placeholderColor
@@ -33,7 +33,7 @@ class TSCustomTextView: UITextView {
         }
     }
     
-    // Text Insets
+    // Placeholder Insets
     var textInsets: UIEdgeInsets = .zero {
         didSet {
             updateTextContainerInset()

+ 2 - 2
AIEmoji/Business/TSPurchaseMembershipVC/TSPurchaseVC.swift

@@ -239,11 +239,11 @@ struct PurchaseView :View {
                     VStack(alignment: .leading,spacing: 8) {
                         HStack(spacing: 8) {
                             Image("check").resizable().frame(width: 24, height: 24)
-                            Text("All Premium Wallpapers")
+                            Text("Unlock all Emojis Include AI")
                         }
                         HStack(spacing: 8) {
                             Image("check").resizable().frame(width: 24, height: 24)
-                            Text("Unlimited Video To Live")
+                            Text("Unlimited AI Chat")
                         }
                         
                         HStack(spacing: 8) {

+ 1 - 1
AIEmoji/Business/TSSetingVC/TSBusinessWebVC/TSBusinessWebVC.swift

@@ -10,7 +10,7 @@ import WebKit
 class TSBusinessWebVC: TSBaseVC , WKNavigationDelegate {
     
     enum UrlType:String {
-        case privacy = "https://doc-hosting.flycricket.io/hahaemoji-privacy-policy/f260e05d-a029-435f-876e-4d6127f7ed25/privacy"
+        case privacy = "http://100yearslater.com/AI-Chat-Privacy-Policy.html"
         case terms = "https://doc-hosting.flycricket.io/hahaemoji-terms-of-use/7488c423-9bb6-480e-9a38-f52fba511335/terms"
 
         func getTitle() -> String {

+ 3 - 3
AIEmoji/Common/NetworkManager/TSNetWork/TSNetworkManager.swift

@@ -61,7 +61,7 @@ class TSNetworkManager {
             case .stream(let result):
                 switch result {
                 case .success(let string):
-//                    print("Received string: \(string)")
+//                    print("Stream Received string: \(string)")
                     streamHandler(string)
                 case .failure(let error):
                     print("Stream error: \(error)")
@@ -69,10 +69,10 @@ class TSNetworkManager {
                 }
             case .complete(let cpl):
                 if let error = cpl.error {
-                    print("Request failed with error: \(error)")
+                    print("Stream Request failed with error: \(error)")
                     completion(.failure(error))
                 } else {
-                    completion(.success("success"))
+                    completion(.success("Stream success"))
                 }
             }
         }