|
@@ -1,12 +1,8 @@
|
|
|
package com.atmob.voiceai.module.clonevoice;
|
|
package com.atmob.voiceai.module.clonevoice;
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
import android.Manifest;
|
|
|
-import android.annotation.SuppressLint;
|
|
|
|
|
-import android.graphics.drawable.Drawable;
|
|
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
import android.os.CountDownTimer;
|
|
import android.os.CountDownTimer;
|
|
|
-import android.os.Handler;
|
|
|
|
|
-import android.os.Looper;
|
|
|
|
|
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
import androidx.lifecycle.LiveData;
|
|
|
import androidx.lifecycle.MediatorLiveData;
|
|
import androidx.lifecycle.MediatorLiveData;
|
|
@@ -16,17 +12,19 @@ import androidx.lifecycle.Transformations;
|
|
|
import com.atmob.app.lib.base.BaseViewModel;
|
|
import com.atmob.app.lib.base.BaseViewModel;
|
|
|
import com.atmob.app.lib.livedata.SingleLiveEvent;
|
|
import com.atmob.app.lib.livedata.SingleLiveEvent;
|
|
|
import com.atmob.common.data.KVUtils;
|
|
import com.atmob.common.data.KVUtils;
|
|
|
-import com.atmob.common.logging.AtmobLog;
|
|
|
|
|
import com.atmob.common.runtime.ActivityUtil;
|
|
import com.atmob.common.runtime.ActivityUtil;
|
|
|
import com.atmob.common.runtime.ContextUtil;
|
|
import com.atmob.common.runtime.ContextUtil;
|
|
|
import com.atmob.voiceai.R;
|
|
import com.atmob.voiceai.R;
|
|
|
import com.atmob.voiceai.data.api.bean.CloneVoiceListBean;
|
|
import com.atmob.voiceai.data.api.bean.CloneVoiceListBean;
|
|
|
import com.atmob.voiceai.data.repositories.CloneRepository;
|
|
import com.atmob.voiceai.data.repositories.CloneRepository;
|
|
|
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.helper.ErrorHelper;
|
|
import com.atmob.voiceai.helper.ErrorHelper;
|
|
|
import com.atmob.voiceai.module.cloning.VoiceCloningActivity;
|
|
import com.atmob.voiceai.module.cloning.VoiceCloningActivity;
|
|
|
|
|
+import com.atmob.voiceai.module.main.MainActivity;
|
|
|
import com.atmob.voiceai.module.setting.SettingActivity;
|
|
import com.atmob.voiceai.module.setting.SettingActivity;
|
|
|
import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
|
|
import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
|
|
|
|
|
+import com.atmob.voiceai.module.voiceai.VoiceAIFragment;
|
|
|
import com.atmob.voiceai.utils.DateUtil;
|
|
import com.atmob.voiceai.utils.DateUtil;
|
|
|
import com.atmob.voiceai.utils.FileUtils;
|
|
import com.atmob.voiceai.utils.FileUtils;
|
|
|
import com.atmob.voiceai.utils.PermissionUtil;
|
|
import com.atmob.voiceai.utils.PermissionUtil;
|
|
@@ -58,11 +56,11 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
public static final int FILE_UPLOAD = 1;
|
|
public static final int FILE_UPLOAD = 1;
|
|
|
public static final int RECORD_UPLOAD = 2;
|
|
public static final int RECORD_UPLOAD = 2;
|
|
|
|
|
|
|
|
- private final LiveData<String> recordStateDesc;
|
|
|
|
|
|
|
+ private final MediatorLiveData<String> recordStateDesc = new MediatorLiveData<>();
|
|
|
|
|
|
|
|
private final LiveData<String> recordTimeTxt;
|
|
private final LiveData<String> recordTimeTxt;
|
|
|
private final MutableLiveData<Integer> recordProgress = new MutableLiveData<>();
|
|
private final MutableLiveData<Integer> recordProgress = new MutableLiveData<>();
|
|
|
- private final MutableLiveData<Drawable> recordProgressDrawable = new MutableLiveData<>();
|
|
|
|
|
|
|
+ private final MutableLiveData<Integer> recordProgressColor = new MutableLiveData<>();
|
|
|
private final MutableLiveData<Boolean> showStopRecord = new MutableLiveData<>();
|
|
private final MutableLiveData<Boolean> showStopRecord = new MutableLiveData<>();
|
|
|
private final MutableLiveData<String> uploadPreviewName = new MutableLiveData<>();
|
|
private final MutableLiveData<String> uploadPreviewName = new MutableLiveData<>();
|
|
|
private final MutableLiveData<String> uploadPreviewSize = new MutableLiveData<>();
|
|
private final MutableLiveData<String> uploadPreviewSize = new MutableLiveData<>();
|
|
@@ -84,6 +82,7 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
private final MutableLiveData<Uri> uploadVoiceUri = new MutableLiveData<>();
|
|
private final MutableLiveData<Uri> uploadVoiceUri = new MutableLiveData<>();
|
|
|
private final MemberRepository memberRepository;
|
|
private final MemberRepository memberRepository;
|
|
|
private final CloneRepository cloneRepository;
|
|
private final CloneRepository cloneRepository;
|
|
|
|
|
+ private final VoiceAIRepository voiceAIRepository;
|
|
|
|
|
|
|
|
private boolean isSeekbarChanging;
|
|
private boolean isSeekbarChanging;
|
|
|
private Timer timer;
|
|
private Timer timer;
|
|
@@ -91,22 +90,42 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
File recordFile;
|
|
File recordFile;
|
|
|
private CountDownTimer countDownTimer;
|
|
private CountDownTimer countDownTimer;
|
|
|
|
|
|
|
|
|
|
+ private int lastColor;
|
|
|
|
|
+
|
|
|
|
|
+ private int color_0_20 = ContextUtil.getContext().getColor(R.color.voice_record_0_20);
|
|
|
|
|
+ private int color_20_30 = ContextUtil.getContext().getColor(R.color.voice_record_20_30);
|
|
|
|
|
+ private int color_exceed_30 = ContextUtil.getContext().getColor(R.color.voice_record_exceed_30);
|
|
|
|
|
+ private String record_can_not = ContextUtil.getContext().getString(R.string.record_can_not);
|
|
|
|
|
+ private String record_maybe_best = ContextUtil.getContext().getString(R.string.record_maybe_best);
|
|
|
|
|
+ private String record_best = ContextUtil.getContext().getString(R.string.record_best);
|
|
|
|
|
+
|
|
|
@Inject
|
|
@Inject
|
|
|
- public CloneVoiceViewModel(MemberRepository memberRepository, CloneRepository cloneRepository) {
|
|
|
|
|
|
|
+ public CloneVoiceViewModel(MemberRepository memberRepository, CloneRepository cloneRepository, VoiceAIRepository voiceAIRepository) {
|
|
|
this.memberRepository = memberRepository;
|
|
this.memberRepository = memberRepository;
|
|
|
this.cloneRepository = cloneRepository;
|
|
this.cloneRepository = cloneRepository;
|
|
|
|
|
+ this.voiceAIRepository = voiceAIRepository;
|
|
|
initCloneTipTxt();
|
|
initCloneTipTxt();
|
|
|
initCloneState();
|
|
initCloneState();
|
|
|
- recordStateDesc = Transformations.map(recordProgress, progress -> {
|
|
|
|
|
|
|
+ recordStateDesc.addSource(recordProgress, progress -> {
|
|
|
if (progress == null) {
|
|
if (progress == null) {
|
|
|
- return "";
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- if (progress >= 0 && progress <= 20) {
|
|
|
|
|
- return ContextUtil.getContext().getString(R.string.record_can_not);
|
|
|
|
|
- } else if (progress > 20 && progress < 30) {
|
|
|
|
|
- return ContextUtil.getContext().getString(R.string.record_maybe_best);
|
|
|
|
|
|
|
+ int newColor;
|
|
|
|
|
+ String newText;
|
|
|
|
|
+ if (progress >= 0 && progress <= 20000) {
|
|
|
|
|
+ newColor = color_0_20;
|
|
|
|
|
+ newText = record_can_not;
|
|
|
|
|
+ } else if (progress > 20000 && progress <= 30000) {
|
|
|
|
|
+ newColor = color_20_30;
|
|
|
|
|
+ newText = record_maybe_best;
|
|
|
} else {
|
|
} else {
|
|
|
- return ContextUtil.getContext().getString(R.string.record_best);
|
|
|
|
|
|
|
+ newColor = color_exceed_30;
|
|
|
|
|
+ newText = record_best;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (newColor != lastColor) {
|
|
|
|
|
+ lastColor = newColor;
|
|
|
|
|
+ recordStateDesc.setValue(newText);
|
|
|
|
|
+ recordProgressColor.setValue(newColor);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
recordTimeTxt = Transformations.map(recordProgress, progress -> {
|
|
recordTimeTxt = Transformations.map(recordProgress, progress -> {
|
|
@@ -130,8 +149,8 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
return recordProgress;
|
|
return recordProgress;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public LiveData<Drawable> getRecordProgressDrawable() {
|
|
|
|
|
- return recordProgressDrawable;
|
|
|
|
|
|
|
+ public LiveData<Integer> getRecordProgressColor() {
|
|
|
|
|
+ return recordProgressColor;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public long getRecordMaxTime() {
|
|
public long getRecordMaxTime() {
|
|
@@ -270,13 +289,9 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public void requestCloneVoice(int type) {
|
|
|
|
|
- Uri value = uploadVoiceUri.getValue();
|
|
|
|
|
- if (value == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void requestCloneVoice(int type, File file) {
|
|
|
|
|
+ cloneRepository.requestVoiceClone(type, file);
|
|
|
VoiceCloningActivity.start(ActivityUtil.getTopActivity());
|
|
VoiceCloningActivity.start(ActivityUtil.getTopActivity());
|
|
|
- cloneRepository.requestVoiceClone(type, value);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void deleteClone(int id) {
|
|
public void deleteClone(int id) {
|
|
@@ -314,10 +329,10 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
//判断是否符合要求
|
|
//判断是否符合要求
|
|
|
//文件小于3M 时长大于20s且小于30s
|
|
//文件小于3M 时长大于20s且小于30s
|
|
|
long durationLong = FileUtils.getAudioDurationFromUri(ContextUtil.getContext(), uri);
|
|
long durationLong = FileUtils.getAudioDurationFromUri(ContextUtil.getContext(), uri);
|
|
|
-// if (durationLong < 20000 || durationLong > 30000) {
|
|
|
|
|
-// ToastUtil.show(R.string.clone_voice_duration_error, ToastUtil.LENGTH_SHORT);
|
|
|
|
|
-// return;
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ if (durationLong < 20000 || durationLong > 30000) {
|
|
|
|
|
+ ToastUtil.show(R.string.clone_voice_duration_error, ToastUtil.LENGTH_SHORT);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
long fileSize = FileUtils.getFileSizeFromUri(ContextUtil.getContext(), uri);
|
|
long fileSize = FileUtils.getFileSizeFromUri(ContextUtil.getContext(), uri);
|
|
|
if (fileSize > 3 * 1024 * 1024) {
|
|
if (fileSize > 3 * 1024 * 1024) {
|
|
|
ToastUtil.show(R.string.clone_voice_size_error, ToastUtil.LENGTH_SHORT);
|
|
ToastUtil.show(R.string.clone_voice_size_error, ToastUtil.LENGTH_SHORT);
|
|
@@ -339,16 +354,26 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void onCloneVoiceClick(int state) {
|
|
public void onCloneVoiceClick(int state) {
|
|
|
- if (state == CloneState.UPLOAD_CHOICE_LOCAL) {
|
|
|
|
|
- requestCloneVoice(FILE_UPLOAD);
|
|
|
|
|
|
|
+ Uri value = uploadVoiceUri.getValue();
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ File file = FileUtils.uriToFileApiQ(value, ContextUtil.getContext());
|
|
|
|
|
+ if (state == CloneState.UPLOAD_CHOICE_RECORDING) {
|
|
|
|
|
+ requestCloneVoice(RECORD_UPLOAD, file);
|
|
|
} else {
|
|
} else {
|
|
|
- requestCloneVoice(RECORD_UPLOAD);
|
|
|
|
|
|
|
+ requestCloneVoice(FILE_UPLOAD, file);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
public void useCloneVoiceClick() {
|
|
public void useCloneVoiceClick() {
|
|
|
-
|
|
|
|
|
|
|
+ MainActivity.start(ActivityUtil.getTopActivity(), VoiceAIFragment.class);
|
|
|
|
|
+ List<CloneVoiceListBean> list = cloneRepository.getCloneVoiceList().getValue();
|
|
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ voiceAIRepository.setUseClonedVoiceEvent(list.get(0).getId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void onDeleteClick() {
|
|
public void onDeleteClick() {
|
|
@@ -371,9 +396,7 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- @SuppressLint("UseCompatLoadingForDrawables")
|
|
|
|
|
public void startRecordAudio() {
|
|
public void startRecordAudio() {
|
|
|
- recordProgressDrawable.setValue(ContextUtil.getContext().getDrawable(R.drawable.bg_progress_bar_horizontal_record_0_20));
|
|
|
|
|
startRecordAudioEvent.call();
|
|
startRecordAudioEvent.call();
|
|
|
recordProgress.setValue(0);
|
|
recordProgress.setValue(0);
|
|
|
cloneState.setValue(CloneState.RECORDING_VOICE);
|
|
cloneState.setValue(CloneState.RECORDING_VOICE);
|
|
@@ -415,7 +438,7 @@ public class CloneVoiceViewModel extends BaseViewModel {
|
|
|
|
|
|
|
|
public String getRecordAudioFilePath() {
|
|
public String getRecordAudioFilePath() {
|
|
|
File cacheFile = FileUtils.getVoiceDownloadSaveRootFile();
|
|
File cacheFile = FileUtils.getVoiceDownloadSaveRootFile();
|
|
|
- recordFile = new File(cacheFile, "record_audio");
|
|
|
|
|
|
|
+ recordFile = new File(cacheFile, "record_audio.mp3");
|
|
|
return recordFile.getPath();
|
|
return recordFile.getPath();
|
|
|
}
|
|
}
|
|
|
|
|
|