|
@@ -1,164 +0,0 @@
|
|
|
-package com.cooleshow.student.ui.web;
|
|
|
-
|
|
|
-import static com.cooleshow.base.common.WebConstants.WEB_URL;
|
|
|
-
|
|
|
-import android.content.Intent;
|
|
|
-import android.view.KeyEvent;
|
|
|
-import android.view.View;
|
|
|
-import android.webkit.WebView;
|
|
|
-import android.widget.LinearLayout;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.cooleshow.base.common.WebConstants;
|
|
|
-import com.cooleshow.usercenter.ui.activity.BaseMVPActivity;
|
|
|
-import com.cooleshow.base.widgets.AgentWebClient;
|
|
|
-import com.cooleshow.student.databinding.ActivityAgentWebBinding;
|
|
|
-import com.cooleshow.student.presenter.web.AgentWebPresenter;
|
|
|
-import com.cooleshow.student.widgets.helper.JsInterfaceHelper;
|
|
|
-import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
-import com.just.agentweb.AgentWeb;
|
|
|
-import com.just.agentweb.WebChromeClient;
|
|
|
-
|
|
|
-import org.json.JSONObject;
|
|
|
-
|
|
|
-/**
|
|
|
- * 创建日期:2022/6/5 13:32
|
|
|
- *
|
|
|
- * @author Ryan
|
|
|
- * 类说明:
|
|
|
- */
|
|
|
-public class AgentWebActivity extends BaseMVPActivity<ActivityAgentWebBinding, AgentWebPresenter> implements JsInterfaceHelper.OnJsMethodCallListener {
|
|
|
- private static final int REQUEST_CODE_FILE_CHOOSER = 500;
|
|
|
- private AgentWeb mAgentWeb;
|
|
|
- private LinearLayout container;
|
|
|
- private TextView tv_title;
|
|
|
- private AgentWebClient mWebClient;
|
|
|
- private JsInterfaceHelper mInterfaceUtils;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void initView() {
|
|
|
- initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "酷乐秀");
|
|
|
- container = viewBinding.container;
|
|
|
- tv_title = viewBinding.toolbarInclude.title;
|
|
|
- viewBinding.toolbarInclude.ivBack.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- goBack();
|
|
|
- }
|
|
|
- });
|
|
|
- String linkurl = getIntent().getStringExtra(WEB_URL);
|
|
|
- mWebClient = new AgentWebClient();
|
|
|
- linkurl = loadUrl(linkurl);
|
|
|
- mInterfaceUtils = new JsInterfaceHelper(this);
|
|
|
- mInterfaceUtils.setOnJsCallListener(this);
|
|
|
- mAgentWeb = AgentWeb.with(this)
|
|
|
- .setAgentWebParent((LinearLayout) container, new LinearLayout.LayoutParams(-1, -1))
|
|
|
- .useDefaultIndicator()
|
|
|
- .setWebChromeClient(mWebChromeClient)
|
|
|
- .setWebViewClient(mWebClient)
|
|
|
-// .setWebChromeClient(new MyWebChromeClient())
|
|
|
- .createAgentWeb()
|
|
|
- .ready()
|
|
|
- .go(linkurl);
|
|
|
-
|
|
|
- mAgentWeb.getJsInterfaceHolder().addJavaObject(WebConstants.WEB_JS_INTERFACE, mInterfaceUtils);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private String loadUrl(String url) {
|
|
|
- String userToken = UserHelper.getUserToken();
|
|
|
- mWebClient.setAuthorization(userToken);
|
|
|
- boolean status = url.contains("?");
|
|
|
- if (status) {
|
|
|
- url = (url + "&Authorization=" + userToken);
|
|
|
- } else {
|
|
|
- url = (url + "?Authorization=" + userToken);
|
|
|
- }
|
|
|
- return url;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void goBack() {
|
|
|
- if (!mAgentWeb.back()) {
|
|
|
- finish();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onPause() {
|
|
|
- mAgentWeb.getWebLifeCycle().onPause();
|
|
|
- super.onPause();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onResume() {
|
|
|
- mAgentWeb.getWebLifeCycle().onResume();
|
|
|
- super.onResume();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDestroy() {
|
|
|
- mAgentWeb.getWebLifeCycle().onDestroy();
|
|
|
- super.onDestroy();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
- if (mAgentWeb.handleKeyEvent(keyCode, event)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return super.onKeyDown(keyCode, event);
|
|
|
- }
|
|
|
-
|
|
|
- private WebChromeClient mWebChromeClient = new WebChromeClient() {
|
|
|
- @Override
|
|
|
- public void onReceivedTitle(WebView view, String title) {
|
|
|
- super.onReceivedTitle(view, title);
|
|
|
- tv_title.setText(title);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- @Override
|
|
|
- protected ActivityAgentWebBinding getLayoutView() {
|
|
|
- return ActivityAgentWebBinding.inflate(getLayoutInflater());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected AgentWebPresenter createPresenter() {
|
|
|
- return new AgentWebPresenter();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setBarStatus(JSONObject message) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void backIconChange(JSONObject message) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void chooseFile(JSONObject message) {
|
|
|
- JSONObject content = (JSONObject) message.opt("content");
|
|
|
- String type = (String) content.opt("image/*");
|
|
|
- String[] types = new String[]{type};
|
|
|
- showFileChooser();
|
|
|
- }
|
|
|
-
|
|
|
- private void showFileChooser() {
|
|
|
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
- intent.setType("*/*");
|
|
|
- intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
- intent.putExtra(Intent.EXTRA_TITLE, "File Chooser");
|
|
|
- intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
|
|
- startActivityForResult(intent, REQUEST_CODE_FILE_CHOOSER);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getNavHeight(JSONObject message) {
|
|
|
-
|
|
|
- }
|
|
|
-}
|