|
@@ -18,6 +18,7 @@ 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/consts/error_code.dart';
|
|
|
|
|
+import '../../data/repository/characters_repository.dart';
|
|
|
import '../../plugins/keyboard_android_platform.dart';
|
|
import '../../plugins/keyboard_android_platform.dart';
|
|
|
import '../../utils/error_handler.dart';
|
|
import '../../utils/error_handler.dart';
|
|
|
import '../../utils/http_handler.dart';
|
|
import '../../utils/http_handler.dart';
|
|
@@ -34,12 +35,12 @@ class KeyboardManageController extends BaseController
|
|
|
|
|
|
|
|
final AccountRepository accountRepository;
|
|
final AccountRepository accountRepository;
|
|
|
|
|
|
|
|
- bool get isLogin => accountRepository.isLogin.value;
|
|
|
|
|
|
|
+ final KeyboardRepository keyboardRepository;
|
|
|
|
|
|
|
|
- // 自定义键盘列表
|
|
|
|
|
- final RxList<KeyboardInfo> _customKeyboardInfoList = RxList();
|
|
|
|
|
|
|
+ RxBool get isLogin => accountRepository.isLogin;
|
|
|
|
|
|
|
|
- List<KeyboardInfo> get customKeyboardInfoList => _customKeyboardInfoList;
|
|
|
|
|
|
|
+ RxList<KeyboardInfo> get customKeyboardInfoList =>
|
|
|
|
|
+ keyboardRepository.customKeyboardInfoList;
|
|
|
|
|
|
|
|
// 当前自定义键盘
|
|
// 当前自定义键盘
|
|
|
final Rx<KeyboardInfo> _currentCustomKeyboardInfo = KeyboardInfo().obs;
|
|
final Rx<KeyboardInfo> _currentCustomKeyboardInfo = KeyboardInfo().obs;
|
|
@@ -71,10 +72,8 @@ class KeyboardManageController extends BaseController
|
|
|
// 存储排序前的定制人设列表,用于比较是否有变化
|
|
// 存储排序前的定制人设列表,用于比较是否有变化
|
|
|
List<CharacterInfo> _oldCustomCharacterList = [];
|
|
List<CharacterInfo> _oldCustomCharacterList = [];
|
|
|
|
|
|
|
|
- // 通用键盘列表
|
|
|
|
|
- final RxList<KeyboardInfo> _generalKeyboardInfoList = RxList();
|
|
|
|
|
-
|
|
|
|
|
- List<KeyboardInfo> get generalKeyboardInfoList => _generalKeyboardInfoList;
|
|
|
|
|
|
|
+ RxList<KeyboardInfo> get generalKeyboardInfoList =>
|
|
|
|
|
+ keyboardRepository.generalKeyboardInfoList;
|
|
|
|
|
|
|
|
// 当前通用键盘
|
|
// 当前通用键盘
|
|
|
final Rx<KeyboardInfo> _currentGeneralKeyboardInfo = KeyboardInfo().obs;
|
|
final Rx<KeyboardInfo> _currentGeneralKeyboardInfo = KeyboardInfo().obs;
|
|
@@ -106,7 +105,7 @@ class KeyboardManageController extends BaseController
|
|
|
// 存储排序前的通用人设列表,用于比较是否有变化
|
|
// 存储排序前的通用人设列表,用于比较是否有变化
|
|
|
late List<CharacterInfo> _oldGeneralCharacterList;
|
|
late List<CharacterInfo> _oldGeneralCharacterList;
|
|
|
|
|
|
|
|
- final KeyboardRepository keyboardRepository;
|
|
|
|
|
|
|
+ late Worker _customKeyboardInfoListWorker;
|
|
|
|
|
|
|
|
// 最小人设数量
|
|
// 最小人设数量
|
|
|
final _minCount = 9;
|
|
final _minCount = 9;
|
|
@@ -137,14 +136,16 @@ class KeyboardManageController extends BaseController
|
|
|
_currentCustomKeyboardInfo.value = args["customKeyboardInfo"];
|
|
_currentCustomKeyboardInfo.value = args["customKeyboardInfo"];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- await _dataLoad();
|
|
|
|
|
|
|
+ await _dataLoad();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
_dataLoad() async {
|
|
_dataLoad() async {
|
|
|
|
|
+ getCustomKeyboard();
|
|
|
|
|
+ getGeneralKeyboard();
|
|
|
tabController = TabController(
|
|
tabController = TabController(
|
|
|
length: keyboardManageType.length,
|
|
length: keyboardManageType.length,
|
|
|
vsync: this,
|
|
vsync: this,
|
|
|
- initialIndex: 0,
|
|
|
|
|
|
|
+ initialIndex: customKeyboardInfoList.isEmpty ? 1 : 0,
|
|
|
);
|
|
);
|
|
|
tabController.addListener(() {
|
|
tabController.addListener(() {
|
|
|
if (tabController.indexIsChanging) {
|
|
if (tabController.indexIsChanging) {
|
|
@@ -157,21 +158,36 @@ class KeyboardManageController extends BaseController
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- pageController = PageController();
|
|
|
|
|
|
|
+ pageController = PageController(
|
|
|
|
|
+ initialPage: customKeyboardInfoList.isEmpty ? 1 : 0,
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- await getCustomKeyboard();
|
|
|
|
|
- if (isFirstLoad.value) {
|
|
|
|
|
- if (_customKeyboardInfoList.isEmpty) {
|
|
|
|
|
- // 去另一个tab
|
|
|
|
|
- pageController.jumpToPage(1);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ _customKeyboardInfoListWorker = everAll(
|
|
|
|
|
+ [customKeyboardInfoList, generalKeyboardInfoList],
|
|
|
|
|
+ (_) {
|
|
|
|
|
|
|
|
- isFirstLoad.value = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (tabController.index == 0) {
|
|
|
|
|
- EventHandler.report(EventId.event_13001);
|
|
|
|
|
- }
|
|
|
|
|
- getGeneralKeyboard();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ 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() {
|
|
clickBack() {
|
|
@@ -187,64 +203,47 @@ class KeyboardManageController extends BaseController
|
|
|
// 获取定制键盘
|
|
// 获取定制键盘
|
|
|
Future<void> getCustomKeyboard() async {
|
|
Future<void> getCustomKeyboard() async {
|
|
|
AtmobLog.i(tag, 'getCustomKeyboard');
|
|
AtmobLog.i(tag, 'getCustomKeyboard');
|
|
|
- await keyboardRepository.getKeyboardList(type: KeyboardType.custom.name).then((
|
|
|
|
|
- keyboardListResponse,
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ if (customKeyboardInfoList.isNotEmpty) {
|
|
|
AtmobLog.i(
|
|
AtmobLog.i(
|
|
|
tag,
|
|
tag,
|
|
|
- 'keyboardListResponse: ${keyboardListResponse.keyboardInfos}',
|
|
|
|
|
|
|
+ 'customKeyboardInfoList: ${customKeyboardInfoList.length}',
|
|
|
);
|
|
);
|
|
|
- _customKeyboardInfoList.value = keyboardListResponse.keyboardInfos;
|
|
|
|
|
-
|
|
|
|
|
- //检查是否是选择的键盘,如果没有选择的键盘,默认选择第一个
|
|
|
|
|
- if (_customKeyboardInfoList.isNotEmpty) {
|
|
|
|
|
- if (_currentCustomKeyboardInfo.value.id == null) {
|
|
|
|
|
- _currentCustomKeyboardInfo.value = _customKeyboardInfoList.firstWhere(
|
|
|
|
|
- (element) => element.isChoose == true,
|
|
|
|
|
- orElse: () => _customKeyboardInfoList.first,
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- _currentCustomIntimacy.value =
|
|
|
|
|
- _currentCustomKeyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
- _currentCustomIntimacy.listen((intimacy) {
|
|
|
|
|
- _customIntimacyChanged.value =
|
|
|
|
|
- _currentCustomKeyboardInfo.value.intimacy != intimacy;
|
|
|
|
|
- AtmobLog.d(tag, 'intimacyChanged: $_customIntimacyChanged');
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (_currentCustomKeyboardInfo.value.id == null) {
|
|
|
|
|
+ _currentCustomKeyboardInfo.value = customKeyboardInfoList.firstWhere(
|
|
|
|
|
+ (element) => element.isChoose == true,
|
|
|
|
|
+ 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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String? id = _currentCustomKeyboardInfo.value.id;
|
|
|
|
|
+ if (id != null) {
|
|
|
|
|
+ getKeyboardCharacterList(keyboardId: id, isCustom: true);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取通用键盘
|
|
// 获取通用键盘
|
|
|
void getGeneralKeyboard() {
|
|
void getGeneralKeyboard() {
|
|
|
- AtmobLog.i(tag, 'getGeneralKeyboard');
|
|
|
|
|
- keyboardRepository.getKeyboardList(type: KeyboardType.system.name).then((
|
|
|
|
|
- keyboardListResponse,
|
|
|
|
|
- ) {
|
|
|
|
|
- AtmobLog.i(
|
|
|
|
|
- tag,
|
|
|
|
|
- 'keyboardListResponse: ${keyboardListResponse.keyboardInfos}',
|
|
|
|
|
- );
|
|
|
|
|
- _generalKeyboardInfoList.value = keyboardListResponse.keyboardInfos;
|
|
|
|
|
- _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) {
|
|
|
|
|
- getKeyboardCharacterList(keyboardId: id, isCustom: false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ _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);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取当前键盘人设列表
|
|
// 获取当前键盘人设列表
|
|
@@ -310,9 +309,9 @@ class KeyboardManageController extends BaseController
|
|
|
|
|
|
|
|
// 切换当前定制键盘
|
|
// 切换当前定制键盘
|
|
|
void switchCustomKeyboard(String? keyboardName) {
|
|
void switchCustomKeyboard(String? keyboardName) {
|
|
|
- _currentCustomKeyboardInfo.value = _customKeyboardInfoList.firstWhere(
|
|
|
|
|
|
|
+ _currentCustomKeyboardInfo.value = customKeyboardInfoList.firstWhere(
|
|
|
(element) => element.name == keyboardName,
|
|
(element) => element.name == keyboardName,
|
|
|
- orElse: () => _customKeyboardInfoList.first,
|
|
|
|
|
|
|
+ orElse: () => customKeyboardInfoList.first,
|
|
|
);
|
|
);
|
|
|
String? keyboardId = _currentCustomKeyboardInfo.value.id;
|
|
String? keyboardId = _currentCustomKeyboardInfo.value.id;
|
|
|
_currentCustomIntimacy.value =
|
|
_currentCustomIntimacy.value =
|
|
@@ -324,7 +323,6 @@ class KeyboardManageController extends BaseController
|
|
|
|
|
|
|
|
// tab切换
|
|
// tab切换
|
|
|
void switchTabKeyboardType(int index) {
|
|
void switchTabKeyboardType(int index) {
|
|
|
- // AtmobLog.i(tag, 'onTabChanged: $index');
|
|
|
|
|
pageController.animateToPage(
|
|
pageController.animateToPage(
|
|
|
index,
|
|
index,
|
|
|
duration: const Duration(milliseconds: 300),
|
|
duration: const Duration(milliseconds: 300),
|
|
@@ -404,7 +402,17 @@ class KeyboardManageController extends BaseController
|
|
|
_oldCustomCharacterList = List<CharacterInfo>.from(
|
|
_oldCustomCharacterList = List<CharacterInfo>.from(
|
|
|
_currentCustomKeyboardCharacterList,
|
|
_currentCustomKeyboardCharacterList,
|
|
|
);
|
|
);
|
|
|
- Get.find<CharacterGroupContentController>().refreshData();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 更具键盘组刷新对应的数据
|
|
|
|
|
+ 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();
|
|
KeyboardAndroidPlatform.refreshCharacterList();
|
|
|
saveSuccessGetBack();
|
|
saveSuccessGetBack();
|
|
@@ -424,6 +432,17 @@ class KeyboardManageController extends BaseController
|
|
|
_oldGeneralCharacterList = List<CharacterInfo>.from(
|
|
_oldGeneralCharacterList = List<CharacterInfo>.from(
|
|
|
_currentGeneralKeyboardCharacterList,
|
|
_currentGeneralKeyboardCharacterList,
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ // 每次保存对应键盘都刷一次数据,一瞬间刷新8次
|
|
|
|
|
+ CharactersRepository.getInstance().characterGroupList.forEach((e) {
|
|
|
|
|
+ final tag = "CharacterGroupContentController${_currentGeneralKeyboardInfo.value.id}${e.id}";
|
|
|
|
|
+
|
|
|
|
|
+ if (Get.isRegistered<CharacterGroupContentController>(tag: tag)) {
|
|
|
|
|
+
|
|
|
|
|
+ var controller = Get.find<CharacterGroupContentController>(tag: tag);
|
|
|
|
|
+ controller.refreshData();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
// 通知键盘,刷新人设列表
|
|
// 通知键盘,刷新人设列表
|
|
|
KeyboardAndroidPlatform.refreshCharacterList();
|
|
KeyboardAndroidPlatform.refreshCharacterList();
|
|
|
},
|
|
},
|
|
@@ -510,19 +529,20 @@ class KeyboardManageController extends BaseController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
clickAddCharacter({required bool isCustom}) {
|
|
clickAddCharacter({required bool isCustom}) {
|
|
|
- if (!isLogin) {
|
|
|
|
|
|
|
+ if (!isLogin.value) {
|
|
|
ToastUtil.show("请先登录");
|
|
ToastUtil.show("请先登录");
|
|
|
LoginDialog.show();
|
|
LoginDialog.show();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (isCustom) {
|
|
if (isCustom) {
|
|
|
CharacterAddDialog.show(
|
|
CharacterAddDialog.show(
|
|
|
- currentKeyboardInfo: currentCustomKeyboardInfo,
|
|
|
|
|
|
|
+ currentKeyboardInfo: _currentCustomKeyboardInfo.value,
|
|
|
clickCallback: () {
|
|
clickCallback: () {
|
|
|
getKeyboardCharacterList(
|
|
getKeyboardCharacterList(
|
|
|
keyboardId: _currentCustomKeyboardInfo.value.id ?? "",
|
|
keyboardId: _currentCustomKeyboardInfo.value.id ?? "",
|
|
|
isCustom: true,
|
|
isCustom: true,
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
} else {
|
|
} else {
|
|
@@ -536,14 +556,14 @@ class KeyboardManageController extends BaseController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
clickCustomCharacter() {
|
|
clickCustomCharacter() {
|
|
|
- if (!isLogin) {
|
|
|
|
|
|
|
+ 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,
|
|
|
|
|
|
|
+ currentKeyboardInfo: _currentCustomKeyboardInfo.value,
|
|
|
clickCallback: () {
|
|
clickCallback: () {
|
|
|
getKeyboardCharacterList(
|
|
getKeyboardCharacterList(
|
|
|
keyboardId: _currentCustomKeyboardInfo.value.id ?? "",
|
|
keyboardId: _currentCustomKeyboardInfo.value.id ?? "",
|
|
@@ -557,6 +577,7 @@ class KeyboardManageController extends BaseController
|
|
|
void onClose() {
|
|
void onClose() {
|
|
|
tabController.dispose();
|
|
tabController.dispose();
|
|
|
pageController.dispose();
|
|
pageController.dispose();
|
|
|
|
|
+ _customKeyboardInfoListWorker.dispose();
|
|
|
super.onClose();
|
|
super.onClose();
|
|
|
}
|
|
}
|
|
|
|
|
|