Browse Source

feat: 添加系统键盘缓存

Destiny 5 months ago
parent
commit
ffe0338686

+ 76 - 12
ios/AiKeyboard/KeyboardViewController.swift

@@ -241,6 +241,23 @@ class KeyboardViewController: UIInputViewController {
         return view
         return view
     }()
     }()
     
     
+    lazy var tipPopView: KeyboardTipsPopView = {
+        
+        let view = KeyboardTipsPopView()
+        view.isHidden = true
+        view.settingBtnClosure = {
+            
+            if let url = URL(string: "com.qihuan.zhuiaijianpan:///open/setting") {
+                self.openURL(url)
+            }
+        }
+        view.backBtnClosure = {
+            
+            self.tipPopView.isHidden = true
+        }
+        return view
+    }()
+    
     var nowShowView: UIView?
     var nowShowView: UIView?
     
     
     // 命令检查定时器
     // 命令检查定时器
@@ -265,6 +282,8 @@ class KeyboardViewController: UIInputViewController {
         if isFullAccess {
         if isFullAccess {
             requestKeyboardList()
             requestKeyboardList()
             requestPrologueList()
             requestPrologueList()
+        } else {
+            getLocalSystemKeyboard()
         }
         }
         
         
         if let defaultType = UserDefaults.standard.value(forKey: "KeyboardChooseType") as? Int, let type = KeyboardType(rawValue: defaultType) {
         if let defaultType = UserDefaults.standard.value(forKey: "KeyboardChooseType") as? Int, let type = KeyboardType(rawValue: defaultType) {
@@ -362,6 +381,24 @@ class KeyboardViewController: UIInputViewController {
 // MARK: - 网络请求
 // MARK: - 网络请求
 extension KeyboardViewController {
 extension KeyboardViewController {
     
     
+    func getLocalSystemKeyboard() {
+        
+        if let systemKeyboardJson = KeyboardSharedDataManager.shared.getSystemkeyboard() {
+            if let jsonData = systemKeyboardJson.data(using: .utf8) {
+                let decoder = JSONDecoder()
+                do {
+                    let characterList = try decoder.decode([CharacterModel].self, from: jsonData)
+                    self.characterList = characterList
+                    self.updateCharacterUI()
+                    // 成功解码,可以使用 keyboardModel
+                    print("CharacterList: \(characterList)")
+                } catch {
+                    print("解码 KeyboardModel 失败: \(error)")
+                }
+            }
+        }
+    }
+    
     // 获取键盘列表
     // 获取键盘列表
     func requestKeyboardList() {
     func requestKeyboardList() {
         
         
@@ -541,6 +578,12 @@ extension KeyboardViewController: KeyboardMenuViewDelegate, KeyboardExchangeView
     // 功能按钮选择点击
     // 功能按钮选择点击
     @objc func functionBtnClickAction() {
     @objc func functionBtnClickAction() {
         
         
+        let isFullAccess = self.hasFullAccess
+        if !isFullAccess {
+            self.popTipsView()
+            return
+        }
+        
         KeyboardFunctionPopView.show(view: self.view, selectType: self.chooseType) { type in
         KeyboardFunctionPopView.show(view: self.view, selectType: self.chooseType) { type in
             self.chooseType = type
             self.chooseType = type
         }
         }
@@ -640,6 +683,12 @@ extension KeyboardViewController: KeyboardMenuViewDelegate, KeyboardExchangeView
     // 选择键盘按钮点击
     // 选择键盘按钮点击
     @objc func changeBtnClickAction() {
     @objc func changeBtnClickAction() {
         
         
+        let isFullAccess = self.hasFullAccess
+        if !isFullAccess {
+            self.popTipsView()
+            return
+        }
+        
         clearPopView()
         clearPopView()
         self.exchangeView.keyboardList = self.keyboardList
         self.exchangeView.keyboardList = self.keyboardList
         self.exchangeView.isHidden = false
         self.exchangeView.isHidden = false
@@ -699,6 +748,13 @@ extension KeyboardViewController: KeyboardHelpViewDelegate, KeyboardTeachViewDel
     // 帮聊点击cell
     // 帮聊点击cell
     func helpCollectionViewDidSelectItem(characterId: String, content: String, complete: @escaping ((Bool) -> ())) {
     func helpCollectionViewDidSelectItem(characterId: String, content: String, complete: @escaping ((Bool) -> ())) {
         
         
+        let isFullAccess = self.hasFullAccess
+        if !isFullAccess {
+            self.popTipsView()
+            complete(false)
+            return
+        }
+        
         // 判断是否登录
         // 判断是否登录
         let isLogin = KeyboardSharedDataManager.shared.isLoggedIn()
         let isLogin = KeyboardSharedDataManager.shared.isLoggedIn()
         if !isLogin {
         if !isLogin {
@@ -716,6 +772,13 @@ extension KeyboardViewController: KeyboardHelpViewDelegate, KeyboardTeachViewDel
     // 教你说点击cell
     // 教你说点击cell
     func teachCollectionViewDidSelectItem(characterId: String, content: String, complete: @escaping (([String], Bool, Bool) -> ())) {
     func teachCollectionViewDidSelectItem(characterId: String, content: String, complete: @escaping (([String], Bool, Bool) -> ())) {
         
         
+        let isFullAccess = self.hasFullAccess
+        if !isFullAccess {
+            self.popTipsView()
+            complete([String](), false, false)
+            return
+        }
+        
         // 判断是否登录
         // 判断是否登录
         let isLogin = KeyboardSharedDataManager.shared.isLoggedIn()
         let isLogin = KeyboardSharedDataManager.shared.isLoggedIn()
         if !isLogin {
         if !isLogin {
@@ -1036,21 +1099,16 @@ extension KeyboardViewController {
         
         
         if !isFullAccess {
         if !isFullAccess {
             
             
-            let tipView = KeyboardTipsPopView()
-            tipView.settingBtnClosure = {
-                
-                if let url = URL(string: UIApplication.openSettingsURLString) {
-                    self.openURL(url)
-                }
-            }
-            self.view.addSubview(tipView)
-            tipView.snp.makeConstraints { make in
-                make.left.right.bottom.equalTo(0)
-                make.top.equalTo(56)
-            }
+            popTipsView()
         }
         }
     }
     }
     
     
+    // 弹出完全访问设置页
+    func popTipsView() {
+        
+        self.tipPopView.isHidden = false
+    }
+    
     // 跳转登录页
     // 跳转登录页
     func popLoginView() {
     func popLoginView() {
         
         
@@ -1222,6 +1280,12 @@ extension KeyboardViewController {
             make.top.left.right.bottom.equalTo(0)
             make.top.left.right.bottom.equalTo(0)
         }
         }
         
         
+        self.view.addSubview(tipPopView)
+        tipPopView.snp.makeConstraints { make in
+            make.left.right.bottom.equalTo(0)
+            make.top.equalTo(56)
+        }
+        
         chooseView.addSubview(functionView)
         chooseView.addSubview(functionView)
         functionView.snp.makeConstraints { make in
         functionView.snp.makeConstraints { make in
             make.top.left.equalTo(1)
             make.top.left.equalTo(1)

+ 8 - 2
ios/AiKeyboard/Model/CharacterModel.swift

@@ -9,13 +9,13 @@ import Foundation
 import ObjectMapper
 import ObjectMapper
 
 
 // MARK: Initializer and Properties
 // MARK: Initializer and Properties
-struct CharacterModel: Mappable {
+struct CharacterModel: Mappable, Codable {
 
 
     var id: String?
     var id: String?
     
     
     var name: String?
     var name: String?
     
     
-    var imageUrl: Int?
+    var imageUrl: String?
     
     
     var description: String?
     var description: String?
     
     
@@ -30,6 +30,12 @@ struct CharacterModel: Mappable {
     var characters: [String]?
     var characters: [String]?
     
     
     var gender: Int?
     var gender: Int?
+    
+    var isLock: Bool?
+    
+    var isAdd: Bool?
+    
+    var createTime: String?
 
 
     // MARK: JSON
     // MARK: JSON
     init?(map: Map) { }
     init?(map: Map) { }

+ 1 - 1
ios/AiKeyboard/Model/KeyboardModel.swift

@@ -9,7 +9,7 @@ import Foundation
 import ObjectMapper
 import ObjectMapper
 
 
 // MARK: Initializer and Properties
 // MARK: Initializer and Properties
-struct KeyboardModel: Mappable {
+struct KeyboardModel: Mappable, Codable {
 
 
     var id: String?
     var id: String?
     /*
     /*

+ 2 - 1
ios/AiKeyboard/View/MainView/KeyboardHelpView.swift

@@ -92,7 +92,8 @@ extension KeyboardHelpView: UICollectionViewDelegate, UICollectionViewDataSource
             helpDelegate?.addCharacterJump()
             helpDelegate?.addCharacterJump()
         } else {
         } else {
             
             
-            if self.dialogueLabel.text?.count == 0 {
+            let openAccess = self.inputViewController?.hasFullAccess
+            if self.dialogueLabel.text?.count == 0 && openAccess == true{
                 self.toast(text: "请先粘贴文字")
                 self.toast(text: "请先粘贴文字")
                 return
                 return
             }
             }

+ 2 - 1
ios/AiKeyboard/View/MainView/KeyboardTeachView.swift

@@ -187,7 +187,8 @@ extension KeyboardTeachView: UICollectionViewDelegate, UICollectionViewDataSourc
             teachDelegate?.addCharacterJump()
             teachDelegate?.addCharacterJump()
         } else {
         } else {
             
             
-            if self.dialogueLabel.text?.count == 0 {
+            let openAccess = self.inputViewController?.hasFullAccess
+            if self.dialogueLabel.text?.count == 0 && openAccess == true{
                 self.toast(text: "请先粘贴文字")
                 self.toast(text: "请先粘贴文字")
                 return
                 return
             }
             }

+ 0 - 1
ios/AiKeyboard/View/PopView/KeyboardTipsPopView.swift

@@ -85,7 +85,6 @@ class KeyboardTipsPopView: UIView {
     
     
     @objc func closeBtnClickAction() {
     @objc func closeBtnClickAction() {
         
         
-        self.removeFromSuperview()
         backBtnClosure?()
         backBtnClosure?()
     }
     }
 }
 }

+ 11 - 0
ios/KeyboardSharedDataManager.swift

@@ -21,6 +21,17 @@ class KeyboardSharedDataManager {
     
     
     private init() {}
     private init() {}
     
     
+    // 保存系统键盘数据
+    func saveSystemkeyboard(_ info: String) {
+        sharedUserDefaults?.set(info, forKey: "system_keyboard")
+        sharedUserDefaults?.synchronize()
+    }
+    
+    // 获取系统键盘数据
+    func getSystemkeyboard() -> String? {
+        return sharedUserDefaults?.string(forKey: "system_keyboard")
+    }
+    
     // 保存Token
     // 保存Token
     func saveToken(_ token: String) {
     func saveToken(_ token: String) {
         sharedUserDefaults?.set(token, forKey: "user_token")
         sharedUserDefaults?.set(token, forKey: "user_token")

+ 2 - 0
ios/Runner/AppDelegate.swift

@@ -85,6 +85,8 @@ import UIKit
                         channel.invokeMethod("navigateToCustomCharacter", arguments: nil)
                         channel.invokeMethod("navigateToCustomCharacter", arguments: nil)
                     }
                     }
                 }
                 }
+            } else if path == "/open/setting" {
+                channel.invokeMethod("openSystemSetting", arguments: nil)
             }
             }
         }
         }
 
 

+ 8 - 0
ios/Runner/FlutterMethodChannelManager.swift

@@ -34,6 +34,14 @@ class FlutterMethodChannelManager: NSObject {
             guard let self = self else { return }
             guard let self = self else { return }
             
             
             switch call.method {
             switch call.method {
+            case "saveSystemKeyboardInfo":
+                if let args = call.arguments as? [String: Any],
+                   let info = args["info"] as? String {
+                    KeyboardSharedDataManager.shared.saveSystemkeyboard(info)
+                    result(true)
+                } else {
+                    result(FlutterError(code: "INVALID_ARGUMENTS", message: "无效的参数", details: nil))
+                }
             case "saveAuthToken":
             case "saveAuthToken":
                 if let args = call.arguments as? [String: Any],
                 if let args = call.arguments as? [String: Any],
                    let token = args["token"] as? String {
                    let token = args["token"] as? String {

+ 22 - 0
lib/data/repository/keyboard_repository.dart

@@ -1,3 +1,5 @@
+import 'dart:ffi';
+
 import 'package:get/get.dart';
 import 'package:get/get.dart';
 import 'package:injectable/injectable.dart';
 import 'package:injectable/injectable.dart';
 import 'package:keyboard/base/app_base_request.dart';
 import 'package:keyboard/base/app_base_request.dart';
@@ -9,6 +11,7 @@ import 'package:keyboard/data/api/response/keyboard_love_index_response.dart';
 import 'package:keyboard/data/api/response/keyboard_meme_explain_response.dart';
 import 'package:keyboard/data/api/response/keyboard_meme_explain_response.dart';
 import 'package:keyboard/data/api/response/keyboard_prologue_list_response.dart';
 import 'package:keyboard/data/api/response/keyboard_prologue_list_response.dart';
 import 'package:keyboard/utils/atmob_log.dart';
 import 'package:keyboard/utils/atmob_log.dart';
+import 'package:keyboard/utils/method_chanel_ios_util.dart';
 import 'dart:convert';
 import 'dart:convert';
 import '../../base/base_response.dart';
 import '../../base/base_response.dart';
 import '../../di/get_it.dart';
 import '../../di/get_it.dart';
@@ -26,6 +29,7 @@ import '../api/request/keyboard_update_request.dart';
 import '../api/response/keyboard_character_list_response.dart';
 import '../api/response/keyboard_character_list_response.dart';
 import '../api/response/keyboard_home_info_response.dart';
 import '../api/response/keyboard_home_info_response.dart';
 import '../api/response/keyboard_list_response.dart';
 import '../api/response/keyboard_list_response.dart';
+import '../bean/character_info.dart';
 import '../bean/keyboard_info.dart';
 import '../bean/keyboard_info.dart';
 import '../consts/constants.dart';
 import '../consts/constants.dart';
 import '../consts/error_code.dart';
 import '../consts/error_code.dart';
@@ -132,6 +136,24 @@ class KeyboardRepository {
               .where((keyboard) => keyboard.type != KeyboardType.system.name)
               .where((keyboard) => keyboard.type != KeyboardType.system.name)
               .toList();
               .toList();
 
 
+      saveIOSSystemKeyboardCharacter(response.keyboardInfos);
+   });
+  }
+
+  // 保存系统键盘人设数据到ios本地
+  void saveIOSSystemKeyboardCharacter(List<KeyboardInfo> keyboardList) {
+
+    List<KeyboardInfo> systemKeyboardList = keyboardList
+        .where((keyboard) => keyboard.type == KeyboardType.system.name).toList();
+    KeyboardInfo systemKeyboard = systemKeyboardList.first;
+
+    getKeyboardCharacterList(keyboardId: systemKeyboard.id ?? "").then((
+        keyboardCharacterListResponse,
+        ) {
+      List<CharacterInfo> characterList = keyboardCharacterListResponse.characterInfos;
+      List<CharacterInfo> sysCharacter = characterList;
+      var systemKeyboardJson = jsonEncode(sysCharacter);
+      MethodChanelIOSUtil.saveSystemKeyboardInfo(systemKeyboardJson);
     });
     });
   }
   }
 
 

+ 11 - 0
lib/utils/method_chanel_ios_util.dart

@@ -8,6 +8,7 @@ import 'package:keyboard/module/main/main_page.dart';
 import 'package:keyboard/module/store/store_page.dart';
 import 'package:keyboard/module/store/store_page.dart';
 import 'package:keyboard/utils/default_keyboard_helper.dart';
 import 'package:keyboard/utils/default_keyboard_helper.dart';
 import 'package:keyboard/utils/toast_util.dart';
 import 'package:keyboard/utils/toast_util.dart';
+import 'package:keyboard/utils/url_launcher_util.dart';
 
 
 import '../module/intimacy_scale/intimacy_scale_page.dart';
 import '../module/intimacy_scale/intimacy_scale_page.dart';
 import '../widget/platform_util.dart';
 import '../widget/platform_util.dart';
@@ -44,6 +45,8 @@ class MethodChanelIOSUtil {
         break;
         break;
       case 'isKeyboardAdd':
       case 'isKeyboardAdd':
         break;
         break;
+      case 'openSystemSetting':
+        UrlLauncherUtil.openIosSystemKeyboardPage();
       default:
       default:
         throw PlatformException(
         throw PlatformException(
           code: 'Unimplemented',
           code: 'Unimplemented',
@@ -53,6 +56,14 @@ class MethodChanelIOSUtil {
   }
   }
 
 
   // 保存token到ios端
   // 保存token到ios端
+  static Future<void> saveSystemKeyboardInfo(String info) async {
+    // 通知iOS键盘扩展
+    if (PlatformUtil.isIOS) {
+      _channel.invokeMethod('saveSystemKeyboardInfo', {'info': info});
+    }
+  }
+
+  // 保存token到ios端
   static Future<void> saveAuthToken(String token) async {
   static Future<void> saveAuthToken(String token) async {
     // 通知iOS键盘扩展
     // 通知iOS键盘扩展
     if (PlatformUtil.isIOS) {
     if (PlatformUtil.isIOS) {

+ 1 - 1
pubspec.yaml

@@ -3,7 +3,7 @@ description: "A new Flutter project."
 
 
 publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 
 
-version: 1.1.3+15
+version: 1.1.3+17
 
 
 environment:
 environment:
   sdk: ^3.7.0
   sdk: ^3.7.0