intimacy_analyze_repository.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import 'package:get/get_rx/src/rx_types/rx_types.dart';
  2. import 'package:injectable/injectable.dart';
  3. import 'package:keyboard/base/app_base_request.dart';
  4. import '../../di/get_it.dart';
  5. import '../../utils/async_util.dart';
  6. import '../../utils/atmob_log.dart';
  7. import '../../utils/http_handler.dart';
  8. import '../api/atmob_api.dart';
  9. import '../api/response/intimacy_analyze_config_response.dart';
  10. /// 亲密度分析Repository层
  11. @LazySingleton()
  12. class IntimacyAnalyzeRepository {
  13. final String tag = "IntimacyAnalyzeRepository";
  14. final AtmobApi atmobApi;
  15. /// 亲密度配置
  16. Rxn<IntimacyAnalyzeConfigResponse> intimacyAnalyzeConfig = Rxn<IntimacyAnalyzeConfigResponse>();
  17. IntimacyAnalyzeRepository(this.atmobApi) {
  18. AtmobLog.d(tag, '$tag...init');
  19. // 初始化时,刷新配置
  20. refreshIntimacyAnalyzeConfig();
  21. }
  22. /// 从Getx的依赖注入中,获取实例,适合在没有依赖注入上下文的地方使用
  23. IntimacyAnalyzeRepository getInstance() {
  24. return getIt.get<IntimacyAnalyzeRepository>();
  25. }
  26. /// 刷新亲密度配置
  27. void refreshIntimacyAnalyzeConfig() {
  28. AsyncUtil.retry(() => requestIntimacyAnalyzeConfig(), Duration(seconds: 3),
  29. maxRetry: 100,).then((IntimacyAnalyzeConfigResponse configResponse) {
  30. AtmobLog.d(tag, "获取亲密度配置成功: ${configResponse.toJson()}");
  31. intimacyAnalyzeConfig.value = configResponse;
  32. });
  33. }
  34. /// 获取亲密度配置
  35. Future<IntimacyAnalyzeConfigResponse> requestIntimacyAnalyzeConfig() {
  36. return atmobApi
  37. .getIntimacyAnalyzeConfig(AppBaseRequest())
  38. .then(HttpHandler.handle(true));
  39. }
  40. }