Browse Source

完善生成以及克隆异常结果流程

zk 1 year ago
parent
commit
c018f15f8b

+ 1 - 1
app/build.gradle

@@ -55,7 +55,7 @@ android {
 
 
     def env_release = PROD
-    def env_debug = PROD
+    def env_debug = LOCAL
 
     buildTypes {
         release {

+ 4 - 0
app/src/main/AndroidManifest.xml

@@ -7,6 +7,7 @@
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.RECORD_AUDIO" />
     <uses-permission android:name="com.android.vending.BILLING" />
+
     <application
         android:name=".App"
         android:allowBackup="false"
@@ -55,6 +56,9 @@
         <activity
             android:name=".module.cloning.VoiceCloningActivity"
             android:screenOrientation="portrait" />
+        <activity
+            android:name=".module.integral.InternalPurchaseActivity"
+            android:screenOrientation="portrait" />
 
         <provider
             android:name="androidx.core.content.FileProvider"

+ 1 - 0
app/src/main/java/com/atmob/voiceai/data/consts/ErrorCode.java

@@ -3,5 +3,6 @@ package com.atmob.voiceai.data.consts;
 public interface ErrorCode {
 
     int ERROR_NOT_SUBSCRIBED = 4002;
+    int ERROR_INTEGRAL_NOT_ENOUGH = 4003;
     int ERROR_SUBSCRIPTION_NOT_FOUND = 2001;
 }

+ 19 - 2
app/src/main/java/com/atmob/voiceai/data/repositories/CloneRepository.java

@@ -8,7 +8,9 @@ import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
 
 import com.atmob.app.lib.handler.RxHttpHandler;
+import com.atmob.common.runtime.ActivityUtil;
 import com.atmob.common.runtime.ContextUtil;
+import com.atmob.voiceai.R;
 import com.atmob.voiceai.data.api.AtmobApi;
 import com.atmob.voiceai.data.api.bean.CloneVoiceListBean;
 import com.atmob.voiceai.data.api.request.BaseRequest;
@@ -16,9 +18,12 @@ import com.atmob.voiceai.data.api.request.CloneDeleteRequest;
 import com.atmob.voiceai.data.api.request.VoiceCloneRequest;
 import com.atmob.voiceai.data.api.response.VoiceCloneListResponse;
 import com.atmob.voiceai.data.api.response.VoiceCloneResponse;
+import com.atmob.voiceai.data.consts.ErrorCode;
 import com.atmob.voiceai.data.consts.EventId;
 import com.atmob.voiceai.handlers.EventHandler;
 import com.atmob.voiceai.helper.ErrorHelper;
+import com.atmob.voiceai.module.integral.InternalPurchaseActivity;
+import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
 import com.atmob.voiceai.utils.ReflectionUtil;
 import com.atmob.voiceai.utils.ToastUtil;
 import com.google.gson.annotations.SerializedName;
@@ -121,10 +126,22 @@ public class CloneRepository {
             }
 
             @Override
-            public void onError(@NonNull Throwable e) {
+            public void onError(@NonNull Throwable throwable) {
                 requestCloneFlag = false;
                 cloneUploadState.setValue(UploadState.ERROR);
-                ErrorHelper.errorThrowableToast(e, ToastUtil.LENGTH_SHORT);
+                if (throwable instanceof RxHttpHandler.ServerErrorException) {
+                    RxHttpHandler.ServerErrorException serverErrorException = (RxHttpHandler.ServerErrorException) throwable;
+                    if (serverErrorException.getCode() == ErrorCode.ERROR_NOT_SUBSCRIBED) {
+                        SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
+                    } else if (serverErrorException.getCode() == ErrorCode.ERROR_INTEGRAL_NOT_ENOUGH) {
+                        InternalPurchaseActivity.start(ActivityUtil.getTopActivity());
+                    } else {
+                        ToastUtil.show(serverErrorException.getMsg(), ToastUtil.LENGTH_SHORT);
+                    }
+                } else {
+                    ToastUtil.show(R.string.net_error_message, ToastUtil.LENGTH_SHORT);
+                }
+
             }
         });
     }

+ 10 - 2
app/src/main/java/com/atmob/voiceai/data/repositories/VoiceAIRepository.java

@@ -9,6 +9,7 @@ import androidx.lifecycle.MutableLiveData;
 
 import com.atmob.app.lib.handler.RxHttpHandler;
 import com.atmob.app.lib.livedata.SingleLiveEvent;
+import com.atmob.common.runtime.ActivityUtil;
 import com.atmob.common.runtime.ContextUtil;
 import com.atmob.voiceai.R;
 import com.atmob.voiceai.data.api.AtmobApi;
@@ -22,6 +23,8 @@ import com.atmob.voiceai.data.api.response.TextToSpeechResponse;
 import com.atmob.voiceai.data.api.response.VoiceListResponse;
 import com.atmob.voiceai.data.api.response.VoiceTypeResponse;
 import com.atmob.voiceai.data.consts.ErrorCode;
+import com.atmob.voiceai.module.integral.InternalPurchaseActivity;
+import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
 import com.atmob.voiceai.utils.ThreePair;
 import com.atmob.voiceai.utils.VoiceFileUtil;
 
@@ -181,10 +184,15 @@ public class VoiceAIRepository {
                         textToSpeechRequest = false;
                         if (throwable instanceof RxHttpHandler.ServerErrorException) {
                             RxHttpHandler.ServerErrorException serverErrorException = (RxHttpHandler.ServerErrorException) throwable;
-                            textToSpeechState.setValue(new ThreePair<>(TextToSpeechState.ERROR, serverErrorException.getMsg(), null));
+                            String msg = serverErrorException.getMsg();
                             if (serverErrorException.getCode() == ErrorCode.ERROR_NOT_SUBSCRIBED) {
-                                memberRepository.refreshUserData();
+                                msg = null;
+                                SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
+                            } else if (serverErrorException.getCode() == ErrorCode.ERROR_INTEGRAL_NOT_ENOUGH) {
+                                msg = null;
+                                InternalPurchaseActivity.start(ActivityUtil.getTopActivity());
                             }
+                            textToSpeechState.setValue(new ThreePair<>(TextToSpeechState.ERROR, msg, null));
                         } else {
                             textToSpeechState.setValue(new ThreePair<>(TextToSpeechState.ERROR, ContextUtil.getContext().getString(R.string.generate_error), null));
                         }

+ 4 - 0
app/src/main/java/com/atmob/voiceai/module/generating/VoiceGeneratingActivity.java

@@ -4,6 +4,7 @@ import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.text.TextUtils;
 
 import androidx.annotation.Nullable;
 
@@ -45,6 +46,9 @@ public class VoiceGeneratingActivity extends BaseActivity<ActivityVoiceGeneratin
         });
         voiceGeneratingViewModel.getGenerateError().observe(this, txt -> {
             finish();
+            if (TextUtils.isEmpty(txt)) {
+                return;
+            }
             ToastUtil.show(txt, ToastUtil.LENGTH_SHORT);
         });
     }

+ 4 - 1
app/src/main/java/com/atmob/voiceai/module/integral/InternalPurchaseActivity.java

@@ -9,8 +9,11 @@ import androidx.annotation.Nullable;
 
 import com.atmob.app.lib.base.BaseActivity;
 import com.atmob.voiceai.databinding.ActivityInternalPurchaseBinding;
-import com.atmob.voiceai.module.main.MainActivity;
 
+import dagger.hilt.android.AndroidEntryPoint;
+
+
+@AndroidEntryPoint
 public class InternalPurchaseActivity extends BaseActivity<ActivityInternalPurchaseBinding> {
 
 

+ 10 - 0
app/src/main/java/com/atmob/voiceai/module/integral/InternalPurchaseViewModel.java

@@ -2,5 +2,15 @@ package com.atmob.voiceai.module.integral;
 
 import com.atmob.app.lib.base.BaseViewModel;
 
+import javax.inject.Inject;
+
+import dagger.hilt.android.lifecycle.HiltViewModel;
+
+
+@HiltViewModel
 public class InternalPurchaseViewModel extends BaseViewModel {
+
+    @Inject
+    public InternalPurchaseViewModel() {
+    }
 }

+ 2 - 1
app/src/main/java/com/atmob/voiceai/module/voiceai/VoiceAIViewModel.java

@@ -148,7 +148,8 @@ public class VoiceAIViewModel extends BaseViewModel {
             ToastUtil.show(R.string.voice_ai_no_choice, ToastUtil.LENGTH_SHORT);
             return;
         }
-        memberRepository.consumptionIntegral(content.length(), this::requestGenerateVoice);
+        requestGenerateVoice();
+//        memberRepository.consumptionIntegral(content.length(), this::requestGenerateVoice);
     }
 
     private void requestGenerateVoice() {