Browse Source

结果页增加加载动效

zk 1 year ago
parent
commit
b8502f0bcf

+ 11 - 0
app/src/main/java/com/atmob/voiceai/module/result/VoiceResultViewModel.java

@@ -52,6 +52,7 @@ public class VoiceResultViewModel extends BaseViewModel {
     private final String TAG = VoiceResultViewModel.class.getSimpleName();
 
     private final VoiceAIRepository voiceAIRepository;
+    private final MutableLiveData<Boolean> isLoading = new MutableLiveData<>();
     private final MutableLiveData<Boolean> isPlay = new MutableLiveData<>();
     private final MutableLiveData<Long> totalDuration = new MutableLiveData<>();
     private final MutableLiveData<Long> currentDuration = new MutableLiveData<>();
@@ -77,6 +78,10 @@ public class VoiceResultViewModel extends BaseViewModel {
         checkScoring();
     }
 
+    public LiveData<Boolean> getIsLoading() {
+        return isLoading;
+    }
+
     public LiveData<Uri> getVoiceUri() {
         return voiceUri;
     }
@@ -274,23 +279,29 @@ public class VoiceResultViewModel extends BaseViewModel {
                     @Override
                     public void onSubscribe(@NonNull Disposable d) {
                         addDisposable(d);
+                        isLoading.setValue(true);
                         AtmobLog.d(TAG, "startDownloadVoice onSubscribe: voiceUrl:" + voiceUrl);
                     }
 
                     @Override
                     public void onSuccess(@NonNull File file) {
+                        isLoading.setValue(false);
                         AtmobLog.d(TAG, "startDownloadVoice onSuccess: " + file.getPath());
                         voiceUri.setValue(Uri.fromFile(file));
                     }
 
                     @Override
                     public void onError(@NonNull Throwable e) {
+                        isLoading.setValue(false);
                         AtmobLog.d(TAG, "startDownloadVoice onError: " + e.getMessage());
                         voiceUri.setValue(Uri.parse(voiceUrl));
                     }
                 });
     }
 
+    public void setIsLoading(boolean isLoading) {
+        this.isLoading.setValue(isLoading);
+    }
 
     @Override
     protected void onCleared() {

+ 1 - 2
app/src/main/java/com/atmob/voiceai/utils/FileDownLoadObserver.java

@@ -56,9 +56,8 @@ public abstract class FileDownLoadObserver<T> {
             try (
                     InputStream is = new BufferedInputStream(responseBody.byteStream());
                     FileOutputStream fos = new FileOutputStream(file);
-                    OutputStream os = new BufferedOutputStream(fos);
             ) {
-                copyStream(is, os, cancellationSignal);
+                copyStream(is, fos, cancellationSignal);
             }
 
         } catch (IOException e) {

+ 15 - 0
app/src/main/res/layout/activity_voice_result.xml

@@ -175,6 +175,21 @@
                     app:layout_constraintWidth_percent="0.1333333333333333"
                     tools:src="@drawable/icon_voice_playing" />
 
+                <com.airbnb.lottie.LottieAnimationView
+                    app:lottie_autoPlay="true"
+                    app:lottie_fileName="anim/anim_loading_voice.json"
+                    app:lottie_loop="true"
+                    isGone="@{!voiceResultViewModel.isLoading}"
+                    android:onClick="@{null}"
+                    android:id="@+id/iv_loading"
+                    android:layout_width="0dp"
+                    android:layout_height="0dp"
+                    app:layout_constraintBottom_toBottomOf="@+id/iv_play"
+                    app:layout_constraintDimensionRatio="1:1"
+                    app:layout_constraintEnd_toEndOf="@+id/iv_play"
+                    app:layout_constraintStart_toStartOf="@+id/iv_play"
+                    app:layout_constraintTop_toTopOf="@+id/iv_play" />
+
                 <ImageView
                     android:id="@+id/iv_voice_speed"
                     android:layout_width="0dp"