|
@@ -0,0 +1,247 @@
|
|
|
+package com.daya.accompanysdk.manager;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.Application;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.pm.ActivityInfo;
|
|
|
+import android.webkit.ClientCertRequest;
|
|
|
+import android.webkit.WebView;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.cooleshow.base.common.BaseConstant;
|
|
|
+import com.cooleshow.base.common.WebConstants;
|
|
|
+import com.cooleshow.base.data.auth.Https;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.utils.LOG;
|
|
|
+import com.cooleshow.base.utils.helper.upload.UploadHelper;
|
|
|
+import com.cooleshow.usercenter.constants.UserConstants;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.daya.accompanysdk.R;
|
|
|
+import com.daya.accompanysdk.engine.GlideEngine;
|
|
|
+import com.daya.accompanysdk.utils.Utils;
|
|
|
+import com.daya.accompanysdk.widget.CustomDelayCheckView;
|
|
|
+import com.daya.orchestra.accompany.bean.AccompanyStartParams;
|
|
|
+import com.daya.orchestra.accompany.bean.MusicSaveParams;
|
|
|
+import com.daya.orchestra.accompany.bean.WebConfig;
|
|
|
+import com.daya.orchestra.accompany.callback.ResultCallback;
|
|
|
+import com.daya.orchestra.accompany.common.AccompanyEventImpl;
|
|
|
+import com.daya.orchestra.accompany.common.AccompanyManager;
|
|
|
+import com.daya.orchestra.accompany.helper.CacheHelper;
|
|
|
+import com.daya.orchestra.accompany.widget.BaseDelayCheckView;
|
|
|
+import com.luck.picture.lib.PictureSelector;
|
|
|
+import com.luck.picture.lib.config.PictureConfig;
|
|
|
+import com.luck.picture.lib.config.PictureMimeType;
|
|
|
+import com.luck.picture.lib.tools.SPUtils;
|
|
|
+
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+import androidx.activity.result.ActivityResultLauncher;
|
|
|
+import androidx.fragment.app.Fragment;
|
|
|
+import androidx.fragment.app.FragmentManager;
|
|
|
+import okhttp3.internal.platform.Platform;
|
|
|
+import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2024/1/17.
|
|
|
+ */
|
|
|
+public class AccompanyHelper {
|
|
|
+
|
|
|
+ private AccompanyHelper() {
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class AccompanyHelperHolder {
|
|
|
+ private static AccompanyHelper sHelper = new AccompanyHelper();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static AccompanyHelper getInstance() {
|
|
|
+ return AccompanyHelperHolder.sHelper;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initAccompany(Application application) {
|
|
|
+ AccompanyManager.getInstance().init(application, new AccompanyEventImpl() {
|
|
|
+ @Override
|
|
|
+ public void showPermissionTipDialog(FragmentManager fragmentManager, Context context, String s, String s1) {
|
|
|
+ Utils.showPermissionTipDialog2(fragmentManager, context, s, s1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getBaseServerUrl() {
|
|
|
+ return BaseConstant.SERVER_ADDRESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void toUpload(Activity activity, File file, String s, String s1, ResultCallback<Object> resultCallback) {
|
|
|
+ UploadHelper uploadHelper = new UploadHelper(activity, s, s1);
|
|
|
+ uploadHelper.uploadFile(file);
|
|
|
+ uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String url) {
|
|
|
+ if (resultCallback != null) {
|
|
|
+ resultCallback.onSuccess(url);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onFailure() {
|
|
|
+ if (resultCallback != null) {
|
|
|
+ resultCallback.onFail(0, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void logout() {
|
|
|
+ ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN)
|
|
|
+ .withString(UserConstants.PHONE_NUM_KEY, UserHelper.getUserPhone())
|
|
|
+ .navigation();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void goChat(String s, String s1) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void openWebView(JSONObject jsonObject) {
|
|
|
+ try {
|
|
|
+ JSONObject content = jsonObject.getJSONObject("content");
|
|
|
+ boolean isHideTitle = false;
|
|
|
+ boolean statusBarTextColor = false;
|
|
|
+ boolean isOpenLight = false;
|
|
|
+ boolean showLoadingAnim = false;
|
|
|
+ int orientation = -1;
|
|
|
+ int c_orientation = -1;
|
|
|
+ try {
|
|
|
+ isHideTitle = content.optBoolean("isHideTitle");
|
|
|
+ statusBarTextColor = content.optBoolean("statusBarTextColor");
|
|
|
+ isOpenLight = content.optBoolean("isOpenLight");
|
|
|
+ showLoadingAnim = content.optBoolean("showLoadingAnim");
|
|
|
+ orientation = content.optInt("orientation");
|
|
|
+ c_orientation = content.optInt("c_orientation");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ String path = RouterPath.WebCenter.ACTIVITY_HTML;
|
|
|
+ ARouter.getInstance().build(path)
|
|
|
+ .withString(WebConstants.WEB_URL, content.optString("url"))
|
|
|
+ .withBoolean("isHideTitle", isHideTitle)
|
|
|
+ .withBoolean("statusBarTextColor", statusBarTextColor)
|
|
|
+ .withBoolean("isOpenLight", isOpenLight)
|
|
|
+ .withBoolean("showLoadingAnim", showLoadingAnim)
|
|
|
+ .withInt("orientation", orientation)
|
|
|
+ .withInt("c_orientation", c_orientation)
|
|
|
+ .navigation();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onReceivedClientCertRequest(WebView view, ClientCertRequest request) {
|
|
|
+ LOG.i("onReceivedClientCertRequest");
|
|
|
+ boolean proceed = Https.proceed(com.cooleshow.base.utils.Utils.getApp(), request);
|
|
|
+ return proceed;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void openMusicMergePage(Activity activity, MusicSaveParams musicSaveParams, int requestCode) {
|
|
|
+ LOG.i("openMusicMergePage:"+musicSaveParams.getMusicSheetId()+"\nmusicRenderType:"+musicSaveParams.getMusicRenderType()+"\nspeedRate:"+musicSaveParams.getEvaluationSpeed());
|
|
|
+ ARouter.getInstance().build(RouterPath.MusicTuner.MUSIC_MERGE_PAGE)
|
|
|
+ .withString("accompanyUrl", musicSaveParams.getAccompanyUrl())
|
|
|
+ .withString("recordFilePath", musicSaveParams.getRecordFilePath())
|
|
|
+ .withString("recordId", musicSaveParams.getRecordId())
|
|
|
+ .withString("title", musicSaveParams.getTitle())
|
|
|
+ .withString("musicSheetId", musicSaveParams.getMusicSheetId())
|
|
|
+ .withString("musicRenderType", musicSaveParams.getMusicRenderType())
|
|
|
+ .withString("coverImg", musicSaveParams.getCoverImg())
|
|
|
+ .withFloat("speedRate", musicSaveParams.getEvaluationSpeed())
|
|
|
+ .withInt("part-index", musicSaveParams.getPartIndex())
|
|
|
+ .withInt("defaultDelay", musicSaveParams.getDefaultDelay())
|
|
|
+ .withInt("evaluateDelay", musicSaveParams.getEvaluateDelay())//此字段给IOS使用
|
|
|
+ .withInt("c_orientation", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
|
|
|
+ .navigation(activity, requestCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void selectPicture(Fragment fragment,ActivityResultLauncher<Intent> activityResultLauncher) {
|
|
|
+ PictureSelector.create(fragment)
|
|
|
+ .openGallery(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
|
|
|
+ .loadImageEngine(GlideEngine.createGlideEngine())
|
|
|
+ .theme(R.style.picture_daya_style)// 主题样式设置 具体参考 values/styles 用法:R .style.picture.white.style
|
|
|
+ .selectionMode(PictureConfig.SINGLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
|
|
|
+ .enableCrop(false)// 是否裁剪 true or false
|
|
|
+ .showCropGrid(false)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
|
|
|
+ .compress(true)// 是否压缩 true or false
|
|
|
+ .circleDimmedLayer(false)// 是否圆形裁剪 true or false
|
|
|
+ .forResult(activityResultLauncher);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDelayCheckView getDelayCheckView(Context context) {
|
|
|
+ return new CustomDelayCheckView(context);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ AccompanyManager.getInstance().setLogDebugMode(com.cooleshow.base.BuildConfig.DEBUG);
|
|
|
+ setWebConfig();
|
|
|
+ AccompanyManager.getInstance().clearDelay();//清除延迟检测值
|
|
|
+ AccompanyManager.getInstance().setLoadingAnimRes(R.layout.accompany_loading_layout,R.drawable.icon_accompany_back);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setWebConfig(){
|
|
|
+ WebConfig webConfig = new WebConfig();
|
|
|
+ webConfig.setWeb_UA_params(WebConstants.getAccompanyUA());
|
|
|
+ webConfig.setWebJsInterfaceName(WebConstants.WEB_JS_INTERFACE);
|
|
|
+ webConfig.setCustomWebSocketUrl(WebConstants.getWebSocketUrl());
|
|
|
+ AccompanyManager.getInstance().setWebConfig(webConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void loginAccompany(String userId, String userToken) {
|
|
|
+ AccompanyManager.getInstance().login(userId, userToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void startAccompanyPage(Context context, String url) {
|
|
|
+ startAccompanyPage(context, url, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void startAccompanyPage(Context context, String url, int orientation) {
|
|
|
+ startAccompanyPage(context, url, orientation, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void startAccompanyPage(Context context, String url, int orientation, int c_orientation) {
|
|
|
+ AccompanyStartParams accompanyStartParams = new AccompanyStartParams();
|
|
|
+ accompanyStartParams.setUrl(url);
|
|
|
+ accompanyStartParams.setOrientation(orientation);
|
|
|
+ accompanyStartParams.setC_orientation(c_orientation);
|
|
|
+ accompanyStartParams.setHideTitle(true);
|
|
|
+ accompanyStartParams.setOpenLight(true);
|
|
|
+ //管理端和学校端可能存在切账号流程,所以每次进入之前重新设置下相关参数把
|
|
|
+ setWebConfig();
|
|
|
+ AccompanyManager.getInstance().startAccompany(context, accompanyStartParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 临时处理
|
|
|
+ * @param context
|
|
|
+ * @param url
|
|
|
+ * @param orientation
|
|
|
+ * @param c_orientation
|
|
|
+ */
|
|
|
+ public void startAccompanyPageByToken(Context context, String url, int orientation, int c_orientation){
|
|
|
+ boolean status = url.contains("?");
|
|
|
+ String userAuthorization = CacheHelper.getUserToken();
|
|
|
+ if (status) {
|
|
|
+ url = (url + "&Authorization=" + userAuthorization);
|
|
|
+ } else {
|
|
|
+ url = (url + "?Authorization=" + userAuthorization);
|
|
|
+ }
|
|
|
+ startAccompanyPage(context,url,orientation,c_orientation);
|
|
|
+ }
|
|
|
+}
|