Skip to content

Commit 9a7cf0b

Browse files
author
lucas
committed
支持jsTitle设置
1 parent 01276c6 commit 9a7cf0b

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

VideoOS/VenvyLibrary/src/main/java/cn/com/venvy/common/webview/JsBridge.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ public void setJsData(String jsData) {
7373
this.mJsData = jsData;
7474
}
7575

76-
public void setJsData(String jsData, String jsTitle) {
77-
this.mJsData = jsData;
76+
public void setJsTitle(String jsTitle){
7877
this.mJsTitle = jsTitle;
7978
}
8079

VideoOS/venvy_pub/src/main/java/cn/com/videopls/pub/VideoProgramTypeBView.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public class VideoProgramTypeBView extends FrameLayout implements VenvyObserver
5050
*/
5151
private HashMap<String, VideoWebToolBarView> h5ProgramMap = new HashMap<>();
5252

53+
// 当前最近启动的容器。为互斥关系,当一方有实例的时候,另一方为null
5354
private VideoProgramToolBarView currentProgram;
54-
5555
private VideoWebToolBarView currentH5Program;
5656

5757
private FrameLayout programContent;
@@ -60,7 +60,6 @@ public class VideoProgramTypeBView extends FrameLayout implements VenvyObserver
6060
private VideoPlusAdapter mAdapter;
6161

6262
private String currentProgramId;
63-
6463
private String currentH5ProgramId;
6564

6665
public VideoProgramTypeBView(@NonNull Context context) {
@@ -152,9 +151,11 @@ public void start(@NonNull String appletId, String data, int orientationType, bo
152151
VideoWebToolBarView h5View = h5ProgramMap.get(appletId);
153152
h5View.reload(appletId);
154153
currentH5Program = h5View;
154+
currentProgram = null;
155155
return;
156156
}
157157
currentH5Program = createH5Program();
158+
currentProgram = null;
158159
if (mAdapter != null) {
159160
currentH5Program.setAdapter(mAdapter);
160161
}
@@ -173,10 +174,12 @@ public void start(@NonNull String appletId, String data, int orientationType, bo
173174
existView.notifyLua(data);
174175
existView.refreshHistory(appletId);
175176
currentProgram = existView;
177+
currentH5Program = null;
176178
return;
177179
}
178180

179181
currentProgram = createProgram(orientationType);
182+
currentH5Program = null;
180183
if (mAdapter != null) {
181184
currentProgram.setVideoOSAdapter(mAdapter);
182185
}
@@ -281,6 +284,10 @@ public void setCurrentProgramTitle(String title) {
281284
if (currentProgram != null) {
282285
currentProgram.setTitle(title);
283286
}
287+
288+
if(currentH5Program != null){
289+
currentH5Program.setTitle(title);
290+
}
284291
}
285292

286293

VideoOS/venvy_pub/src/main/java/cn/com/videopls/pub/VideoWebToolBarView.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class VideoWebToolBarView extends BaseVideoVisionView {
4242

4343
private VideoPlusH5Controller controller;
4444

45+
private JsBridge jsBridge;
46+
4547
public VideoWebToolBarView(Context context) {
4648
super(context);
4749
init();
@@ -110,12 +112,12 @@ public void showErrorPage(final String showErrorPage) {
110112
public void run() {
111113
errorContent.setVisibility(VISIBLE);
112114
String message = "";
113-
if(TextUtils.isEmpty(showErrorPage)){
115+
if (TextUtils.isEmpty(showErrorPage)) {
114116
message = getContext().getString(
115117
VenvyResourceUtil.getStringId(getContext(), "errorDesc"));
116-
}else{
118+
} else {
117119
try {
118-
message = new JSONObject(showErrorPage).getString("message");
120+
message = new JSONObject(showErrorPage).getString("message");
119121
} catch (JSONException e) {
120122
e.printStackTrace();
121123
}
@@ -226,6 +228,12 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
226228
addView(webView);
227229
}
228230

231+
public void setTitle(final String title) {
232+
tvTitle.setText(title);
233+
if (jsBridge != null) {
234+
jsBridge.setJsTitle(title);
235+
}
236+
}
229237

230238
public void fetchTargetUrl(String appletId, String data) {
231239
this.appletId = appletId;
@@ -235,13 +243,15 @@ public void fetchTargetUrl(String appletId, String data) {
235243
controller.startH5Program(appletId);
236244
freshProgram(appletId);
237245

238-
JsBridge jsBridge = new JsBridge(getContext(), webView, controller.getPlatform());
246+
if (jsBridge == null) {
247+
jsBridge = new JsBridge(getContext(), webView, controller.getPlatform());
248+
}
239249
jsBridge.setJsData(data);
240250
webView.setJsBridge(jsBridge);
241251
}
242252

243253

244-
public void freshProgram(String appletId){
254+
public void freshProgram(String appletId) {
245255
controller.refreshRecentHistory(appletId);
246256
}
247257

@@ -253,7 +263,7 @@ public void openLink(final String url) {
253263
cancelLoadingAnimation();
254264
}
255265

256-
public void reload(String appletId){
266+
public void reload(String appletId) {
257267
webView.reload();
258268
freshProgram(appletId);
259269
}

0 commit comments

Comments
 (0)