11package cn .com .venvy .lua .plugin ;
22
3+ import android .text .TextUtils ;
4+
35import com .taobao .luaview .util .LuaUtil ;
46
7+ import org .luaj .vm2 .LuaTable ;
58import org .luaj .vm2 .LuaValue ;
69import org .luaj .vm2 .Varargs ;
710import org .luaj .vm2 .lib .VarArgFunction ;
811
12+ import java .util .Map ;
13+
914import cn .com .venvy .Platform ;
1015import cn .com .venvy .common .bean .WidgetInfo ;
1116import cn .com .venvy .lua .binder .VenvyLVLibBinder ;
@@ -20,6 +25,7 @@ public class LVCallbackPlugin {
2025
2126 public static void install (VenvyLVLibBinder venvyLVLibBinder , Platform platform ) {
2227 venvyLVLibBinder .set ("widgetEvent" , new WidgetDelegate (platform ));
28+ venvyLVLibBinder .set ("widgetNotify" , new WidgetTableDelegate (platform ));
2329 }
2430
2531 private static class WidgetDelegate extends VarArgFunction {
@@ -88,4 +94,80 @@ public LuaValue invoke(Varargs args) {
8894 return LuaValue .NIL ;
8995 }
9096 }
97+
98+ private static class WidgetTableDelegate extends VarArgFunction {
99+ private Platform mPlatform ;
100+
101+ WidgetTableDelegate (Platform platform ) {
102+ super ();
103+ this .mPlatform = platform ;
104+ }
105+
106+ @ Override
107+ public LuaValue invoke (Varargs args ) {
108+ int fixIndex = VenvyLVLibBinder .fixIndex (args );
109+ LuaTable table = LuaUtil .getTable (args , fixIndex + 1 );
110+ Map <String , String > map = LuaUtil .toMap (table );
111+ if (map == null || map .size () <= 0 ) {
112+ return LuaValue .NIL ;
113+ }
114+ String eventType = map .get ("eventType" );
115+ String adID = map .get ("adID" );
116+ String adName = map .get ("adName" );
117+ String actionType = map .get ("actionType" );
118+ String actionString = map .get ("actionString" );
119+ String linkUrl = map .get ("linkUrl" );
120+ String deepLink = map .get ("deepLink" );
121+ String selfLink = map .get ("selfLink" );
122+ WidgetInfo .WidgetActionType widgetActionType = WidgetInfo .WidgetActionType .findTypeById (!TextUtils .isEmpty (actionType ) ? Integer .valueOf (actionType ) : 0 );
123+ if (TextUtils .isEmpty (eventType )) {
124+ return LuaValue .NIL ;
125+ }
126+ if (mPlatform == null ) {
127+ return LuaValue .NIL ;
128+ }
129+
130+ WidgetInfo widgetInfo = new WidgetInfo .Builder ()
131+ .setAdId (adID )
132+ .setWidgetActionType (widgetActionType )
133+ .setUrl (actionString )
134+ .setWidgetName (adName )
135+ .setDeepLink (deepLink )
136+ .setLinkUrl (linkUrl )
137+ .setSelfLink (selfLink )
138+ .build ();
139+ switch (Integer .valueOf (eventType )) {
140+ case 1 :
141+ if (mPlatform .getPrepareShowListener () != null && adID != null ) {
142+ mPlatform .getPrepareShowListener ().prepareShow (widgetInfo );
143+ }
144+ break ;
145+
146+ case 2 :
147+ if (mPlatform .getWidgetShowListener () != null && adID != null ) {
148+ mPlatform .getWidgetShowListener ().onShow (widgetInfo );
149+ }
150+
151+ break ;
152+
153+ case 3 :
154+ if (mPlatform .getWidgetClickListener () != null && adID != null ) {
155+ mPlatform .getWidgetClickListener ().onClick (widgetInfo );
156+ }
157+ break ;
158+
159+ case 4 :
160+ if (mPlatform .getWidgetCloseListener () != null && adID != null ) {
161+ mPlatform .getWidgetCloseListener ().onClose (widgetInfo );
162+ }
163+ break ;
164+ case 5 :
165+ if (mPlatform .getWedgeListener () != null && adID != null ) {
166+ mPlatform .getWedgeListener ().goBack ();
167+ }
168+ break ;
169+ }
170+ return LuaValue .NIL ;
171+ }
172+ }
91173}
0 commit comments