Commit 739ad685 by amateur

1

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