Commit 2cd945e5 by amateur

添加底部菜单栏 动态隐藏显示

1 parent f4913a1b
...@@ -8,8 +8,8 @@ import androidx.fragment.app.Fragment; ...@@ -8,8 +8,8 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import com.polysoft.nafmii.R; import com.polysoft.nafmii.R;
import com.polysoft.nafmii.bean.MenuBean;
import com.polysoft.nafmii.enums.ModulesEnum; import com.polysoft.nafmii.enums.ModulesEnum;
import com.polysoft.nafmii.fragment.FingerprintDialogFragment;
import com.polysoft.nafmii.fragment.ModulesFragmentMgr; import com.polysoft.nafmii.fragment.ModulesFragmentMgr;
import java.util.HashMap; import java.util.HashMap;
...@@ -20,6 +20,7 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene ...@@ -20,6 +20,7 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene
private ModulesFragmentMgr modulesMgr; private ModulesFragmentMgr modulesMgr;
private HashMap<ModulesEnum, RadioButton> moduleViewsMap; private HashMap<ModulesEnum, RadioButton> moduleViewsMap;
private View footerView;
@Override @Override
public void onCoreInitFinished(boolean flag) { public void onCoreInitFinished(boolean flag) {
...@@ -29,7 +30,8 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene ...@@ -29,7 +30,8 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene
} }
private void initView() { private void initView() {
super.findViewById(R.id.home_footer_group).setVisibility(View.VISIBLE); this.footerView = super.findViewById(R.id.home_footer_group);
this.footerView.setVisibility(View.VISIBLE);
HashMap<ModulesEnum, RadioButton> modulesMap = new HashMap<>(); HashMap<ModulesEnum, RadioButton> modulesMap = new HashMap<>();
modulesMap.put(ModulesEnum.HOME, super.findViewById(R.id.home_btn_home)); modulesMap.put(ModulesEnum.HOME, super.findViewById(R.id.home_btn_home));
...@@ -88,6 +90,17 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene ...@@ -88,6 +90,17 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public void setModuleStatus(MenuBean bean) {
if (bean.isHide()) {
this.footerView.setVisibility(View.GONE);
} else if (bean.isShow()) {
this.footerView.setVisibility(View.VISIBLE);
} else if (bean.isChange()) {
this.modulesMgr.showModule(bean);
}
}
@Override @Override
public void changeModule(ModulesEnum module, Fragment fragment) { public void changeModule(ModulesEnum module, Fragment fragment) {
RadioButton moduleButton = this.moduleViewsMap.get(module); RadioButton moduleButton = this.moduleViewsMap.get(module);
......
...@@ -2,7 +2,7 @@ package com.polysoft.nafmii.bean; ...@@ -2,7 +2,7 @@ package com.polysoft.nafmii.bean;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
public class JsMenu { public class MenuBean {
public static final String SHOW = "1"; public static final String SHOW = "1";
public static final String HIDE = "2"; public static final String HIDE = "2";
...@@ -11,19 +11,18 @@ public class JsMenu { ...@@ -11,19 +11,18 @@ public class JsMenu {
@JSONField(name = "type") @JSONField(name = "type")
private String type; private String type;
@JSONField(name = "name") @JSONField(name = "moduleName")
private String name; private String moduleName;
@JSONField(name = "url") @JSONField(name = "url")
private String url; private String url;
public String getName() { @JSONField(name = "routePath")
return this.name; private String routePath;
}
@JSONField(name = "routeName")
private String routeName;
public String getUrl() {
return this.url;
}
public boolean isShow() { public boolean isShow() {
return SHOW.equals(this.type); return SHOW.equals(this.type);
...@@ -36,4 +35,40 @@ public class JsMenu { ...@@ -36,4 +35,40 @@ public class JsMenu {
public boolean isChange() { public boolean isChange() {
return CHANGE.equals(this.type); return CHANGE.equals(this.type);
} }
public String getUrl() {
return url;
}
public String getRouteName() {
return routeName;
}
public String getRoutePath() {
return routePath;
}
public String getModuleName() {
return moduleName;
}
public void setType(String type) {
this.type = type;
}
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public void setUrl(String url) {
this.url = url;
}
public void setRoutePath(String routePath) {
this.routePath = routePath;
}
public void setRouteName(String routeName) {
this.routeName = routeName;
}
} }
...@@ -3,7 +3,7 @@ package com.polysoft.nafmii.bean; ...@@ -3,7 +3,7 @@ package com.polysoft.nafmii.bean;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
public class JsResult { public class Result {
public static final String SUCCESS = "0"; public static final String SUCCESS = "0";
public static final String FAIL = "1"; public static final String FAIL = "1";
...@@ -18,33 +18,57 @@ public class JsResult { ...@@ -18,33 +18,57 @@ public class JsResult {
protected Object data; protected Object data;
private JsResult() { private Result() {
} }
public JsResult(String status, String statusText, Object data) { public Result(String status, String statusText, Object data) {
this.status = status; this.status = status;
this.statusText = statusText; this.statusText = statusText;
this.data = data; this.data = data;
} }
public String getStatus() {
return status;
}
public String getStatusText() {
return statusText;
}
public Object getData() {
return data;
}
public void setStatus(String status) {
this.status = status;
}
public void setStatusText(String statusText) {
this.statusText = statusText;
}
public void setData(Object data) {
this.data = data;
}
@Override @Override
public String toString() { public String toString() {
return JSON.toJSONString(this); return JSON.toJSONString(this);
} }
public static JsResult success(String statusText, Object data) { public static Result success(String statusText, Object data) {
return new JsResult(SUCCESS, statusText, data); return new Result(SUCCESS, statusText, data);
} }
public static JsResult success(Object data) { public static Result success(Object data) {
return success("success", data); return success("success", data);
} }
public static JsResult fail(String statusText, Object data) { public static Result fail(String statusText, Object data) {
return new JsResult(FAIL, statusText, data); return new Result(FAIL, statusText, data);
} }
public static JsResult fail(String statusText) { public static Result fail(String statusText) {
return fail(statusText, null); return fail(statusText, null);
} }
} }
...@@ -4,9 +4,9 @@ import android.content.Context; ...@@ -4,9 +4,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.polysoft.nafmii.wechat.ShareResult; import com.polysoft.nafmii.bean.Result;
public class ShareReceiver extends Receiver<ShareResult> { public class ShareReceiver extends Receiver<Result> {
public static final String ACTION = "com.polysoft.nafmii.action_share"; public static final String ACTION = "com.polysoft.nafmii.action_share";
...@@ -14,12 +14,12 @@ public class ShareReceiver extends Receiver<ShareResult> { ...@@ -14,12 +14,12 @@ public class ShareReceiver extends Receiver<ShareResult> {
super(context); super(context);
} }
public static Receiver<ShareResult> getInstance(Context context) { public static Receiver<Result> getInstance(Context context) {
Receiver<ShareResult> receiver = getReceiver(ShareReceiver.class); Receiver<Result> receiver = getReceiver(ShareReceiver.class);
return null != receiver ? receiver : new ShareReceiver(context.getApplicationContext()); return null != receiver ? receiver : new ShareReceiver(context.getApplicationContext());
} }
public static void sendBroadcast(Context context, ShareResult data) { public static void sendBroadcast(Context context, Result data) {
Intent intent = new Intent().setAction(ACTION); Intent intent = new Intent().setAction(ACTION);
intent.putExtra("data", JSON.toJSONString(data)); intent.putExtra("data", JSON.toJSONString(data));
onSendBroadcast(context, intent); onSendBroadcast(context, intent);
...@@ -31,10 +31,10 @@ public class ShareReceiver extends Receiver<ShareResult> { ...@@ -31,10 +31,10 @@ public class ShareReceiver extends Receiver<ShareResult> {
} }
@Override @Override
protected ShareResult onReceiverData(String action, Intent intent) { protected Result onReceiverData(String action, Intent intent) {
if (ACTION.equals(action)) { if (ACTION.equals(action)) {
String dataJson = intent.getStringExtra("data"); String dataJson = intent.getStringExtra("data");
return JSON.parseObject(dataJson, ShareResult.class); return JSON.parseObject(dataJson, Result.class);
} }
return null; return null;
} }
......
package com.polysoft.nafmii.fragment; package com.polysoft.nafmii.fragment;
import android.text.TextUtils;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import com.polysoft.nafmii.bean.MenuBean;
import com.polysoft.nafmii.enums.ModulesEnum; import com.polysoft.nafmii.enums.ModulesEnum;
import com.polysoft.nafmii.webview.IWebview;
import java.util.List; import java.util.List;
...@@ -29,18 +33,24 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis ...@@ -29,18 +33,24 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
this.addModuleFragment(modules[i]); this.addModuleFragment(modules[i]);
} }
Fragment fragment = this.manager.findFragmentByTag(modules[0].fmtKey); WebViewFragment fragment = this.findFragment(modules[0]);
FragmentTransaction transaction = this.manager.beginTransaction(); FragmentTransaction transaction = this.manager.beginTransaction();
transaction.show(fragment).commitNow(); transaction.show(fragment).commitNow();
this.setCurrentModule(modules[0]); this.setCurrentModule(modules[0]);
} }
public Fragment getCurrentFragment() { public WebViewFragment getCurrentFragment() {
String tag = this.currentModule.fmtKey; return this.findFragment(this.currentModule);
return this.manager.findFragmentByTag(tag);
} }
public boolean onBackStack() { public boolean onBackStack() {
WebViewFragment fragment = getCurrentFragment();
IWebview webview = fragment.getWebview();
if (null != webview && webview.canGoBack()) {
return false;
}
if (this.manager.getBackStackEntryCount() > 0) { if (this.manager.getBackStackEntryCount() > 0) {
this.manager.addOnBackStackChangedListener(this); this.manager.addOnBackStackChangedListener(this);
this.manager.popBackStack(); this.manager.popBackStack();
...@@ -50,28 +60,39 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis ...@@ -50,28 +60,39 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
} }
public void showModule(ModulesEnum module) { public void showModule(ModulesEnum module) {
if (module.name.equals(this.currentModule.name)) { if (!module.fmtKey.equals(this.currentModule.fmtKey)) {
return; WebViewFragment fragment = this.findFragment(module);
FragmentTransaction transaction = this.manager.beginTransaction();
transaction.hide(this.getCurrentFragment());
transaction.addToBackStack("").show(fragment).commit();
} }
this.setCurrentModule(module);
}
public void showModule(MenuBean bean) {
ModulesEnum module = ModulesEnum.findModule(bean.getModuleName());
Fragment fragment = this.findFragment(module); Fragment fragment = this.findFragment(module);
FragmentTransaction transaction = this.manager.beginTransaction(); if (!TextUtils.isEmpty(bean.getUrl())) {
((IWebview) fragment).loadUrl(bean.getUrl());
}
if (!module.fmtKey.equals(this.currentModule.fmtKey)) { if (!module.fmtKey.equals(this.currentModule.fmtKey)) {
FragmentTransaction transaction = this.manager.beginTransaction();
transaction.hide(this.getCurrentFragment()); transaction.hide(this.getCurrentFragment());
transaction.addToBackStack("").show(fragment).commit(); transaction.addToBackStack("").show(fragment).commit();
} }
this.setCurrentModule(module); this.setCurrentModule(module);
} }
public Fragment findFragment(ModulesEnum module) { public WebViewFragment findFragment(ModulesEnum module) {
Fragment fragment = this.manager.findFragmentByTag(module.fmtKey); WebViewFragment fragment = (WebViewFragment) this.manager.findFragmentByTag(module.fmtKey);
if (null == fragment) { if (null == fragment) {
return this.addModuleFragment(module); return this.addModuleFragment(module);
} }
return fragment; return fragment;
} }
private Fragment addModuleFragment(ModulesEnum module) { private WebViewFragment addModuleFragment(ModulesEnum module) {
Fragment fragment = this.manager.findFragmentByTag(module.fmtKey); WebViewFragment fragment = (WebViewFragment) this.manager.findFragmentByTag(module.fmtKey);
if (null == fragment) { if (null == fragment) {
FragmentTransaction transaction = this.manager.beginTransaction(); FragmentTransaction transaction = this.manager.beginTransaction();
fragment = WebViewFragment.newInstances(module.webUrl); fragment = WebViewFragment.newInstances(module.webUrl);
...@@ -101,7 +122,7 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis ...@@ -101,7 +122,7 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
} }
public static interface OnChangeModuleListener { public interface OnChangeModuleListener {
void changeModule(ModulesEnum module, Fragment fragment); void changeModule(ModulesEnum module, Fragment fragment);
} }
} }
...@@ -2,7 +2,6 @@ package com.polysoft.nafmii.fragment; ...@@ -2,7 +2,6 @@ package com.polysoft.nafmii.fragment;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -13,9 +12,9 @@ import androidx.annotation.Nullable; ...@@ -13,9 +12,9 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.polysoft.nafmii.R; import com.polysoft.nafmii.R;
import com.polysoft.nafmii.webview.JavaToJsinterface; import com.polysoft.nafmii.webview.IWebview;
import com.polysoft.nafmii.webview.JsToJavaInterface;
import com.polysoft.nafmii.webview.MyWebViewClient; import com.polysoft.nafmii.webview.MyWebViewClient;
import com.polysoft.nafmii.webview.WebviewHandler;
import com.polysoft.nafmii.webview.WebviewLoadListener; import com.polysoft.nafmii.webview.WebviewLoadListener;
import com.polysoft.nafmii.webview.X5WebviewUtils; import com.polysoft.nafmii.webview.X5WebviewUtils;
import com.tencent.smtt.sdk.WebView; import com.tencent.smtt.sdk.WebView;
...@@ -27,6 +26,8 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener { ...@@ -27,6 +26,8 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
private ViewGroup layout; private ViewGroup layout;
private WebView webView; private WebView webView;
private WebviewHandler webviewHandler;
public static WebViewFragment newInstances(String url) { public static WebViewFragment newInstances(String url) {
WebViewFragment fragment = new WebViewFragment(); WebViewFragment fragment = new WebViewFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
...@@ -40,17 +41,15 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener { ...@@ -40,17 +41,15 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
if (null == this.rootView) { super.setHasOptionsMenu(true);
this.rootView = inflater.inflate(R.layout.fragment_webview, container, false); return inflater.inflate(R.layout.fragment_webview, null, false);
}
return this.rootView;
} }
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
this.layout = view.findViewById(R.id.webview_layout); this.layout = view.findViewById(R.id.webview_layout);
this.initWebview(); this.initWebview();
} }
...@@ -58,8 +57,7 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener { ...@@ -58,8 +57,7 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
private void initWebview() { private void initWebview() {
WebView webView = X5WebviewUtils.create(getActivity()); WebView webView = X5WebviewUtils.create(getActivity());
webView.setWebViewClient(new MyWebViewClient(this)); webView.setWebViewClient(new MyWebViewClient(this));
JsToJavaInterface nativeApi = new JsToJavaInterface(getActivity(), new JavaToJsinterface(webView)); this.webviewHandler = new WebviewHandler(this, webView);
webView.addJavascriptInterface(nativeApi, "$NativeApi");
this.layout.removeAllViews(); this.layout.removeAllViews();
int match = ViewGroup.LayoutParams.MATCH_PARENT; int match = ViewGroup.LayoutParams.MATCH_PARENT;
...@@ -70,7 +68,10 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener { ...@@ -70,7 +68,10 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
Bundle bundle = getArguments(); Bundle bundle = getArguments();
String url = bundle.getString("url", ""); String url = bundle.getString("url", "");
this.webView.loadUrl(url); this.webView.loadUrl(url);
}
public IWebview getWebview() {
return this.webviewHandler;
} }
@Override @Override
......
...@@ -4,5 +4,8 @@ public interface IWebview { ...@@ -4,5 +4,8 @@ public interface IWebview {
void loadUrl(String url); void loadUrl(String url);
boolean onBack(); String getUrl();
boolean canGoBack();
} }
...@@ -4,7 +4,7 @@ import android.app.Activity; ...@@ -4,7 +4,7 @@ import android.app.Activity;
import android.text.TextUtils; import android.text.TextUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.polysoft.nafmii.bean.JsResult; import com.polysoft.nafmii.bean.Result;
public class JsInterfaceHandler { public class JsInterfaceHandler {
...@@ -25,7 +25,7 @@ public class JsInterfaceHandler { ...@@ -25,7 +25,7 @@ public class JsInterfaceHandler {
jsHandle.handle(data, new JsInterfaceImpl()); jsHandle.handle(data, new JsInterfaceImpl());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
this.sendMessage2Js(JsResult.fail("接口调用异常").toString()); this.sendMessage2Js(Result.fail("接口调用异常").toString());
} }
} }
...@@ -43,18 +43,18 @@ public class JsInterfaceHandler { ...@@ -43,18 +43,18 @@ public class JsInterfaceHandler {
class JsInterfaceImpl implements JsInterface { class JsInterfaceImpl implements JsInterface {
@Override @Override
public void callJs(JsResult result) { public void callJs(Result result) {
sendMessage2Js(result.toString()); sendMessage2Js(result.toString());
} }
@Override @Override
public void success(Object obj) { public void success(Object obj) {
this.callJs(JsResult.success(obj)); this.callJs(Result.success(obj));
} }
@Override @Override
public void fail(String statusText) { public void fail(String statusText) {
this.callJs(JsResult.fail(statusText)); this.callJs(Result.fail(statusText));
} }
} }
...@@ -64,7 +64,7 @@ public class JsInterfaceHandler { ...@@ -64,7 +64,7 @@ public class JsInterfaceHandler {
} }
public interface JsInterface { public interface JsInterface {
void callJs(JsResult result); void callJs(Result result);
void success(Object obj); void success(Object obj);
......
...@@ -10,13 +10,13 @@ import androidx.fragment.app.Fragment; ...@@ -10,13 +10,13 @@ import androidx.fragment.app.Fragment;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.TypeUtils; import com.alibaba.fastjson.util.TypeUtils;
import com.polysoft.nafmii.bean.JsResult; import com.polysoft.nafmii.bean.MenuBean;
import com.polysoft.nafmii.bean.Result;
import com.polysoft.nafmii.broadcast.Receiver; import com.polysoft.nafmii.broadcast.Receiver;
import com.polysoft.nafmii.broadcast.ShareReceiver; import com.polysoft.nafmii.broadcast.ShareReceiver;
import com.polysoft.nafmii.utils.CtxUtils; import com.polysoft.nafmii.utils.CtxUtils;
import com.polysoft.nafmii.utils.StatusBarUtils; import com.polysoft.nafmii.utils.StatusBarUtils;
import com.polysoft.nafmii.wechat.ShareBean; import com.polysoft.nafmii.wechat.ShareBean;
import com.polysoft.nafmii.wechat.ShareResult;
import com.polysoft.nafmii.wechat.WechatApi; import com.polysoft.nafmii.wechat.WechatApi;
import java.util.HashMap; import java.util.HashMap;
...@@ -26,15 +26,17 @@ public class JsToJavaInterface { ...@@ -26,15 +26,17 @@ public class JsToJavaInterface {
private final Activity mActivity; private final Activity mActivity;
private final JavaToJsinterface javaTojs; private final JavaToJsinterface javaTojs;
private Fragment mFragment; private Fragment mFragment;
WebviewHandler handler;
public JsToJavaInterface(Activity activity, JavaToJsinterface javaTojs) { public JsToJavaInterface(Activity activity, JavaToJsinterface javaTojs) {
this.mActivity = activity; this.mActivity = activity;
this.javaTojs = javaTojs; this.javaTojs = javaTojs;
} }
public JsToJavaInterface(Fragment fragment, JavaToJsinterface javaTojs) { public JsToJavaInterface(WebviewHandler handler, Fragment fragment, JavaToJsinterface javaTojs) {
this(fragment.getActivity(), javaTojs); this(fragment.getActivity(), javaTojs);
this.mFragment = fragment; this.mFragment = fragment;
this.handler = handler;
} }
@JavascriptInterface @JavascriptInterface
...@@ -52,7 +54,8 @@ public class JsToJavaInterface { ...@@ -52,7 +54,8 @@ public class JsToJavaInterface {
@JavascriptInterface @JavascriptInterface
public void nativeMenu(String params) { public void nativeMenu(String params) {
new JsInterfaceHandler(mActivity, javaTojs).parse(params, (data, js) -> { new JsInterfaceHandler(mActivity, javaTojs).parse(params, (data, js) -> {
MenuBean bean = TypeUtils.castToJavaBean(data, MenuBean.class);
mActivity.runOnUiThread(() -> handler.setButtomMenu(bean));
}); });
} }
...@@ -69,9 +72,9 @@ public class JsToJavaInterface { ...@@ -69,9 +72,9 @@ public class JsToJavaInterface {
new JsInterfaceHandler(mActivity, javaTojs).parse(params, (data, js) -> { new JsInterfaceHandler(mActivity, javaTojs).parse(params, (data, js) -> {
WechatApi instance = WechatApi.getInstance(mActivity); WechatApi instance = WechatApi.getInstance(mActivity);
if (!instance.isWXAppInstalled()) { if (!instance.isWXAppInstalled()) {
js.callJs(JsResult.fail("未安装应用")); js.callJs(Result.fail("未安装应用"));
} }
final Receiver<ShareResult> shareReceiver = ShareReceiver.getInstance(mActivity); final Receiver<Result> shareReceiver = ShareReceiver.getInstance(mActivity);
shareReceiver.addDefaultListener((action, share) -> { shareReceiver.addDefaultListener((action, share) -> {
js.callJs(share); js.callJs(share);
shareReceiver.addDefaultListener(null); shareReceiver.addDefaultListener(null);
......
package com.polysoft.nafmii.webview;
import androidx.fragment.app.Fragment;
import com.polysoft.nafmii.activity.HomeActivity;
import com.polysoft.nafmii.bean.MenuBean;
import com.tencent.smtt.sdk.WebView;
public class WebviewHandler implements IWebview{
private static final String TAG = WebviewHandler.class.getName();
private final Fragment fragment;
private final WebView webView;
private final JavaToJsinterface java2js;
private final JsToJavaInterface js2java;
private boolean backIntercept = false;
public WebviewHandler(Fragment fragment, WebView webView) {
this.fragment = fragment;
this.webView = webView;
this.java2js = new JavaToJsinterface(webView);
this.js2java = new JsToJavaInterface(this, fragment, this.java2js);
webView.addJavascriptInterface(this.js2java, "$NativeApi");
}
public void setButtomMenu(MenuBean bean) {
HomeActivity activity = (HomeActivity) this.fragment.getActivity();
activity.setModuleStatus(bean);
}
@Override
public boolean canGoBack() {
if (this.backIntercept) {
return true;
}
if (this.webView.canGoBack()) {
this.webView.goBack();
return true;
}
return false;
}
@Override
public void loadUrl(String url) {
this.webView.loadUrl(url);
}
@Override
public String getUrl() {
return this.webView.getUrl();
}
}
...@@ -2,26 +2,22 @@ package com.polysoft.nafmii.wechat; ...@@ -2,26 +2,22 @@ package com.polysoft.nafmii.wechat;
import android.text.TextUtils; import android.text.TextUtils;
import com.polysoft.nafmii.bean.JsResult; import com.polysoft.nafmii.bean.Result;
public class ShareResult extends JsResult{ public class ShareResult {
public static final String CANCEL = "-2"; public static final String CANCEL = "-2";
public ShareResult(String status, String statusText, Object data) { public static Result shareSuccess() {
super(status, statusText, data); return Result.success("分享成功", null);
} }
public static JsResult shareSuccess() { public static Result shareFail(String text) {
return JsResult.success("分享成功", null);
}
public static JsResult shareFail(String text) {
String statusText = TextUtils.isEmpty(text) ? text : "分享失败"; String statusText = TextUtils.isEmpty(text) ? text : "分享失败";
return JsResult.fail(statusText); return Result.fail(statusText);
} }
public static JsResult shareCancel() { public static Result shareCancel() {
return new JsResult(CANCEL, "分享取消", null); return new Result(CANCEL, "分享取消", null);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!