profile_edit_controller.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'package:injectable/injectable.dart';
  2. import 'package:keyboard/base/base_controller.dart';
  3. import 'package:keyboard/data/bean/keyboard_info.dart';
  4. import 'package:keyboard/utils/atmob_log.dart';
  5. import 'package:get/get.dart';
  6. import '../../../data/bean/custom_config_info.dart';
  7. import '../../../data/repository/config_repository.dart';
  8. @injectable
  9. class ProfileEditController extends BaseController {
  10. final tag = "ProfileEditController";
  11. final ConfigRepository configRepository;
  12. final RxInt _gender = 1.obs;
  13. final RxString _avatarUrl = "".obs;
  14. String get avatarUrl => _avatarUrl.value;
  15. CustomConfigInfo? get currentCharacterCustomConfig =>
  16. configRepository.characterCustomConfig;
  17. final Rx<KeyboardInfo> _currentCustomKeyboardInfo = KeyboardInfo().obs;
  18. KeyboardInfo get currentCustomKeyboardInfo =>
  19. _currentCustomKeyboardInfo.value;
  20. // 当前自定义键盘亲密度
  21. final RxInt _currentCustomIntimacy = 0.obs;
  22. int get currentCustomIntimacy => _currentCustomIntimacy.value;
  23. // 当前定制亲密度是否有变化
  24. final RxBool _customIntimacyChanged = false.obs;
  25. bool get customIntimacyChanged => _customIntimacyChanged.value;
  26. final List<String> _boyAvatars = [];
  27. final List<String> _girlAvatars = [];
  28. ProfileEditController(this.configRepository);
  29. @override
  30. void onInit() {
  31. super.onInit();
  32. initData();
  33. }
  34. void initData() {
  35. AtmobLog.d(tag, "initData");
  36. _boyAvatars.addAll(currentCharacterCustomConfig?.boyAvatars ?? []);
  37. _girlAvatars.addAll(currentCharacterCustomConfig?.girlAvatars ?? []);
  38. if (_gender.value == 1) {
  39. _avatarUrl.value = _boyAvatars[0];
  40. } else {
  41. _avatarUrl.value = _girlAvatars[0];
  42. }
  43. }
  44. clickSaveButton() {
  45. AtmobLog.d(tag, 'clickSaveButton');
  46. }
  47. void nextAvatar() {
  48. AtmobLog.d(tag, "nextAvatar");
  49. if (_gender.value == 1) {
  50. int currentIndex = _boyAvatars.indexOf(_avatarUrl.value);
  51. _avatarUrl.value = _boyAvatars[(currentIndex + 1) % _boyAvatars.length];
  52. } else {
  53. int currentIndex = _girlAvatars.indexOf(_avatarUrl.value);
  54. _avatarUrl.value = _girlAvatars[(currentIndex + 1) % _girlAvatars.length];
  55. }
  56. }
  57. // 更新亲密度
  58. void updateIntimacy(int intimacy) {
  59. _currentCustomIntimacy.value = intimacy;
  60. }
  61. clickBack() {
  62. AtmobLog.d(tag, 'clickBackButton');
  63. Get.back();
  64. }
  65. }