Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_goodmoney
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_goodmoney
Commits
7af44bbb
Commit
7af44bbb
authored
Apr 09, 2021
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加听读视频
parent
6752303b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
208 additions
and
123 deletions
+208
-123
ReadToutiaoAD.java
.../main/java/com/mints/goodmoney/manager/ReadToutiaoAD.java
+2
-5
ReadYlhAd.java
.../src/main/java/com/mints/goodmoney/manager/ReadYlhAd.java
+131
-0
ReaderManager.java
.../main/java/com/mints/goodmoney/manager/ReaderManager.java
+0
-111
ReaderManager.kt
...rc/main/java/com/mints/goodmoney/manager/ReaderManager.kt
+68
-0
ReaderFragment.kt
...in/java/com/mints/goodmoney/ui/fragment/ReaderFragment.kt
+7
-7
No files found.
GoodMoney/app/src/main/java/com/mints/goodmoney/manager/ToutiaoAD.java
→
GoodMoney/app/src/main/java/com/mints/goodmoney/manager/
Read
ToutiaoAD.java
View file @
7af44bbb
...
...
@@ -24,13 +24,10 @@ import com.mints.library.utils.json.JsonUtil;
import
java.util.List
;
public
class
ToutiaoAD
{
public
class
Read
ToutiaoAD
{
private
static
final
String
tag
=
"ToutiaoAD"
;
/*
开屏和信息流都用此
*/
//开屏广告加载超时时间,建议大于200
private
static
final
int
AD_TIME_OUT
=
3000
;
private
TTAdNative
mTTAdNative
;
...
...
@@ -136,7 +133,7 @@ public class ToutiaoAD {
// 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
.
setCodeId
(
TtCsjAdManager
.
TT_AD_NATIVEEXPRESS_
AWARD
)
//广告位id
.
setSupportDeepLink
(
true
)
.
setAdCount
(
1
)
//请求广告数量为1到3条
.
setExpressViewAcceptedSize
(
width
,
height
)
//必填:期望个性化模板广告view的size,单位dp
...
...
GoodMoney/app/src/main/java/com/mints/goodmoney/manager/ReadYlhAd.java
0 → 100644
View file @
7af44bbb
package
com
.
mints
.
goodmoney
.
manager
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.os.SystemClock
;
import
android.widget.Toast
;
import
com.bytedance.sdk.openadsdk.TTAppDownloadListener
;
import
com.bytedance.sdk.openadsdk.TTRewardVideoAd
;
import
com.chineseall.reader.lib.reader.callbacks.OnAdViewReceiver
;
import
com.chineseall.reader17ksdk.utils.LogUtils
;
import
com.mints.goodmoney.common.AppConfig
;
import
com.mints.goodmoney.common.Constant
;
import
com.mints.goodmoney.utils.LogUtil
;
import
com.qq.e.ads.rewardvideo.RewardVideoAD
;
import
com.qq.e.ads.rewardvideo.RewardVideoADListener
;
import
com.qq.e.comm.util.AdError
;
public
class
ReadYlhAd
{
private
Context
context
;
private
RewardVideoAD
rewardVideoAD
;
private
boolean
isClickScreen
=
true
;
// 是否点击屏幕跳转广告
public
void
loadVideoAd
(
Context
context
,
OnAdViewReceiver
receiver
,
OnVideoCloseCallBack
callBack
)
{
this
.
context
=
context
;
initVedioAD
(
context
,
receiver
,
callBack
);
}
private
void
initVedioAD
(
final
Context
context
,
OnAdViewReceiver
receiver
,
OnVideoCloseCallBack
callBack
)
{
rewardVideoAD
=
new
RewardVideoAD
(
context
,
YlhAdManager
.
INSTANCE
.
getYLH_AD_VEDIO_DRINK_POSTID
(),
new
RewardVideoADListener
()
{
@Override
public
void
onADLoad
()
{
//广告加载成功,可在此回调后进行广告展示,此时广告过期时间确定,可通过RewardVideoAD.getExpireTimestamp()获取
receiver
.
onReceive
(
true
,
null
);
}
@Override
public
void
onVideoCached
()
{
//视频素材缓存成功,可在此回调后进行广告展示
}
@Override
public
void
onADShow
()
{
//激励视频广告页面展示,此后RewardVideoAD.hasShown()返回true
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_YLH
,
Constant
.
EVENT_TYPE_ZERO
,
""
,
""
);
}
@Override
public
void
onADExpose
()
{
//激励视频广告曝光
}
@Override
public
void
onReward
()
{
//激励视频广告激励发放
// if (activity != null) {
// ylhVideoAdPresenter.reportAddCoinMsg(activity, getAdMapVO(carrierType));
// }
}
@Override
public
void
onADClick
()
{
//激励视频广告被点击
if
(
AppConfig
.
needReportClickAdEvent
)
{
TrackManager
.
getInstance
().
reportClickAdEvent
();
}
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_YLH
,
Constant
.
EVENT_TYPE_TWO
,
""
,
""
);
if
(
isClickScreen
)
{
// 防止重复
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_YLH
,
Constant
.
EVENT_TYPE_FOUR
,
""
,
""
);
isClickScreen
=
false
;
}
}
@Override
public
void
onVideoComplete
()
{
//广告视频素材播放完毕
}
@Override
public
void
onADClose
()
{
//激励视频广告被关闭
if
(
callBack
!=
null
)
{
callBack
.
onClose
();
}
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_YLH
,
Constant
.
EVENT_TYPE_THREE
,
""
,
""
);
}
@Override
public
void
onError
(
AdError
adError
)
{
//广告流程出错,AdError中包含错误码和错误描述
receiver
.
onReceive
(
false
,
null
);
if
(
adError
!=
null
)
{
LogUtil
.
d
(
"YlhVideoAdManager"
,
"onError "
+
adError
.
getErrorCode
()
+
adError
.
getErrorMsg
());
// 0 成功 1失败 2点击 3-有效展示
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_YLH
,
Constant
.
EVENT_TYPE_ONE
,
String
.
valueOf
(
adError
.
getErrorCode
()),
adError
.
getErrorMsg
());
}
}
});
rewardVideoAD
.
loadAD
();
}
public
void
showVideo
()
{
try
{
if
(!
rewardVideoAD
.
hasShown
())
{
//广告展示检查2:当前广告数据还没有展示过
long
delta
=
1000
;
//建议给广告过期时间加个buffer,单位ms,这里demo采用1000ms的buffer
//广告展示检查3:展示广告前判断广告数据未过期
if
(
SystemClock
.
elapsedRealtime
()
<
(
rewardVideoAD
.
getExpireTimestamp
()
-
delta
))
{
rewardVideoAD
.
showAD
();
}
else
{
// showToast("广告已过期,请再次请求广告后进行广告展示!");
}
}
else
{
// showToast("此条广告已经展示过,请再次请求广告后进行广告展示!");
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_YLH
,
Constant
.
EVENT_TYPE_ONE
,
"999999"
,
"Load Fail"
);
}
}
public
interface
OnVideoCloseCallBack
{
void
onClose
();
}
public
interface
OnClickListener
{
void
onClick
();
}
}
GoodMoney/app/src/main/java/com/mints/goodmoney/manager/ReaderManager.java
deleted
100644 → 0
View file @
6752303b
package
com
.
mints
.
goodmoney
.
manager
;
import
android.app.Application
;
import
android.app.Dialog
;
import
android.content.DialogInterface
;
import
android.view.View
;
import
androidx.appcompat.app.AlertDialog
;
import
com.chineseall.reader.lib.reader.callbacks.OnAdViewReceiver
;
import
com.chineseall.reader17ksdk.ChineseAllReaderApplication
;
import
com.chineseall.reader17ksdk.callbacks.AdProvider
;
import
com.chineseall.reader17ksdk.callbacks.OnReadCallBack
;
import
com.chineseall.reader17ksdk.utils.ActivityStackManager
;
import
com.chineseall.reader17ksdk.utils.DensityUtil
;
import
com.chineseall.reader17ksdk.utils.NetworkUtil
;
import
com.chineseall.reader17ksdk.utils.ToastUtil
;
import
com.chineseall.reader17ksdk.utils.book.ScreenUtils
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.Map
;
import
kotlin.Unit
;
import
kotlin.jvm.functions.Function0
;
/**
* 中文在线 听读
* 作者:孟崔广
* 时间:2021/04/08 14:44
* 邮箱:mengcga@163.com
*/
public
class
ReaderManager
{
public
static
void
init
(
Application
applicationContext
)
{
ToutiaoAD
csjAd
=
new
ToutiaoAD
();
ChineseAllReaderApplication
.
Companion
.
install
(
applicationContext
,
"1242"
,
"hzq@1242"
,
"32"
,
"0"
,
new
AdProvider
()
{
/**
* 阅读⻚弹窗广告确认按钮的点击回调-激励视频
* @param dialog
* @param block 对话框关闭回调,必须调用,否则计时每次切换章节都会出现弹窗
*/
@Override
public
void
onAdDialogPositiveClick
(
@Nullable
Dialog
dialog
,
@NotNull
Function0
<
Unit
>
function0
)
{
if
(
NetworkUtil
.
isNetworkAvailable
(
applicationContext
)
&&
!
NetworkUtil
.
INSTANCE
.
isWifiConnected
(
applicationContext
))
{
new
AlertDialog
.
Builder
(
ActivityStackManager
.
getInstance
().
getTopActivity
())
.
setTitle
(
"温馨提示"
)
.
setMessage
(
"当前处于移动网络,播放视频会消耗流量,确定播放?"
)
.
setPositiveButton
(
"观看视频"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
csjAd
.
showVideo
(
ActivityStackManager
.
getInstance
().
getTopActivity
(),
new
ToutiaoAD
.
OnVideoCloseCallBack
()
{
@Override
public
void
onClose
()
{
function0
.
invoke
();
}
});
}
}).
setNegativeButton
(
"取消"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
dismiss
();
}
}).
create
().
show
();
return
;
}
else
{
csjAd
.
showVideo
(
ActivityStackManager
.
getInstance
().
getTopActivity
(),
new
ToutiaoAD
.
OnVideoCloseCallBack
()
{
@Override
public
void
onClose
()
{
function0
.
invoke
();
}
});
}
}
/**
* 阅读⻚首次打开 弹框广告(信息流) 广告宽度 320 高度 260 * @param adViewContainer 广告view的容器
*/
@Override
public
void
getReaderScreenAd
(
@NotNull
View
view
,
@NotNull
OnAdViewReceiver
receiver
,
@Nullable
Dialog
dialog
)
{
csjAd
.
loadAD
(
applicationContext
,
receiver
,
320
,
260
,
new
ToutiaoAD
.
OnClickListener
()
{
@Override
public
void
onClick
()
{
dialog
.
dismiss
();
}
});
}
/**
* 阅读⻚翻⻚广告(信息流) 广告宽度 320 高度 260 */
@Override
public
void
getReaderPageAd
(
@NotNull
OnAdViewReceiver
receiver
)
{
csjAd
.
loadAD
(
applicationContext
,
receiver
,
DensityUtil
.
px2dip
(
applicationContext
,
ScreenUtils
.
getScreenWidth
(
applicationContext
)
-
DensityUtil
.
dip2px
(
applicationContext
,
30
f
)),
DensityUtil
.
px2dip
(
applicationContext
,
854
f
),
null
);
}
/**
* 阅读⻚定时弹窗广告 (激励视频)
*/
@Override
public
void
getReaderDialogAd
(
@NotNull
View
view
,
@NotNull
OnAdViewReceiver
receiver
,
@Nullable
Dialog
dialog
)
{
csjAd
.
loadVideoAd
(
ActivityStackManager
.
getInstance
().
getTopActivity
(),
receiver
);
}
});
}
}
GoodMoney/app/src/main/java/com/mints/goodmoney/manager/ReaderManager.kt
0 → 100644
View file @
7af44bbb
package
com.mints.goodmoney.manager
import
android.app.Application
import
android.app.Dialog
import
android.view.View
import
androidx.appcompat.app.AlertDialog
import
com.chineseall.reader.lib.reader.callbacks.OnAdViewReceiver
import
com.chineseall.reader17ksdk.ChineseAllReaderApplication.Companion.install
import
com.chineseall.reader17ksdk.callbacks.AdProvider
import
com.chineseall.reader17ksdk.utils.ActivityStackManager
import
com.chineseall.reader17ksdk.utils.DensityUtil.dip2px
import
com.chineseall.reader17ksdk.utils.DensityUtil.px2dip
import
com.chineseall.reader17ksdk.utils.NetworkUtil.isNetworkAvailable
import
com.chineseall.reader17ksdk.utils.NetworkUtil.isWifiConnected
import
com.chineseall.reader17ksdk.utils.book.ScreenUtils
/**
* 中文在线 听读
* 作者:孟崔广
* 时间:2021/04/08 14:44
* 邮箱:mengcga@163.com
*/
object
ReaderManager
{
@JvmStatic
fun
init
(
applicationContext
:
Application
)
{
val
csjAd
=
ReadToutiaoAD
()
install
(
applicationContext
,
"1242"
,
"hzq@1242"
,
"32"
,
"0"
,
object
:
AdProvider
{
/**
* 阅读⻚弹窗广告确认按钮的点击回调-激励视频
* @param dialog
* @param block 对话框关闭回调,必须调用,否则计时每次切换章节都会出现弹窗
*/
override
fun
onAdDialogPositiveClick
(
dialog
:
Dialog
?,
function0
:
Function0
<
Unit
>)
{
if
(
isNetworkAvailable
(
applicationContext
)
&&
!
isWifiConnected
(
applicationContext
))
{
AlertDialog
.
Builder
(
ActivityStackManager
.
getInstance
().
topActivity
)
.
setTitle
(
"温馨提示"
)
.
setMessage
(
"当前处于移动网络,播放视频会消耗流量,确定播放?"
)
.
setPositiveButton
(
"观看视频"
)
{
dialog
,
which
->
csjAd
.
showVideo
(
ActivityStackManager
.
getInstance
().
topActivity
)
{
function0
.
invoke
()
}
}.
setNegativeButton
(
"取消"
)
{
dialog
,
which
->
dialog
.
dismiss
()
}.
create
().
show
()
return
}
else
{
csjAd
.
showVideo
(
ActivityStackManager
.
getInstance
().
topActivity
)
{
function0
.
invoke
()
}
}
}
/**
* 阅读⻚首次打开 弹框广告(信息流) 广告宽度 320 高度 260 * @param adViewContainer 广告view的容器
*/
override
fun
getReaderScreenAd
(
view
:
View
,
receiver
:
OnAdViewReceiver
,
dialog
:
Dialog
?)
{
csjAd
.
loadAD
(
applicationContext
,
receiver
,
320
,
260
,
ReadToutiaoAD
.
OnClickListener
{
dialog
!!
.
dismiss
()
})
}
/**
* 阅读⻚翻⻚广告(信息流) 广告宽度 320 高度 260
*/
override
fun
getReaderPageAd
(
receiver
:
OnAdViewReceiver
)
{
csjAd
.
loadAD
(
applicationContext
,
receiver
,
px2dip
(
applicationContext
,
ScreenUtils
.
getScreenWidth
(
applicationContext
)
-
dip2px
(
applicationContext
,
30f
).
toFloat
()),
px2dip
(
applicationContext
,
854f
),
null
)
}
/**
* 阅读⻚定时弹窗广告 (激励视频)
*/
override
fun
getReaderDialogAd
(
view
:
View
,
receiver
:
OnAdViewReceiver
,
dialog
:
Dialog
?)
{
csjAd
.
loadVideoAd
(
ActivityStackManager
.
getInstance
().
topActivity
,
receiver
)
}
})
}
}
\ No newline at end of file
GoodMoney/app/src/main/java/com/mints/goodmoney/ui/fragment/ReaderFragment.kt
View file @
7af44bbb
...
...
@@ -32,13 +32,13 @@ class ReaderFragment : LazyLoadBaseFragment(), BookView, OnReadCallBack {
override
fun
onFragmentFirstVisible
()
{
bookPresenter
.
attachView
(
this
)
val
transaction
:
FragmentTransaction
=
supportFragmentManager
.
beginTransaction
()
transaction
.
add
(
R
.
id
.
fragment
,
wellChosenFragment
,
ReaderFragment
::
class
.
java
.
simpleName
)
transaction
.
show
(
wellChosenFragment
)
transaction
.
commitAllowingStateLoss
()
//间隔30秒 回调一次 间隔任意设置
ChineseAllReaderApplication
.
setOnReadCallBack
(
this
,
30
*
1000
)
//
val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
//
transaction.add(R.id.fragment, wellChosenFragment, ReaderFragment::class.java.simpleName)
//
transaction.show(wellChosenFragment)
//
transaction.commitAllowingStateLoss()
//
//
//间隔30秒 回调一次 间隔任意设置
//
ChineseAllReaderApplication.setOnReadCallBack(this, 30 * 1000)
}
override
fun
onFragmentResume
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment