ModuleUrlHandle.java
3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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.enums.ModulesEnum;
import com.polysoft.nafmii.utils.FileUtils;
import com.polysoft.nafmii.webview.IWebview;
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) {
if (null == this.moduleUrl) {
this.moduleUrl = new ModuleUrlImpl(module);
}
return this.moduleUrl;
}
public IModuleHandle getModuleHandle(MenuBean bean) {
if (null == this.moduleBean) {
this.moduleBean = new ModuleBeanImpl(bean);
}
return this.moduleBean;
}
public String getModuleUrl(ModulesEnum module) {
Intent intent = activity.getIntent();
String url = intent.getStringExtra(module.name);
if (!TextUtils.isEmpty(url)) {
return url;
}
if (module == ModulesEnum.LEARN) {
return Constants.MODULE_URL_LEARN;
}
String indexUrl = Uri.fromFile(FileUtils.getIndex()).toString();
return indexUrl + module.webUrl;
}
public interface IModuleHandle {
ModulesEnum getModule();
void loadUrl(IWebview webview);
}
static class ModuleBeanImpl implements IModuleHandle {
private final MenuBean bean;
ModuleBeanImpl(MenuBean bean) {
this.bean = bean;
}
@Override
public ModulesEnum getModule() {
return ModulesEnum.findModule(this.bean.getModuleName());
}
@Override
public void loadUrl(IWebview webview) {
if (!TextUtils.isEmpty(bean.getUrl())) {
webview.loadUrl(bean.getUrl());
} 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));
}
}
}
class ModuleUrlImpl implements IModuleHandle {
private final ModulesEnum module;
ModuleUrlImpl(ModulesEnum module) {
this.module = module;
}
@Override
public ModulesEnum getModule() {
return this.module;
}
@Override
public void loadUrl(IWebview webview) {
// Intent intent = activity.getIntent();
// String url = intent.getStringExtra(module.name);
}
}
}