|
|
@@ -1,17 +1,28 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebSettings;
|
|
|
import android.webkit.WebView;
|
|
|
import android.webkit.WebViewClient;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.kfzs.android.view.widget.SafeWebView;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
+import com.sheep.gamegroup.model.entity.AboutUsEntity;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.WebviewEntity;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
|
|
|
/**
|
|
|
* Created by ljy on 2018/4/16.
|
|
|
@@ -21,7 +32,9 @@ public class WebviewAct extends BaseActivity {
|
|
|
|
|
|
@BindView(R.id.activity_webview)
|
|
|
SafeWebView activityWebview;
|
|
|
- private String url;
|
|
|
+ @BindView(R.id.title_name_tv)
|
|
|
+ TextView title_name_tv;
|
|
|
+ private WebviewEntity webviewEntity;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
@@ -30,10 +43,14 @@ public class WebviewAct extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
+ webviewEntity = (WebviewEntity) getIntent().getSerializableExtra("webview_entity");
|
|
|
+ if(webviewEntity == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
TitleBarUtils.getInstance()
|
|
|
.setTitleFinish(this)
|
|
|
- .setTitle(this, "专属福利");
|
|
|
- url = getIntent().getStringExtra("url");
|
|
|
+ .setTitle(this,
|
|
|
+ TextUtils.isEmpty(webviewEntity.getTitle()) ?"专属福利":webviewEntity.getTitle());
|
|
|
|
|
|
WebSettings webSettings = activityWebview.getSettings();
|
|
|
|
|
|
@@ -47,13 +64,7 @@ public class WebviewAct extends BaseActivity {
|
|
|
webSettings.setDefaultTextEncodingName("utf-8");
|
|
|
// activityWebview.setWebChromeClient(new chromClient());
|
|
|
|
|
|
- if(TextUtils.isEmpty(url)){
|
|
|
-// activityWebview.loadUrl("file:///android_asset/sheep_show.html");
|
|
|
-
|
|
|
- }else {
|
|
|
- activityWebview.loadUrl(url);
|
|
|
|
|
|
- }
|
|
|
|
|
|
activityWebview.setWebViewClient(new WebViewClient() {
|
|
|
@Override
|
|
|
@@ -92,6 +103,52 @@ public class WebviewAct extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
+ //封装头文件
|
|
|
+ final String sHead= "<html><head><meta name=\"viewport\" content=\"width=device-width, " +
|
|
|
+ "initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" />"+
|
|
|
+ "<style>img{max-width:100% !important;height:auto !important;}</style>"
|
|
|
+ +"<style>body{max-width:100% !important;}</style>"+"</head><body>";
|
|
|
+ switch (webviewEntity.getType()){
|
|
|
+ case 0:
|
|
|
+ default:
|
|
|
+ title_name_tv.setVisibility(View.GONE);
|
|
|
+ activityWebview.loadUrl(webviewEntity.getUrl()+"");
|
|
|
+ break;
|
|
|
+ case 1://关于我们
|
|
|
+ showProgress(true);
|
|
|
+ SheepApp.get(this)
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .aboutUs()
|
|
|
+ .observeOn(Schedulers.io())
|
|
|
+ .subscribeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(this) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ G.showToast(baseMessage.getMsg() + "");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ AboutUsEntity aboutUsEntity = JSONObject.parseObject(JSONObject.toJSONString(baseMessage.getData()), AboutUsEntity.class);
|
|
|
+ if(aboutUsEntity != null){
|
|
|
+ title_name_tv.setVisibility(View.VISIBLE);
|
|
|
+ title_name_tv.setText(webviewEntity.getTitle()+"");
|
|
|
+ activityWebview.loadDataWithBaseURL(
|
|
|
+ null,
|
|
|
+ sHead + aboutUsEntity.getContent() + "</body></html>",
|
|
|
+ "text/html",
|
|
|
+ "utf-8",
|
|
|
+ null);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|