ModuleUrlHandle.java
3.61 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
110
111
112
113
114
115
116
117
118
package com.polysoft.nafmii.fragment.home;
import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
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.webview.IWebview;
import com.polysoft.nafmii.webview.JavaToJsinterface;
public class ModuleUrlHandle {
private final Activity activity;
ModuleUrlHandle(Activity activity) {
this.activity = activity;
}
public IModuleHandle getModuleHandle(ModulesEnum module) {
return new ModuleUrlImpl(module);
}
public IModuleHandle getModuleHandle(MenuBean bean) {
return new ModuleBeanImpl(bean);
}
public String getModuleUrl(ModulesEnum module) {
Intent intent = activity.getIntent();
String url = intent.getStringExtra(module.name);
if (!TextUtils.isEmpty(url)) {
return url;
}
if (module == ModulesEnum.HOME) {
return Constants.MODULE_URL_HOME;
} else if (module == ModulesEnum.LEARN) {
return Constants.MODULE_URL_LEARN;
}
return "";
}
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())) {
webview.getJsInterface().callJs(JSMethodsEnum.CALL_CHANGE_ROUTE, "");
} else if (!TextUtils.isEmpty(bean.getRoutePath())) {
webview.getJsInterface().callJs(JSMethodsEnum.CALL_CHANGE_ROUTE, "");
}
}
}
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);
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);
}
return;
}
if (module == ModulesEnum.HOME) {
webview.loadUrl(Constants.MODULE_URL_HOME);
} else if (ModulesEnum.LEARN == module) {
webview.loadUrl(Constants.MODULE_URL_LEARN);
} else if (ModulesEnum.MEMBER == module) {
webview.loadUrl(Constants.MODULE_URL_MEMBER);
} else if (ModulesEnum.MY == module) {
webview.loadUrl(Constants.MODULE_URL_MY);
}
}
}
}