@@ -75,18 +75,23 @@ public ScriptBundle doInBackground(String... params) {
7575 if (LuaScriptManager .existsScriptBundle (urlOrAssetPath )) {//读取并加载,之前的脚本
7676 scriptBundle = AppCache .getCache (AppCache .CACHE_SCRIPTS ).getLru (urlOrAssetPath );
7777 if (scriptBundle != null ) {
78+
79+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_CACHE , scriptBundle );
7880 return scriptBundle ;
7981 } else {
8082 DebugUtil .tsi ("luaviewp-loadBundle" );
8183
8284 scriptBundle = ScriptBundleUnpackDelegate .loadBundle (LuaScriptManager .isLuaBytecodeUrl (urlOrAssetPath ), urlOrAssetPath , destFolderPath );//TODO 性能瓶颈
8385
8486 DebugUtil .tei ("luaviewp-loadBundle" );
87+
88+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_LOCAL , scriptBundle );
8589 }
8690
8791 } else if (LuaScriptManager .existsPredownloadBundle (urlOrAssetPath )) {//预先加载的地址有脚本,则尝试解压并加载 xxx.zip
8892 scriptBundle = AppCache .getCache (AppCache .CACHE_SCRIPTS ).getLru (urlOrAssetPath );
8993 if (scriptBundle != null ) {
94+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_CACHE , scriptBundle );
9095 return scriptBundle ;
9196 } else {
9297 DebugUtil .tsi ("luaviewp-loadPredownloadBundle" );
@@ -96,18 +101,22 @@ public ScriptBundle doInBackground(String... params) {
96101 scriptBundle = ScriptBundleUnpackDelegate .unpack (urlOrAssetPath , inputStream );
97102
98103 DebugUtil .tei ("luaviewp-loadPredownloadBundle" );
104+
105+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_PREDOWNLOAD , scriptBundle );
99106 }
100107 } else if (URLUtil .isAssetUrl (urlOrAssetPath ) && AssetUtil .exists (mContext , urlOrAssetPath )) {//asset file exists
101108 if (LuaScriptManager .isLuaScriptZip (urlOrAssetPath )) {//asset下的包加载
102109 scriptBundle = ScriptBundleUnpackDelegate .unpack (mContext , FileUtil .removePostfix (urlOrAssetPath ), urlOrAssetPath );
103110 }
111+
112+ callLoaderCallbackOnEvent (LuaScriptLoader .LuaScriptLoadEvent .EVENT_LOAD_ASSET , scriptBundle );
104113 } else {//下载解压加载
105114
106115 // Assert 预置包
107116 // loadAssertScriptBundle();
108117
109118 // 下载包
110- callLoaderDownloadStart ( );
119+ callLoaderCallbackOnEvent ( LuaScriptLoader . LuaScriptLoadEvent . EVENT_DOWNLOAD_START , null );
111120
112121 // download
113122 ScriptBundleDownloadDelegate downloadDelegate = new ScriptBundleDownloadDelegate (urlOrAssetPath , sha256 );
@@ -123,7 +132,7 @@ public ScriptBundle doInBackground(String... params) {
123132 }
124133
125134 //下载结束
126- callLoaderDownloadEnd ( scriptBundle );
135+ callLoaderCallbackOnEvent ( LuaScriptLoader . LuaScriptLoadEvent . EVENT_DOWNLOAD_END , scriptBundle );
127136 }
128137
129138 scriptBundle = new ScriptBundleLoadDelegate ().load (mContext , scriptBundle );//解密脚本或者加载Prototype
@@ -216,22 +225,13 @@ protected void onPostExecute(ScriptBundle unzippedScripts) {
216225 }
217226
218227 /**
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
231231 */
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 );
235235 }
236236 }
237237
0 commit comments