|
@@ -4,6 +4,7 @@ import android.text.TextUtils;
|
|
|
|
|
|
|
|
import androidx.annotation.ColorInt;
|
|
import androidx.annotation.ColorInt;
|
|
|
import androidx.lifecycle.LiveData;
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
|
+import androidx.lifecycle.MediatorLiveData;
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
import androidx.lifecycle.Transformations;
|
|
import androidx.lifecycle.Transformations;
|
|
|
|
|
|
|
@@ -22,6 +23,7 @@ import com.atmob.voiceai.data.api.response.VoiceTypeResponse;
|
|
|
import com.atmob.voiceai.data.repositories.MemberRepository;
|
|
import com.atmob.voiceai.data.repositories.MemberRepository;
|
|
|
import com.atmob.voiceai.data.repositories.VoiceAIRepository;
|
|
import com.atmob.voiceai.data.repositories.VoiceAIRepository;
|
|
|
import com.atmob.voiceai.helper.ErrorHelper;
|
|
import com.atmob.voiceai.helper.ErrorHelper;
|
|
|
|
|
+import com.atmob.voiceai.module.generating.VoiceGeneratingActivity;
|
|
|
import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
|
|
import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
|
|
|
import com.atmob.voiceai.utils.BoxingUtil;
|
|
import com.atmob.voiceai.utils.BoxingUtil;
|
|
|
import com.atmob.voiceai.utils.SpannableUtil;
|
|
import com.atmob.voiceai.utils.SpannableUtil;
|
|
@@ -29,6 +31,7 @@ import com.atmob.voiceai.utils.ToastUtil;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
@@ -42,7 +45,7 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
|
|
|
|
|
private final String LAST_GENERATE_TEXT = "last_generate_text";
|
|
private final String LAST_GENERATE_TEXT = "last_generate_text";
|
|
|
|
|
|
|
|
- private final LiveData<CharSequence> voiceProbationTxt;
|
|
|
|
|
|
|
+ private final MediatorLiveData<CharSequence> voiceProbationTxt = new MediatorLiveData<>();
|
|
|
private final MutableLiveData<String> voicePrintTxt = new MutableLiveData<>();
|
|
private final MutableLiveData<String> voicePrintTxt = new MutableLiveData<>();
|
|
|
private final LiveData<String> voicePrintLimitTxt;
|
|
private final LiveData<String> voicePrintLimitTxt;
|
|
|
private final MemberRepository memberRepository;
|
|
private final MemberRepository memberRepository;
|
|
@@ -51,17 +54,16 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
private final int freeTxtColor;
|
|
private final int freeTxtColor;
|
|
|
private final VoiceAIRepository voiceAIRepository;
|
|
private final VoiceAIRepository voiceAIRepository;
|
|
|
|
|
|
|
|
- private CloneVoiceListBean cloneBean;
|
|
|
|
|
- private VoiceListBean addVoiceBean;
|
|
|
|
|
|
|
|
|
|
private final MutableLiveData<List<TypeListBean>> voiceTypeList = new MutableLiveData<>();
|
|
private final MutableLiveData<List<TypeListBean>> voiceTypeList = new MutableLiveData<>();
|
|
|
private final MutableLiveData<List<VoiceListBean>> voiceDetailList = new MutableLiveData<>();
|
|
private final MutableLiveData<List<VoiceListBean>> voiceDetailList = new MutableLiveData<>();
|
|
|
|
|
|
|
|
- private final MutableLiveData<VoiceListBean> choiceVoiceBean = new MutableLiveData<>();
|
|
|
|
|
|
|
+ private VoiceListBean choiceVoiceBean;
|
|
|
|
|
+ private final SingleLiveEvent<VoiceListBean> playExampleVoice = new SingleLiveEvent<>();
|
|
|
|
|
|
|
|
private final SingleLiveEvent<?> showGenerateAd = new SingleLiveEvent<>();
|
|
private final SingleLiveEvent<?> showGenerateAd = new SingleLiveEvent<>();
|
|
|
|
|
|
|
|
- private int currentTypeId = -1;
|
|
|
|
|
|
|
+ private String currentTypeId;
|
|
|
private Disposable voiceListDisposable;
|
|
private Disposable voiceListDisposable;
|
|
|
|
|
|
|
|
@Inject
|
|
@Inject
|
|
@@ -76,18 +78,29 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
return length + "/200";
|
|
return length + "/200";
|
|
|
});
|
|
});
|
|
|
freeTxtColor = ContextUtil.getApplication().getResources().getColor(R.color.voice_free_crux_txt_color);
|
|
freeTxtColor = ContextUtil.getApplication().getResources().getColor(R.color.voice_free_crux_txt_color);
|
|
|
- voiceProbationTxt = Transformations.map(adFreeGenerateNumber, number -> {
|
|
|
|
|
- if (BoxingUtil.boxing(number) <= 0) {
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ voiceProbationTxt.addSource(adFreeGenerateNumber, number -> {
|
|
|
|
|
+ if (BoxingUtil.boxing(memberRepository.getIsMember().getValue())) {
|
|
|
|
|
+ voiceProbationTxt.setValue("");
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- String allTxt = ContextUtil.getContext().getString(R.string.voice_ai_get_free_number, number);
|
|
|
|
|
- return SpannableUtil.getSpannableStringBuilder(allTxt, String.valueOf(number), freeTxtColor, false);
|
|
|
|
|
|
|
+ setFreeGenerateText(BoxingUtil.boxing(number));
|
|
|
});
|
|
});
|
|
|
voicePrintTxt.setValue(KVUtils.getDefault().getString(LAST_GENERATE_TEXT, ""));
|
|
voicePrintTxt.setValue(KVUtils.getDefault().getString(LAST_GENERATE_TEXT, ""));
|
|
|
-
|
|
|
|
|
|
|
+ voiceProbationTxt.addSource(memberRepository.getIsMember(), isMember -> {
|
|
|
|
|
+ if (BoxingUtil.boxing(isMember)) {
|
|
|
|
|
+ voiceProbationTxt.setValue("");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ setFreeGenerateText(BoxingUtil.boxing(adFreeGenerateNumber.getValue()));
|
|
|
|
|
+ });
|
|
|
iniVoiceAI();
|
|
iniVoiceAI();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public LiveData<VoiceListBean> getPlayExampleVoice() {
|
|
|
|
|
+ return playExampleVoice;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public LiveData<?> getShowGenerateAd() {
|
|
public LiveData<?> getShowGenerateAd() {
|
|
|
return showGenerateAd;
|
|
return showGenerateAd;
|
|
|
}
|
|
}
|
|
@@ -125,17 +138,27 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
voicePrintTxt.setValue("");
|
|
voicePrintTxt.setValue("");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void setFreeGenerateText(int number) {
|
|
|
|
|
+ voiceProbationTxt.setValue(SpannableUtil.getSpannableStringBuilder(
|
|
|
|
|
+ ContextUtil.getContext().getString(R.string.voice_ai_get_free_number, number),
|
|
|
|
|
+ String.valueOf(number), freeTxtColor, false));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void onGenerateClick() {
|
|
public void onGenerateClick() {
|
|
|
- VoiceListBean bean = choiceVoiceBean.getValue();
|
|
|
|
|
- if (bean == null) {
|
|
|
|
|
|
|
+ String content = voicePrintTxt.getValue();
|
|
|
|
|
+ if (TextUtils.isEmpty(content)) {
|
|
|
|
|
+ ToastUtil.show(R.string.voice_ai_print_hint, ToastUtil.LENGTH_SHORT);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (choiceVoiceBean == null) {
|
|
|
ToastUtil.show(R.string.voice_ai_no_choice, ToastUtil.LENGTH_SHORT);
|
|
ToastUtil.show(R.string.voice_ai_no_choice, ToastUtil.LENGTH_SHORT);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (BoxingUtil.boxing(isMember().getValue())) {
|
|
if (BoxingUtil.boxing(isMember().getValue())) {
|
|
|
- requestGenerateVoice(bean);
|
|
|
|
|
|
|
+ requestGenerateVoice();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (bean.isHasPro()) {
|
|
|
|
|
|
|
+ if (choiceVoiceBean.isHasPro()) {
|
|
|
SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
|
|
SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -146,8 +169,9 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
|
|
SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void requestGenerateVoice(VoiceListBean bean) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private void requestGenerateVoice() {
|
|
|
|
|
+ voiceAIRepository.requestTextToSpeech(choiceVoiceBean, voicePrintTxt.getValue());
|
|
|
|
|
+ VoiceGeneratingActivity.start(ActivityUtil.getTopActivity());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -166,18 +190,6 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
@Override
|
|
@Override
|
|
|
public void onSuccess(@NonNull VoiceInfoResponse voiceInfoResponse) {
|
|
public void onSuccess(@NonNull VoiceInfoResponse voiceInfoResponse) {
|
|
|
adFreeGenerateNumber.setValue(voiceInfoResponse.getVoiceTimes());
|
|
adFreeGenerateNumber.setValue(voiceInfoResponse.getVoiceTimes());
|
|
|
- List<CloneVoiceListBean> cloneVoiceList = voiceInfoResponse.getCloneVoiceList();
|
|
|
|
|
- if (cloneVoiceList != null && !cloneVoiceList.isEmpty()) {
|
|
|
|
|
- cloneBean = cloneVoiceList.get(0);
|
|
|
|
|
- cloneBean.setCloneVoiceAvatar(voiceInfoResponse.getCloneVoiceAvatar());
|
|
|
|
|
- cloneBean.setCloneVoiceName(voiceInfoResponse.getCloneVoiceName());
|
|
|
|
|
- if (addVoiceBean != null) {
|
|
|
|
|
- addVoiceBean.setId(cloneBean.getId());
|
|
|
|
|
- addVoiceBean.setName(cloneBean.getCloneVoiceName());
|
|
|
|
|
- addVoiceBean.setAvatarUrl(cloneBean.getCloneVoiceAvatar());
|
|
|
|
|
- addVoiceBean.setVoiceUrl(cloneBean.getVoiceUrl());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -211,8 +223,8 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
KVUtils.getDefault().putString(LAST_GENERATE_TEXT, generateTxt);
|
|
KVUtils.getDefault().putString(LAST_GENERATE_TEXT, generateTxt);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void refreshVoiceList(int id) {
|
|
|
|
|
- if (id == this.currentTypeId) {
|
|
|
|
|
|
|
+ public void refreshVoiceList(String id) {
|
|
|
|
|
+ if (Objects.equals(this.currentTypeId, id)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
this.currentTypeId = id;
|
|
this.currentTypeId = id;
|
|
@@ -229,27 +241,16 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
@Override
|
|
@Override
|
|
|
public void onSuccess(@NonNull VoiceListResponse voiceListResponse) {
|
|
public void onSuccess(@NonNull VoiceListResponse voiceListResponse) {
|
|
|
List<VoiceListBean> voiceList = voiceListResponse.getVoiceList();
|
|
List<VoiceListBean> voiceList = voiceListResponse.getVoiceList();
|
|
|
- if (voiceList == null) {
|
|
|
|
|
- voiceList = new ArrayList<>();
|
|
|
|
|
- }
|
|
|
|
|
- if (cloneBean == null) {
|
|
|
|
|
- VoiceListBean cloneVoiceListBean = new VoiceListBean();
|
|
|
|
|
- cloneVoiceListBean.setAddIcon(true);
|
|
|
|
|
- cloneVoiceListBean.setId(-1);
|
|
|
|
|
- cloneVoiceListBean.setName(ContextUtil.getContext().getString(R.string.add_voice));
|
|
|
|
|
- addVoiceBean = cloneVoiceListBean;
|
|
|
|
|
- voiceList.add(0, cloneVoiceListBean);
|
|
|
|
|
- } else {
|
|
|
|
|
- VoiceListBean cloneVoiceBean = getVoiceBeans(cloneBean);
|
|
|
|
|
- voiceList.add(0, cloneVoiceBean);
|
|
|
|
|
|
|
+ if (voiceList != null) {
|
|
|
|
|
+ for (VoiceListBean voiceListBean : voiceList) {
|
|
|
|
|
+ if (voiceListBean.isAddIcon()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ setChoiceVoiceBean(voiceListBean, false);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
voiceDetailList.setValue(voiceList);
|
|
voiceDetailList.setValue(voiceList);
|
|
|
- VoiceListBean choiceBean = choiceVoiceBean.getValue();
|
|
|
|
|
- if (choiceBean != null) {
|
|
|
|
|
- choiceBean.setVoicePlayState(VoiceListBean.VoicePlayState.INITIAL);
|
|
|
|
|
- choiceBean.setCheck(false);
|
|
|
|
|
- }
|
|
|
|
|
- choiceVoiceBean.setValue(null);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -268,24 +269,33 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
return voiceListBean;
|
|
return voiceListBean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void setChoiceVoiceBean(VoiceListBean voiceListBean) {
|
|
|
|
|
- choiceVoiceBean.setValue(voiceListBean);
|
|
|
|
|
|
|
+ private void setChoiceVoiceBean(VoiceListBean voiceListBean, boolean playVoice) {
|
|
|
|
|
+ if (this.choiceVoiceBean != null) {
|
|
|
|
|
+ this.choiceVoiceBean.setCheck(false);
|
|
|
|
|
+ this.choiceVoiceBean.setVoicePlayState(VoiceListBean.VoicePlayState.INITIAL);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.choiceVoiceBean = voiceListBean;
|
|
|
|
|
+ this.choiceVoiceBean.setCheck(true);
|
|
|
|
|
+ if (playVoice) {
|
|
|
|
|
+ playExampleVoice.setValue(choiceVoiceBean);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ public void voiceItemClick(VoiceListBean voiceListBean) {
|
|
|
|
|
+ setChoiceVoiceBean(voiceListBean, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void seeAdGenerate() {
|
|
public void seeAdGenerate() {
|
|
|
- VoiceListBean bean = choiceVoiceBean.getValue();
|
|
|
|
|
- if (bean == null) {
|
|
|
|
|
|
|
+ if (choiceVoiceBean == null) {
|
|
|
ToastUtil.show(R.string.voice_ai_no_choice, ToastUtil.LENGTH_SHORT);
|
|
ToastUtil.show(R.string.voice_ai_no_choice, ToastUtil.LENGTH_SHORT);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- requestGenerateVoice(bean);
|
|
|
|
|
|
|
+ requestGenerateVoice();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void setVoicePlayEnd() {
|
|
public void setVoicePlayEnd() {
|
|
|
- VoiceListBean bean = choiceVoiceBean.getValue();
|
|
|
|
|
- if (bean != null) {
|
|
|
|
|
- bean.setVoicePlayState(VoiceListBean.VoicePlayState.INITIAL);
|
|
|
|
|
|
|
+ if (choiceVoiceBean != null) {
|
|
|
|
|
+ choiceVoiceBean.setVoicePlayState(VoiceListBean.VoicePlayState.INITIAL);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|