Skip to content

Commit f555b49

Browse files
authored
Merge pull request #27 from VideoOS/dev_2.7.0_dev_mode
Dev 2.7.0 dev mode
2 parents cd53ebf + 25b5c26 commit f555b49

39 files changed

+1278
-617
lines changed

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/LuaHelper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static void registerNativeLibs(@NonNull LuaView luaView, Platform platfo
7575
getMediaLifeCycleBinder(platform),
7676
getMqttBinder(),
7777
getSvgaBinder(),
78-
getWebViewBinder(),
78+
getWebViewBinder(platform),
7979
getActivityLifeCycleBinder(),
8080
getKeyboardBinder(),
8181
getMediaViewBinder(),
@@ -128,8 +128,10 @@ private static VenvyNativeBinder getNativeBinder(Platform platform, ViewGroup vi
128128
return target;
129129
}
130130

131-
private static VenvyWebViewBinder getWebViewBinder() {
132-
return venvyWebViewBinder == null ? venvyWebViewBinder = new VenvyWebViewBinder() : venvyWebViewBinder;
131+
private static VenvyWebViewBinder getWebViewBinder(Platform platform) {
132+
VenvyWebViewBinder target = venvyWebViewBinder == null ? venvyWebViewBinder = new VenvyWebViewBinder() : venvyWebViewBinder;
133+
target.setPlatform(platform);
134+
return target;
133135
}
134136

135137
private static VenvySvgaBinder getSvgaBinder() {

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/binder/VenvyLVLibBinder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import cn.com.venvy.lua.plugin.LVPreLoadPlugin;
2525
import cn.com.venvy.lua.plugin.LVRSAPlugin;
2626
import cn.com.venvy.lua.plugin.LVReportPlugin;
27+
import cn.com.venvy.lua.plugin.LVStatisticsPlugin;
2728
import cn.com.venvy.lua.plugin.LVTableToJsonPlugin;
2829
import cn.com.venvy.lua.plugin.LVUrlPlugin;
2930
import cn.com.venvy.lua.plugin.LVVideoPlugin;
@@ -69,6 +70,7 @@ void installPlugin(VenvyNativeBinder venvyNativeBinder) {
6970
LVPlayerPlugin.install(this, venvyNativeBinder.getPlatform());
7071
LVCallbackPlugin.install(this, venvyNativeBinder.getPlatform());
7172
LVPreLoadPlugin.install(this, venvyNativeBinder.getPlatform());
73+
LVStatisticsPlugin.install(this);
7274
}
7375

7476
@Override

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/binder/VenvyWebViewBinder.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.luaj.vm2.Varargs;
1010
import org.luaj.vm2.lib.LibFunction;
1111

12+
import cn.com.venvy.Platform;
1213
import cn.com.venvy.lua.maper.LVWebViewMethodMapper;
1314
import cn.com.venvy.lua.view.VenvyLVWebView;
1415

@@ -18,11 +19,16 @@
1819
*/
1920

2021
public class VenvyWebViewBinder extends BaseFunctionBinder {
22+
private Platform platform;
2123

2224
public VenvyWebViewBinder() {
2325
super("WebView");
2426
}
2527

28+
public void setPlatform(Platform platform) {
29+
this.platform = platform;
30+
}
31+
2632
@Override
2733
public Class<? extends LibFunction> getMapperClass() {
2834
return LVWebViewMethodMapper.class;
@@ -33,8 +39,8 @@ public LuaValue createCreator(LuaValue env, LuaValue metaTable) {
3339
return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) {
3440
@Override
3541
public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) {
36-
VenvyLVWebView venvyLVWebView = new VenvyLVWebView(globals, metaTable, varargs);
37-
venvyLVWebView.init(globals.getContext());
42+
VenvyLVWebView venvyLVWebView = new VenvyLVWebView(platform, globals, metaTable, varargs);
43+
venvyLVWebView.init(globals.getContext(),globals);
3844
return venvyLVWebView;
3945
}
4046
};

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/plugin/LVPreLoadPlugin.java

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
package cn.com.venvy.lua.plugin;
22

3+
import android.text.TextUtils;
4+
35
import com.taobao.luaview.util.LuaUtil;
46

57
import org.json.JSONArray;
68
import org.json.JSONObject;
9+
import org.luaj.vm2.LuaFunction;
710
import org.luaj.vm2.LuaTable;
811
import org.luaj.vm2.LuaValue;
912
import org.luaj.vm2.Varargs;
1013
import org.luaj.vm2.lib.VarArgFunction;
1114

15+
import java.util.ArrayList;
1216
import java.util.HashMap;
17+
import java.util.List;
1318
import java.util.Map;
1419

15-
import cn.com.venvy.Platform;
1620
import cn.com.venvy.App;
21+
import cn.com.venvy.Platform;
22+
import cn.com.venvy.PreloadLuaUpdate;
23+
import cn.com.venvy.common.bean.LuaFileInfo;
1724
import cn.com.venvy.common.download.DownloadDbHelper;
1825
import cn.com.venvy.lua.binder.VenvyLVLibBinder;
1926

@@ -28,7 +35,7 @@ public class LVPreLoadPlugin {
2835
public static void install(VenvyLVLibBinder venvyLVLibBinder, Platform platform) {
2936
venvyLVLibBinder.set("preloadImage", new PreLoadImageData(platform));
3037
venvyLVLibBinder.set("preloadVideo", new PreLoadVideoCacheData(platform));
31-
venvyLVLibBinder.set("preloadLuaList", new PreLoadLuaCacheData(platform));
38+
venvyLVLibBinder.set("preloadMiniAppLua", new PreLoadMiniAppLuaCacheData(platform));
3239
venvyLVLibBinder.set("isCacheVideo", sISVideoCachedData == null ? sISVideoCachedData = new ISVideoCachedData() : sISVideoCachedData);
3340
}
3441

@@ -86,10 +93,10 @@ public LuaValue invoke(Varargs args) {
8693
}
8794
}
8895

89-
private static class PreLoadLuaCacheData extends VarArgFunction {
96+
private static class PreLoadMiniAppLuaCacheData extends VarArgFunction {
9097
private Platform mPlatform;
9198

92-
PreLoadLuaCacheData(Platform platform) {
99+
PreLoadMiniAppLuaCacheData(Platform platform) {
93100
super();
94101
this.mPlatform = platform;
95102
}
@@ -99,16 +106,54 @@ public LuaValue invoke(Varargs args) {
99106
int fixIndex = VenvyLVLibBinder.fixIndex(args);
100107
if (args.narg() > fixIndex) {
101108
LuaTable table = LuaUtil.getTable(args, fixIndex + 1);
109+
final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 2);
102110
try {
103111
HashMap<String, String> paramsMap = LuaUtil.toMap(table);
104112
if (paramsMap == null || paramsMap.size() <= 0) {
105113
return LuaValue.NIL;
106114
}
107-
JSONArray proLoadArray=new JSONArray();
108-
for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
109-
proLoadArray.put(new JSONObject(entry.getValue().toString()));
115+
116+
JSONObject miniAppInfoObj = new JSONObject(paramsMap);
117+
if(miniAppInfoObj == null){
118+
return LuaValue.NIL;
110119
}
111-
mPlatform.preloadLuaList(mPlatform, proLoadArray);
120+
String miniAppId = miniAppInfoObj.optString("miniAppId");
121+
String luaListStr = miniAppInfoObj.optString("luaList");
122+
if(TextUtils.isEmpty(miniAppId) || TextUtils.isEmpty(luaListStr)){
123+
return LuaValue.NIL;
124+
}
125+
126+
JSONArray luaListArray = new JSONArray(luaListStr);
127+
if(luaListArray == null || luaListArray.length() <= 0){
128+
return LuaValue.NIL;
129+
}
130+
List<LuaFileInfo> luaFileInfoList = new ArrayList<>();
131+
LuaFileInfo luaFileInfo = new LuaFileInfo();
132+
luaFileInfo.setMiniAppId(miniAppId);
133+
List<LuaFileInfo.LuaListBean> luaList = luaArray2LuaList(luaListArray);
134+
135+
if (luaList == null || luaList.size() <= 0) {
136+
return LuaValue.NIL;
137+
}
138+
139+
luaFileInfo.setLuaList(luaList);
140+
luaFileInfoList.add(luaFileInfo);
141+
142+
mPlatform.preloadMiniAppLua(mPlatform, luaFileInfoList, new PreloadLuaUpdate.CacheLuaUpdateCallback() {
143+
@Override
144+
public void updateComplete(boolean isUpdateByNetWork) {
145+
if (callback != null && callback.isfunction()) {
146+
LuaUtil.callFunction(callback, LuaValue.valueOf(true));
147+
}
148+
}
149+
150+
@Override
151+
public void updateError(Throwable t) {
152+
if (callback != null && callback.isfunction()) {
153+
LuaUtil.callFunction(callback, LuaValue.valueOf(false));
154+
}
155+
}
156+
});
112157
} catch (Exception e) {
113158
e.printStackTrace();
114159
}
@@ -139,4 +184,32 @@ public LuaValue invoke(Varargs args) {
139184
return LuaValue.valueOf(info.status == DownloadDbHelper.DownloadStatus.DOWNLOAD_SUCCESS);
140185
}
141186
}
187+
188+
public static List<LuaFileInfo.LuaListBean> luaArray2LuaList(JSONArray luaArray) {
189+
if(luaArray == null || luaArray.length() <= 0){
190+
return null;
191+
}
192+
List<LuaFileInfo.LuaListBean> videoModeLuaList = new ArrayList<>();
193+
for (int j = 0; j < luaArray.length(); j++) {
194+
JSONObject luaFileObj = luaArray.optJSONObject(j);
195+
if(luaFileObj == null){
196+
break;
197+
}
198+
String luaName = luaFileObj.optString("name");
199+
String luaMD5 = luaFileObj.optString("md5");
200+
String luaUrl = luaFileObj.optString("url");
201+
String luaPath = luaFileObj.optString("path");
202+
if(TextUtils.isEmpty(luaMD5) || TextUtils.isEmpty(luaUrl)){
203+
break;
204+
}
205+
LuaFileInfo.LuaListBean luaListBean = new LuaFileInfo.LuaListBean();
206+
luaListBean.setLuaFileMd5(luaMD5);
207+
luaListBean.setLuaFileName(luaName);
208+
luaListBean.setLuaFilePath(luaPath);
209+
luaListBean.setLuaFileUrl(luaUrl);
210+
211+
videoModeLuaList.add(luaListBean);
212+
}
213+
return videoModeLuaList;
214+
}
142215
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cn.com.venvy.lua.plugin;
2+
3+
import com.taobao.luaview.util.LuaUtil;
4+
5+
import org.json.JSONObject;
6+
import org.luaj.vm2.LuaTable;
7+
import org.luaj.vm2.LuaValue;
8+
import org.luaj.vm2.Varargs;
9+
import org.luaj.vm2.lib.VarArgFunction;
10+
11+
import java.util.HashMap;
12+
13+
import cn.com.venvy.common.statistics.VenvyStatisticsManager;
14+
import cn.com.venvy.lua.binder.VenvyLVLibBinder;
15+
16+
/**
17+
* Created by videopls on 2019/11/12.
18+
*/
19+
20+
public class LVStatisticsPlugin {
21+
22+
private static CommonTrack commonTrack;
23+
public static void install(VenvyLVLibBinder venvyLVLibBinder) {
24+
venvyLVLibBinder.set("commonTrack", commonTrack == null ? commonTrack = new CommonTrack() : commonTrack);
25+
}
26+
27+
private static class CommonTrack extends VarArgFunction {
28+
@Override
29+
public Varargs invoke(Varargs args) {
30+
int fixIndex = VenvyLVLibBinder.fixIndex(args);
31+
Integer type = LuaUtil.getInt(args, fixIndex + 1);//事件类型
32+
LuaTable table = LuaUtil.getTable(args, fixIndex + 2);
33+
if(type == null || table == null){
34+
return LuaValue.NIL;
35+
}
36+
HashMap<String, String> miniAppMap = LuaUtil.toMap(table);
37+
if (miniAppMap == null) {
38+
return LuaValue.NIL;
39+
}
40+
JSONObject dataObj = new JSONObject(miniAppMap);
41+
if(dataObj != null){
42+
VenvyStatisticsManager.getInstance().submitCommonTrack(type,dataObj);
43+
}
44+
return LuaValue.NIL;
45+
}
46+
}
47+
}

VideoOS/LuaViewSDK/src/cn/com/venvy/lua/view/VenvyLVWebView.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44
import android.graphics.Bitmap;
55
import android.view.View;
66
import android.view.ViewGroup;
7+
import android.view.ViewParent;
78
import android.widget.FrameLayout;
89

910
import com.taobao.luaview.userdata.ui.UDView;
1011
import com.taobao.luaview.view.interfaces.ILVNativeViewProvider;
1112
import com.taobao.luaview.view.interfaces.ILVView;
1213

14+
import org.json.JSONObject;
1315
import org.luaj.vm2.Globals;
1416
import org.luaj.vm2.LuaValue;
1517
import org.luaj.vm2.Varargs;
1618

19+
import java.lang.reflect.Field;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
import cn.com.venvy.Platform;
1724
import cn.com.venvy.common.webview.IVenvyWebView;
1825
import cn.com.venvy.common.webview.IVenvyWebViewClient;
26+
import cn.com.venvy.common.webview.JsBridge;
27+
import cn.com.venvy.common.webview.VenvyWebView;
1928
import cn.com.venvy.common.webview.WebViewFactory;
2029
import cn.com.venvy.lua.ud.VenvyUDWebView;
30+
import cn.com.venvy.processor.annotation.VenvyAutoData;
2131

2232

2333
/**
@@ -28,15 +38,23 @@ public class VenvyLVWebView extends FrameLayout implements ILVNativeViewProvider
2838

2939
protected UDView mLuaUserdata;
3040
protected IVenvyWebView mWebView;
41+
protected JsBridge mJsBridge;
3142
protected boolean mIsLoading;
43+
protected Platform platform;
3244

33-
public VenvyLVWebView(Globals globals, LuaValue metaTable, Varargs varargs) {
45+
public VenvyLVWebView(Platform platform, Globals globals, LuaValue metaTable, Varargs varargs) {
3446
super(globals.getContext());
47+
this.platform = platform;
3548
this.mLuaUserdata = new VenvyUDWebView(this, globals, metaTable, varargs);
3649
}
3750

38-
public void init(Context context) {
51+
public void init(Context context, Globals globals) {
3952
this.mWebView = WebViewFactory.createWebView(context);
53+
mJsBridge = new JsBridge(context, mWebView, platform);
54+
mJsBridge.setDeveloperUserId(getDeveloperUserId(globals));
55+
if (mWebView instanceof VenvyWebView) {
56+
((VenvyWebView) mWebView).setJsBridge(mJsBridge);
57+
}
4058
if (mWebView instanceof View) {
4159
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
4260
((View) mWebView).setLayoutParams(params);
@@ -89,4 +107,44 @@ public View getNativeView() {
89107
public UDView getUserdata() {
90108
return mLuaUserdata;
91109
}
110+
111+
private Map getViewPriority(Globals globals) {
112+
try {
113+
ViewParent view = globals.container.getParent();
114+
if (view != null) {
115+
Field field = view.getClass().getDeclaredField("data");
116+
if (field != null && field.getAnnotation(VenvyAutoData.class) != null) {
117+
field.setAccessible(true);
118+
Object targetPriority = field.get(view);
119+
if (targetPriority != null && targetPriority instanceof Map) {
120+
return (Map) targetPriority;
121+
}
122+
}
123+
}
124+
} catch (Exception e) {
125+
//忽略此处异常
126+
}
127+
return new HashMap();
128+
}
129+
130+
/***
131+
* JS交互参数 获取开发者id
132+
* @param globals
133+
* @return
134+
*/
135+
private String getDeveloperUserId(Globals globals) {
136+
String developerUserId = null;
137+
Map<String, String> dataParams = getViewPriority(globals);
138+
if (dataParams != null || dataParams.size() <= 0) {
139+
return developerUserId;
140+
}
141+
try {
142+
JSONObject dataObj = new JSONObject(dataParams.get("data"));
143+
JSONObject miniAppInfoObj = dataObj.optJSONObject("miniAppInfo");
144+
developerUserId = miniAppInfoObj.optString("developerUserId");
145+
} catch (Exception e) {
146+
e.printStackTrace();
147+
}
148+
return developerUserId;
149+
}
92150
}

0 commit comments

Comments
 (0)