Commit cb20f0ca authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 284e3ca2
......@@ -16,6 +16,7 @@ import com.mints.goodmoney.manager.KsManager;
import com.mints.goodmoney.manager.LiebaoManager;
import com.mints.goodmoney.manager.MhManager;
import com.mints.goodmoney.manager.MiitHelper;
import com.mints.goodmoney.manager.ReaderManager;
import com.mints.goodmoney.manager.RsNewsManager;
import com.mints.goodmoney.manager.TtCsjAdManager;
import com.mints.goodmoney.manager.TzManager;
......@@ -148,6 +149,8 @@ public class MintsApplication extends MultiDexApplication {
// 自定义logger
bindLogger();
ReaderManager.init(this);
// 子线程初始化三方SDK
String processName = SystemUtils.INSTANCE.getProcessName(this, android.os.Process.myPid());
......
......@@ -28,42 +28,26 @@ import kotlin.jvm.functions.Function0;
public class ReaderManager {
public static void init(Application applicationContext) {
ChineseAllReaderApplication.Companion.install(applicationContext, "1209", "asdf!@", "6", "0", new AdProvider() {
ToutiaoAD ad = new ToutiaoAD();
ChineseAllReaderApplication.Companion.install(applicationContext, "1242", "hzq@1242", "32", "0", new AdProvider() {
@Override
public void onAdDialogPositiveClick(@Nullable Dialog dialog, @NotNull Function0<Unit> function0) {
if (NetworkUtil.isNetworkAvailable(applicationContext) && !NetworkUtil.INSTANCE.isWifiConnected(
applicationContext
)
) {
// 网络可用&&wifi没有连接 kotlin 写法
// AlertDialog.Builder(ActivityStackManager.getInstance().getTopActivity())
// .setTitle("温馨提示")
// .setMessage("当前处于移动网络,播放视频会消耗流量,确定播放?")
// .setPositiveButton("观看视频") { d, _ ->
// d.dismiss()
// ad.showVideo(ActivityStackManager.getInstance().getTopActivity()) {
// block()
// }
// }
// .setNegativeButton("取消") { d, _ ->
// d.dismiss()
// }.create().show()
// return
new AlertDialog.Builder(ActivityStackManager.getInstance().getTopActivity())
.setTitle("温馨提示")
.setMessage("当前处于移动网络,播放视频会消耗流量,确定播放?")
.setPositiveButton("观看视频", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// ad.showVideo(ActivityStackManager.getInstance().getTopActivity(), new ToutiaoAD.OnVideoCloseCallBack() {
// @Override
// public void onClose() {
// function0.invoke();
// }
// });
ad.showVideo(ActivityStackManager.getInstance().getTopActivity(), new ToutiaoAD.OnVideoCloseCallBack() {
@Override
public void onClose() {
function0.invoke();
}
});
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
......@@ -80,40 +64,40 @@ public class ReaderManager {
@Override
public void getReaderScreenAd(@NotNull View view, @NotNull OnAdViewReceiver receiver,
@Nullable Dialog dialog) {
// ad.loadAD(applicationContext, receiver, 320, 260, new ToutiaoAD.OnClickListener() {
// @Override
// public void onClick() {
// dialog.dismiss();
// }
// });
ad.loadAD(applicationContext, receiver, 320, 260, new ToutiaoAD.OnClickListener() {
@Override
public void onClick() {
dialog.dismiss();
}
});
}
@Override
public void getReaderPageAd(@NotNull OnAdViewReceiver receiver) {
// ad.loadAD(applicationContext, receiver, DensityUtil.px2dip(applicationContext, ScreenUtils.getScreenWidth(applicationContext) - DensityUtil.dip2px(applicationContext, 30f)), DensityUtil.px2dip(applicationContext, 854f), null);
ad.loadAD(applicationContext, receiver, DensityUtil.px2dip(applicationContext, ScreenUtils.getScreenWidth(applicationContext) - DensityUtil.dip2px(applicationContext, 30f)), DensityUtil.px2dip(applicationContext, 854f), null);
}
@Override
public void getReaderDialogAd(@NotNull View view, @NotNull OnAdViewReceiver receiver, @Nullable Dialog dialog) {
// ad.loadVideoAd(ActivityStackManager.getInstance().getTopActivity(), receiver);
ad.loadVideoAd(ActivityStackManager.getInstance().getTopActivity(), receiver);
}
});
ChineseAllReaderApplication.Companion.setOnReadCallBack(new OnReadCallBack() {
/**
* "time" : 阅读总时长
* "bookName" : 书名
* "chapterName" : 当前章节名
* "pageInChapter" : 当前章节内阅读页码
* "chapterTotalPages" : 当前章节总页数
*/
@Override
public void onReceive(@NotNull Map<String, ?> map) {
Object time = map.get("time");
ToastUtil.toast(time + "");
}
}, 30 * 1000);//间隔30秒 回调一次 间隔任意设置
// ChineseAllReaderApplication.Companion.setOnReadCallBack(new OnReadCallBack() {
// /**
// * "time" : 阅读总时长
// * "bookName" : 书名
// * "chapterName" : 当前章节名
// * "pageInChapter" : 当前章节内阅读页码
// * "chapterTotalPages" : 当前章节总页数
// */
// @Override
// public void onReceive(@NotNull Map<String, ?> map) {
// Object time = map.get("time");
//// ToastUtil.toast(time + "");
//
// }
// }, 30 * 1000);//间隔30秒 回调一次 间隔任意设置
}
}
//package com.mints.goodmoney.manager;
//
//import android.app.Activity;
//import android.content.Context;
//import android.view.View;
//import android.widget.Toast;
//
//import com.bytedance.sdk.openadsdk.AdSlot;
//import com.bytedance.sdk.openadsdk.BuildConfig;
//import com.bytedance.sdk.openadsdk.TTAdConfig;
//import com.bytedance.sdk.openadsdk.TTAdConstant;
//import com.bytedance.sdk.openadsdk.TTAdNative;
//import com.bytedance.sdk.openadsdk.TTAdSdk;
//import com.bytedance.sdk.openadsdk.TTAppDownloadListener;
//import com.bytedance.sdk.openadsdk.TTFeedAd;
//import com.bytedance.sdk.openadsdk.TTImage;
//import com.bytedance.sdk.openadsdk.TTNativeExpressAd;
//import com.bytedance.sdk.openadsdk.TTRewardVideoAd;
//import com.chineseall.reader.lib.reader.callbacks.OnAdViewReceiver;
//import com.chineseall.reader17ksdk.ChineseAllReaderApplication;
//import com.chineseall.reader17ksdk.aop.AspectTest;
//import com.chineseall.reader17ksdk.utils.LogUtils;
//import com.chineseall.reader17ksdk.utils.book.ScreenUtils;
//
//import java.util.List;
//
//
///**
// * Created by yangleo on 2017/12/11.
// */
//
//public class ToutiaoAD {
//
// private static final String tag = "ToutiaoAD";
//
// /*
// 开屏和信息流都用此
// */
// //开屏广告加载超时时间,建议大于200
// private static final int AD_TIME_OUT = 3000;
// private TTAdNative mTTAdNative;
// private Context context;
//
// private TTFeedAd feedAd; //信息流回调类
// private TTRewardVideoAd mttRewardVideoAd;
// private View mView;
//
//// public String getChannel() {
//// return adParamers.channel;
//// }
//
// public String getIcon() {
// if (feedAd == null) {
// return null;
// }
// TTImage ttImage = feedAd.getIcon();
// if (ttImage != null && ttImage.getImageUrl() != null) {
// return ttImage.getImageUrl();
// }
// return null;
// }
//
// public String getImage() {
// if (feedAd == null) {
// return null;
// }
// List<TTImage> list = feedAd.getImageList();
// if (list != null && list.size() > 0) {
// TTImage ttImage = list.get(0);
// if (ttImage != null && ttImage.getImageUrl() != null) {
// return ttImage.getImageUrl();
// }
// }
// return null;
// }
//
// public String getTitle() {
// if (feedAd == null) {
// return null;
// }
// return feedAd.getTitle();
// }
//
// public String getDesc() {
// if (feedAd == null) {
// return null;
// }
// return feedAd.getDescription();
// }
//
// public String getUrl() {
// return null;
// }
package com.mints.goodmoney.manager;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.Toast;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTAppDownloadListener;
import com.bytedance.sdk.openadsdk.TTFeedAd;
import com.bytedance.sdk.openadsdk.TTImage;
import com.bytedance.sdk.openadsdk.TTNativeExpressAd;
import com.bytedance.sdk.openadsdk.TTRewardVideoAd;
import com.chineseall.reader.lib.reader.callbacks.OnAdViewReceiver;
import com.chineseall.reader17ksdk.ChineseAllReaderApplication;
import com.chineseall.reader17ksdk.aop.AspectTest;
import com.chineseall.reader17ksdk.utils.LogUtils;
import com.chineseall.reader17ksdk.utils.book.ScreenUtils;
import java.util.List;
public class ToutiaoAD {
private static final String tag = "ToutiaoAD";
/*
开屏和信息流都用此
*/
//开屏广告加载超时时间,建议大于200
private static final int AD_TIME_OUT = 3000;
private TTAdNative mTTAdNative;
private Context context;
private TTFeedAd feedAd; //信息流回调类
private TTRewardVideoAd mttRewardVideoAd;
private View mView;
public String getIcon() {
if (feedAd == null) {
return null;
}
TTImage ttImage = feedAd.getIcon();
if (ttImage != null && ttImage.getImageUrl() != null) {
return ttImage.getImageUrl();
}
return null;
}
public String getImage() {
if (feedAd == null) {
return null;
}
List<TTImage> list = feedAd.getImageList();
if (list != null && list.size() > 0) {
TTImage ttImage = list.get(0);
if (ttImage != null && ttImage.getImageUrl() != null) {
return ttImage.getImageUrl();
}
}
return null;
}
public String getTitle() {
if (feedAd == null) {
return null;
}
return feedAd.getTitle();
}
public String getDesc() {
if (feedAd == null) {
return null;
}
return feedAd.getDescription();
}
public String getUrl() {
return null;
}
public boolean isApp() {
return false;
}
public View getView() {
return mView;
}
public List<String> getImageList() {
return null;
}
// @Override
public void loadAD(final Context context, OnAdViewReceiver receiver, int width, int height, OnClickListener listener) {
this.context = context;
LogUtils.d(tag, "load ad");
if (mTTAdNative == null) {
mTTAdNative = TTAdSdk.getAdManager().createAdNative(context);
}
// if (ADConfig.TYPE_NATIVE.equals(adParamers.type)){
//信息流
// initNativeAD();
// }else if(ADConfig.TYPE_SPLASH.equals(adParamers.type)){
// 开屏
// initSplashAD();
// }else if(ADConfig.TYPE_INTERSTITIAL.equals(adParamers.type)){
//插屏广告
// initInteractionAD((Activity) context);
// }else if (ADConfig.TYPE_VIDEO.equals(adParamers.type)){
// initVedioAD(context);
// }else if (ADConfig.TYPE_FEED.equals(adParamers.type)){
initFeedAD(receiver, width, height, listener);
// }
}
public void loadVideoAd(Context context, OnAdViewReceiver receiver) {
this.context = context;
if (mTTAdNative == null) {
mTTAdNative = TTAdSdk.getAdManager().createAdNative(context);
}
initVedioAD(context, receiver);
}
private void initFeedAD(OnAdViewReceiver receiver, int width, int height, OnClickListener clickListener) {
// DensityUtil.px2dip(context, ScreenUtils.getScreenWidth(context) - DensityUtil.dip2px(context, 30)), DensityUtil.px2dip(context, 854)
//设置广告参数
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(TtCsjAdManager.TT_AD_NATIVEEXPRESS_WALK) //广告位id
.setSupportDeepLink(true)
.setAdCount(1) //请求广告数量为1到3条
.setExpressViewAcceptedSize(width, height) //必填:期望个性化模板广告view的size,单位dp
.setImageAcceptedSize(400, 150) //这个参数设置即可,不影响个性化模板广告的size
.build();
mTTAdNative.loadNativeExpressAd(adSlot, new TTAdNative.NativeExpressAdListener() {
@Override
public void onError(int code, String message) {
LogUtils.d(tag, "code: " + code + ", " + message);
receiver.onReceive(false, null);
// TToast.show(NativeExpressActivity.this, "load error : " + code + ", " + message);
// getAdParamers().parent.removeAllViews();
}
@Override
public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
if (ads == null || ads.size() == 0) {
return;
}
LogUtils.d(tag, "onNativeExpressAdLoad : " + ads.size());
TTNativeExpressAd mTTAd = ads.get(0);
bindAdListener(mTTAd, receiver, clickListener);
mTTAd.render();//调用render开始渲染广告
}
});
}
//绑定广告行为
private void bindAdListener(TTNativeExpressAd ad, OnAdViewReceiver receiver, OnClickListener clickListener) {
ad.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
@Override
public void onAdClicked(View view, int type) {
LogUtils.d(tag, "onAdClicked : " + type);
LogUtils.d("onAdClicked");
if (clickListener != null) {
clickListener.onClick();
}
}
@Override
public void onAdShow(View view, int type) {
LogUtils.d(tag, "onAdShow : " + type);
LogUtils.d("onAdShow");
}
@Override
public void onRenderFail(View view, String msg, int code) {
LogUtils.d(tag, "onRenderFail : " + msg + ", " + code);
receiver.onReceive(false, view);
}
@Override
public void onRenderSuccess(View view, float width, float height) {
LogUtils.d(tag, "onRenderSuccess : " + view.getClass().getName());
//返回view的宽高 单位 dp
//在渲染成功回调时展示广告,提升体验
// getAdParamers().parent.removeAllViews();
// getAdParamers().parent.addView(view);
mView = view;
if (mView != null && !AspectTest.views.contains(view.getClass().getName())) {
AspectTest.views.add(view.getClass().getName());
}
receiver.onReceive(true, view);
// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
}
});
//dislike设置
// bindDislike(ad, false);
if (ad.getInteractionType() != TTAdConstant.INTERACTION_TYPE_DOWNLOAD) {
return;
}
//可选,下载监听设置
ad.setDownloadListener(new TTAppDownloadListener() {
@Override
public void onIdle() {
LogUtils.d(tag, "onIdle : ");
// TToast.show(NativeExpressActivity.this, "点击开始下载", Toast.LENGTH_LONG);
}
@Override
public void onDownloadActive(long totalBytes, long currBytes, String fileName, String appName) {
LogUtils.d(tag, "onDownloadActive : ");
// if (!mHasShowDownloadActive) {
// mHasShowDownloadActive = true;
// TToast.show(NativeExpressActivity.this, "下载中,点击暂停", Toast.LENGTH_LONG);
// }
}
@Override
public void onDownloadPaused(long totalBytes, long currBytes, String fileName, String appName) {
LogUtils.d(tag, "onDownloadPaused : ");
// TToast.show(NativeExpressActivity.this, "下载暂停,点击继续", Toast.LENGTH_LONG);
}
@Override
public void onDownloadFailed(long totalBytes, long currBytes, String fileName, String appName) {
LogUtils.d(tag, "onDownloadFailed : ");
// TToast.show(NativeExpressActivity.this, "下载失败,点击重新下载", Toast.LENGTH_LONG);
}
@Override
public void onInstalled(String fileName, String appName) {
LogUtils.d(tag, "onInstalled : ");
// TToast.show(NativeExpressActivity.this, "安装完成,点击图片打开", Toast.LENGTH_LONG);
}
@Override
public void onDownloadFinished(long totalBytes, String fileName, String appName) {
LogUtils.d(tag, "onDownloadFinished : ");
// TToast.show(NativeExpressActivity.this, "点击安装", Toast.LENGTH_LONG);
}
});
}
private void initVedioAD(final Context context, OnAdViewReceiver receiver) {
// SharedPreferencesUtil.getInstance().putBoolean(StringConstants.VIDEO_TASK_FINISH, false);
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(TtCsjAdManager.TT_AD_NATIVEEXPRESS_WALK)
.setSupportDeepLink(true)
.setAdCount(1)
.setImageAcceptedSize(ScreenUtils.getScreenWidth(ChineseAllReaderApplication.globalContext) / 4, ScreenUtils.getScreenHeight(ChineseAllReaderApplication.globalContext) / 4)
.setRewardName("金币") //奖励的名称
.setRewardAmount(3) //奖励的数量
//必传参数,表来标识应用侧唯一用户;若非服务器回调模式或不需sdk透传
//可设置为空字符串
.setUserID("")
.setOrientation(TTAdConstant.VERTICAL) //设置期望视频播放的方向,为TTAdConstant.HORIZONTAL或TTAdConstant.VERTICAL
.setMediaExtra("media_extra") //用户透传的信息,可不传
.build();
mTTAdNative.loadRewardVideoAd(adSlot, new TTAdNative.RewardVideoAdListener() {
@Override
public void onError(int code, String message) {
LogUtils.i("ToutiaoAd", message);
// adParamers.listener.onAdFailed("error");
receiver.onReceive(false, null);
}
//视频广告加载后的视频文件资源缓存到本地的回调
@Override
public void onRewardVideoCached() {
LogUtils.i("ToutiaoAd", "rewardVideoAd video cached");
}
//视频广告素材加载到,如title,视频url等,不包括视频文件
@Override
public void onRewardVideoAdLoad(TTRewardVideoAd ad) {
// Log.i("ToutiaoAd","rewardVideoAd loaded");
mttRewardVideoAd = ad;
receiver.onReceive(true, null);
//mttRewardVideoAd.setShowDownLoadBar(false);
}
});
}
public void showVideo(Context context, OnVideoCloseCallBack callBack) {
if (mttRewardVideoAd != null) {
mttRewardVideoAd.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
@Override
public void onAdShow() {
LogUtils.i("ToutiaoAd", "rewardVideoAd onAdShow");
// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
}
@Override
public void onAdVideoBarClick() {
LogUtils.i("ToutiaoAd", "rewardVideoAd onAdVideoBarClick");
// adParamers.listener.onAdClick();
}
@Override
public void onAdClose() {
LogUtils.i("ToutiaoAd", "rewardVideoAd onAdClose");
if (callBack != null) {
callBack.onClose();
}
// adParamers.listener.onAdDismiss();
// EventBus.getDefault().post(new ADCloseEvent(SharedPreferencesUtil.getInstance().getInt(StringConstants.LOOK_VEDIO_TYPE, LOOK_VEDIO_AD_TYPE.NORMAL)));
}
@Override
public void onVideoComplete() {
LogUtils.i("ToutiaoAd", "rewardVideoAd complete");
// Toast.makeText(context,"恭喜您,观看完毕!",Toast.LENGTH_SHORT).show();
}
@Override
public void onVideoError() {
LogUtils.i("ToutiaoAd", "rewardVideoAd onVideoError");
// if (com.burst.ad_toutiao_lib.BuildConfig.DEBUG){
Toast.makeText(context, "视频播放错误", Toast.LENGTH_SHORT).show();
// }
}
@Override
public void onRewardVerify(boolean b, int i, String s, int i1, String s1) {
}
@Override
public void onSkippedVideo() {
}
});
mttRewardVideoAd.setDownloadListener(new TTAppDownloadListener() {
@Override
public void onIdle() {
}
@Override
public void onDownloadActive(long totalBytes, long currBytes, String fileName, String appName) {
}
@Override
public void onDownloadPaused(long totalBytes, long currBytes, String fileName, String appName) {
}
@Override
public void onDownloadFailed(long totalBytes, long currBytes, String fileName, String appName) {
}
@Override
public void onDownloadFinished(long totalBytes, String fileName, String appName) {
}
@Override
public void onInstalled(String fileName, String appName) {
}
});
mttRewardVideoAd.showRewardVideoAd((Activity) context);
}
}
public interface OnVideoCloseCallBack {
void onClose();
}
public interface OnClickListener {
void onClick();
}
// private void initInteractionAD(final Activity context) {
// //插屏广告请求类型数据
// AdSlot adSlot = new AdSlot.Builder()
// .setCodeId(adParamers.key)
// .setSupportDeepLink(true)
// .setImageAcceptedSize(600, 600)
// .build();
// //调用插屏广告异步请求接口
// mTTAdNative.loadInteractionAd(adSlot, new TTAdNative.InteractionAdListener() {
// @Override
// public void onError(int i, String s) {
//
// public boolean isApp() {
// return false;
// }
//
// public View getView() {
// return mView;
// @Override
// public void onInteractionAdLoad(TTInteractionAd ttInteractionAd) {
// ttInteractionAd.setAdInteractionListener(new TTInteractionAd.AdInteractionListener() {
// @Override
// public void onAdClicked() {
// adParamers.listener.onAdClick();
// }
//
// public List<String> getImageList() {
// return null;
// @Override
// public void onAdShow() {
// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
// }
//
//// public int getBannerIndex() {
//// return adParamers.banner_index;
//// }
//
//
// // @Override
// public void loadAD(final Context context, OnAdViewReceiver receiver, int width, int height, OnClickListener listener) {
// this.context = context;
//
// LogUtils.d(tag, "load ad");
//
// if (mTTAdNative == null) {
// mTTAdNative = TTAdSdk.getAdManager().createAdNative(context);
// }
//// if (ADConfig.TYPE_NATIVE.equals(adParamers.type)){
// //信息流
//// initNativeAD();
//// }else if(ADConfig.TYPE_SPLASH.equals(adParamers.type)){
//// 开屏
//// initSplashAD();
//// }else if(ADConfig.TYPE_INTERSTITIAL.equals(adParamers.type)){
// //插屏广告
//// initInteractionAD((Activity) context);
//// }else if (ADConfig.TYPE_VIDEO.equals(adParamers.type)){
//// initVedioAD(context);
//// }else if (ADConfig.TYPE_FEED.equals(adParamers.type)){
// initFeedAD(receiver, width, height, listener);
//// }
// @Override
// public void onAdDismiss() {
//
// }
//
// public void loadVideoAd(Context context, OnAdViewReceiver receiver) {
// this.context = context;
//
// if (mTTAdNative == null) {
// mTTAdNative = TTAdSdk.getAdManager().createAdNative(context);
// });
// //弹出插屏广告
// ttInteractionAd.showInteractionAd(context);
// }
// initVedioAD(context, receiver);
// });
// }
//
// private void initFeedAD(OnAdViewReceiver receiver, int width, int height, OnClickListener clickListener) {
//
// // DensityUtil.px2dip(context, ScreenUtils.getScreenWidth(context) - DensityUtil.dip2px(context, 30)), DensityUtil.px2dip(context, 854)
// //设置广告参数
// private void initSplashAD() {
// //开屏广告参数
// AdSlot adSlot = new AdSlot.Builder()
// .setCodeId("945685076") //广告位id
// .setCodeId(adParamers.key)
// .setSupportDeepLink(true)
// .setAdCount(1) //请求广告数量为1到3条
// .setExpressViewAcceptedSize(width, height) //必填:期望个性化模板广告view的size,单位dp
// .setImageAcceptedSize(400, 150) //这个参数设置即可,不影响个性化模板广告的size
// .setImageAcceptedSize(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight())
// .build();
// mTTAdNative.loadNativeExpressAd(adSlot, new TTAdNative.NativeExpressAdListener() {
// mTTAdNative.loadSplashAd(adSlot, new TTAdNative.SplashAdListener() {
// @Override
// public void onError(int code, String message) {
// LogUtils.d(tag, "code: " + code + ", " + message);
// receiver.onReceive(false, null);
//// TToast.show(NativeExpressActivity.this, "load error : " + code + ", " + message);
//// getAdParamers().parent.removeAllViews();
// //开屏广告请求失败
// adParamers.listener.onAdFailed(message);
// }
//
// @Override
// public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
// if (ads == null || ads.size() == 0) {
// return;
// }
// LogUtils.d(tag, "onNativeExpressAdLoad : " + ads.size());
// TTNativeExpressAd mTTAd = ads.get(0);
// bindAdListener(mTTAd, receiver, clickListener);
// mTTAd.render();//调用render开始渲染广告
// }
// });
// public void onTimeout() {
// //开屏广告请求超时
// adParamers.listener.onAdFailed("请求超时了");
// }
//
// //绑定广告行为
// private void bindAdListener(TTNativeExpressAd ad, OnAdViewReceiver receiver, OnClickListener clickListener) {
// ad.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
// @Override
// public void onAdClicked(View view, int type) {
// LogUtils.d(tag, "onAdClicked : " + type);
// LogUtils.d("onAdClicked");
// if (clickListener != null) {
// clickListener.onClick();
// }
// }
// public void onSplashAdLoad(TTSplashAd ttSplashAd) {
//
// @Override
// public void onAdShow(View view, int type) {
// LogUtils.d(tag, "onAdShow : " + type);
// LogUtils.d("onAdShow");
// //开屏广告请求成功了
// if(ttSplashAd == null){
// return;
// }
//
// @Override
// public void onRenderFail(View view, String msg, int code) {
// LogUtils.d(tag, "onRenderFail : " + msg + ", " + code);
// receiver.onReceive(false, view);
// }
// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
//
// @Override
// public void onRenderSuccess(View view, float width, float height) {
// LogUtils.d(tag, "onRenderSuccess : " + view.getClass().getName());
// //返回view的宽高 单位 dp
// //在渲染成功回调时展示广告,提升体验
//// getAdParamers().parent.removeAllViews();
//// getAdParamers().parent.addView(view);
// mView = view;
// if (mView != null && !AspectTest.views.contains(view.getClass().getName())) {
// AspectTest.views.add(view.getClass().getName());
// }
// receiver.onReceive(true, view);
//// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
// }
// });
// //dislike设置
//// bindDislike(ad, false);
// if (ad.getInteractionType() != TTAdConstant.INTERACTION_TYPE_DOWNLOAD) {
// return;
// }
// //可选,下载监听设置
// ad.setDownloadListener(new TTAppDownloadListener() {
// @Override
// public void onIdle() {
// LogUtils.d(tag, "onIdle : ");
//// TToast.show(NativeExpressActivity.this, "点击开始下载", Toast.LENGTH_LONG);
// }
// //获取SplashView
// View view = ttSplashAd.getSplashView();
// adParamers.parent.removeAllViews();
// //把SplashView 添加到ViewGroup中
// adParamers.parent.addView(view);
//
// @Override
// public void onDownloadActive(long totalBytes, long currBytes, String fileName, String appName) {
// LogUtils.d(tag, "onDownloadActive : ");
//// if (!mHasShowDownloadActive) {
//// mHasShowDownloadActive = true;
//// TToast.show(NativeExpressActivity.this, "下载中,点击暂停", Toast.LENGTH_LONG);
//// }
// }
// //设置不显示SDK自带的跳过和倒计时
// ttSplashAd.setNotAllowSdkCountdown();
//
// ttSplashAd.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() {
// @Override
// public void onDownloadPaused(long totalBytes, long currBytes, String fileName, String appName) {
// LogUtils.d(tag, "onDownloadPaused : ");
//// TToast.show(NativeExpressActivity.this, "下载暂停,点击继续", Toast.LENGTH_LONG);
// public void onAdClicked(View view, int i) {
// //广告点击了
// adParamers.listener.onAdClick();
// }
//
// @Override
// public void onDownloadFailed(long totalBytes, long currBytes, String fileName, String appName) {
// LogUtils.d(tag, "onDownloadFailed : ");
//// TToast.show(NativeExpressActivity.this, "下载失败,点击重新下载", Toast.LENGTH_LONG);
// public void onAdShow(View view, int i) {
// //广告显示了
//// adParamers.listener.onADLoaded(ToutiaoAD.this);
// }
//
// @Override
// public void onInstalled(String fileName, String appName) {
// LogUtils.d(tag, "onInstalled : ");
//// TToast.show(NativeExpressActivity.this, "安装完成,点击图片打开", Toast.LENGTH_LONG);
// public void onAdSkip() {
// //广告跳过
// adParamers.listener.onAdDismiss();
// }
//
// @Override
// public void onDownloadFinished(long totalBytes, String fileName, String appName) {
// LogUtils.d(tag, "onDownloadFinished : ");
//// TToast.show(NativeExpressActivity.this, "点击安装", Toast.LENGTH_LONG);
// public void onAdTimeOver() {
// //开屏广告倒计时结束
// adParamers.listener.onAdDismiss();
// }
// });
// }
//
// private void initVedioAD(final Context context, OnAdViewReceiver receiver) {
//// SharedPreferencesUtil.getInstance().putBoolean(StringConstants.VIDEO_TASK_FINISH, false);
//
// },AD_TIME_OUT);
// }
// private void initNativeAD() {
// //feed广告请求类型参数
// AdSlot adSlot = new AdSlot.Builder()
// .setCodeId("945710075")
// .setCodeId(adParamers.key)
// .setSupportDeepLink(true)
// .setImageAcceptedSize(640, 320)
// .setAdCount(1)
// .setImageAcceptedSize(ScreenUtils.getScreenWidth(ChineseAllReaderApplication.globalContext) / 4, ScreenUtils.getScreenHeight(ChineseAllReaderApplication.globalContext) / 4)
// .setRewardName("金币") //奖励的名称
// .setRewardAmount(3) //奖励的数量
// //必传参数,表来标识应用侧唯一用户;若非服务器回调模式或不需sdk透传
// //可设置为空字符串
// .setUserID("")
// .setOrientation(TTAdConstant.VERTICAL) //设置期望视频播放的方向,为TTAdConstant.HORIZONTAL或TTAdConstant.VERTICAL
// .setMediaExtra("media_extra") //用户透传的信息,可不传
// .build();
// mTTAdNative.loadRewardVideoAd(adSlot, new TTAdNative.RewardVideoAdListener() {
// mTTAdNative.loadFeedAd(adSlot, new TTAdNative.FeedAdListener() {
// @Override
// public void onError(int code, String message) {
// LogUtils.i("ToutiaoAd", message);
//// adParamers.listener.onAdFailed("error");
// receiver.onReceive(false, null);
//
// adParamers.listener.onAdFailed(message);
// }
//
// //视频广告加载后的视频文件资源缓存到本地的回调
// @Override
// public void onRewardVideoCached() {
// LogUtils.i("ToutiaoAd", "rewardVideoAd video cached");
// public void onFeedAdLoad(List<TTFeedAd> ads) {
// if(ads != null && ads.size() > 0){
// feedAd = ads.get(0);
// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
// }else{
// adParamers.listener.onAdFailed("没有广告");
// }
//
// //视频广告素材加载到,如title,视频url等,不包括视频文件
// @Override
// public void onRewardVideoAdLoad(TTRewardVideoAd ad) {
//// Log.i("ToutiaoAd","rewardVideoAd loaded");
// mttRewardVideoAd = ad;
// receiver.onReceive(true, null);
// //mttRewardVideoAd.setShowDownLoadBar(false);
// }
// });
// }
//
// public void showVideo(Context context, OnVideoCloseCallBack callBack) {
// if (mttRewardVideoAd != null) {
// mttRewardVideoAd.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
//
// @Override
// public void onAdShow() {
// LogUtils.i("ToutiaoAd", "rewardVideoAd onAdShow");
//// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
// }
//
// @Override
public boolean onExposured(View view) {
// if (ADConfig.TYPE_NATIVE.equals(adParamers.type)){
//
// if(feedAd != null){
// feedAd.registerViewForInteraction(adParamers.parent, adParamers.clickViewList, null, new TTNativeAd.AdInteractionListener() {
// @Override
// public void onAdVideoBarClick() {
// LogUtils.i("ToutiaoAd", "rewardVideoAd onAdVideoBarClick");
// public void onAdClicked(View view, TTNativeAd ttNativeAd) {
//// adParamers.listener.onAdClick();
// }
//
// @Override
// public void onAdClose() {
// LogUtils.i("ToutiaoAd", "rewardVideoAd onAdClose");
// if (callBack != null) {
// callBack.onClose();
// }
//// adParamers.listener.onAdDismiss();
//// EventBus.getDefault().post(new ADCloseEvent(SharedPreferencesUtil.getInstance().getInt(StringConstants.LOOK_VEDIO_TYPE, LOOK_VEDIO_AD_TYPE.NORMAL)));
//
// }
// public void onAdCreativeClick(View view, TTNativeAd ttNativeAd) {
//
// @Override
// public void onVideoComplete() {
// LogUtils.i("ToutiaoAd", "rewardVideoAd complete");
//// Toast.makeText(context,"恭喜您,观看完毕!",Toast.LENGTH_SHORT).show();
// }
//
// @Override
// public void onVideoError() {
// LogUtils.i("ToutiaoAd", "rewardVideoAd onVideoError");
//// if (com.burst.ad_toutiao_lib.BuildConfig.DEBUG){
// Toast.makeText(context, "视频播放错误", Toast.LENGTH_SHORT).show();
//// }
// public void onAdShow(TTNativeAd ttNativeAd) {
// if(ttNativeAd != null){
// //广告显示了
//// adParamers.listener.onAdShow(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
// }
//
// @Override
// public void onRewardVerify(boolean rewardVerify, int rewardAmount, String rewardName) {
// LogUtils.i("ToutiaoAd", "verify:" + rewardVerify + " amount:" + rewardAmount +
// " name:" + rewardName);
// }
//
// @Override
// public void onSkippedVideo() {
//
// }
// });
// mttRewardVideoAd.setDownloadListener(new TTAppDownloadListener() {
// @Override
// public void onIdle() {
//
// }
//
// @Override
// public void onDownloadActive(long totalBytes, long currBytes, String fileName, String appName) {
//
// }
//
// @Override
// public void onDownloadPaused(long totalBytes, long currBytes, String fileName, String appName) {
//
// }
//
// @Override
// public void onDownloadFailed(long totalBytes, long currBytes, String fileName, String appName) {
//
// }
//
// @Override
// public void onDownloadFinished(long totalBytes, String fileName, String appName) {
//
// }
//
// @Override
// public void onInstalled(String fileName, String appName) {
//
// }
// });
// mttRewardVideoAd.showRewardVideoAd((Activity) context);
// }
// }
//
// public interface OnVideoCloseCallBack {
// void onClose();
// }
//
// public interface OnClickListener {
// void onClick();
// }
//
//// private void initInteractionAD(final Activity context) {
//// //插屏广告请求类型数据
//// AdSlot adSlot = new AdSlot.Builder()
//// .setCodeId(adParamers.key)
//// .setSupportDeepLink(true)
//// .setImageAcceptedSize(600, 600)
//// .build();
//// //调用插屏广告异步请求接口
//// mTTAdNative.loadInteractionAd(adSlot, new TTAdNative.InteractionAdListener() {
//// @Override
//// public void onError(int i, String s) {
////
//// }
////
//// @Override
//// public void onInteractionAdLoad(TTInteractionAd ttInteractionAd) {
//// ttInteractionAd.setAdInteractionListener(new TTInteractionAd.AdInteractionListener() {
//// @Override
//// public void onAdClicked() {
//// adParamers.listener.onAdClick();
//// }
////
//// @Override
//// public void onAdShow() {
//// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
//// }
////
//// @Override
//// public void onAdDismiss() {
////
//// }
//// });
//// //弹出插屏广告
//// ttInteractionAd.showInteractionAd(context);
//// }
//// });
//// }
////
//// private void initSplashAD() {
//// //开屏广告参数
//// AdSlot adSlot = new AdSlot.Builder()
//// .setCodeId(adParamers.key)
//// .setSupportDeepLink(true)
//// .setImageAcceptedSize(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight())
//// .build();
//// mTTAdNative.loadSplashAd(adSlot, new TTAdNative.SplashAdListener() {
//// @Override
//// public void onError(int code, String message) {
//// //开屏广告请求失败
//// adParamers.listener.onAdFailed(message);
//// }
////
//// @Override
//// public void onTimeout() {
//// //开屏广告请求超时
//// adParamers.listener.onAdFailed("请求超时了");
//// }
////
//// @Override
//// public void onSplashAdLoad(TTSplashAd ttSplashAd) {
////
//// //开屏广告请求成功了
//// if(ttSplashAd == null){
//// return;
//// }
////
//// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
////
//// //获取SplashView
//// View view = ttSplashAd.getSplashView();
//// adParamers.parent.removeAllViews();
//// //把SplashView 添加到ViewGroup中
//// adParamers.parent.addView(view);
////
//// //设置不显示SDK自带的跳过和倒计时
//// ttSplashAd.setNotAllowSdkCountdown();
////
//// ttSplashAd.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() {
//// @Override
//// public void onAdClicked(View view, int i) {
//// //广告点击了
//// adParamers.listener.onAdClick();
//// }
////
//// @Override
//// public void onAdShow(View view, int i) {
//// //广告显示了
////// adParamers.listener.onADLoaded(ToutiaoAD.this);
//// }
////
//// @Override
//// public void onAdSkip() {
//// //广告跳过
//// adParamers.listener.onAdDismiss();
//// }
////
//// @Override
//// public void onAdTimeOver() {
//// //开屏广告倒计时结束
//// adParamers.listener.onAdDismiss();
//// }
//// });
//// }
//// },AD_TIME_OUT);
//// }
//
//// private void initNativeAD() {
//// //feed广告请求类型参数
//// AdSlot adSlot = new AdSlot.Builder()
//// .setCodeId(adParamers.key)
//// .setSupportDeepLink(true)
//// .setImageAcceptedSize(640, 320)
//// .setAdCount(1)
//// .build();
//// mTTAdNative.loadFeedAd(adSlot, new TTAdNative.FeedAdListener() {
//// @Override
//// public void onError(int code, String message) {
//// adParamers.listener.onAdFailed(message);
//// }
////
//// @Override
//// public void onFeedAdLoad(List<TTFeedAd> ads) {
//// if(ads != null && ads.size() > 0){
//// feedAd = ads.get(0);
//// adParamers.listener.onADLoaded(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
//// }else{
//// adParamers.listener.onAdFailed("没有广告");
//// }
//// }
//// });
//// }
//
// // @Override
// public boolean onExposured(View view) {
//// if (ADConfig.TYPE_NATIVE.equals(adParamers.type)){
// //
//// if(feedAd != null){
//// feedAd.registerViewForInteraction(adParamers.parent, adParamers.clickViewList, null, new TTNativeAd.AdInteractionListener() {
//// @Override
//// public void onAdClicked(View view, TTNativeAd ttNativeAd) {
////// adParamers.listener.onAdClick();
//// }
////
//// @Override
//// public void onAdCreativeClick(View view, TTNativeAd ttNativeAd) {
////
//// }
////
//// @Override
//// public void onAdShow(TTNativeAd ttNativeAd) {
//// if(ttNativeAd != null){
//// //广告显示了
////// adParamers.listener.onAdShow(com.rice.gluepudding.ad.impl.ToutiaoAD.this);
//// }
//// }
//// });
////
//// }
//// }
// return false;
// }
//
// // @Override
// public boolean onClicked(View view) {
// return false;
// }
//}
return false;
}
// @Override
public boolean onClicked(View view) {
return false;
}
}
......@@ -3,12 +3,15 @@ package com.mints.goodmoney.ui.activitys
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.fly.scenemodule.fragment.IdiomFragment
import androidx.fragment.app.FragmentTransaction
import com.chineseall.reader17ksdk.feature.main.bookshop.wellchosen.WellChosenFragment
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.fragment.*
import com.mints.goodmoney.ui.widgets.seekbar.BubbleUtils
import com.mints.goodmoney.ui.fragment.FriendsFragment
import com.mints.goodmoney.ui.fragment.KuYinYueFragment
import com.mints.goodmoney.ui.fragment.WzFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.android.synthetic.main.activity_wrapper.*
import kotlinx.android.synthetic.main.header_layout.*
......@@ -17,6 +20,7 @@ import kotlinx.android.synthetic.main.header_layout.*
* 作者:孟崔广
* 时间:2020/12/10 12:39
*/
@AndroidEntryPoint
class WrapperActivity : BaseActivity(), View.OnClickListener {
private var wrapperType = Constant.WRAPPER_TYPE_NEWS
......@@ -50,11 +54,28 @@ class WrapperActivity : BaseActivity(), View.OnClickListener {
var currentFragment: Fragment?
when (wrapperType) {
Constant.WRAPPER_TYPE_NEWS -> {
layoutWrapper.visibility = View.INVISIBLE
val layoutParams = layoutWrapper.layoutParams
layoutParams.height = BubbleUtils.dp2px(30)
tv_title.text = "新闻"
currentFragment = RsNewsFragment()
// layoutWrapper.visibility = View.INVISIBLE
// val layoutParams = layoutWrapper.layoutParams
// layoutParams.height = BubbleUtils.dp2px(30)
// tv_title.text = "新闻"
// currentFragment = RsNewsFragment()
// val wellChosenFragment = WellChosenFragment("home")
// val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
// transaction.add(R.id.flWrapper, wellChosenFragment, WellChosenFragment::class.java.simpleName)
// transaction.show(wellChosenFragment)
// transaction.commitAllowingStateLoss()
// ViewPager viewPager = findViewById(R.id.view_pager);
// TabLayout tabLayout = findViewById(R.id.tabs);
//
// viewPager.setAdapter(new MyViewPageAdapter(getSupportFragmentManager()));
// tabLayout.setupWithViewPager(viewPager);
val wellChosenFragment = WellChosenFragment("home")
val transaction = supportFragmentManager.beginTransaction()
transaction.add(R.id.flWrapper, wellChosenFragment, WellChosenFragment::class.java.toString())
transaction.show(wellChosenFragment)
transaction.commitAllowingStateLoss()
}
Constant.WRAPPER_TYPE_FRIENDS -> {
tv_title.text = "瓜分百万现金福利"
......@@ -74,11 +95,11 @@ class WrapperActivity : BaseActivity(), View.OnClickListener {
}
}
if (!currentFragment.isAdded) {
// 提交事务
supportFragmentManager.beginTransaction()
.add(R.id.flWrapper, currentFragment).commitAllowingStateLoss()
}
// if (!currentFragment.isAdded) {
// // 提交事务
// supportFragmentManager.beginTransaction()
// .add(R.id.flWrapper, currentFragment,currentFragment.tag).commitAllowingStateLoss()
// }
}
private fun initListener() {
......
package com.mints.goodmoney.ui.fragment
import androidx.fragment.app.FragmentTransaction
import com.chineseall.reader17ksdk.feature.main.bookshop.wellchosen.WellChosenFragment
import com.mints.goodmoney.R
import com.mints.goodmoney.mvp.presenters.RsNewsPresenter
import com.mints.goodmoney.mvp.views.RsNewsView
import com.mints.goodmoney.ui.fragment.base.LazyLoadBaseFragment
/**
* 描述:听读
* 作者:孟崔广
* 时间:2020/12/9 10:55
*/
class ReaderFragment : LazyLoadBaseFragment(), RsNewsView {
private val wellChosenFragment by lazy { WellChosenFragment("home") }
private val rsNewsPresenter by lazy { RsNewsPresenter() }
override fun getContentViewLayoutID() = R.layout.fragment_main_zy
override fun initViewsAndEvents() {}
override fun onFragmentFirstVisible() {
rsNewsPresenter.attachView(this)
val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
transaction.add(R.id.fragment, wellChosenFragment, ReaderFragment::class.java.simpleName)
transaction.show(wellChosenFragment)
transaction.commitAllowingStateLoss()
}
override fun onDestroy() {
super.onDestroy()
rsNewsPresenter.detachView()
}
override fun readSecondsSuc(coin: Int, video: Int, supr: Int) {
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment