|
|
@@ -1,6 +1,7 @@
|
|
|
package com.atmob.voiceai.module.voiceai;
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
+import android.util.Pair;
|
|
|
|
|
|
import androidx.annotation.ColorInt;
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
@@ -14,7 +15,6 @@ 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;
|
|
|
import com.atmob.voiceai.data.api.bean.TypeListBean;
|
|
|
import com.atmob.voiceai.data.api.bean.VoiceListBean;
|
|
|
import com.atmob.voiceai.data.api.response.VoiceInfoResponse;
|
|
|
@@ -56,12 +56,16 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
|
|
|
|
|
|
private final MutableLiveData<List<TypeListBean>> voiceTypeList = new MutableLiveData<>();
|
|
|
- private final MutableLiveData<List<VoiceListBean>> voiceDetailList = new MutableLiveData<>();
|
|
|
+ private final MutableLiveData<Pair<List<VoiceListBean>, VoiceListBean>> voiceDetailList = new MutableLiveData<>();
|
|
|
|
|
|
private VoiceListBean choiceVoiceBean;
|
|
|
- private final SingleLiveEvent<VoiceListBean> playExampleVoice = new SingleLiveEvent<>();
|
|
|
|
|
|
+ private final SingleLiveEvent<VoiceListBean> scrollToBean = new SingleLiveEvent<>();
|
|
|
+
|
|
|
+ private final SingleLiveEvent<VoiceListBean> playExampleVoice = new SingleLiveEvent<>();
|
|
|
+ private final SingleLiveEvent<Integer> scrollToTabPosition = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<?> showGenerateAd = new SingleLiveEvent<>();
|
|
|
+ private final SingleLiveEvent<VoiceListBean> notifyBean = new SingleLiveEvent<>();
|
|
|
|
|
|
private String currentTypeId;
|
|
|
private Disposable voiceListDisposable;
|
|
|
@@ -97,6 +101,14 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
iniVoiceAI();
|
|
|
}
|
|
|
|
|
|
+ public LiveData<Integer> getScrollToTabPosition() {
|
|
|
+ return scrollToTabPosition;
|
|
|
+ }
|
|
|
+
|
|
|
+ public LiveData<VoiceListBean> getNotifyBean() {
|
|
|
+ return notifyBean;
|
|
|
+ }
|
|
|
+
|
|
|
public LiveData<VoiceListBean> getPlayExampleVoice() {
|
|
|
return playExampleVoice;
|
|
|
}
|
|
|
@@ -105,7 +117,7 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
return showGenerateAd;
|
|
|
}
|
|
|
|
|
|
- public LiveData<List<VoiceListBean>> getVoiceDetailList() {
|
|
|
+ public LiveData<Pair<List<VoiceListBean>, VoiceListBean>> getVoiceDetailList() {
|
|
|
return voiceDetailList;
|
|
|
}
|
|
|
|
|
|
@@ -113,6 +125,9 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
return voiceTypeList;
|
|
|
}
|
|
|
|
|
|
+ public LiveData<VoiceListBean> getScrollToBean() {
|
|
|
+ return scrollToBean;
|
|
|
+ }
|
|
|
|
|
|
public LiveData<Integer> getAdFreeGenerateNumber() {
|
|
|
return adFreeGenerateNumber;
|
|
|
@@ -178,8 +193,50 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
private void iniVoiceAI() {
|
|
|
refreshVoiceInfo();
|
|
|
requestVoiceTypeList();
|
|
|
+ fromOtherRecommendSelectVoice();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fromOtherRecommendSelectVoice() {
|
|
|
+ voiceAIRepository.getRecommendClickBean().observeForever(bean -> {
|
|
|
+ if (bean == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ voiceAIRepository.setRecommendClickBean(null);
|
|
|
+ voicePrintTxt.setValue(bean.getContent());
|
|
|
+ List<TypeListBean> typeList = voiceTypeList.getValue();
|
|
|
+ if (typeList == null || typeList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Objects.equals(this.currentTypeId, String.valueOf(bean.getTypeId())) || Objects.equals(String.valueOf(typeList.get(0).getId()), this.currentTypeId)) {
|
|
|
+ //在当前列表项或当前列表项为第一个(一般为ALL)
|
|
|
+ scrollToListPosition(bean);
|
|
|
+ } else {
|
|
|
+ //将列表项设置为第一个
|
|
|
+ scrollToTabPosition.setValue(0);
|
|
|
+ refreshVoiceList(String.valueOf(typeList.get(0).getId()), bean);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public void scrollToListPosition(@NonNull VoiceListBean bean) {
|
|
|
+ Pair<List<VoiceListBean>, VoiceListBean> voiceDetail = voiceDetailList.getValue();
|
|
|
+ if (voiceDetail == null || voiceDetail.first == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (VoiceListBean voiceListBean : voiceDetail.first) {
|
|
|
+ if (TextUtils.isEmpty(voiceListBean.getVoiceUrl())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (voiceListBean.getId() == bean.getId()) {
|
|
|
+ scrollToBean.setValue(voiceListBean);
|
|
|
+ setChoiceVoiceBean(voiceListBean, true);
|
|
|
+ notifyBean.setValue(voiceListBean);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void refreshVoiceInfo() {
|
|
|
voiceAIRepository.requestVoiceInfo().subscribe(new SingleObserver<VoiceInfoResponse>() {
|
|
|
@Override
|
|
|
@@ -223,7 +280,12 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
KVUtils.getDefault().putString(LAST_GENERATE_TEXT, generateTxt);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public void refreshVoiceList(String id) {
|
|
|
+ refreshVoiceList(id, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void refreshVoiceList(String id, VoiceListBean bean) {
|
|
|
if (Objects.equals(this.currentTypeId, id)) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -251,14 +313,18 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
voiceListBean.setName(ContextUtil.getContext().getString(R.string.add_voice));
|
|
|
voiceList.add(0, voiceListBean);
|
|
|
}
|
|
|
- for (VoiceListBean voiceListBean : voiceList) {
|
|
|
- if (voiceListBean.isAddIcon()) {
|
|
|
- continue;
|
|
|
+ if (bean != null) {
|
|
|
+ voiceDetailList.setValue(new Pair<>(voiceList, bean));
|
|
|
+ } else {
|
|
|
+ for (VoiceListBean voiceListBean : voiceList) {
|
|
|
+ if (voiceListBean.isAddIcon()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ setChoiceVoiceBean(voiceListBean, false);
|
|
|
+ break;
|
|
|
}
|
|
|
- setChoiceVoiceBean(voiceListBean, false);
|
|
|
- break;
|
|
|
+ voiceDetailList.setValue(new Pair<>(voiceList, null));
|
|
|
}
|
|
|
- voiceDetailList.setValue(voiceList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -268,14 +334,6 @@ public class VoiceAIViewModel extends BaseViewModel {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @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;
|
|
|
- }
|
|
|
|
|
|
private void setChoiceVoiceBean(VoiceListBean voiceListBean, boolean playVoice) {
|
|
|
if (this.choiceVoiceBean != null) {
|