调整客服页面返回键交给h5处理(含系统按键/手势)

统一客服页面为同一个WebView
调整短剧与社区使用原生分开加载
调整送礼-包裹接口为新接口
调整粉丝团礼物送礼为新接口
修复战令-兑换-列表页面在名字过长晴空下高度不统一
This commit is contained in:
zlzw 2024-01-09 16:37:43 +08:00
parent b175e42ee1
commit 1759757176
17 changed files with 978 additions and 359 deletions

View File

@ -20,6 +20,14 @@ public class LiveClassBean {
@SerializedName("channel_show") @SerializedName("channel_show")
private int channel_show; private int channel_show;
public LiveClassBean() {
}
public LiveClassBean(String chinese, String english) {
this.chinese = chinese;
this.english = english;
}
public String getChinese() { public String getChinese() {
return chinese; return chinese;
} }

View File

@ -3,6 +3,7 @@ package com.yunbao.common.bean;
import android.view.View; import android.view.View;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.google.gson.annotations.SerializedName;
/** /**
* Created by cxf on 2018/10/12. * Created by cxf on 2018/10/12.
@ -18,6 +19,8 @@ public class LiveGiftBean {
// public static final int MARK_LUCK = 3; // public static final int MARK_LUCK = 3;
private int id; private int id;
@SerializedName("gift_id")
private int gift_id;//包裹礼物id
private int type;//0 普通礼物 1是贵族 2守护 3粉丝团 5盲盒礼物 private int type;//0 普通礼物 1是贵族 2守护 3粉丝团 5盲盒礼物
private int mark;// 0 普通 1热门 2守护 3幸运 private int mark;// 0 普通 1热门 2守护 3幸运
private String name; private String name;
@ -34,6 +37,7 @@ public class LiveGiftBean {
private String isweek; private String isweek;
private String end_time; private String end_time;
private String tag; private String tag;
private boolean isPageGift;
@JSONField(name = "blind_box_type") @JSONField(name = "blind_box_type")
private int blind_box_type = 0; private int blind_box_type = 0;
//礼物角标 //礼物角标
@ -71,6 +75,14 @@ public class LiveGiftBean {
@JSONField(name = "blind_box_ticket_id") @JSONField(name = "blind_box_ticket_id")
private int blindBoxTicketId; private int blindBoxTicketId;
public boolean isPageGift() {
return isPageGift;
}
public void setPageGift(boolean pageGift) {
isPageGift = pageGift;
}
public int getBlindBoxTicketId() { public int getBlindBoxTicketId() {
return blindBoxTicketId; return blindBoxTicketId;
} }
@ -80,6 +92,14 @@ public class LiveGiftBean {
return this; return this;
} }
public int getGift_id() {
return gift_id;
}
public void setGift_id(int gift_id) {
this.gift_id = gift_id;
}
public int getBlindBoxTicket() { public int getBlindBoxTicket() {
return blindBoxTicket; return blindBoxTicket;
} }

View File

@ -11,6 +11,7 @@ import com.yunbao.common.utils.L;
import com.yunbao.common.utils.MD5Util; import com.yunbao.common.utils.MD5Util;
import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.VersionUtil; import com.yunbao.common.utils.VersionUtil;
import com.yunbao.common.utils.WordUtil;
import java.io.File; import java.io.File;
@ -644,7 +645,40 @@ public class LiveHttpUtil {
.params("appVersion", CommonAppConfig.getInstance().getVersion()) .params("appVersion", CommonAppConfig.getInstance().getVersion())
.execute(callback); .execute(callback);
} }
/**
* 观众给主播送礼物 - 包裹
*
* @param isContactGift 是否为联系方式礼物
*/
public static void sendGiftForPage(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, boolean isFansGroupGift, HttpCallback callback) {
HttpClient.getInstance().get("Live.sendPackGift", LiveHttpConsts.SEND_GIFT)
.params("liveuid", liveUid)
.params("stream", stream)
.params("giftid", giftId)
.params("isContactGift", isContactGift)
.params("giftcount", giftCount)
.params("isprank", by)
.params("fans_exclusive_pack", isFansGroupGift ? "1" : "0")
.params("appVersion", CommonAppConfig.getInstance().getVersion())
.execute(callback);
}
/**
* 观众给主播送礼物 - 粉丝团
*
* @param isContactGift 是否为联系方式礼物
*/
public static void sendGiftForFansGroup(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, boolean isFansGroupGift, HttpCallback callback) {
HttpClient.getInstance().get("Live.fansExclusivePack", LiveHttpConsts.SEND_GIFT)
.params("liveuid", liveUid)
.params("stream", stream)
.params("giftid", giftId)
.params("isContactGift", isContactGift)
.params("giftcount", giftCount)
.params("isprank", by)
.params("fans_exclusive_pack", isFansGroupGift ? "1" : "0")
.params("appVersion", CommonAppConfig.getInstance().getVersion())
.execute(callback);
}
public static void sendBlindBoxTicket(String by, String liveUid, String stream, int giftId, HttpCallback callback) { public static void sendBlindBoxTicket(String by, String liveUid, String stream, int giftId, HttpCallback callback) {
HttpClient.getInstance().get("Live.sendBlindBoxTicket", LiveHttpConsts.SEND_GIFT) HttpClient.getInstance().get("Live.sendBlindBoxTicket", LiveHttpConsts.SEND_GIFT)
.params("liveuid", liveUid) .params("liveuid", liveUid)
@ -1003,5 +1037,13 @@ public class LiveHttpUtil {
.execute(callback); .execute(callback);
} }
/**
* 获取短剧Url
*/
public static void getCoolydrama(HttpCallback callback){
HttpClient.getInstance().get("cool.register", "Home.getFollow")
.params("lang", WordUtil.isNewZh()?"zh_CN":"en")
.execute(callback);
}
} }

View File

@ -44,13 +44,14 @@ public class GoogleUtils {
public boolean getGoogleService() { public boolean getGoogleService() {
boolean flag; boolean flag =false;
try { try {
Class<?> clz = mActivity.getClassLoader().loadClass("com.shayu.lib_google.utils.GoogleBillingManage"); Class<?> clz = mActivity.getClassLoader().loadClass("com.shayu.lib_google.utils.GoogleBillingManage");
googlePay = clz.getConstructor(Activity.class).newInstance(mActivity); googlePay = clz.getConstructor(Activity.class).newInstance(mActivity);
flag = (boolean) googlePay.getClass().getMethod("getGoogleService").invoke(googlePay); flag = (boolean) googlePay.getClass().getMethod("getGoogleService").invoke(googlePay);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); e.printStackTrace();
// throw new RuntimeException(e);
} }
return flag; return flag;
} }

View File

@ -678,4 +678,8 @@ public class JavascriptInterfaceUtils {
}); });
} }
@JavascriptInterface
public void androidGotoCustomerService(String url) {
RouteUtil.forwardCustomerService(url);
}
} }

View File

@ -42,6 +42,7 @@ public class LiveParcelItemAdapter extends RecyclerView.Adapter {
frameGiftViewHolder.giftSelect(giftJson.get(position), position, mStream, mLiveUid, new LiveParcelItemViewHolder.FrameGiftClickListener() { frameGiftViewHolder.giftSelect(giftJson.get(position), position, mStream, mLiveUid, new LiveParcelItemViewHolder.FrameGiftClickListener() {
@Override @Override
public void onCallBack(int position, LiveGiftBean model) { public void onCallBack(int position, LiveGiftBean model) {
model.setPageGift(true);
Bus.get().post(new LiveGiftItemEvent().setLiveGiftModel(model)); Bus.get().post(new LiveGiftItemEvent().setLiveGiftModel(model));
giftSelect(model); giftSelect(model);
} }

View File

@ -55,7 +55,7 @@ public class LiveFansGroupSendGiftDialog extends AbsDialogCenterPopupWindow {
recyclerView = findViewById(R.id.giftList); recyclerView = findViewById(R.id.giftList);
adapter = new LiveFansGroupSendGiftAdapter(mContext); adapter = new LiveFansGroupSendGiftAdapter(mContext);
adapter.setOnItemClickListener((bean, position) -> { adapter.setOnItemClickListener((bean, position) -> {
LiveHttpUtil.sendGift("0", LiveHttpUtil.sendGiftForFansGroup("0",
liveUid, liveUid,
mStream, mStream,
bean.getId(), bean.getId(),

View File

@ -619,9 +619,13 @@ public class LiveGiftPopup extends AbsDialogFragment {
public void run() { public void run() {
if (isWrap && liveGiftModel.getType() == 7) { if (isWrap && liveGiftModel.getType() == 7) {
sendBlindBoxTicket(); sendBlindBoxTicket();
} else {
if (liveGiftModel.isPageGift()) {
sendGiftForPage();
} else { } else {
sendGift(); sendGift();
} }
}
} }
}; };
@ -636,7 +640,7 @@ public class LiveGiftPopup extends AbsDialogFragment {
LiveHttpUtil.sendBlindBoxTicket((by != null ? "1" : "0"), LiveHttpUtil.sendBlindBoxTicket((by != null ? "1" : "0"),
mLiveUid, mLiveUid,
mStream, mStream,
isWrap ? liveGiftModel.getId() : liveGiftModel.getBlindBoxTicketId(), new HttpCallback() { isWrap ? liveGiftModel.getGift_id() : liveGiftModel.getBlindBoxTicketId(), new HttpCallback() {
@Override @Override
public void onSuccess(int code, String msg, String[] info) { public void onSuccess(int code, String msg, String[] info) {
if (code == 0) { if (code == 0) {
@ -755,6 +759,16 @@ public class LiveGiftPopup extends AbsDialogFragment {
} }
} }
private void sendGiftForPage() {
if (liveGiftModel == null) return;
SendGiftCallback callback = new SendGiftCallback(liveGiftModel);
if (by != null) {
LiveHttpUtil.sendGiftForPage("1", mLiveUid, mStream, liveGiftModel.getGift_id(), mCount, 0, false, callback);
} else {
LiveHttpUtil.sendGiftForPage("0", mLiveUid, mStream, liveGiftModel.getGift_id(), mCount, 0, false, callback);
}
}
/** /**
* 跳转到我的钻石 * 跳转到我的钻石
*/ */
@ -1446,6 +1460,7 @@ public class LiveGiftPopup extends AbsDialogFragment {
} }
} }
} }
private FragmentTransaction getTransaction() { private FragmentTransaction getTransaction() {
if (contentFragment != null && transaction != null) { if (contentFragment != null && transaction != null) {
transaction.remove(contentFragment); transaction.remove(contentFragment);

View File

@ -8,6 +8,7 @@ import android.os.Build;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
@ -234,12 +235,25 @@ public class CustomerServiceWebViewActivity extends AbsActivity {
} }
protected boolean canGoBack() { protected boolean canGoBack() {
return mWebView != null && mWebView.canGoBack(); // return mWebView != null && mWebView.canGoBack();
ToastUtil.showDebug("2调用js userBackShowPraise");
mWebView.loadUrl("javascript:userBackShowPraise()");
return false;
}
@Override
public void onBackPressed() {
// finish();
ToastUtil.showDebug("调用js userBackShowPraise");
mWebView.loadUrl("javascript:userBackShowPraise()");
} }
@Override @Override
public void onBackPressed() { public boolean onKeyDown(int keyCode, KeyEvent event) {
finish(); if(keyCode==KeyEvent.KEYCODE_ESCAPE || keyCode==KeyEvent.KEYCODE_BACK){
onBackPressed();
return false;
}
return super.onKeyDown(keyCode, event);
} }
@Override @Override

View File

@ -388,7 +388,8 @@ public class EntryActivity extends AppCompatActivity {
public void onClick(View v) { public void onClick(View v) {
if (!"".equals(kefuUrl)) { if (!"".equals(kefuUrl)) {
Constants.LoginKefu = true; Constants.LoginKefu = true;
WebViewActivity.forward(EntryActivity.this, kefuUrl, false); // WebViewActivity.forward(EntryActivity.this, kefuUrl, false);
RouteUtil.forwardCustomerService(kefuUrl);
} }
} }
}); });

View File

@ -0,0 +1,443 @@
package com.yunbao.main.fragment;
import static android.content.Context.CLIPBOARD_SERVICE;
import android.app.Activity;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.RequiresApi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lxj.xpopup.XPopup;
import com.momo.mcamera.util.JsonUtil;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
import com.yunbao.common.HtmlConfig;
import com.yunbao.common.bean.CoolConfig;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.NativeCallbackModel;
import com.yunbao.common.dialog.CinemaTicketPopupWindow;
import com.yunbao.common.event.JavascriptInterfaceEvent;
import com.yunbao.common.fragment.BaseFragment;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.LiveHttpUtil;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.JavascriptInterfacePlayLetUtils;
import com.yunbao.common.utils.JavascriptInterfaceUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.LiveRoomCheckLivePresenter;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.views.LoadingView;
import com.yunbao.main.R;
import com.yunbao.main.activity.MainActivity;
import com.yunbao.main.activity.MyWalletActivity;
import com.yunbao.main.dialog.EncourageDialog;
import com.yunbao.main.utils.BottomBarUtil;
import com.yunbao.share.ui.SharePopDialog;
import com.yunbao.video.activity.VideoPlayActivity;
import com.yunbao.video.utils.VideoStorge;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.Arrays;
import java.util.Locale;
public class MainHomeCommunityFragment extends BaseFragment {
private ProgressBar mProgressBar;
private WebView mWebView;
public final int CHOOSE = 100;//Android 5.0以下的
public final int CHOOSE_ANDROID_5 = 200;//Android 5.0以上的
public ValueCallback<Uri> mValueCallback;
public ValueCallback<Uri[]> mValueCallback2;
private MainActivity nowMainActivity;
Context mContext;
public MainHomeCommunityFragment(MainActivity nowMainActivity) {
super();
this.nowMainActivity=nowMainActivity;
}
@Override
public View createView(LayoutInflater inflater, ViewGroup container) {
return inflater.inflate(R.layout.view_main_encourage, container, false);
}
@Override
protected void initVariables(Bundle bundle) {
}
@Override
protected void initViews(Bundle savedInstanceState, View contentView) {
//Bus.getOn(MainHomeCommunityFragment.this);
mContext = contentView.getContext();
nowMainActivity= (MainActivity) mContext;
String url = HtmlConfig.ENCOURAGE + "?t=" + Math.random() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken()
+ "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0");
// String url = "https://api.coolydrama.com/?agentCode=186279";
final LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
mWebView = new WebView(mContext);
int aa = BottomBarUtil.getNavigationBarHeightIfRoom(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.topMargin = DpUtil.dp2px(1);
mWebView.setLayoutParams(params);
mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);
LoadingView loadingView = new LoadingView(mContext);
loadingView.show();
rootView.addView(loadingView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.setAcceptThirdPartyCookies(mWebView, true);
} else {
cookieManager.setAcceptCookie(true);
}
String appCachePath = mContext.getCacheDir().getAbsolutePath();
// mWebView.getSettings().setAppCachePath(appCachePath);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setUseWideViewPort(true); // 关键点
mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// 不加载缓存内容
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(nowMainActivity, mWebView), "androidObject");
//短剧
// mWebView.addJavascriptInterface(JavascriptInterfacePlayLetUtils.getInstance().setmContext(nowMainActivity, mWebView), "jsBridge");
mWebView.getSettings().setSupportMultipleWindows(true);
rootView.addView(mWebView);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
L.e("H5-------->" + url);
if (url.startsWith(Constants.COPY_PREFIX)) {
String content = url.substring(Constants.COPY_PREFIX.length());
if (!TextUtils.isEmpty(content)) {
copy(content);
}
} else {
view.loadUrl(url);
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
setTitle(view.getTitle());
if (url.contains("for")) {
mWebView.loadUrl("javascript:goAnchorTab()");
}
String userAgent = "shixinzhang";
String js = "window.localStorage.setItem('userAgent','" + userAgent + "');";
String jsUrl = "javascript:(function({ var localStorage = window.localStorage; localStorage.setItem('userAgent','" + userAgent + "') })()";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
view.evaluateJavascript(js, null);
} else {
view.loadUrl(jsUrl);
view.reload();
}
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
loadingView.hide();
mProgressBar.setVisibility(View.GONE);
} else {
loadingView.show();
mProgressBar.setProgress(newProgress);
}
}
//以下是在各个Android版本中 WebView调用文件选择器的方法
// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> valueCallback) {
openImageChooserActivity(valueCallback);
}
// For Android >= 3.0
public void openFileChooser(ValueCallback valueCallback, String acceptType) {
openImageChooserActivity(valueCallback);
}
//For Android >= 4.1
public void openFileChooser(ValueCallback<Uri> valueCallback,
String acceptType, String capture) {
openImageChooserActivity(valueCallback);
}
// For Android >= 5.0
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onShowFileChooser(WebView webView,
ValueCallback<Uri[]> filePathCallback,
FileChooserParams fileChooserParams) {
mValueCallback2 = filePathCallback;
WebChromeClient.FileChooserParams mFileChooserParams;
mFileChooserParams = fileChooserParams;
String at = Arrays.toString(mFileChooserParams.getAcceptTypes());
String type;
if (at.contains("image/")) {//图片
type = "image/*";
} else if (at.contains("video/")) {
type = "video/*";
} else {
type = "*/*";
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(type);
nowMainActivity.startActivityMain2(intent, CHOOSE_ANDROID_5);
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
mWebView.loadUrl(url);
findViewById(R.id.native_callback).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
protected void setTitle(String title) {
TextView titleView = (TextView) findViewById(R.id.titleView);
if (titleView != null) {
titleView.setText(title);
}
}
private void gotoLive(final String live_id) {
LiveHttpUtil.getLiveInfo(live_id + "", new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class);
new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() {
@Override
public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) {
RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal));
}
@Override
public void onCheckError(String contextError) {
}
});
} else {
RouteUtil.forwardUserHome(mContext, String.valueOf(live_id), 0);
}
}
});
}
private void openImageChooserActivity(ValueCallback<Uri> valueCallback) {
mValueCallback = valueCallback;
Intent intent = new Intent();
if (Build.VERSION.SDK_INT < 19) {
intent.setAction(Intent.ACTION_GET_CONTENT);
} else {
intent.setAction(Intent.ACTION_PICK);
intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
intent.setType("image/*");
nowMainActivity.startActivityMain(Intent.createChooser(intent, mContext.getString(R.string.choose_flie)), CHOOSE);
// startActivityForResult(Intent.createChooser(intent,mContext.getString(R.string.choose_flie)), CHOOSE);
}
@Override
public void onDestroy() {
// Bus.getOff(MainHomeCommunityFragment.this);
if (mWebView != null) {
ViewGroup parent = (ViewGroup) mWebView.getParent();
if (parent != null) {
parent.removeView(mWebView);
}
mWebView.reload();
mWebView.destroy();
}
super.onDestroy();
}
/**
* 复制到剪贴板
*/
private void copy(String content) {
ClipboardManager cm = (ClipboardManager) mContext.getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("text", content);
cm.setPrimaryClip(clipData);
ToastUtil.show(mContext.getString(R.string.copy_success));
}
public void closeFinger() {
if (Build.VERSION.SDK_INT >= 21) {
mWebView.post(new Runnable() {
@Override
public void run() {
String method = "Left()";//拼接参数就可以把数据传递给js
mWebView.evaluateJavascript(method, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Log.i("Log", "Left()js返回" + value);
}
});
}
});
} else {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mWebView.loadUrl("javascript:Left()");
}
});
}
});
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onJavascriptInterfaceEvent2(JavascriptInterfaceEvent event) {
if (!TextUtils.isEmpty(event.getMethod())) {
if (TextUtils.equals(event.getMethod(), "androidCommunityGift")) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
EncourageDialog fragment = new EncourageDialog();
fragment.setId(event.getPostsId());
if (mContext instanceof MainActivity) {
fragment.show(((MainActivity) mContext).getSupportFragmentManager(), "EncourageDialog");
}
}
});
} else if (TextUtils.equals(event.getMethod(), "androidPlayVideo")) {
VideoStorge.getInstance().put(Constants.VIDEO_COMMUNITY, event.getVideoBeanList());
VideoPlayActivity.forward(mContext, event.getPosition(), Constants.VIDEO_COMMUNITY, 1);
} else if (TextUtils.equals(event.getMethod(), "androidMethodLookToLive")) {
//看直播
gotoLive(event.getLiveId());
} else if (TextUtils.equals(event.getMethod(), "isCloseNavigation")) {
if (nowMainActivity != null) {
nowMainActivity.isClose(event.getIsClose());
}
} else if (TextUtils.equals(event.getMethod(), "androidCommunityShare")) {
JSONObject json = JSONObject.parseObject(event.getData());
new SharePopDialog(mContext)
.setShareLink(CommonAppConfig.HOST + json.getString("link"))
.setAnchorAvatar(json.getString("avatar"))
.showDialog();
} else if (TextUtils.equals(event.getMethod(), "postWeakBalance")) {
LiveNetManager.get(mContext).
getCoolConfig(new com.yunbao.common.http.base.HttpCallback<CoolConfig>() {
@Override
public void onSuccess(CoolConfig data) {
new XPopup.Builder(mContext)
.enableDrag(false)
.autoOpenSoftInput(false)
.maxWidth(DeviceUtils.getScreenHeight((Activity) mContext) - DpUtil.dp2px(34))
.asCustom(new CinemaTicketPopupWindow(mContext, data.setTicketCount(event.getCoolConfig().getTicketCount()), new CinemaTicketPopupWindow.CinemaTicketPopupWindowCallBack() {
@Override
public void onCallBack(String data) {
if (TextUtils.equals(data, "2")) {
DialogUitl.showSimpleDialog(mContext, mContext.getString(com.yunbao.live.R.string.live_coin_not_enough), false,
new DialogUitl.SimpleCallback2() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
mContext.startActivity(new Intent(mContext, MyWalletActivity.class).putExtra("p", 1));
}
@Override
public void onCancelClick() {
}
});
} else if (TextUtils.equals(data, "1")) {
ToastUtil.show(WordUtil.isNewZh() ? "兑换成功" : "Successful exchange");
mWebView.post(new Runnable() {
@Override
public void run() {
NativeCallbackModel model = new NativeCallbackModel();
model.setUid(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()));
String nativeJson = new JsonUtil().toJson(model);
mWebView.evaluateJavascript("javascript:nativeCallback('" + nativeJson + "')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
}
});
}
});
}
}
})).show();
}
@Override
public void onError(String error) {
ToastUtil.show(error);
}
});
}
}
}
@Override
protected void loadData() {
}
}

View File

@ -0,0 +1,200 @@
package com.yunbao.main.fragment;
import static android.content.Context.CLIPBOARD_SERVICE;
import android.app.Activity;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.alibaba.fastjson.JSONObject;
import com.lxj.xpopup.XPopup;
import com.momo.mcamera.util.JsonUtil;
import com.yunbao.common.Constants;
import com.yunbao.common.bean.CoolConfig;
import com.yunbao.common.bean.NativeCallbackModel;
import com.yunbao.common.dialog.CinemaTicketPopupWindow;
import com.yunbao.common.event.JavascriptInterfaceEvent;
import com.yunbao.common.fragment.BaseFragment;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.LiveHttpUtil;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.JavascriptInterfacePlayLetUtils;
import com.yunbao.common.utils.JavascriptInterfaceUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.main.R;
import com.yunbao.main.activity.MyWalletActivity;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.Arrays;
public class MainHomeCommunityVideoFragment extends BaseFragment {
WebView mWebView;
private Context mContext;
@Override
public View createView(LayoutInflater inflater, ViewGroup container) {
return inflater.inflate(R.layout.view_main_community_video, container, false);
}
@Override
protected void initVariables(Bundle bundle) {
}
@Override
protected void initViews(Bundle savedInstanceState, View contentView) {
mContext = getActivity();
mWebView = findViewById(R.id.webView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.setAcceptThirdPartyCookies(mWebView, true);
} else {
cookieManager.setAcceptCookie(true);
}
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setUseWideViewPort(true); // 关键点
mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// 不加载缓存内容
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
//短剧
mWebView.addJavascriptInterface(JavascriptInterfacePlayLetUtils.getInstance().setmContext(getActivity(), mWebView), "jsBridge");
mWebView.getSettings().setSupportMultipleWindows(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
L.e("H5-------->" + url);
if (url.startsWith(Constants.COPY_PREFIX)) {
String content = url.substring(Constants.COPY_PREFIX.length());
if (!TextUtils.isEmpty(content)) {
copy(content);
}
} else {
view.loadUrl(url);
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (url.contains("for")) {
mWebView.loadUrl("javascript:goAnchorTab()");
}
String userAgent = "shixinzhang";
String js = "window.localStorage.setItem('userAgent','" + userAgent + "');";
String jsUrl = "javascript:(function({ var localStorage = window.localStorage; localStorage.setItem('userAgent','" + userAgent + "') })()";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
view.evaluateJavascript(js, null);
} else {
view.loadUrl(jsUrl);
view.reload();
}
}
});
}
private void copy(String content) {
ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("text", content);
cm.setPrimaryClip(clipData);
ToastUtil.show(getActivity().getString(R.string.copy_success));
}
@Override
protected void loadData() {
LiveHttpUtil.getCoolydrama(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.toString(info));
if (code == 0) {
mWebView.loadUrl(JSONObject.parseObject(info[0]).getString("url"));
}
}
});
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onJavascriptInterfaceEvent2(JavascriptInterfaceEvent event) {
if (TextUtils.equals(event.getMethod(), "postWeakBalance")) {
LiveNetManager.get(mContext).
getCoolConfig(new com.yunbao.common.http.base.HttpCallback<CoolConfig>() {
@Override
public void onSuccess(CoolConfig data) {
new XPopup.Builder(mContext)
.enableDrag(false)
.autoOpenSoftInput(false)
.maxWidth(DeviceUtils.getScreenHeight((Activity) mContext) - DpUtil.dp2px(34))
.asCustom(new CinemaTicketPopupWindow(mContext, data.setTicketCount(event.getCoolConfig().getTicketCount()), new CinemaTicketPopupWindow.CinemaTicketPopupWindowCallBack() {
@Override
public void onCallBack(String data) {
if (TextUtils.equals(data, "2")) {
DialogUitl.showSimpleDialog(mContext, mContext.getString(com.yunbao.live.R.string.live_coin_not_enough), false,
new DialogUitl.SimpleCallback2() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
mContext.startActivity(new Intent(mContext, MyWalletActivity.class).putExtra("p", 1));
}
@Override
public void onCancelClick() {
}
});
} else if (TextUtils.equals(data, "1")) {
ToastUtil.show(WordUtil.isNewZh() ? "兑换成功" : "Successful exchange");
mWebView.post(new Runnable() {
@Override
public void run() {
NativeCallbackModel model = new NativeCallbackModel();
model.setUid(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()));
String nativeJson = new JsonUtil().toJson(model);
mWebView.evaluateJavascript("javascript:nativeCallback('" + nativeJson + "')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
}
});
}
});
}
}
})).show();
}
@Override
public void onError(String error) {
ToastUtil.show(error);
}
});
}
}
}

View File

@ -8,6 +8,7 @@ import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
@ -27,7 +28,15 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -38,10 +47,12 @@ import com.yunbao.common.Constants;
import com.yunbao.common.HtmlConfig; import com.yunbao.common.HtmlConfig;
import com.yunbao.common.bean.CoolConfig; import com.yunbao.common.bean.CoolConfig;
import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.LiveClassBean;
import com.yunbao.common.bean.NativeCallbackModel; import com.yunbao.common.bean.NativeCallbackModel;
import com.yunbao.common.dialog.CinemaTicketPopupWindow; import com.yunbao.common.dialog.CinemaTicketPopupWindow;
import com.yunbao.common.dialog.WarOrderExchangeDetailsPopupWindow; import com.yunbao.common.dialog.WarOrderExchangeDetailsPopupWindow;
import com.yunbao.common.event.JavascriptInterfaceEvent; import com.yunbao.common.event.JavascriptInterfaceEvent;
import com.yunbao.common.fragment.BaseFragment;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.LiveHttpUtil; import com.yunbao.common.http.LiveHttpUtil;
import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.http.live.LiveNetManager;
@ -62,16 +73,33 @@ import com.yunbao.live.views.LoadingView;
import com.yunbao.main.R; import com.yunbao.main.R;
import com.yunbao.main.activity.MainActivity; import com.yunbao.main.activity.MainActivity;
import com.yunbao.main.activity.MyWalletActivity; import com.yunbao.main.activity.MyWalletActivity;
import com.yunbao.main.adapter.MainHomeLivesClassAdapter;
import com.yunbao.main.dialog.EncourageDialog; import com.yunbao.main.dialog.EncourageDialog;
import com.yunbao.main.fragment.BattlePassRewardFragment;
import com.yunbao.main.fragment.MainHomeCommunityFragment;
import com.yunbao.main.fragment.MainHomeCommunityVideoFragment;
import com.yunbao.main.fragment.SearchResultsFragment;
import com.yunbao.main.utils.BottomBarUtil; import com.yunbao.main.utils.BottomBarUtil;
import com.yunbao.share.ui.SharePopDialog; import com.yunbao.share.ui.SharePopDialog;
import com.yunbao.video.activity.VideoPlayActivity; import com.yunbao.video.activity.VideoPlayActivity;
import com.yunbao.video.utils.VideoStorge; import com.yunbao.video.utils.VideoStorge;
import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Locale; import java.util.Locale;
/** /**
@ -88,359 +116,156 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl
public ValueCallback<Uri> mValueCallback; public ValueCallback<Uri> mValueCallback;
public ValueCallback<Uri[]> mValueCallback2; public ValueCallback<Uri[]> mValueCallback2;
private MainActivity nowMainActivity; private MainActivity nowMainActivity;
List<BaseFragment> fragments;
ViewPager2 viewPager;
private MagicIndicator mIndicator;
public MainHomeCommunityViewHolder(Context context, ViewGroup parentView, MainActivity mainActivity) { public MainHomeCommunityViewHolder(Context context, ViewGroup parentView, MainActivity mainActivity) {
super(context, parentView); super(context, parentView);
mContext = context;
nowMainActivity = mainActivity; nowMainActivity = mainActivity;
} }
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
return R.layout.view_main_encourage; return R.layout.view_main_community;
}
@Override
public void onCreate() {
super.onCreate();
} }
@Override @Override
public void init() { public void init() {
Bus.getOn(this); mIndicator = (MagicIndicator) findViewById(R.id.indicator);
String url = HtmlConfig.ENCOURAGE + "?t=" + Math.random() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() viewPager = (ViewPager2) findViewById(R.id.community_viewpager);
+ "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"); fragments = new ArrayList<>();
// String url = "https://api.coolydrama.com/?agentCode=186279"; fragments.add(new MainHomeCommunityFragment(nowMainActivity));
final LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView); fragments.add(new MainHomeCommunityVideoFragment());
mProgressBar = (ProgressBar) findViewById(R.id.progressbar); viewPager.setAdapter(new FragmentStateAdapter(((AppCompatActivity) mContext)) {
mWebView = new WebView(mContext); @NonNull
int aa = BottomBarUtil.getNavigationBarHeightIfRoom(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.topMargin = DpUtil.dp2px(1);
mWebView.setLayoutParams(params);
mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);
LoadingView loadingView = new LoadingView(mContext);
loadingView.show();
rootView.addView(loadingView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.setAcceptThirdPartyCookies(mWebView, true);
} else {
cookieManager.setAcceptCookie(true);
}
String appCachePath = mContext.getCacheDir().getAbsolutePath();
// mWebView.getSettings().setAppCachePath(appCachePath);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setUseWideViewPort(true); // 关键点
mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// 不加载缓存内容
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(nowMainActivity, mWebView), "androidObject");
//短剧
mWebView.addJavascriptInterface(JavascriptInterfacePlayLetUtils.getInstance().setmContext(nowMainActivity, mWebView), "jsBridge");
mWebView.getSettings().setSupportMultipleWindows(true);
rootView.addView(mWebView);
mWebView.setWebViewClient(new WebViewClient() {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public Fragment createFragment(int position) {
L.e("H5-------->" + url); return fragments.get(position);
if (url.startsWith(Constants.COPY_PREFIX)) {
String content = url.substring(Constants.COPY_PREFIX.length());
if (!TextUtils.isEmpty(content)) {
copy(content);
}
} else {
view.loadUrl(url);
}
return true;
} }
@Override @Override
public void onPageFinished(WebView view, String url) { public int getItemCount() {
super.onPageFinished(view, url); return fragments.size();
setTitle(view.getTitle());
if (url.contains("for")) {
mWebView.loadUrl("javascript:goAnchorTab()");
} }
String userAgent = "shixinzhang"; @Override
String js = "window.localStorage.setItem('userAgent','" + userAgent + "');"; public long getItemId(int position) {
String jsUrl = "javascript:(function({ var localStorage = window.localStorage; localStorage.setItem('userAgent','" + userAgent + "') })()"; return super.getItemId(position);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { }
view.evaluateJavascript(js, null); });
} else { viewPager.setUserInputEnabled(false);
view.loadUrl(jsUrl); initTab();
view.reload(); }
@Override
public void onStart() {
super.onStart();
}
String[] titles;
private void initTab() {
titles = new String[]{"社區", "短劇"};
if (!WordUtil.isNewZh()) {
titles = new String[]{"Community", "Theater"};
}
CommonNavigator commonNavigator = new CommonNavigator(mContext);
commonNavigator.setAdjustMode(true);
commonNavigator.setAdapter(new CommonNavigatorAdapter() {
@Override
public int getCount() {
return titles.length;
}
@Override
public IPagerTitleView getTitleView(Context context, int index) {
SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context);
simplePagerTitleView.setNormalColor(Color.parseColor("#B1B1B1"));
simplePagerTitleView.setSelectedColor(Color.parseColor("#FFC621"));
simplePagerTitleView.setText(titles[index]);
simplePagerTitleView.setTextSize(18);
simplePagerTitleView.getPaint().setFakeBoldText(true);
simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewPager != null) {
viewPager.setCurrentItem(index);
} }
} }
}); });
mWebView.setWebChromeClient(new WebChromeClient() { return simplePagerTitleView;
}
@Override @Override
public void onProgressChanged(WebView view, int newProgress) { public IPagerIndicator getIndicator(Context context) {
if (newProgress == 100) { LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
loadingView.hide(); linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
mProgressBar.setVisibility(View.GONE); linePagerIndicator.setXOffset(DpUtil.dp2px(5));
} else { linePagerIndicator.setRoundRadius(DpUtil.dp2px(2));
loadingView.show(); linePagerIndicator.setColors(Color.parseColor("#FFC621"));
mProgressBar.setProgress(newProgress); return linePagerIndicator;
}
}
//以下是在各个Android版本中 WebView调用文件选择器的方法
// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> valueCallback) {
openImageChooserActivity(valueCallback);
}
// For Android >= 3.0
public void openFileChooser(ValueCallback valueCallback, String acceptType) {
openImageChooserActivity(valueCallback);
}
//For Android >= 4.1
public void openFileChooser(ValueCallback<Uri> valueCallback,
String acceptType, String capture) {
openImageChooserActivity(valueCallback);
}
// For Android >= 5.0
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onShowFileChooser(WebView webView,
ValueCallback<Uri[]> filePathCallback,
FileChooserParams fileChooserParams) {
mValueCallback2 = filePathCallback;
WebChromeClient.FileChooserParams mFileChooserParams;
mFileChooserParams = fileChooserParams;
String at = Arrays.toString(mFileChooserParams.getAcceptTypes());
String type;
if (at.contains("image/")) {//图片
type = "image/*";
} else if (at.contains("video/")) {
type = "video/*";
} else {
type = "*/*";
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(type);
nowMainActivity.startActivityMain2(intent, CHOOSE_ANDROID_5);
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
mWebView.loadUrl(url);
findViewById(R.id.native_callback).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
} }
}); });
}//战令等级 mIndicator.setNavigator(commonNavigator);
bind(mIndicator, viewPager);
mIndicator.onPageSelected(0);
viewPager.setCurrentItem(0);
}
public void loadNewUrl() { public void loadNewUrl() {
} }
protected void setTitle(String title) {
TextView titleView = (TextView) findViewById(R.id.titleView);
if (titleView != null) {
titleView.setText(title);
}
}
@Override @Override
public void onItemClick(LiveBean bean, int position) { public void onItemClick(LiveBean bean, int position) {
} }
public static void bind(final MagicIndicator magicIndicator, ViewPager2 viewPager) {
private void gotoLive(final String live_id) { viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
LiveHttpUtil.getLiveInfo(live_id + "", new HttpCallback() {
@Override @Override
public void onSuccess(int code, String msg, String[] info) { public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (code == 0 && info.length > 0) { magicIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels);
LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class);
new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() {
@Override
public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) {
RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal));
} }
@Override @Override
public void onCheckError(String contextError) { public void onPageSelected(int position) {
super.onPageSelected(position);
magicIndicator.onPageSelected(position);
}
@Override
public void onPageScrollStateChanged(int state) {
super.onPageScrollStateChanged(state);
magicIndicator.onPageScrollStateChanged(state);
} }
}); });
} else {
RouteUtil.forwardUserHome(mContext, String.valueOf(live_id), 0);
}
}
});
}
private void openImageChooserActivity(ValueCallback<Uri> valueCallback) {
mValueCallback = valueCallback;
Intent intent = new Intent();
if (Build.VERSION.SDK_INT < 19) {
intent.setAction(Intent.ACTION_GET_CONTENT);
} else {
intent.setAction(Intent.ACTION_PICK);
intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
intent.setType("image/*");
nowMainActivity.startActivityMain(Intent.createChooser(intent, mContext.getString(R.string.choose_flie)), CHOOSE);
// startActivityForResult(Intent.createChooser(intent,mContext.getString(R.string.choose_flie)), CHOOSE);
}
@Override
public void onDestroy() {
Bus.getOff(this);
if (mWebView != null) {
ViewGroup parent = (ViewGroup) mWebView.getParent();
if (parent != null) {
parent.removeView(mWebView);
}
mWebView.reload();
mWebView.destroy();
}
super.onDestroy();
}
/**
* 复制到剪贴板
*/
private void copy(String content) {
ClipboardManager cm = (ClipboardManager) mContext.getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("text", content);
cm.setPrimaryClip(clipData);
ToastUtil.show(mContext.getString(R.string.copy_success));
} }
public void closeFinger() { public void closeFinger() {
if (Build.VERSION.SDK_INT >= 21) { BaseFragment fragment = fragments.get(viewPager.getCurrentItem());
mWebView.post(new Runnable() { if (fragment instanceof MainHomeCommunityFragment) {
@Override ((MainHomeCommunityFragment) fragment).closeFinger();
public void run() {
String method = "Left()";//拼接参数就可以把数据传递给js
mWebView.evaluateJavascript(method, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Log.i("Log", "Left()js返回" + value);
}
});
}
});
} else {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mWebView.loadUrl("javascript:Left()");
}
});
}
});
} }
} }
@Subscribe(threadMode = ThreadMode.MAIN) public void setValueCallback2(Uri[] results) {
public void onJavascriptInterfaceEvent(JavascriptInterfaceEvent event) { BaseFragment fragment = fragments.get(viewPager.getCurrentItem());
if (!TextUtils.isEmpty(event.getMethod())) { if (fragment instanceof MainHomeCommunityFragment) {
if (TextUtils.equals(event.getMethod(), "androidCommunityGift")) { if (((MainHomeCommunityFragment) fragment).mValueCallback2 == null) {
new Handler(Looper.getMainLooper()).post(new Runnable() { return;
public void run() {
EncourageDialog fragment = new EncourageDialog();
fragment.setId(event.getPostsId());
if (mContext instanceof MainActivity) {
fragment.show(((MainActivity) mContext).getSupportFragmentManager(), "EncourageDialog");
}
}
});
} else if (TextUtils.equals(event.getMethod(), "androidPlayVideo")) {
VideoStorge.getInstance().put(Constants.VIDEO_COMMUNITY, event.getVideoBeanList());
VideoPlayActivity.forward(mContext, event.getPosition(), Constants.VIDEO_COMMUNITY, 1);
} else if (TextUtils.equals(event.getMethod(), "androidMethodLookToLive")) {
//看直播
gotoLive(event.getLiveId());
} else if (TextUtils.equals(event.getMethod(), "isCloseNavigation")) {
if (nowMainActivity != null) {
nowMainActivity.isClose(event.getIsClose());
}
} else if (TextUtils.equals(event.getMethod(), "androidCommunityShare")) {
JSONObject json = JSONObject.parseObject(event.getData());
new SharePopDialog(mContext)
.setShareLink(CommonAppConfig.HOST + json.getString("link"))
.setAnchorAvatar(json.getString("avatar"))
.showDialog();
} else if (TextUtils.equals(event.getMethod(), "postWeakBalance")) {
LiveNetManager.get(mContext).
getCoolConfig(new com.yunbao.common.http.base.HttpCallback<CoolConfig>() {
@Override
public void onSuccess(CoolConfig data) {
new XPopup.Builder(mContext)
.enableDrag(false)
.autoOpenSoftInput(false)
.maxWidth(DeviceUtils.getScreenHeight((Activity) mContext) - DpUtil.dp2px(34))
.asCustom(new CinemaTicketPopupWindow(mContext, data.setTicketCount(event.getCoolConfig().getTicketCount()), new CinemaTicketPopupWindow.CinemaTicketPopupWindowCallBack() {
@Override
public void onCallBack(String data) {
if (TextUtils.equals(data, "2")) {
DialogUitl.showSimpleDialog(mContext, mContext.getString(com.yunbao.live.R.string.live_coin_not_enough), false,
new DialogUitl.SimpleCallback2() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
mContext.startActivity(new Intent(mContext, MyWalletActivity.class).putExtra("p", 1));
}
@Override
public void onCancelClick() {
}
});
} else if (TextUtils.equals(data, "1")) {
ToastUtil.show(WordUtil.isNewZh() ? "兑换成功" : "Successful exchange");
mWebView.post(new Runnable() {
@Override
public void run() {
NativeCallbackModel model = new NativeCallbackModel();
model.setUid(String.valueOf(IMLoginManager.get(mContext).getUserInfo().getId()));
String nativeJson = new JsonUtil().toJson(model);
mWebView.evaluateJavascript("javascript:nativeCallback('" + nativeJson + "')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
}
});
}
});
}
}
})).show();
}
@Override
public void onError(String error) {
ToastUtil.show(error);
}
});
} }
((MainHomeCommunityFragment) fragment).mValueCallback2.onReceiveValue(results);
((MainHomeCommunityFragment) fragment).mValueCallback2 = null;
} }
} }

View File

@ -5,7 +5,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dp" android:layout_width="100dp"
android:gravity="center" android:gravity="center"
android:layout_height="wrap_content" android:layout_height="200dp"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"> android:layout_marginTop="10dp">
@ -64,9 +64,10 @@
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="彩鑽之翼(92天)" tools:text="彩鑽之翼(92天)"
android:gravity="center" android:gravity="center"
android:layout_gravity="center" android:layout_gravity="center"
android:textColor="#0D21B2" android:textColor="#0D21B2"

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:paddingTop="36dp"
android:layout_height="match_parent">
<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:overScrollMode="never"
android:layout_gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</net.lucode.hackware.magicindicator.MagicIndicator>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/community_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/indicator" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="68dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:paddingTop="36dp">
<LinearLayout <LinearLayout
android:id="@+id/rootView" android:id="@+id/rootView"