|
|
@@ -8,12 +8,14 @@ import 'package:keyboard/data/repository/account_repository.dart';
|
|
|
import 'package:keyboard/data/repository/keyboard_repository.dart';
|
|
|
import 'package:keyboard/dialog/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/module/character/content/character_group_content_controller.dart';
|
|
|
import 'package:keyboard/resource/string.gen.dart';
|
|
|
import 'package:keyboard/utils/atmob_log.dart';
|
|
|
import 'package:keyboard/utils/toast_util.dart';
|
|
|
|
|
|
import '../../data/bean/keyboard_info.dart';
|
|
|
+import '../../data/consts/error_code.dart';
|
|
|
import '../../utils/error_handler.dart';
|
|
|
import '../../utils/http_handler.dart';
|
|
|
|
|
|
@@ -64,7 +66,7 @@ class KeyboardManageController extends BaseController
|
|
|
_customKeyboardCharacterListChanged.value;
|
|
|
|
|
|
// 存储排序前的定制人设列表,用于比较是否有变化
|
|
|
- List<CharacterInfo> _oldCustomCharacterList = [];
|
|
|
+ List<CharacterInfo> _oldCustomCharacterList = [];
|
|
|
|
|
|
// 通用键盘列表
|
|
|
final RxList<KeyboardInfo> _generalKeyboardInfoList = RxList();
|
|
|
@@ -118,10 +120,13 @@ class KeyboardManageController extends BaseController
|
|
|
// 键盘管理页面的pageController,用于控制通用键盘和自定义键盘的切换
|
|
|
late PageController pageController;
|
|
|
|
|
|
+ // 首次加载数据标志
|
|
|
+ final isFirstLoad = true.obs;
|
|
|
+
|
|
|
KeyboardManageController(this.keyboardRepository, this.accountRepository);
|
|
|
|
|
|
@override
|
|
|
- void onInit() {
|
|
|
+ void onInit() async {
|
|
|
super.onInit();
|
|
|
|
|
|
final args = Get.arguments;
|
|
|
@@ -129,10 +134,10 @@ class KeyboardManageController extends BaseController
|
|
|
_currentCustomKeyboardInfo.value = args["customKeyboardInfo"];
|
|
|
}
|
|
|
|
|
|
- _dataLoad();
|
|
|
+ await _dataLoad();
|
|
|
}
|
|
|
|
|
|
- _dataLoad() {
|
|
|
+ _dataLoad() async {
|
|
|
tabController = TabController(
|
|
|
length: keyboardManageType.length,
|
|
|
vsync: this,
|
|
|
@@ -146,7 +151,16 @@ class KeyboardManageController extends BaseController
|
|
|
|
|
|
pageController = PageController();
|
|
|
|
|
|
- getCustomKeyboard();
|
|
|
+ await getCustomKeyboard();
|
|
|
+ if (isFirstLoad.value) {
|
|
|
+ if (_customKeyboardInfoList.isEmpty) {
|
|
|
+ // 去另一个tab
|
|
|
+ pageController.jumpToPage(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ isFirstLoad.value = false;
|
|
|
+ }
|
|
|
+
|
|
|
getGeneralKeyboard();
|
|
|
}
|
|
|
|
|
|
@@ -155,10 +169,15 @@ class KeyboardManageController extends BaseController
|
|
|
Get.back();
|
|
|
}
|
|
|
|
|
|
+ @override
|
|
|
+ void onReady() {
|
|
|
+ super.onReady();
|
|
|
+ }
|
|
|
+
|
|
|
// 获取定制键盘
|
|
|
- void getCustomKeyboard() {
|
|
|
+ Future<void> getCustomKeyboard() async {
|
|
|
AtmobLog.i(tag, 'getCustomKeyboard');
|
|
|
- keyboardRepository.getKeyboardList(type: KeyboardType.custom.name).then((
|
|
|
+ await keyboardRepository.getKeyboardList(type: KeyboardType.custom.name).then((
|
|
|
keyboardListResponse,
|
|
|
) {
|
|
|
AtmobLog.i(
|
|
|
@@ -171,11 +190,10 @@ class KeyboardManageController extends BaseController
|
|
|
if (_customKeyboardInfoList.isNotEmpty) {
|
|
|
if (_currentCustomKeyboardInfo.value.id == null) {
|
|
|
_currentCustomKeyboardInfo.value = _customKeyboardInfoList.firstWhere(
|
|
|
- (element) => element.isChoose == true,
|
|
|
+ (element) => element.isChoose == true,
|
|
|
orElse: () => _customKeyboardInfoList.first,
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
_currentCustomIntimacy.value =
|
|
|
_currentCustomKeyboardInfo.value.intimacy ?? 0;
|
|
|
_currentCustomIntimacy.listen((intimacy) {
|
|
|
@@ -294,20 +312,6 @@ class KeyboardManageController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 切换当前通用键盘
|
|
|
- void switchGeneralKeyboard(String? keyboardName) {
|
|
|
- _currentGeneralKeyboardInfo.value = _generalKeyboardInfoList.firstWhere(
|
|
|
- (element) => element.name == keyboardName,
|
|
|
- orElse: () => _generalKeyboardInfoList.first,
|
|
|
- );
|
|
|
- String? keyboardId = _currentGeneralKeyboardInfo.value.id;
|
|
|
- _currentGeneralIntimacy.value =
|
|
|
- _currentGeneralKeyboardInfo.value.intimacy ?? 0;
|
|
|
- if (keyboardId != null) {
|
|
|
- getKeyboardCharacterList(keyboardId: keyboardId, isCustom: false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// tab切换
|
|
|
void switchTabKeyboardType(int index) {
|
|
|
// AtmobLog.i(tag, 'onTabChanged: $index');
|
|
|
@@ -335,7 +339,7 @@ class KeyboardManageController extends BaseController
|
|
|
_currentCustomIntimacy.value =
|
|
|
_currentCustomKeyboardInfo.value.intimacy ?? 0;
|
|
|
|
|
|
- if(_oldCustomCharacterList.isNotEmpty){
|
|
|
+ if (_oldCustomCharacterList.isNotEmpty) {
|
|
|
_currentCustomKeyboardCharacterList.value = _oldCustomCharacterList;
|
|
|
}
|
|
|
|
|
|
@@ -374,8 +378,6 @@ class KeyboardManageController extends BaseController
|
|
|
isCustom
|
|
|
? saveCustomKeyboardCharacterList()
|
|
|
: saveGeneralKeyboardCharacterList();
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void saveCustomKeyboardCharacterList() {
|
|
|
@@ -426,14 +428,18 @@ class KeyboardManageController extends BaseController
|
|
|
keyboardRepository
|
|
|
.updateKeyboardInfo(keyboardId: keyboardId, intimacy: currentIntimacy)
|
|
|
.then((_) async {
|
|
|
- ToastUtil.show(StringName.keyboardSaveSuccess);
|
|
|
- await keyboardRepository.refreshData();
|
|
|
+ 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);
|
|
|
}
|
|
|
- ToastUtil.show(StringName.keyboardSaveFailed);
|
|
|
})
|
|
|
.whenComplete(() => intimacyChanged.value = false);
|
|
|
}
|
|
|
@@ -455,8 +461,12 @@ class KeyboardManageController extends BaseController
|
|
|
.catchError((error) {
|
|
|
if (error is ServerErrorException) {
|
|
|
ErrorHandler.toastError(error);
|
|
|
+ if (error.code == ErrorCode.noLoginError) {
|
|
|
+ LoginDialog.show();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ToastUtil.show(StringName.keyboardSaveFailed);
|
|
|
}
|
|
|
- ToastUtil.show(StringName.keyboardSaveFailed);
|
|
|
})
|
|
|
.whenComplete(() => characterListChanged.value = false);
|
|
|
}
|
|
|
@@ -484,6 +494,7 @@ class KeyboardManageController extends BaseController
|
|
|
clickAddCharacter({required bool isCustom}) {
|
|
|
if (!isLogin) {
|
|
|
ToastUtil.show("请先登录");
|
|
|
+ LoginDialog.show();
|
|
|
return;
|
|
|
}
|
|
|
if (isCustom) {
|
|
|
@@ -509,6 +520,7 @@ class KeyboardManageController extends BaseController
|
|
|
clickCustomCharacter() {
|
|
|
if (!isLogin) {
|
|
|
ToastUtil.show("请先登录");
|
|
|
+ LoginDialog.show();
|
|
|
return;
|
|
|
}
|
|
|
AtmobLog.i(tag, 'clickCustomCharacter');
|
|
|
@@ -530,8 +542,7 @@ class KeyboardManageController extends BaseController
|
|
|
super.onClose();
|
|
|
}
|
|
|
|
|
|
- void saveSuccessGetBack(){
|
|
|
-
|
|
|
- Get.back(result: _currentCustomKeyboardCharacterList);
|
|
|
- }
|
|
|
+ void saveSuccessGetBack() {
|
|
|
+ Get.back(result: _currentCustomKeyboardCharacterList);
|
|
|
+ }
|
|
|
}
|