|
@@ -0,0 +1,113 @@
|
|
|
|
|
+package com.webrain.happywork.ui.widget.dialog;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.Dialog;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.webkit.JavascriptInterface;
|
|
|
|
|
+import android.webkit.WebSettings;
|
|
|
|
|
+import android.webkit.WebView;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import com.webrain.happywork.BuildConfig;
|
|
|
|
|
+import com.webrain.happywork.R;
|
|
|
|
|
+import com.webrain.happywork.ui.base.BaseViewHolder;
|
|
|
|
|
+
|
|
|
|
|
+import butterknife.BindView;
|
|
|
|
|
+import io.reactivex.Observable;
|
|
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
|
+import io.reactivex.functions.Consumer;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+public class WebVerifyDialog {
|
|
|
|
|
+ private Context mContext;
|
|
|
|
|
+ private Dialog mDialog;
|
|
|
|
|
+ private ViewHolder mViewHolder;
|
|
|
|
|
+ private OnVerifyListener onVerifyListener;
|
|
|
|
|
+
|
|
|
|
|
+ public WebVerifyDialog(final Context mContext, String phone) {
|
|
|
|
|
+ this.mContext = mContext;
|
|
|
|
|
+ mViewHolder = new ViewHolder(mContext, phone);
|
|
|
|
|
+ mDialog = new Dialog(mContext, R.style.HappyJobDialog);
|
|
|
|
|
+ mDialog.setContentView(mViewHolder.getView());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void dismiss() {
|
|
|
|
|
+ if (mDialog != null && mDialog.isShowing())
|
|
|
|
|
+ mDialog.dismiss();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void show() {
|
|
|
|
|
+ if (mDialog != null && !mDialog.isShowing())
|
|
|
|
|
+ mDialog.show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void initData(String phone) {
|
|
|
|
|
+ mViewHolder.initData(phone);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setOnVerifyListener(OnVerifyListener onVerifyListener) {
|
|
|
|
|
+ this.onVerifyListener = onVerifyListener;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class ViewHolder extends BaseViewHolder {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @BindView(R.id.wv)
|
|
|
|
|
+ WebView wv;
|
|
|
|
|
+
|
|
|
|
|
+ public ViewHolder(Context mContext, String phone) {
|
|
|
|
|
+ super(mContext);
|
|
|
|
|
+ WebSettings webSetting = wv.getSettings();
|
|
|
|
|
+ webSetting.setJavaScriptEnabled(true);
|
|
|
|
|
+ webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
|
|
|
+ webSetting.setTextZoom(100);
|
|
|
|
|
+ webSetting.setAllowFileAccess(true);
|
|
|
|
|
+ webSetting.setUseWideViewPort(true);
|
|
|
|
|
+ webSetting.setLoadWithOverviewMode(true);
|
|
|
|
|
+ webSetting.setAppCacheEnabled(true);
|
|
|
|
|
+ webSetting.setDatabaseEnabled(true);
|
|
|
|
|
+ wv.addJavascriptInterface(new JavaScriptInterface(), "hap");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int bindViewLayoutId() {
|
|
|
|
|
+ return R.layout.dialog_web_verify;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void initData(String phone) {
|
|
|
|
|
+ wv.loadUrl(BuildConfig.VERIFY_URL + phone);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class JavaScriptInterface {
|
|
|
|
|
+ public JavaScriptInterface() {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 验证成功
|
|
|
|
|
+ */
|
|
|
|
|
+ @JavascriptInterface
|
|
|
|
|
+ public void verificationCode(final String code) {
|
|
|
|
|
+ Observable.just(code)
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread()) // 主线程更新UI
|
|
|
|
|
+ .subscribe(new Consumer<String>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void accept(String s) throws Exception {
|
|
|
|
|
+ if (onVerifyListener != null && code.equals("0"))
|
|
|
|
|
+ onVerifyListener.onSuccess();
|
|
|
|
|
+ dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public interface OnVerifyListener {
|
|
|
|
|
+ void onSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|