|
|
@@ -6,9 +6,12 @@ import androidx.lifecycle.MutableLiveData;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.atmob.app.lib.handler.RxHttpHandler;
|
|
|
+import com.atmob.common.data.KVUtils;
|
|
|
import com.atmob.voiceai.data.api.AtmobApi;
|
|
|
+import com.atmob.voiceai.data.api.request.AttributionRequest;
|
|
|
import com.atmob.voiceai.data.api.request.ConfigRequest;
|
|
|
import com.atmob.voiceai.data.api.response.ConfigsResponse;
|
|
|
+import com.atmob.voiceai.sdk.kochava.KochavaHelper;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
@@ -29,12 +32,15 @@ public class ConfigRepository {
|
|
|
|
|
|
private final String VOICE_TEXT_LIMIT = "voice_text_limit";
|
|
|
|
|
|
+ private final String ATTRIBUTION_INFO_SUCCESS = "attribution_info_success";
|
|
|
+
|
|
|
private final String[] configs = {
|
|
|
VOICE_TEXT_LIMIT
|
|
|
};
|
|
|
private final AtmobApi atmobApi;
|
|
|
|
|
|
private boolean requesting;
|
|
|
+ private boolean requestAttribution;
|
|
|
|
|
|
private final MutableLiveData<Integer> voiceTextLimit = new MutableLiveData<>(-1);
|
|
|
|
|
|
@@ -42,12 +48,44 @@ public class ConfigRepository {
|
|
|
public ConfigRepository(AtmobApi atmobApi) {
|
|
|
this.atmobApi = atmobApi;
|
|
|
refreshConfigs();
|
|
|
+ attributionInfo();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public LiveData<Integer> getVoiceTextLimit() {
|
|
|
return voiceTextLimit;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void attributionInfo() {
|
|
|
+ if (KVUtils.getDefault().getBoolean(ATTRIBUTION_INFO_SUCCESS, false) || requestAttribution) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ KochavaHelper.registerAttributionResultCallback((attributed, attributionInfo) -> {
|
|
|
+ if (!attributed || attributionInfo == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ attribution(attributionInfo.toString())
|
|
|
+ .subscribe(new SingleObserver<Object>() {
|
|
|
+ @Override
|
|
|
+ public void onSubscribe(@NonNull Disposable d) {
|
|
|
+ requestAttribution = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(@NonNull Object o) {
|
|
|
+ requestAttribution = false;
|
|
|
+ KVUtils.getDefault().putBoolean(ATTRIBUTION_INFO_SUCCESS, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(@NonNull Throwable e) {
|
|
|
+ requestAttribution = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private void refreshConfigs() {
|
|
|
if (requesting) {
|
|
|
return;
|
|
|
@@ -89,6 +127,13 @@ public class ConfigRepository {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private Single<Object> attribution(String attribution) {
|
|
|
+ return atmobApi.attributionInfo(new AttributionRequest(attribution))
|
|
|
+ .compose(RxHttpHandler.handle(true))
|
|
|
+ .retryWhen(RxJavaUtil.exponentialBackOff(null, 8, TimeUnit.SECONDS))
|
|
|
+ .compose(RxJavaUtil.SingleSchedule.ioOnly());
|
|
|
+ }
|
|
|
+
|
|
|
private Single<ConfigsResponse> getConfig(String[] configs) {
|
|
|
return atmobApi.configs(new ConfigRequest(configs))
|
|
|
.compose(RxHttpHandler.handle(true))
|