diff --git a/common/src/main/java/com/yunbao/common/views/weight/OnClickShakeListener.java b/common/src/main/java/com/yunbao/common/views/weight/OnClickShakeListener.java new file mode 100644 index 000000000..64223dcbe --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/weight/OnClickShakeListener.java @@ -0,0 +1,35 @@ +package com.yunbao.common.views.weight; + +import android.view.View; + +import com.jakewharton.rxbinding3.view.RxView; + +import java.util.concurrent.TimeUnit; + +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; +import kotlin.Unit; + +/** + * View防抖 + */ +public class OnClickShakeListener implements View.OnClickListener{ + + + private long mDuration=800; + private View.OnClickListener mListener; + private long lastTime=0; + public OnClickShakeListener(View.OnClickListener listener){ + mListener=listener; + } + + @Override + public void onClick(View v) { + if (System.currentTimeMillis()-lastTime { + showStartDialog(); + }); MobclickAgent.onEvent(mContext, "broadcast", "开播按钮"); -// ViewClicksAntiShake.clicksAntiShake(v, () -> { -// -// }); + if (isFrist){ + isFrist=false; + v.callOnClick(); + } } else if (i == R.id.btn_search) { SearchActivity.forward(mContext); @@ -901,32 +914,46 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //RandomPkDialogFragment fragment = new RandomPkDialogFragment(); //fragment.show(this.getSupportFragmentManager(), "RandomPkDialogFragment"); } - - } + + private void startStartDialog(){ + if(!IMLoginManager.get(mContext).getUserInfo().anchorUserType()){ + ToastUtil.show(getString(R.string.only_open_anchor)); + }else { + if (isWifiProxy(mContext) || checkVPN((ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE))) { + ToastUtil.show(WordUtil.isNewZh() ? "檢測開啓了VPN或者代理,請先關閉VPN或者代理再開播。" : + "It is detected that VPN or proxy is turned on. Please turn off VPN or proxy before starting the broadcast."); + DebugUtils.runDebugCode(() -> onLiveClick()); + } else { + onLiveClick(); + } + } + } + + private void showStartDialog() { if (isReady == true) { - MainStartDialogFragment dialogFragment = new MainStartDialogFragment(); - dialogFragment.setMainStartChooseCallback(true, this); - dialogFragment.show(getSupportFragmentManager(), "MainStartDialogFragment"); + startStartDialog(); + Log.i(TAG,"connectIM isReady"); } else { connectIM(AppManager.getInstance().getMainActivity(), new RongIMClient.ConnectCallback() { @Override public void onSuccess(String t) { - MainStartDialogFragment dialogFragment = new MainStartDialogFragment(); - dialogFragment.setMainStartChooseCallback(true, MainActivity.this); - dialogFragment.show(getSupportFragmentManager(), "MainStartDialogFragment"); + startStartDialog(); + Log.i(TAG,"connectIM onSuccess"); } @Override public void onError(RongIMClient.ConnectionErrorCode e) { ToastUtil.show(R.string.net_error + "" + e.toString()); + Log.i(TAG,"connectIM onError"); } @Override public void onDatabaseOpened(RongIMClient.DatabaseOpenStatus code) { ToastUtil.show(R.string.net_error + "" + code); + Log.i(TAG,"connectIM onDatabaseOpened"); } }); } @@ -1706,4 +1733,168 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene } }); } + + + + + //这些是开播的逻辑 + private boolean isWifiProxy(Context context) { + final boolean IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; + String proxyAddress; + int proxyPort; + if (IS_ICS_OR_LATER) { + proxyAddress = System.getProperty("http.proxyHost"); + String portStr = System.getProperty("http.proxyPort"); + proxyPort = Integer.parseInt((portStr != null ? portStr : "-1")); + } else { + proxyAddress = android.net.Proxy.getHost(context); + proxyPort = android.net.Proxy.getPort(context); + } + return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -1); + } + + private boolean checkVPN(ConnectivityManager connMgr) { + //don't know why always returns null: + NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_VPN); + boolean isVpnConn = networkInfo == null ? false : networkInfo.isConnected(); + return isVpnConn; + } + + + + + + + private HttpCallback mGetLiveSdkCallback; + public void onLiveClick() { + boolean isAnchor = IMLoginManager.get(mContext).getUserInfo().anchorUserType(); + if (isAnchor) { + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + permissions = new String[]{ + Manifest.permission.CAMERA, + Manifest.permission.RECORD_AUDIO + }; + } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{ + //Manifest.permission.READ_MEDIA_IMAGES, 去掉选择图片的权限,到里面选择封面的时候再去申请 + Manifest.permission.CAMERA, + Manifest.permission.RECORD_AUDIO + }; + } else { + permissions = new String[]{ + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.CAMERA, + Manifest.permission.RECORD_AUDIO + }; + } + mProcessResultUtil.requestPermissions(permissions, mStartLiveRunnable); + } else { + ToastUtil.show(getString(R.string.only_open_anchor)); + } + } + + + private Runnable mStartLiveRunnable = new Runnable() { + @Override + public void run() { + if (CommonAppConfig.LIVE_SDK_CHANGED) { + if (mGetLiveSdkCallback == null) { + mGetLiveSdkCallback = new HttpCallback() { + @Override + public void onSuccess(int code, String msg, final String[] info) { + if (code == 0 && info.length > 0) { + LiveHttpUtil.getisRong(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info1) { + try { + LiveHttpUtil.getIsSw(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] infos) { + JSONObject obj = JSON.parseObject(info[0]); + JSONObject obj1 = JSON.parseObject(info1[0]); + try { + if (code == 201) { //声网 + LiveSwAnchorActivity.forward(mContext, Constants.LIVE_SDK_SW, JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); + } else if (code == 200) {//融云 + LiveRyAnchorActivity.forward(mContext, obj.getIntValue("live_sdk"), JSON.parseObject(obj.getString("android"), LiveKsyConfigBean.class)); + } + } catch (Exception e) { + + } + } + }); + } catch (Exception e) { + + } + } + }); + } + } + }; + } + if (!CommonAppConfig.IS_PLUGIN_MODEL || PluginManager.getInstance().isDownloadApk()) { + PluginManager.getInstance().loadAnchorPlugin(it -> { + LiveHttpUtil.getLiveSdk(mGetLiveSdkCallback); + }); + } else { + String tips = "需要下載開播插件,是否下載"; + if (!WordUtil.isNewZh()) { + tips = "You need to download the plug-in, whether to download"; + } + DialogUitl.showSimpleDialog(mContext, tips, new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + Dialog downloadDialog = DialogUitl.loadingDialog(mContext, "Downloading..."); + downloadDialog.show(); + PluginManager.getInstance().loadAnchorPlugin(it -> { + LiveHttpUtil.getLiveSdk(mGetLiveSdkCallback); + downloadDialog.dismiss(); + }); + } + }); + } + } else { + LiveAnchorActivity.forward(mContext, CommonAppConfig.LIVE_SDK_USED, LiveConfig.getDefaultKsyConfig()); + } + } + }; + + private MainStartChooseCallback mMainStartChooseCallback = new MainStartChooseCallback() { + @Override + public void onLiveClick() { + boolean isAnchor = IMLoginManager.get(mContext).getUserInfo().anchorUserType(); + if (isAnchor) { + String[] permissions; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + permissions = new String[]{ + Manifest.permission.CAMERA, + Manifest.permission.RECORD_AUDIO + }; + } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU) { + permissions = new String[]{ + //Manifest.permission.READ_MEDIA_IMAGES, 去掉选择图片的权限,到里面选择封面的时候再去申请 + Manifest.permission.CAMERA, + Manifest.permission.RECORD_AUDIO + }; + } else { + permissions = new String[]{ + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.CAMERA, + Manifest.permission.RECORD_AUDIO + }; + } + mProcessResultUtil.requestPermissions(permissions, mStartLiveRunnable); + } else { + ToastUtil.show(getString(R.string.only_open_anchor)); + } + } + + @Override + public void onVideoClick() { + // + } + }; }