Browse Source

修改部分问题

Pq 1 year ago
parent
commit
12902c0e84

+ 1 - 0
BaseLibrary/src/main/java/com/cooleshow/base/common/WebApi.java

@@ -19,4 +19,5 @@ public class WebApi {
     public static final String API_OPEN_ADJUST_RECORDING = "openAdjustRecording";
 
     public static final String API_SAVE_FILE = "saveFile";
+    public static final String API_VIDEO_CROP = "videoCrop";
 }

+ 23 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/UrlUtils.java

@@ -0,0 +1,23 @@
+package com.cooleshow.base.utils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Author by pq, Date on 2023/11/10.
+ */
+public class UrlUtils {
+    public static boolean isValidDownloadUrl(String url) {
+        try {
+            URL downloadUrl = new URL(url);
+            // 检查协议是否为HTTP或HTTPS
+            String protocol = downloadUrl.getProtocol();
+            if (!"http".equalsIgnoreCase(protocol) && !"https".equalsIgnoreCase(protocol)) {
+                return false;
+            }
+            return true;
+        } catch (MalformedURLException e) {
+            return false;
+        }
+    }
+}

+ 3 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/helper/upload/UploadHelper.java

@@ -324,6 +324,9 @@ public class UploadHelper {
                     @Override
                     public void onError(@NonNull Throwable e) {
                         uploadToken = "";
+                        if (upLoadCallBack != null) {
+                            upLoadCallBack.onFailure();
+                        }
                     }
 
                     @Override

+ 25 - 14
musicMerge/src/main/java/com/cooleshow/musicmerge/ui/MusicHandleActivity.java

@@ -35,6 +35,7 @@ import com.cooleshow.base.utils.NumberUtils;
 import com.cooleshow.base.utils.SizeUtils;
 import com.cooleshow.base.utils.TimeUtils;
 import com.cooleshow.base.utils.ToastUtil;
+import com.cooleshow.base.utils.UrlUtils;
 import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
 import com.cooleshow.base.utils.helper.upload.UploadHelper;
 import com.cooleshow.base.widgets.dialog.CommonConfirmDialog;
@@ -425,7 +426,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
         MixHelper.getInstance().startMixForMp4(accompanimentMp3Path, recordFilePath, offsetValue, recordFileVolume, accompanyFileVolume, new ResultCallback<String>() {
             @Override
             public void onSuccess(String s) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -449,7 +450,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onProgress(int progressPercent) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -463,7 +464,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onFail(int errorCode, String errorStr) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -484,7 +485,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
         MixHelper.getInstance().startMix(accompanimentMp3Path, recordFilePath, offsetValue, recordFileVolume, accompanyFileVolume, new ResultCallback<String>() {
             @Override
             public void onSuccess(String s) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -508,7 +509,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onProgress(int progressPercent) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -522,7 +523,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onFail(int errorCode, String errorStr) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -712,13 +713,18 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
         if (file.exists()) {
             return true;
         }
+        boolean validDownloadUrl = UrlUtils.isValidDownloadUrl(recordUrl);
+        if (!validDownloadUrl) {
+            ToastUtil.getInstance().showShort("未找到演奏文件,请退出重试");
+            return false;
+        }
         Log.i("pq", "下载草稿");
         setLoadingCancelable(false);
         showLoading("草稿下载中");
         MixHelper.getInstance().download(recordUrl, fileEndSuffix, new ResultCallback<String>() {
             @Override
             public void onSuccess(String s) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -732,7 +738,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onProgress(int progressPercent) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -745,7 +751,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onFail(int errorCode, String errorStr) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -770,12 +776,17 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
         if (file.exists()) {
             return true;
         }
+        boolean validDownloadUrl = UrlUtils.isValidDownloadUrl(accompanyUrl);
+        if (!validDownloadUrl) {
+            ToastUtil.getInstance().showShort("未找到伴奏文件,请退出重试");
+            return false;
+        }
         setLoadingCancelable(false);
         showLoading("伴奏下载中");
         MixHelper.getInstance().download(accompanyUrl, MyFileUtils.MP3_FILE_SUFFIX, new ResultCallback<String>() {
             @Override
             public void onSuccess(String s) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -789,7 +800,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onProgress(int progressPercent) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -802,7 +813,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
 
             @Override
             public void onFail(int errorCode, String errorStr) {
-                if(!checkActivityExist()){
+                if (!checkActivityExist()) {
                     return;
                 }
                 runOnUiThread(new Runnable() {
@@ -1018,7 +1029,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
             return;
         }
         currentStep = 2;
-        showToastViewAndFinish("发布成功",true);
+        showToastViewAndFinish("发布成功", true);
     }
 
     private void toFinish(boolean isReCallBack) {
@@ -1065,7 +1076,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
         currentStep = 1;
         mViewModel.getUpdateEvent().setValue(false);
         if (isNeedFinishPage) {
-            showToastViewAndFinish("保存成功",false);
+            showToastViewAndFinish("保存成功", false);
         } else {
             toUpdateLoadingText(getCurrentProgress(100), "保存成功");
             mHandler.postDelayed(new Runnable() {

+ 6 - 0
musicMerge/src/main/java/com/cooleshow/musicmerge/ui/SelectVideoFrameActivity.java

@@ -16,6 +16,7 @@ import com.cooleshow.base.utils.MyFileUtils;
 import com.cooleshow.base.utils.SizeUtils;
 import com.cooleshow.base.utils.ToastUtil;
 import com.cooleshow.base.utils.UiUtils;
+import com.cooleshow.base.utils.UrlUtils;
 import com.cooleshow.base.utils.Utils;
 import com.cooleshow.musicmerge.R;
 import com.cooleshow.musicmerge.callback.ResultCallback;
@@ -114,6 +115,11 @@ public class SelectVideoFrameActivity extends BaseMVPActivity<AcSelectVideoFrame
             mVideoPath = filePath;
             return true;
         }
+        boolean validDownloadUrl = UrlUtils.isValidDownloadUrl(recordUrl);
+        if (!validDownloadUrl) {
+            ToastUtil.getInstance().showShort("未找到演奏文件,请退出重试");
+            return false;
+        }
         setLoadingCancelable(false);
         showLoading("视频下载中");
         MixHelper.getInstance().download(recordUrl, fileEndSuffix, new ResultCallback<String>() {

+ 5 - 0
student/src/main/java/com/cooleshow/student/ui/main/MallFragment.java

@@ -553,6 +553,11 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
 
     }
 
+    @Override
+    public void videoCrop(JSONObject jsonObject) {
+
+    }
+
     private boolean goPay = false;
 
     @Subscribe(threadMode = ThreadMode.MAIN)

+ 78 - 0
student/src/main/java/com/cooleshow/student/ui/web/HtmlActivity.java

@@ -50,6 +50,7 @@ import com.cooleshow.base.bean.WxPayResult;
 import com.cooleshow.base.common.WebConstants;
 import com.cooleshow.base.constanst.Constants;
 import com.cooleshow.base.constanst.StyleConfig;
+import com.cooleshow.base.constanst.UploadConstants;
 import com.cooleshow.base.data.net.RetrofitClientNoToken;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.activity.BaseActivity;
@@ -135,6 +136,8 @@ import okhttp3.ResponseBody;
 public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements JsInterfaceUtils.onGetMethodsListener {
     private static final int REQUEST_CODE_FILE_CHOOSER = 500;
     private static final int SHARE_CHAT_REQUEST_CODE = 501;
+
+    private static final int REQUEST_CODE_VIDEO_COVER = 502;
     public static final String TAG = "HtmlActivity";
     private IWXAPI api;
     private static final int SDK_PAY_FLAG = 1;
@@ -952,6 +955,21 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
                 });
     }
 
+    @Override
+    public void videoCrop(JSONObject jsonObject) {
+        baseJsonObject = jsonObject;
+        JSONObject contentJson = jsonObject.optJSONObject("content");
+        if (contentJson != null) {
+            String videoUrl = contentJson.optString("url");
+            if(!TextUtils.isEmpty(videoUrl)){
+                ARouter.getInstance().build(RouterPath.MusicTuner.MUSIC_SELECT_VIDEO_FRAME)
+                        .withString("videoFilePath", videoUrl)
+                        .withBoolean("isLocalFile", false)
+                        .navigation(HtmlActivity.this, REQUEST_CODE_VIDEO_COVER);
+            }
+        }
+    }
+
     private void showWifiTipDialog2(String url) {
         CommonConfirmDialog2 commonDialog2 = new CommonConfirmDialog2(this);
         commonDialog2.show();
@@ -1319,6 +1337,11 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
             if (result != null) {
                 File file = UriUtils.uri2File(result);
                 if (file != null && file.exists()) {
+                    if (!isMatchFile(file.getAbsolutePath())) {
+                        ToastUtil.getInstance().showShort("请上传正确类型的文件");
+                        upLoadFileFaile();
+                        return;
+                    }
                     UploadHelper uploadHelper = new UploadHelper(HtmlActivity.this, buckName);
                     uploadHelper.uploadFile(file);
                     uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
@@ -1360,6 +1383,11 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
             }
             clearUploadMessage();
             return;
+        } else if(requestCode == REQUEST_CODE_VIDEO_COVER){
+            if (data != null) {
+                String videoPath = data.getStringExtra(Constants.COMMON_EXTRA_KEY);
+                uploadVideoCoverFile(videoPath);
+            }
         } else if (requestCode == 1011) {
             //选择地址
             if (data == null) {
@@ -1367,8 +1395,58 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
             }
             String selectAddress = data.getStringExtra("selectAddress");
             selectAddress(selectAddress);
+        }else {
+            if (mUploadCallbackAboveL != null)
+                mUploadCallbackAboveL.onReceiveValue(new Uri[]{});
+        }
+
+    }
+
+    private void uploadVideoCoverFile(String filePath){
+        File file =new File(filePath);
+        if(!file.exists()){
+            return;
         }
+        UploadHelper uploadHelper = new UploadHelper(HtmlActivity.this, UploadConstants.UPLOAD_TYPE_OTHER);
+        uploadHelper.uploadFile(file);
+        uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
+            @Override
+            public void onSuccess(String url) {
+                hideLoading();
+                try {
+                    JSONObject contentObj = baseJsonObject.getJSONObject("content");
+                    String uuid = contentObj.optString("uuid");
+                    contentObj.put("videoCover", url);
+                    contentObj.put("uuid", uuid);
+                    baseJsonObject.put("content", contentObj);
+                    onSendMessage(baseJsonObject.toString());
+                } catch (JSONException e) {
+                    e.printStackTrace();
+                }
+            }
+
+            @Override
+            public void onFailure() {
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        ToastUtil.getInstance().showShort("上传失败,请重新选择");
+                        upLoadFileFaile();
+                    }
+                });
+            }
+        });
+    }
 
+    private boolean isMatchFile(String filePath) {
+        try {
+            JSONObject contentJsonObject = baseJsonObject.getJSONObject("content");
+            String type = contentJsonObject.optString("type");
+            return FileUtils.isMatchTargetFileType(type, filePath);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return true;
     }
 
     private void upLoadFileFaile() {

+ 5 - 0
student/src/main/java/com/cooleshow/student/ui/web/HtmlHorizontalScreenActivity.java

@@ -683,6 +683,11 @@ public class HtmlHorizontalScreenActivity extends BaseActivity<ActivityHtml1Bind
 
     }
 
+    @Override
+    public void videoCrop(JSONObject jsonObject) {
+
+    }
+
     private boolean goPay = false;
 
     @Subscribe(threadMode = ThreadMode.MAIN)

+ 9 - 0
student/src/main/java/com/cooleshow/student/widgets/helper/JsInterfaceUtils.java

@@ -306,6 +306,13 @@ public class JsInterfaceUtils extends Object {
                     }
                     return;
                 }
+
+                if(TextUtils.equals(WebApi.API_VIDEO_CROP,api)){
+                    if (onListener != null) {
+                        onListener.videoCrop(jsonObject);
+                    }
+                    return;
+                }
             } catch (Exception e) {
             }
         });
@@ -414,6 +421,8 @@ public class JsInterfaceUtils extends Object {
 
         void shareTripartite(JSONObject jsonObject);
 
+        void videoCrop(JSONObject jsonObject);
+
     }
 
 }

+ 5 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/main/MallFragment.java

@@ -558,6 +558,11 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
 
     }
 
+    @Override
+    public void videoCrop(JSONObject jsonObject) {
+
+    }
+
     private boolean goPay = false;
 
     @Subscribe(threadMode = ThreadMode.MAIN)

+ 60 - 1
teacher/src/main/java/com/cooleshow/teacher/ui/web/HtmlActivity.java

@@ -49,6 +49,7 @@ import com.cooleshow.base.bean.DownloadTaskBean;
 import com.cooleshow.base.bean.WxPayResult;
 import com.cooleshow.base.common.WebConstants;
 import com.cooleshow.base.constanst.Constants;
+import com.cooleshow.base.constanst.UploadConstants;
 import com.cooleshow.base.data.net.RetrofitClientNoToken;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.activity.BaseActivity;
@@ -133,6 +134,8 @@ import okhttp3.ResponseBody;
 public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements JsInterfaceUtils.onGetMethodsListener {
     private static final int REQUEST_CODE_FILE_CHOOSER = 500;
     private static final int SHARE_CHAT_REQUEST_CODE = 501;
+
+    private static final int REQUEST_CODE_VIDEO_COVER = 502;
     public static final String TAG = "HtmlActivity";
     private IWXAPI api;
     private static final int SDK_PAY_FLAG = 1;
@@ -402,6 +405,21 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
                 });
     }
 
+    @Override
+    public void videoCrop(JSONObject jsonObject) {
+        baseJsonObject = jsonObject;
+        JSONObject contentJson = jsonObject.optJSONObject("content");
+        if (contentJson != null) {
+            String videoUrl = contentJson.optString("url");
+            if(!TextUtils.isEmpty(videoUrl)){
+                ARouter.getInstance().build(RouterPath.MusicTuner.MUSIC_SELECT_VIDEO_FRAME)
+                        .withString("videoFilePath", videoUrl)
+                        .withBoolean("isLocalFile", false)
+                        .navigation(HtmlActivity.this, REQUEST_CODE_VIDEO_COVER);
+            }
+        }
+    }
+
     private void showWifiTipDialog2(String url) {
         CommonConfirmDialog2 commonDialog2 = new CommonConfirmDialog2(this);
         commonDialog2.show();
@@ -1364,7 +1382,12 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
             }
             clearUploadMessage();
             return;
-        } else if (requestCode == 1011) {
+        } else if(requestCode == REQUEST_CODE_VIDEO_COVER){
+            if (data != null) {
+                String videoPath = data.getStringExtra(Constants.COMMON_EXTRA_KEY);
+                uploadVideoCoverFile(videoPath);
+            }
+        }else if (requestCode == 1011) {
             if (data == null) {
                 return;
             }
@@ -1388,6 +1411,42 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
         return true;
     }
 
+    private void uploadVideoCoverFile(String filePath){
+        File file =new File(filePath);
+        if(!file.exists()){
+            return;
+        }
+        UploadHelper uploadHelper = new UploadHelper(HtmlActivity.this, UploadConstants.UPLOAD_TYPE_OTHER);
+        uploadHelper.uploadFile(file);
+        uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
+            @Override
+            public void onSuccess(String url) {
+                hideLoading();
+                try {
+                    JSONObject contentObj = baseJsonObject.getJSONObject("content");
+                    String uuid = contentObj.optString("uuid");
+                    contentObj.put("videoCover", url);
+                    contentObj.put("uuid", uuid);
+                    baseJsonObject.put("content", contentObj);
+                    onSendMessage(baseJsonObject.toString());
+                } catch (JSONException e) {
+                    e.printStackTrace();
+                }
+            }
+
+            @Override
+            public void onFailure() {
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        ToastUtil.getInstance().showShort("上传失败,请重新选择");
+                        upLoadFileFaile();
+                    }
+                });
+            }
+        });
+    }
+
     private void upLoadFileFaile() {
         try {
             JSONObject contentObj = baseJsonObject.getJSONObject("content");

+ 5 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/web/HtmlHorizontalScreenActivity.java

@@ -680,6 +680,11 @@ public class HtmlHorizontalScreenActivity extends BaseActivity<ActivityHtml1Bind
 
     }
 
+    @Override
+    public void videoCrop(JSONObject jsonObject) {
+
+    }
+
     private boolean goPay = false;
 
     @Subscribe(threadMode = ThreadMode.MAIN)

+ 8 - 0
teacher/src/main/java/com/cooleshow/teacher/widgets/helper/JsInterfaceUtils.java

@@ -353,6 +353,13 @@ public class JsInterfaceUtils extends Object {
                     }
                     return;
                 }
+
+                if(TextUtils.equals(WebApi.API_VIDEO_CROP,api)){
+                    if (onListener != null) {
+                        onListener.videoCrop(jsonObject);
+                    }
+                    return;
+                }
             } catch (Exception e) {
             }
         });
@@ -461,6 +468,7 @@ public class JsInterfaceUtils extends Object {
 
         void shareTripartite(JSONObject jsonObject);
 
+        void videoCrop(JSONObject jsonObject);
     }
 
 }