|
@@ -1,4 +1,3 @@
|
|
|
-import 'package:collection/collection.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get.dart';
|
|
|
import 'package:injectable/injectable.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
@@ -11,21 +10,18 @@ import 'package:keyboard/dialog/character_add_dialog.dart';
|
|
|
import 'package:keyboard/dialog/custom_character/custom_character_add_dialog.dart';
|
|
import 'package:keyboard/dialog/custom_character/custom_character_add_dialog.dart';
|
|
|
import 'package:keyboard/dialog/login/login_dialog.dart';
|
|
import 'package:keyboard/dialog/login/login_dialog.dart';
|
|
|
import 'package:keyboard/handler/event_handler.dart';
|
|
import 'package:keyboard/handler/event_handler.dart';
|
|
|
-import 'package:keyboard/module/character/content/character_group_content_controller.dart';
|
|
|
|
|
import 'package:keyboard/resource/string.gen.dart';
|
|
import 'package:keyboard/resource/string.gen.dart';
|
|
|
import 'package:keyboard/utils/atmob_log.dart';
|
|
import 'package:keyboard/utils/atmob_log.dart';
|
|
|
import 'package:keyboard/utils/toast_util.dart';
|
|
import 'package:keyboard/utils/toast_util.dart';
|
|
|
|
|
|
|
|
import '../../data/bean/keyboard_info.dart';
|
|
import '../../data/bean/keyboard_info.dart';
|
|
|
-import '../../data/consts/error_code.dart';
|
|
|
|
|
-import '../../data/repository/characters_repository.dart';
|
|
|
|
|
-import '../../plugins/keyboard_android_platform.dart';
|
|
|
|
|
-import '../../utils/error_handler.dart';
|
|
|
|
|
-import '../../utils/http_handler.dart';
|
|
|
|
|
|
|
+import 'keyboard_type_controller.dart';
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
enum KeyboardType {
|
|
enum KeyboardType {
|
|
|
- system, //通用键盘
|
|
|
|
|
- custom, //自定义键盘
|
|
|
|
|
|
|
+ system, // 通用键盘
|
|
|
|
|
+ custom, // 自定义键盘
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@injectable
|
|
@injectable
|
|
@@ -34,81 +30,24 @@ class KeyboardManageController extends BaseController
|
|
|
final String tag = 'KeyboardManageController';
|
|
final String tag = 'KeyboardManageController';
|
|
|
|
|
|
|
|
final AccountRepository accountRepository;
|
|
final AccountRepository accountRepository;
|
|
|
-
|
|
|
|
|
final KeyboardRepository keyboardRepository;
|
|
final KeyboardRepository keyboardRepository;
|
|
|
|
|
|
|
|
|
|
+ // 登录状态
|
|
|
RxBool get isLogin => accountRepository.isLogin;
|
|
RxBool get isLogin => accountRepository.isLogin;
|
|
|
|
|
|
|
|
|
|
+ // 键盘列表
|
|
|
RxList<KeyboardInfo> get customKeyboardInfoList =>
|
|
RxList<KeyboardInfo> get customKeyboardInfoList =>
|
|
|
keyboardRepository.customKeyboardInfoList;
|
|
keyboardRepository.customKeyboardInfoList;
|
|
|
-
|
|
|
|
|
- // 当前自定义键盘
|
|
|
|
|
- final Rx<KeyboardInfo> _currentCustomKeyboardInfo = KeyboardInfo().obs;
|
|
|
|
|
-
|
|
|
|
|
- KeyboardInfo get currentCustomKeyboardInfo =>
|
|
|
|
|
- _currentCustomKeyboardInfo.value;
|
|
|
|
|
-
|
|
|
|
|
- //当前自定义键盘人设列表
|
|
|
|
|
- final RxList<CharacterInfo> _currentCustomKeyboardCharacterList = RxList();
|
|
|
|
|
-
|
|
|
|
|
- RxList<CharacterInfo> get currentCustomKeyboardCharacterList =>
|
|
|
|
|
- _currentCustomKeyboardCharacterList;
|
|
|
|
|
-
|
|
|
|
|
- // 当前自定义键盘亲密度
|
|
|
|
|
- final RxInt _currentCustomIntimacy = 0.obs;
|
|
|
|
|
-
|
|
|
|
|
- int get currentCustomIntimacy => _currentCustomIntimacy.value;
|
|
|
|
|
-
|
|
|
|
|
- // 当前定制亲密度是否有变化
|
|
|
|
|
- final RxBool _customIntimacyChanged = false.obs;
|
|
|
|
|
-
|
|
|
|
|
- bool get customIntimacyChanged => _customIntimacyChanged.value;
|
|
|
|
|
-
|
|
|
|
|
- final RxBool _customKeyboardCharacterListChanged = false.obs;
|
|
|
|
|
-
|
|
|
|
|
- bool get customKeyboardCharacterListChanged =>
|
|
|
|
|
- _customKeyboardCharacterListChanged.value;
|
|
|
|
|
-
|
|
|
|
|
- // 存储排序前的定制人设列表,用于比较是否有变化
|
|
|
|
|
- List<CharacterInfo> _oldCustomCharacterList = [];
|
|
|
|
|
-
|
|
|
|
|
RxList<KeyboardInfo> get generalKeyboardInfoList =>
|
|
RxList<KeyboardInfo> get generalKeyboardInfoList =>
|
|
|
keyboardRepository.generalKeyboardInfoList;
|
|
keyboardRepository.generalKeyboardInfoList;
|
|
|
|
|
|
|
|
- // 当前通用键盘
|
|
|
|
|
- final Rx<KeyboardInfo> _currentGeneralKeyboardInfo = KeyboardInfo().obs;
|
|
|
|
|
-
|
|
|
|
|
- KeyboardInfo get currentGeneralKeyboardInfo =>
|
|
|
|
|
- _currentGeneralKeyboardInfo.value;
|
|
|
|
|
|
|
+ // 子控制器
|
|
|
|
|
+ late KeyboardTypeController customKeyboardController;
|
|
|
|
|
+ late KeyboardTypeController generalKeyboardController;
|
|
|
|
|
|
|
|
- // 当前通用键盘人设列表
|
|
|
|
|
- final RxList<CharacterInfo> _currentGeneralKeyboardCharacterList = RxList();
|
|
|
|
|
-
|
|
|
|
|
- List<CharacterInfo> get currentGeneralKeyboardCharacterList =>
|
|
|
|
|
- _currentGeneralKeyboardCharacterList;
|
|
|
|
|
-
|
|
|
|
|
- // 当前通用键盘亲密度
|
|
|
|
|
- final RxInt _currentGeneralIntimacy = 0.obs;
|
|
|
|
|
-
|
|
|
|
|
- int get currentGeneralIntimacy => _currentGeneralIntimacy.value;
|
|
|
|
|
-
|
|
|
|
|
- // 当前通用亲密度是否有变化
|
|
|
|
|
- final RxBool _generalIntimacyChanged = false.obs;
|
|
|
|
|
-
|
|
|
|
|
- RxBool get generalIntimacyChanged => _generalIntimacyChanged;
|
|
|
|
|
-
|
|
|
|
|
- final RxBool _generalKeyboardCharacterListChanged = false.obs;
|
|
|
|
|
-
|
|
|
|
|
- bool get generalKeyboardCharacterListChanged =>
|
|
|
|
|
- _generalKeyboardCharacterListChanged.value;
|
|
|
|
|
-
|
|
|
|
|
- // 存储排序前的通用人设列表,用于比较是否有变化
|
|
|
|
|
- late List<CharacterInfo> _oldGeneralCharacterList;
|
|
|
|
|
-
|
|
|
|
|
- late Worker _customKeyboardInfoListWorker;
|
|
|
|
|
-
|
|
|
|
|
- // 最小人设数量
|
|
|
|
|
- final _minCount = 9;
|
|
|
|
|
|
|
+ // UI控制器
|
|
|
|
|
+ late TabController tabController;
|
|
|
|
|
+ late PageController pageController;
|
|
|
|
|
|
|
|
// 键盘管理类型
|
|
// 键盘管理类型
|
|
|
List<String> keyboardManageType = [
|
|
List<String> keyboardManageType = [
|
|
@@ -116,37 +55,49 @@ class KeyboardManageController extends BaseController
|
|
|
StringName.generalKeyboard,
|
|
StringName.generalKeyboard,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- // 键盘管理页面的tabController,用于控制通用键盘和自定义键盘的切换
|
|
|
|
|
- late TabController tabController;
|
|
|
|
|
-
|
|
|
|
|
- // 键盘管理页面的pageController,用于控制通用键盘和自定义键盘的切换
|
|
|
|
|
- late PageController pageController;
|
|
|
|
|
|
|
+ // worker
|
|
|
|
|
+ late Worker _keyboardInfoListWorker;
|
|
|
|
|
|
|
|
// 首次加载数据标志
|
|
// 首次加载数据标志
|
|
|
final isFirstLoad = true.obs;
|
|
final isFirstLoad = true.obs;
|
|
|
|
|
|
|
|
- KeyboardManageController(this.keyboardRepository, this.accountRepository);
|
|
|
|
|
|
|
+ KeyboardManageController(this.keyboardRepository, this.accountRepository) {
|
|
|
|
|
+ // 初始化子控制器
|
|
|
|
|
+ customKeyboardController = KeyboardTypeController(
|
|
|
|
|
+ tag: '$tag-Custom',
|
|
|
|
|
+ keyboardRepository: keyboardRepository,
|
|
|
|
|
+ isCustom: true,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ generalKeyboardController = KeyboardTypeController(
|
|
|
|
|
+ tag: '$tag-General',
|
|
|
|
|
+ keyboardRepository: keyboardRepository,
|
|
|
|
|
+ isCustom: false,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
void onInit() async {
|
|
void onInit() async {
|
|
|
super.onInit();
|
|
super.onInit();
|
|
|
|
|
|
|
|
|
|
+ // 处理传入的自定义键盘信息
|
|
|
final args = Get.arguments;
|
|
final args = Get.arguments;
|
|
|
if (args is Map && args["customKeyboardInfo"] is KeyboardInfo) {
|
|
if (args is Map && args["customKeyboardInfo"] is KeyboardInfo) {
|
|
|
- _currentCustomKeyboardInfo.value = args["customKeyboardInfo"];
|
|
|
|
|
|
|
+ customKeyboardController.keyboardInfo.value = args["customKeyboardInfo"];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- await _dataLoad();
|
|
|
|
|
|
|
+ await _initializeControllers();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _dataLoad() async {
|
|
|
|
|
- getCustomKeyboard();
|
|
|
|
|
- getGeneralKeyboard();
|
|
|
|
|
|
|
+ // 初始化控制器
|
|
|
|
|
+ Future<void> _initializeControllers() async {
|
|
|
|
|
+ // 初始化Tab控制器
|
|
|
tabController = TabController(
|
|
tabController = TabController(
|
|
|
length: keyboardManageType.length,
|
|
length: keyboardManageType.length,
|
|
|
vsync: this,
|
|
vsync: this,
|
|
|
initialIndex: customKeyboardInfoList.isEmpty ? 1 : 0,
|
|
initialIndex: customKeyboardInfoList.isEmpty ? 1 : 0,
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
tabController.addListener(() {
|
|
tabController.addListener(() {
|
|
|
if (tabController.indexIsChanging) {
|
|
if (tabController.indexIsChanging) {
|
|
|
switchTabKeyboardType(tabController.index);
|
|
switchTabKeyboardType(tabController.index);
|
|
@@ -158,170 +109,64 @@ class KeyboardManageController extends BaseController
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ // 初始化Page控制器
|
|
|
pageController = PageController(
|
|
pageController = PageController(
|
|
|
initialPage: customKeyboardInfoList.isEmpty ? 1 : 0,
|
|
initialPage: customKeyboardInfoList.isEmpty ? 1 : 0,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- _customKeyboardInfoListWorker = everAll(
|
|
|
|
|
- [customKeyboardInfoList, generalKeyboardInfoList],
|
|
|
|
|
- (_) {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if (customKeyboardInfoList.isNotEmpty) {
|
|
|
|
|
- _currentCustomKeyboardInfo.value = customKeyboardInfoList.firstWhere(
|
|
|
|
|
- (element) => element.isChoose == true,
|
|
|
|
|
- orElse: () => customKeyboardInfoList.first,
|
|
|
|
|
- );
|
|
|
|
|
- getCustomKeyboard();
|
|
|
|
|
- }else
|
|
|
|
|
- {
|
|
|
|
|
- _oldCustomCharacterList = [];
|
|
|
|
|
- _currentCustomKeyboardInfo.value = KeyboardInfo();
|
|
|
|
|
- _currentCustomKeyboardCharacterList.clear();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if (generalKeyboardInfoList.isNotEmpty) {
|
|
|
|
|
- _currentGeneralKeyboardInfo.value = generalKeyboardInfoList.first;
|
|
|
|
|
- getGeneralKeyboard();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- clickBack() {
|
|
|
|
|
- AtmobLog.i(tag, 'clickBack');
|
|
|
|
|
- Get.back();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 监听键盘列表变化
|
|
|
|
|
+ _keyboardInfoListWorker = everAll([
|
|
|
|
|
+ customKeyboardInfoList,
|
|
|
|
|
+ generalKeyboardInfoList,
|
|
|
|
|
+ ], (_) => _loadKeyboardData());
|
|
|
|
|
|
|
|
- @override
|
|
|
|
|
- void onReady() {
|
|
|
|
|
- super.onReady();
|
|
|
|
|
|
|
+ // 首次加载数据
|
|
|
|
|
+ _loadKeyboardData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 获取定制键盘
|
|
|
|
|
- Future<void> getCustomKeyboard() async {
|
|
|
|
|
- AtmobLog.i(tag, 'getCustomKeyboard');
|
|
|
|
|
|
|
+ // 加载键盘数据
|
|
|
|
|
+ void _loadKeyboardData() {
|
|
|
|
|
+ // 加载自定义键盘数据
|
|
|
if (customKeyboardInfoList.isNotEmpty) {
|
|
if (customKeyboardInfoList.isNotEmpty) {
|
|
|
- AtmobLog.i(
|
|
|
|
|
- tag,
|
|
|
|
|
- 'customKeyboardInfoList: ${customKeyboardInfoList.length}',
|
|
|
|
|
- );
|
|
|
|
|
- if (_currentCustomKeyboardInfo.value.id == null) {
|
|
|
|
|
- _currentCustomKeyboardInfo.value = customKeyboardInfoList.firstWhere(
|
|
|
|
|
- (element) => element.isChoose == true,
|
|
|
|
|
|
|
+ KeyboardInfo keyboard;
|
|
|
|
|
+
|
|
|
|
|
+ // 如果已有选择的键盘,就用它
|
|
|
|
|
+ if (customKeyboardController.keyboardInfo.value.id != null) {
|
|
|
|
|
+ keyboard = customKeyboardController.keyboardInfo.value;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 否则选择默认选中的或第一个键盘
|
|
|
|
|
+ keyboard = customKeyboardInfoList.firstWhere(
|
|
|
|
|
+ (element) => element.isChoose == true,
|
|
|
orElse: () => customKeyboardInfoList.first,
|
|
orElse: () => customKeyboardInfoList.first,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
- _currentCustomIntimacy.value =
|
|
|
|
|
- _currentCustomKeyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
- _currentCustomIntimacy.listen((intimacy) {
|
|
|
|
|
- _customIntimacyChanged.value =
|
|
|
|
|
- _currentCustomKeyboardInfo.value.intimacy != intimacy;
|
|
|
|
|
- AtmobLog.d(tag, 'intimacyChanged: $_customIntimacyChanged');
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- String? id = _currentCustomKeyboardInfo.value.id;
|
|
|
|
|
- if (id != null) {
|
|
|
|
|
- getKeyboardCharacterList(keyboardId: id, isCustom: true);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // 获取通用键盘
|
|
|
|
|
- void getGeneralKeyboard() {
|
|
|
|
|
- _currentGeneralKeyboardInfo.value = generalKeyboardInfoList.first;
|
|
|
|
|
- _currentGeneralIntimacy.value =
|
|
|
|
|
- _currentGeneralKeyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
- _currentGeneralIntimacy.listen((intimacy) {
|
|
|
|
|
- _generalIntimacyChanged.value =
|
|
|
|
|
- _currentGeneralKeyboardInfo.value.intimacy != intimacy;
|
|
|
|
|
- AtmobLog.d(tag, 'intimacyChanged: $_generalIntimacyChanged');
|
|
|
|
|
- });
|
|
|
|
|
- String? id = _currentGeneralKeyboardInfo.value.id;
|
|
|
|
|
- if (id != null) {
|
|
|
|
|
- AtmobLog.i(tag, 'getGeneralKeyboard id: $id');
|
|
|
|
|
- getKeyboardCharacterList(keyboardId: id, isCustom: false);
|
|
|
|
|
|
|
+ customKeyboardController.loadKeyboard(keyboard);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ customKeyboardController.characterList.clear();
|
|
|
|
|
+ customKeyboardController.oldCharacterList = [];
|
|
|
|
|
+ customKeyboardController.keyboardInfo.value = KeyboardInfo();
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // 获取当前键盘人设列表
|
|
|
|
|
- void getKeyboardCharacterList({
|
|
|
|
|
- required String keyboardId,
|
|
|
|
|
- required bool isCustom,
|
|
|
|
|
- }) {
|
|
|
|
|
- if (isCustom) {
|
|
|
|
|
- keyboardRepository.getKeyboardCharacterList(keyboardId: keyboardId).then((
|
|
|
|
|
- keyboardCharacterListResponse,
|
|
|
|
|
- ) {
|
|
|
|
|
- AtmobLog.i(
|
|
|
|
|
- tag,
|
|
|
|
|
- 'keyboardCharacterListResponse: ${keyboardCharacterListResponse.characterInfos.toString()}',
|
|
|
|
|
- );
|
|
|
|
|
- _currentCustomKeyboardCharacterList.assignAll(
|
|
|
|
|
- keyboardCharacterListResponse.characterInfos,
|
|
|
|
|
- );
|
|
|
|
|
- _oldCustomCharacterList = List<CharacterInfo>.from(
|
|
|
|
|
- _currentCustomKeyboardCharacterList,
|
|
|
|
|
- );
|
|
|
|
|
- _customKeyboardCharacterListChanged.value = false;
|
|
|
|
|
- _currentCustomKeyboardCharacterList.listen((event) {
|
|
|
|
|
- _customKeyboardCharacterListChanged.value =
|
|
|
|
|
- !ListEquality().equals(_oldCustomCharacterList, event);
|
|
|
|
|
- AtmobLog.d(
|
|
|
|
|
- tag,
|
|
|
|
|
- '_customKeyboardCharacterListChanged: $_customKeyboardCharacterListChanged',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- keyboardRepository.getKeyboardCharacterList(keyboardId: keyboardId).then((
|
|
|
|
|
- keyboardCharacterListResponse,
|
|
|
|
|
- ) {
|
|
|
|
|
- AtmobLog.i(
|
|
|
|
|
- tag,
|
|
|
|
|
- 'keyboardCharacterListResponse: ${keyboardCharacterListResponse.characterInfos.toString()}',
|
|
|
|
|
- );
|
|
|
|
|
- if (_currentGeneralKeyboardInfo.value.id == keyboardId) {
|
|
|
|
|
- _currentGeneralKeyboardCharacterList.value =
|
|
|
|
|
- keyboardCharacterListResponse.characterInfos;
|
|
|
|
|
- _oldGeneralCharacterList = List<CharacterInfo>.from(
|
|
|
|
|
- _currentGeneralKeyboardCharacterList,
|
|
|
|
|
- );
|
|
|
|
|
- _generalKeyboardCharacterListChanged.value = false;
|
|
|
|
|
- _currentGeneralKeyboardCharacterList.listen((event) {
|
|
|
|
|
- _generalKeyboardCharacterListChanged.value =
|
|
|
|
|
- !ListEquality().equals(_oldGeneralCharacterList, event);
|
|
|
|
|
- AtmobLog.d(
|
|
|
|
|
- tag,
|
|
|
|
|
- '_generalKeyboardCharacterListChanged: $_generalKeyboardCharacterListChanged',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- if (_currentCustomKeyboardInfo.value.id == keyboardId) {
|
|
|
|
|
- _currentCustomKeyboardCharacterList.value =
|
|
|
|
|
- keyboardCharacterListResponse.characterInfos;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // 加载通用键盘数据
|
|
|
|
|
+ if (generalKeyboardInfoList.isNotEmpty) {
|
|
|
|
|
+ generalKeyboardController.loadKeyboard(generalKeyboardInfoList.first);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 切换当前定制键盘
|
|
|
|
|
|
|
+ // 切换自定义键盘
|
|
|
void switchCustomKeyboard(String? keyboardName) {
|
|
void switchCustomKeyboard(String? keyboardName) {
|
|
|
- _currentCustomKeyboardInfo.value = customKeyboardInfoList.firstWhere(
|
|
|
|
|
- (element) => element.name == keyboardName,
|
|
|
|
|
|
|
+ if (keyboardName == null) return;
|
|
|
|
|
+
|
|
|
|
|
+ KeyboardInfo keyboard = customKeyboardInfoList.firstWhere(
|
|
|
|
|
+ (element) => element.name == keyboardName,
|
|
|
orElse: () => customKeyboardInfoList.first,
|
|
orElse: () => customKeyboardInfoList.first,
|
|
|
);
|
|
);
|
|
|
- String? keyboardId = _currentCustomKeyboardInfo.value.id;
|
|
|
|
|
- _currentCustomIntimacy.value =
|
|
|
|
|
- _currentCustomKeyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
- if (keyboardId != null) {
|
|
|
|
|
- getKeyboardCharacterList(keyboardId: keyboardId, isCustom: true);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ customKeyboardController.loadKeyboard(keyboard);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // tab切换
|
|
|
|
|
|
|
+ // Tab切换
|
|
|
void switchTabKeyboardType(int index) {
|
|
void switchTabKeyboardType(int index) {
|
|
|
pageController.animateToPage(
|
|
pageController.animateToPage(
|
|
|
index,
|
|
index,
|
|
@@ -330,245 +175,142 @@ class KeyboardManageController extends BaseController
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // page切换
|
|
|
|
|
|
|
+ // Page切换
|
|
|
void switchPageKeyboardType(int index) {
|
|
void switchPageKeyboardType(int index) {
|
|
|
- // AtmobLog.i(tag, 'onPageChanged: $index');
|
|
|
|
|
-
|
|
|
|
|
tabController.animateTo(index, duration: const Duration(milliseconds: 300));
|
|
tabController.animateTo(index, duration: const Duration(milliseconds: 300));
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
if (index == 0) {
|
|
|
- _currentGeneralIntimacy.value =
|
|
|
|
|
- _currentGeneralKeyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
- _currentGeneralKeyboardCharacterList.value = _oldGeneralCharacterList;
|
|
|
|
|
- _generalIntimacyChanged.value = false;
|
|
|
|
|
- _generalKeyboardCharacterListChanged.value = false;
|
|
|
|
|
- getCustomKeyboard();
|
|
|
|
|
|
|
+ // 切换到自定义键盘,重置通用键盘状态
|
|
|
|
|
+ generalKeyboardController.intimacy.value =
|
|
|
|
|
+ generalKeyboardController.keyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
+ generalKeyboardController.characterList.value =
|
|
|
|
|
+ generalKeyboardController.oldCharacterList;
|
|
|
|
|
+ generalKeyboardController.intimacyChanged.value = false;
|
|
|
|
|
+ generalKeyboardController.characterListChanged.value = false;
|
|
|
|
|
+
|
|
|
|
|
+ // 刷新自定义键盘数据
|
|
|
|
|
+ if (customKeyboardController.keyboardInfo.value.id != null) {
|
|
|
|
|
+ customKeyboardController.getKeyboardCharacterList(
|
|
|
|
|
+ keyboardId: customKeyboardController.keyboardInfo.value.id!,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- _currentCustomIntimacy.value =
|
|
|
|
|
- _currentCustomKeyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
|
|
+ // 切换到通用键盘,重置自定义键盘状态
|
|
|
|
|
+ customKeyboardController.intimacy.value =
|
|
|
|
|
+ customKeyboardController.keyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
|
|
|
- if (_oldCustomCharacterList.isNotEmpty) {
|
|
|
|
|
- _currentCustomKeyboardCharacterList.value = _oldCustomCharacterList;
|
|
|
|
|
|
|
+ if (customKeyboardController.oldCharacterList.isNotEmpty) {
|
|
|
|
|
+ customKeyboardController.characterList.value =
|
|
|
|
|
+ customKeyboardController.oldCharacterList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _customIntimacyChanged.value = false;
|
|
|
|
|
- _customKeyboardCharacterListChanged.value = false;
|
|
|
|
|
- getGeneralKeyboard();
|
|
|
|
|
|
|
+ customKeyboardController.intimacyChanged.value = false;
|
|
|
|
|
+ customKeyboardController.characterListChanged.value = false;
|
|
|
|
|
+
|
|
|
|
|
+ // 刷新通用键盘数据
|
|
|
|
|
+ if (generalKeyboardController.keyboardInfo.value.id != null) {
|
|
|
|
|
+ generalKeyboardController.getKeyboardCharacterList(
|
|
|
|
|
+ keyboardId: generalKeyboardController.keyboardInfo.value.id!,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 点击返回
|
|
|
|
|
+ void clickBack() {
|
|
|
|
|
+ AtmobLog.i(tag, 'clickBack');
|
|
|
|
|
+ Get.back();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 更新亲密度
|
|
// 更新亲密度
|
|
|
void updateIntimacy(int intimacy, bool isCustom) {
|
|
void updateIntimacy(int intimacy, bool isCustom) {
|
|
|
if (isCustom) {
|
|
if (isCustom) {
|
|
|
- _currentCustomIntimacy.value = intimacy;
|
|
|
|
|
|
|
+ customKeyboardController.updateIntimacy(intimacy);
|
|
|
} else {
|
|
} else {
|
|
|
- _currentGeneralIntimacy.value = intimacy;
|
|
|
|
|
|
|
+ generalKeyboardController.updateIntimacy(intimacy);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 排序
|
|
// 排序
|
|
|
void onReorder(int oldIndex, int newIndex, bool isCustom) {
|
|
void onReorder(int oldIndex, int newIndex, bool isCustom) {
|
|
|
if (isCustom) {
|
|
if (isCustom) {
|
|
|
- reorderList(_currentCustomKeyboardCharacterList, oldIndex, newIndex);
|
|
|
|
|
|
|
+ customKeyboardController.reorderCharacters(oldIndex, newIndex);
|
|
|
} else {
|
|
} else {
|
|
|
- reorderList(_currentGeneralKeyboardCharacterList, oldIndex, newIndex);
|
|
|
|
|
|
|
+ generalKeyboardController.reorderCharacters(oldIndex, newIndex);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 排序
|
|
|
|
|
- void reorderList<T>(RxList<T> list, int oldIndex, int newIndex) {
|
|
|
|
|
- AtmobLog.d(tag, 'reorderList: $oldIndex, $newIndex');
|
|
|
|
|
- final item = list.removeAt(oldIndex);
|
|
|
|
|
- list.insert(newIndex, item);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // 保存
|
|
|
void clickSave(bool isCustom) {
|
|
void clickSave(bool isCustom) {
|
|
|
- isCustom
|
|
|
|
|
- ? saveCustomKeyboardCharacterList()
|
|
|
|
|
- : saveGeneralKeyboardCharacterList();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- void saveCustomKeyboardCharacterList() {
|
|
|
|
|
-
|
|
|
|
|
- EventHandler.report(EventId.event_13002);
|
|
|
|
|
-
|
|
|
|
|
- _saveKeyboardInfo(
|
|
|
|
|
- intimacyChanged: _customIntimacyChanged,
|
|
|
|
|
- currentIntimacy: currentCustomIntimacy,
|
|
|
|
|
- currentKeyboardInfo: _currentCustomKeyboardInfo,
|
|
|
|
|
- characterListChanged: _customKeyboardCharacterListChanged,
|
|
|
|
|
- currentCharacterList: _currentCustomKeyboardCharacterList,
|
|
|
|
|
- onUpdateSuccess: () {
|
|
|
|
|
- _oldCustomCharacterList = List<CharacterInfo>.from(
|
|
|
|
|
- _currentCustomKeyboardCharacterList,
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // 更具键盘组刷新对应的数据
|
|
|
|
|
- CharactersRepository.getInstance().characterGroupList.forEach((e) {
|
|
|
|
|
- final tag = "CharacterGroupContentController${_currentCustomKeyboardInfo.value.id}${e.id}";
|
|
|
|
|
-
|
|
|
|
|
- if (Get.isRegistered<CharacterGroupContentController>(tag: tag)) {
|
|
|
|
|
-
|
|
|
|
|
- var controller = Get.find<CharacterGroupContentController>(tag: tag);
|
|
|
|
|
- controller.refreshData();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- // 通知键盘,刷新人设列表
|
|
|
|
|
- KeyboardAndroidPlatform.refreshCharacterList();
|
|
|
|
|
- saveSuccessGetBack();
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- void saveGeneralKeyboardCharacterList() {
|
|
|
|
|
- EventHandler.report(EventId.event_13004);
|
|
|
|
|
- _saveKeyboardInfo(
|
|
|
|
|
- intimacyChanged: _generalIntimacyChanged,
|
|
|
|
|
- currentIntimacy: currentGeneralIntimacy,
|
|
|
|
|
- currentKeyboardInfo: _currentGeneralKeyboardInfo,
|
|
|
|
|
- characterListChanged: _generalKeyboardCharacterListChanged,
|
|
|
|
|
- currentCharacterList: _currentGeneralKeyboardCharacterList,
|
|
|
|
|
- onUpdateSuccess: () {
|
|
|
|
|
- _oldGeneralCharacterList = List<CharacterInfo>.from(
|
|
|
|
|
- _currentGeneralKeyboardCharacterList,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ final controller =
|
|
|
|
|
+ isCustom ? customKeyboardController : generalKeyboardController;
|
|
|
|
|
+ final eventId = isCustom ? EventId.event_13002 : EventId.event_13004;
|
|
|
|
|
|
|
|
- // 每次保存对应键盘都刷一次数据,一瞬间刷新8次
|
|
|
|
|
- CharactersRepository.getInstance().characterGroupList.forEach((e) {
|
|
|
|
|
- final tag = "CharacterGroupContentController${_currentGeneralKeyboardInfo.value.id}${e.id}";
|
|
|
|
|
|
|
+ EventHandler.report(eventId);
|
|
|
|
|
|
|
|
- if (Get.isRegistered<CharacterGroupContentController>(tag: tag)) {
|
|
|
|
|
-
|
|
|
|
|
- var controller = Get.find<CharacterGroupContentController>(tag: tag);
|
|
|
|
|
- controller.refreshData();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- // 通知键盘,刷新人设列表
|
|
|
|
|
- KeyboardAndroidPlatform.refreshCharacterList();
|
|
|
|
|
|
|
+ controller.saveKeyboardInfo(
|
|
|
|
|
+ onSuccess: () {
|
|
|
|
|
+ if (isCustom) {
|
|
|
|
|
+ saveSuccessGetBack();
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void _saveKeyboardInfo({
|
|
|
|
|
- required RxBool intimacyChanged,
|
|
|
|
|
- required int currentIntimacy,
|
|
|
|
|
- required Rx<KeyboardInfo> currentKeyboardInfo,
|
|
|
|
|
- required RxBool characterListChanged,
|
|
|
|
|
- required List<CharacterInfo> currentCharacterList,
|
|
|
|
|
- required VoidCallback onUpdateSuccess,
|
|
|
|
|
- }) {
|
|
|
|
|
- String? keyboardId = currentKeyboardInfo.value.id;
|
|
|
|
|
-
|
|
|
|
|
- if (intimacyChanged.value && keyboardId != null) {
|
|
|
|
|
- AtmobLog.i(tag, 'clickSave intimacyChanged');
|
|
|
|
|
- currentKeyboardInfo.value.intimacy = currentIntimacy;
|
|
|
|
|
- keyboardRepository
|
|
|
|
|
- .updateKeyboardInfo(keyboardId: keyboardId, intimacy: currentIntimacy)
|
|
|
|
|
- .then((_) async {
|
|
|
|
|
- ToastUtil.show(StringName.keyboardSaveSuccess);
|
|
|
|
|
- await keyboardRepository.refreshData();
|
|
|
|
|
- })
|
|
|
|
|
- .catchError((error) {
|
|
|
|
|
- if (error is ServerErrorException) {
|
|
|
|
|
- ErrorHandler.toastError(error);
|
|
|
|
|
- if (error.code == ErrorCode.noLoginError) {
|
|
|
|
|
- LoginDialog.show();
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- ToastUtil.show(StringName.keyboardSaveFailed);
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .whenComplete(() => intimacyChanged.value = false);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (characterListChanged.value && keyboardId != null) {
|
|
|
|
|
- AtmobLog.i(tag, 'clickSave keyboardChanged');
|
|
|
|
|
- List<String> characterIds =
|
|
|
|
|
- currentCharacterList.map((e) => e.id).cast<String>().toList();
|
|
|
|
|
- keyboardRepository
|
|
|
|
|
- .keyboardCharacterUpdate(
|
|
|
|
|
- keyboardId: keyboardId,
|
|
|
|
|
- characterIds: characterIds,
|
|
|
|
|
- )
|
|
|
|
|
- .then((_) async {
|
|
|
|
|
- onUpdateSuccess();
|
|
|
|
|
- ToastUtil.show(StringName.keyboardSaveSuccess);
|
|
|
|
|
- await keyboardRepository.refreshData();
|
|
|
|
|
- })
|
|
|
|
|
- .catchError((error) {
|
|
|
|
|
- if (error is ServerErrorException) {
|
|
|
|
|
- ErrorHandler.toastError(error);
|
|
|
|
|
- if (error.code == ErrorCode.noLoginError) {
|
|
|
|
|
- LoginDialog.show();
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- ToastUtil.show(StringName.keyboardSaveFailed);
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .whenComplete(() => characterListChanged.value = false);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // 移除人设
|
|
|
void clickRemoveCharacter(CharacterInfo characterInfo, bool isCustom) {
|
|
void clickRemoveCharacter(CharacterInfo characterInfo, bool isCustom) {
|
|
|
- if (isCustom) {
|
|
|
|
|
- if (_currentCustomKeyboardCharacterList.length <= _minCount) {
|
|
|
|
|
- ToastUtil.show("最少需要保持$_minCount个人设");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- AtmobLog.i(tag, 'clickRemoveCharacter');
|
|
|
|
|
- _currentCustomKeyboardCharacterList.remove(characterInfo);
|
|
|
|
|
- } else {
|
|
|
|
|
- if (_currentGeneralKeyboardCharacterList.length <= _minCount) {
|
|
|
|
|
- ToastUtil.show("最少需要保持$_minCount个人设");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- AtmobLog.i(tag, 'clickRemoveCharacter');
|
|
|
|
|
-
|
|
|
|
|
- _currentGeneralKeyboardCharacterList.remove(characterInfo);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ final controller =
|
|
|
|
|
+ isCustom ? customKeyboardController : generalKeyboardController;
|
|
|
|
|
+ controller.removeCharacter(characterInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- clickAddCharacter({required bool isCustom}) {
|
|
|
|
|
|
|
+ // 添加人设
|
|
|
|
|
+ void clickAddCharacter({required bool isCustom}) {
|
|
|
if (!isLogin.value) {
|
|
if (!isLogin.value) {
|
|
|
ToastUtil.show("请先登录");
|
|
ToastUtil.show("请先登录");
|
|
|
LoginDialog.show();
|
|
LoginDialog.show();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (isCustom) {
|
|
|
|
|
- CharacterAddDialog.show(
|
|
|
|
|
- currentKeyboardInfo: _currentCustomKeyboardInfo.value,
|
|
|
|
|
- clickCallback: () {
|
|
|
|
|
- getKeyboardCharacterList(
|
|
|
|
|
- keyboardId: _currentCustomKeyboardInfo.value.id ?? "",
|
|
|
|
|
- isCustom: true,
|
|
|
|
|
- );
|
|
|
|
|
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- } else {
|
|
|
|
|
- CharacterAddDialog.show(
|
|
|
|
|
- currentKeyboardInfo: currentGeneralKeyboardInfo,
|
|
|
|
|
- clickCallback: () {
|
|
|
|
|
- getGeneralKeyboard();
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ final KeyboardInfo currentKeyboard =
|
|
|
|
|
+ isCustom
|
|
|
|
|
+ ? customKeyboardController.keyboardInfo.value
|
|
|
|
|
+ : generalKeyboardController.keyboardInfo.value;
|
|
|
|
|
+
|
|
|
|
|
+ CharacterAddDialog.show(
|
|
|
|
|
+ currentKeyboardInfo: currentKeyboard,
|
|
|
|
|
+ clickCallback: () {
|
|
|
|
|
+ if (isCustom) {
|
|
|
|
|
+ customKeyboardController.getKeyboardCharacterList(
|
|
|
|
|
+ keyboardId: customKeyboardController.keyboardInfo.value.id ?? "",
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ generalKeyboardController.getKeyboardCharacterList(
|
|
|
|
|
+ keyboardId: generalKeyboardController.keyboardInfo.value.id ?? "",
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- clickCustomCharacter() {
|
|
|
|
|
|
|
+ // 自定义人设
|
|
|
|
|
+ void clickCustomCharacter() {
|
|
|
if (!isLogin.value) {
|
|
if (!isLogin.value) {
|
|
|
ToastUtil.show("请先登录");
|
|
ToastUtil.show("请先登录");
|
|
|
LoginDialog.show();
|
|
LoginDialog.show();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
AtmobLog.i(tag, 'clickCustomCharacter');
|
|
AtmobLog.i(tag, 'clickCustomCharacter');
|
|
|
CustomCharacterAddDialog.show(
|
|
CustomCharacterAddDialog.show(
|
|
|
- currentKeyboardInfo: _currentCustomKeyboardInfo.value,
|
|
|
|
|
|
|
+ currentKeyboardInfo: customKeyboardController.keyboardInfo.value,
|
|
|
clickCallback: () {
|
|
clickCallback: () {
|
|
|
- getKeyboardCharacterList(
|
|
|
|
|
- keyboardId: _currentCustomKeyboardInfo.value.id ?? "",
|
|
|
|
|
- isCustom: true,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ String? keyboardId = customKeyboardController.keyboardInfo.value.id;
|
|
|
|
|
+ if (keyboardId != null) {
|
|
|
|
|
+ customKeyboardController.getKeyboardCharacterList(
|
|
|
|
|
+ keyboardId: keyboardId,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -577,11 +319,11 @@ class KeyboardManageController extends BaseController
|
|
|
void onClose() {
|
|
void onClose() {
|
|
|
tabController.dispose();
|
|
tabController.dispose();
|
|
|
pageController.dispose();
|
|
pageController.dispose();
|
|
|
- _customKeyboardInfoListWorker.dispose();
|
|
|
|
|
|
|
+ _keyboardInfoListWorker.dispose();
|
|
|
super.onClose();
|
|
super.onClose();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void saveSuccessGetBack() {
|
|
void saveSuccessGetBack() {
|
|
|
- Get.back(result: _currentCustomKeyboardCharacterList);
|
|
|
|
|
|
|
+ Get.back(result: customKeyboardController.characterList);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|