@@ -75,18 +75,23 @@ public ScriptBundle doInBackground(String... params) {
75
75
if (LuaScriptManager .existsScriptBundle (urlOrAssetPath )) {//读取并加载,之前的脚本
76
76
scriptBundle = AppCache .getCache (AppCache .CACHE_SCRIPTS ).getLru (urlOrAssetPath );
77
77
if (scriptBundle != null ) {
78
+
79
+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_CACHE , scriptBundle );
78
80
return scriptBundle ;
79
81
} else {
80
82
DebugUtil .tsi ("luaviewp-loadBundle" );
81
83
82
84
scriptBundle = ScriptBundleUnpackDelegate .loadBundle (LuaScriptManager .isLuaBytecodeUrl (urlOrAssetPath ), urlOrAssetPath , destFolderPath );//TODO 性能瓶颈
83
85
84
86
DebugUtil .tei ("luaviewp-loadBundle" );
87
+
88
+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_LOCAL , scriptBundle );
85
89
}
86
90
87
91
} else if (LuaScriptManager .existsPredownloadBundle (urlOrAssetPath )) {//预先加载的地址有脚本,则尝试解压并加载 xxx.zip
88
92
scriptBundle = AppCache .getCache (AppCache .CACHE_SCRIPTS ).getLru (urlOrAssetPath );
89
93
if (scriptBundle != null ) {
94
+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_CACHE , scriptBundle );
90
95
return scriptBundle ;
91
96
} else {
92
97
DebugUtil .tsi ("luaviewp-loadPredownloadBundle" );
@@ -96,18 +101,22 @@ public ScriptBundle doInBackground(String... params) {
96
101
scriptBundle = ScriptBundleUnpackDelegate .unpack (urlOrAssetPath , inputStream );
97
102
98
103
DebugUtil .tei ("luaviewp-loadPredownloadBundle" );
104
+
105
+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_PREDOWNLOAD , scriptBundle );
99
106
}
100
107
} else if (URLUtil .isAssetUrl (urlOrAssetPath ) && AssetUtil .exists (mContext , urlOrAssetPath )) {//asset file exists
101
108
if (LuaScriptManager .isLuaScriptZip (urlOrAssetPath )) {//asset下的包加载
102
109
scriptBundle = ScriptBundleUnpackDelegate .unpack (mContext , FileUtil .removePostfix (urlOrAssetPath ), urlOrAssetPath );
103
110
}
111
+
112
+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_ASSET , scriptBundle );
104
113
} else {//下载解压加载
105
114
106
115
// Assert 预置包
107
116
// loadAssertScriptBundle();
108
117
109
118
// 下载包
110
- callLoaderDownloadStart ( );
119
+ callLoaderCallbackOnEvent ( LuaScriptLoader . LuaScriptLoadEvent . EVENT_DOWNLOAD_START , null );
111
120
112
121
// download
113
122
ScriptBundleDownloadDelegate downloadDelegate = new ScriptBundleDownloadDelegate (urlOrAssetPath , sha256 );
@@ -123,7 +132,7 @@ public ScriptBundle doInBackground(String... params) {
123
132
}
124
133
125
134
//下载结束
126
- callLoaderDownloadEnd ( scriptBundle );
135
+ callLoaderCallbackOnEvent ( LuaScriptLoader . LuaScriptLoadEvent . EVENT_DOWNLOAD_END , scriptBundle );
127
136
}
128
137
129
138
scriptBundle = new ScriptBundleLoadDelegate ().load (mContext , scriptBundle );//解密脚本或者加载Prototype
@@ -216,22 +225,13 @@ protected void onPostExecute(ScriptBundle unzippedScripts) {
216
225
}
217
226
218
227
/**
219
- * 开始下载
220
- */
221
- private void callLoaderDownloadStart () {
222
- if (mScriptLoaderCallback instanceof LuaScriptLoader .ScriptLoaderCallback2 ) {
223
- ((LuaScriptLoader .ScriptLoaderCallback2 ) mScriptLoaderCallback ).onScriptDownloadStart ();
224
- }
225
- }
226
-
227
- /**
228
- * 下载结束
229
- *
230
- * @param bundle
228
+ * 事件回调
229
+ * @param event
230
+ * @param args
231
231
*/
232
- private void callLoaderDownloadEnd ( ScriptBundle bundle ) {
233
- if (mScriptLoaderCallback instanceof LuaScriptLoader .ScriptLoaderCallback2 ) {
234
- ((LuaScriptLoader .ScriptLoaderCallback2 ) mScriptLoaderCallback ).onScriptDownloadEnd ( bundle );
232
+ private void callLoaderCallbackOnEvent ( LuaScriptLoader . LuaScriptLoadEvent event , Object args ) {
233
+ if (mScriptLoaderCallback instanceof LuaScriptLoader .ScriptExecuteCallback2 ) {
234
+ ((LuaScriptLoader .ScriptExecuteCallback2 ) mScriptLoaderCallback ).onEvent ( event , args );
235
235
}
236
236
}
237
237
0 commit comments