Commit 739ad685 by amateur

1

1 parent 73f4f731
......@@ -2,30 +2,41 @@ package com.polysoft.nafmii.fragment.home;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import com.alibaba.fastjson.JSON;
import com.polysoft.nafmii.bean.MenuBean;
import com.polysoft.nafmii.constants.Constants;
import com.polysoft.nafmii.constants.JsApi;
import com.polysoft.nafmii.enums.JSMethodsEnum;
import com.polysoft.nafmii.enums.ModulesEnum;
import com.polysoft.nafmii.utils.FileUtils;
import com.polysoft.nafmii.webview.IWebview;
import com.polysoft.nafmii.webview.JavaToJsinterface;
import com.polysoft.nafmii.webview.JSApi;
import java.util.HashMap;
import java.util.Map;
public class ModuleUrlHandle {
private final Activity activity;
private IModuleHandle moduleUrl, moduleBean;
ModuleUrlHandle(Activity activity) {
this.activity = activity;
}
public IModuleHandle getModuleHandle(ModulesEnum module) {
return new ModuleUrlImpl(module);
if (null == this.moduleUrl) {
this.moduleUrl = new ModuleUrlImpl(module);
}
return this.moduleUrl;
}
public IModuleHandle getModuleHandle(MenuBean bean) {
return new ModuleBeanImpl(bean);
if (null == this.moduleBean) {
this.moduleBean = new ModuleBeanImpl(bean);
}
return this.moduleBean;
}
public String getModuleUrl(ModulesEnum module) {
......@@ -34,13 +45,11 @@ public class ModuleUrlHandle {
if (!TextUtils.isEmpty(url)) {
return url;
}
if (module == ModulesEnum.HOME) {
return Constants.MODULE_URL_HOME;
} else if (module == ModulesEnum.LEARN) {
if (module == ModulesEnum.LEARN) {
return Constants.MODULE_URL_LEARN;
}
return "";
String indexUrl = Uri.fromFile(FileUtils.getIndex()).toString();
return indexUrl + module.webUrl;
}
public interface IModuleHandle {
......@@ -50,6 +59,7 @@ public class ModuleUrlHandle {
void loadUrl(IWebview webview);
}
static class ModuleBeanImpl implements IModuleHandle {
private final MenuBean bean;
......@@ -66,10 +76,12 @@ public class ModuleUrlHandle {
public void loadUrl(IWebview webview) {
if (!TextUtils.isEmpty(bean.getUrl())) {
webview.loadUrl(bean.getUrl());
} else if (!TextUtils.isEmpty(bean.getRouteName())) {
webview.getJsInterface().callJs(JSMethodsEnum.CALL_CHANGE_ROUTE, "");
} else if (!TextUtils.isEmpty(bean.getRoutePath())) {
webview.getJsInterface().callJs(JSMethodsEnum.CALL_CHANGE_ROUTE, "");
} else if (!TextUtils.isEmpty(bean.getRouteName())
|| !TextUtils.isEmpty(bean.getRoutePath())) {
Map<String, String> map = new HashMap<>(2);
map.put("routePath", bean.getRoutePath());
map.put("routeName", bean.getRouteName());
JSApi.callOnRouteChange(webview.getWebview(), JSON.toJSONString(map));
}
}
}
......@@ -91,11 +103,8 @@ public class ModuleUrlHandle {
Intent intent = activity.getIntent();
String url = intent.getStringExtra(module.name);
if (!TextUtils.isEmpty(url)) {
JavaToJsinterface jsInterface = webview.getJsInterface();
if (module == ModulesEnum.MEMBER) {
webview.getJsInterface().callJs(JSMethodsEnum.CALL_CHANGE_ROUTE, "");
} else if (module == ModulesEnum.MY) {
webview.getJsInterface().callJs(JSMethodsEnum.CALL_CHANGE_ROUTE, "");
} else {
webview.loadUrl(url);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!