|
|
@@ -8,7 +8,9 @@ import androidx.lifecycle.MutableLiveData;
|
|
|
import androidx.lifecycle.Transformations;
|
|
|
|
|
|
import com.atmob.app.lib.base.BaseViewModel;
|
|
|
+import com.atmob.app.lib.livedata.SingleLiveEvent;
|
|
|
import com.atmob.common.data.KVUtils;
|
|
|
+import com.atmob.common.runtime.ActivityUtil;
|
|
|
import com.atmob.common.runtime.ContextUtil;
|
|
|
import com.atmob.voiceai.R;
|
|
|
import com.atmob.voiceai.data.api.bean.CloneVoiceListBean;
|
|
|
@@ -20,6 +22,7 @@ import com.atmob.voiceai.data.api.response.VoiceTypeResponse;
|
|
|
import com.atmob.voiceai.data.repositories.MemberRepository;
|
|
|
import com.atmob.voiceai.data.repositories.VoiceAIRepository;
|
|
|
import com.atmob.voiceai.helper.ErrorHelper;
|
|
|
+import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
|
|
|
import com.atmob.voiceai.utils.BoxingUtil;
|
|
|
import com.atmob.voiceai.utils.SpannableUtil;
|
|
|
import com.atmob.voiceai.utils.ToastUtil;
|
|
|
@@ -48,11 +51,16 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
private final int freeTxtColor;
|
|
|
private final VoiceAIRepository voiceAIRepository;
|
|
|
|
|
|
- private final MutableLiveData<List<CloneVoiceListBean>> userCloneList = new MutableLiveData<>();
|
|
|
+ private CloneVoiceListBean cloneBean;
|
|
|
+ private VoiceListBean addVoiceBean;
|
|
|
|
|
|
private final MutableLiveData<List<TypeListBean>> voiceTypeList = new MutableLiveData<>();
|
|
|
private final MutableLiveData<List<VoiceListBean>> voiceDetailList = new MutableLiveData<>();
|
|
|
|
|
|
+ private final MutableLiveData<VoiceListBean> choiceVoiceBean = new MutableLiveData<>();
|
|
|
+
|
|
|
+ private final SingleLiveEvent<?> showGenerateAd = new SingleLiveEvent<>();
|
|
|
+
|
|
|
private int currentTypeId = -1;
|
|
|
private Disposable voiceListDisposable;
|
|
|
|
|
|
@@ -80,6 +88,10 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
iniVoiceAI();
|
|
|
}
|
|
|
|
|
|
+ public LiveData<?> getShowGenerateAd() {
|
|
|
+ return showGenerateAd;
|
|
|
+ }
|
|
|
+
|
|
|
public LiveData<List<VoiceListBean>> getVoiceDetailList() {
|
|
|
return voiceDetailList;
|
|
|
}
|
|
|
@@ -114,6 +126,27 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
}
|
|
|
|
|
|
public void onGenerateClick() {
|
|
|
+ VoiceListBean bean = choiceVoiceBean.getValue();
|
|
|
+ if (bean == null) {
|
|
|
+ ToastUtil.show(R.string.voice_ai_no_choice, ToastUtil.LENGTH_SHORT);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (BoxingUtil.boxing(isMember().getValue())) {
|
|
|
+ requestGenerateVoice(bean);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (bean.isHasPro()) {
|
|
|
+ SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (BoxingUtil.boxing(adFreeGenerateNumber.getValue()) > 0) {
|
|
|
+ showGenerateAd.call();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void requestGenerateVoice(VoiceListBean bean) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -135,12 +168,16 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
adFreeGenerateNumber.setValue(voiceInfoResponse.getVoiceTimes());
|
|
|
List<CloneVoiceListBean> cloneVoiceList = voiceInfoResponse.getCloneVoiceList();
|
|
|
if (cloneVoiceList != null && !cloneVoiceList.isEmpty()) {
|
|
|
- for (CloneVoiceListBean cloneVoiceListBean : cloneVoiceList) {
|
|
|
- cloneVoiceListBean.setCloneVoiceAvatar(voiceInfoResponse.getCloneVoiceAvatar());
|
|
|
- cloneVoiceListBean.setCloneVoiceName(voiceInfoResponse.getCloneVoiceName());
|
|
|
+ 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());
|
|
|
}
|
|
|
}
|
|
|
- userCloneList.setValue(cloneVoiceList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -195,18 +232,23 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
if (voiceList == null) {
|
|
|
voiceList = new ArrayList<>();
|
|
|
}
|
|
|
- List<CloneVoiceListBean> value = userCloneList.getValue();
|
|
|
- if (value == null || value.isEmpty()) {
|
|
|
+ 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 {
|
|
|
- List<VoiceListBean> list = getVoiceListBeans(value);
|
|
|
- voiceList.addAll(0, list);
|
|
|
+ VoiceListBean cloneVoiceBean = getVoiceBeans(cloneBean);
|
|
|
+ voiceList.add(0, cloneVoiceBean);
|
|
|
}
|
|
|
voiceDetailList.setValue(voiceList);
|
|
|
+ VoiceListBean choiceBean = choiceVoiceBean.getValue();
|
|
|
+ if (choiceBean != null) {
|
|
|
+ choiceBean.setCheck(false);
|
|
|
+ }
|
|
|
+ choiceVoiceBean.setValue(null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -216,16 +258,26 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @androidx.annotation.NonNull
|
|
|
- private List<VoiceListBean> getVoiceListBeans(List<CloneVoiceListBean> value) {
|
|
|
- List<VoiceListBean> list = new ArrayList<>();
|
|
|
- for (CloneVoiceListBean cloneVoiceListBean : value) {
|
|
|
- VoiceListBean voiceListBean = new VoiceListBean();
|
|
|
- voiceListBean.setName(cloneVoiceListBean.getCloneVoiceName());
|
|
|
- voiceListBean.setAvatarUrl(cloneVoiceListBean.getCloneVoiceAvatar());
|
|
|
- voiceListBean.setId(cloneVoiceListBean.getId());
|
|
|
- list.add(voiceListBean);
|
|
|
+ @NonNull
|
|
|
+ private VoiceListBean getVoiceBeans(@NonNull CloneVoiceListBean bean) {
|
|
|
+ VoiceListBean voiceListBean = new VoiceListBean();
|
|
|
+ voiceListBean.setName(bean.getCloneVoiceName());
|
|
|
+ voiceListBean.setAvatarUrl(bean.getCloneVoiceAvatar());
|
|
|
+ voiceListBean.setId(bean.getId());
|
|
|
+ return voiceListBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setChoiceVoiceBean(VoiceListBean voiceListBean) {
|
|
|
+ choiceVoiceBean.setValue(voiceListBean);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void seeAdGenerate() {
|
|
|
+ VoiceListBean bean = choiceVoiceBean.getValue();
|
|
|
+ if (bean == null) {
|
|
|
+ ToastUtil.show(R.string.voice_ai_no_choice, ToastUtil.LENGTH_SHORT);
|
|
|
+ return;
|
|
|
}
|
|
|
- return list;
|
|
|
+ requestGenerateVoice(bean);
|
|
|
}
|
|
|
}
|