| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import 'dart:io';
- import 'package:get/get_rx/src/rx_types/rx_types.dart';
- import 'package:injectable/injectable.dart';
- import 'package:keyboard/base/app_base_request.dart';
- import '../../di/get_it.dart';
- import '../../utils/async_util.dart';
- import '../../utils/atmob_log.dart';
- import '../../utils/http_handler.dart';
- import '../api/atmob_api.dart';
- import '../api/response/intimacy_analyze_config_response.dart';
- /// 亲密度分析Repository层
- @LazySingleton()
- class IntimacyAnalyzeRepository {
- final String tag = "IntimacyAnalyzeRepository";
- final AtmobApi atmobApi;
- /// 亲密度配置
- Rxn<IntimacyAnalyzeConfigResponse> intimacyAnalyzeConfig = Rxn<IntimacyAnalyzeConfigResponse>();
- IntimacyAnalyzeRepository(this.atmobApi) {
- AtmobLog.d(tag, '$tag...init');
- // 初始化时,刷新配置
- refreshIntimacyAnalyzeConfig();
- }
- /// 从Getx的依赖注入中,获取实例,适合在没有依赖注入上下文的地方使用
- IntimacyAnalyzeRepository getInstance() {
- return getIt.get<IntimacyAnalyzeRepository>();
- }
- /// 刷新亲密度配置
- void refreshIntimacyAnalyzeConfig() {
- AsyncUtil.retry(() => requestIntimacyAnalyzeConfig(), Duration(seconds: 3),
- maxRetry: 100,).then((IntimacyAnalyzeConfigResponse configResponse) {
- AtmobLog.d(tag, "获取亲密度配置成功: ${configResponse.toJson()}");
- intimacyAnalyzeConfig.value = configResponse;
- });
- }
- /// 获取亲密度配置
- Future<IntimacyAnalyzeConfigResponse> requestIntimacyAnalyzeConfig() {
- return atmobApi
- .getIntimacyAnalyzeConfig(AppBaseRequest())
- .then(HttpHandler.handle(true));
- }
- }
|