Commit 0120cce4 authored by mengcuiguang's avatar mengcuiguang

更换书城sdk,信息流改为权重调用

parent 9b9cf32a
......@@ -9,8 +9,8 @@ android {
applicationId "com.mints.goodmoney"
minSdkVersion rootProject.ext.androidMinSdkVersion
targetSdkVersion rootProject.ext.androidTargetSdkVersion
versionCode 19
versionName "1.1.8"
versionCode 20
versionName "1.1.9"
flavorDimensions "default"
// dex突破65535的限制
......@@ -233,8 +233,7 @@ dependencies {
implementation 'com.liulishuo.filedownloader:library:1.7.7'
implementation "org.greenrobot:eventbus:3.1.0-RC"
// 掌阅书城
// implementation(name: 'iReader-release-androidx-1.0.3.1_haozhuanqian', ext: 'aar')
implementation(name: 'iReader-release-1.0.1', ext: 'aar')
implementation(name: 'iReader-release-androidx-1.0.3.1-haozhuanqian', ext: 'aar')
implementation 'com.alibaba:fastjson:1.2.11'
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'androidx.core:core:1.0.0'
......
......@@ -4,7 +4,11 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.mvp.model.WeightBean
import com.mints.goodmoney.utils.LogUtil
import com.qq.e.ads.nativ.NativeExpressADView
import java.util.*
/**
......@@ -12,6 +16,8 @@ import com.qq.e.ads.nativ.NativeExpressADView
*/
object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener, KSADLoadSuccessListener {
private val TAG = PreLoadExpressManager::class.java.simpleName
// 是否是穿山甲信息流
@Volatile
private var currentIndex = 0
......@@ -19,6 +25,11 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
@Volatile
private var mAdFrameLayout: FrameLayout? = null
private var weightList: MutableList<WeightBean> = mutableListOf()
private var csjWeight = 0
private var ylhWeight = 0
private var ksWeight = 0
init {
mAdFrameLayout = FrameLayout(MintsApplication.getContext())
YlhPreLoadExpressManager.setListener(this)
......@@ -26,24 +37,83 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
KsPreLoadExpressManager.setListener(this)
}
fun init(csjWeight: Int, ylhWeight: Int, ksWeight: Int) {
this.csjWeight = csjWeight
this.ylhWeight = ylhWeight
this.ksWeight = ksWeight
}
fun loadADFrameLayout() {
mAdFrameLayout?.removeAllViews()
when (++currentIndex) {
1 -> {
// when (++currentIndex) {
// 1 -> {
// TTPreLoadExpressManager.getInstance().loadTtFrameLayout(mAdFrameLayout)
// }
// 2 -> {
// YlhPreLoadExpressManager.loadYlhFrameLayout()
// }
// 3 -> {
// KsPreLoadExpressManager.loadKsFrameLayout(mAdFrameLayout as ViewGroup)
// }
// }
when (getRandomWeight()) {
Constant.CSJ_EXPRESS_AD -> TTPreLoadExpressManager.getInstance().loadTtFrameLayout(mAdFrameLayout)
Constant.YLH_EXPRESS_AD -> YlhPreLoadExpressManager.loadYlhFrameLayout()
Constant.KS_EXPRESS_AD -> KsPreLoadExpressManager.loadKsFrameLayout(mAdFrameLayout as ViewGroup)
else -> {
TTPreLoadExpressManager.getInstance().loadTtFrameLayout(mAdFrameLayout)
}
2 -> {
YlhPreLoadExpressManager.loadYlhFrameLayout()
}
3 -> {
KsPreLoadExpressManager.loadKsFrameLayout(mAdFrameLayout as ViewGroup)
}
/**
* 根据权重获取广告类型
*/
private fun getRandomWeight(): String {
if (weightList != null) {
weightList.clear()
}
var weight = 0
// 若没有视频完成数,不加入权重计算范围内
if (csjWeight > 0) {
weightList.add(WeightBean(csjWeight, Constant.CSJ_EXPRESS_AD))
weight = weight + csjWeight
LogUtil.d(TAG, "EXPRESS权重值:csjWeight:$csjWeight")
}
if (ylhWeight > 0) {
weightList.add(WeightBean(ylhWeight, Constant.YLH_EXPRESS_AD))
weight = weight + ylhWeight
LogUtil.d(TAG, "EXPRESS权重值:ylhWeight:$ylhWeight")
}
if (ksWeight > 0) {
weightList.add(WeightBean(ksWeight, Constant.KS_EXPRESS_AD))
weight = weight + ksWeight
LogUtil.d(TAG, "EXPRESS权重值:ksWeight:$ksWeight")
}
// 权重随机
if (weightList != null && weightList.size > 0 && weight > 0) {
LogUtil.d(TAG, "1、权重总值EXPRESS:$weight")
val r = Random()
var randomWeight = r.nextInt(weight) + 1
LogUtil.d(TAG, "2、权重随机值EXPRESS:$randomWeight")
// ToastUtil.show(MintsApplication.getContext(), "权重随机值:" + randomWeight);
for (weightBean in weightList) {
randomWeight -= weightBean.weight
if (randomWeight <= 0) {
LogUtil.d(TAG, "3、权重结果EXPRESS:" + weightBean.type)
return weightBean.type
}
}
}
return ""
}
fun getADFrameLayout(): FrameLayout? {
if (currentIndex >= 3) currentIndex = 0
// if (currentIndex >= 3) currentIndex = 0
return mAdFrameLayout
}
......@@ -55,22 +125,25 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
}
override fun onTTAdLoadSuc(adFrameLayout: FrameLayout?) {
if (currentIndex == 1) {
// if (currentIndex == 1) {
// mAdFrameLayout = adFrameLayout
// }
mAdFrameLayout = adFrameLayout
}
}
override fun onYlhAdLoadSuc(view: NativeExpressADView?) {
if (currentIndex == 2) {
// if (currentIndex == 2) {
// mAdFrameLayout?.addView(view)
// }
mAdFrameLayout?.addView(view)
}
}
override fun onKSAdLoadSuc(view: View?) {
if (currentIndex == 3) {
// if (currentIndex == 3) {
// mAdFrameLayout?.addView(view)
// }
mAdFrameLayout?.addView(view)
}
}
}
......
......@@ -170,6 +170,11 @@ object Constant {
const val SH_VEDIO_AD = "SH_VEDIO_AD"
const val KS_VEDIO_AD = "KS_VEDIO_AD"
// 信息流广告类型
const val CSJ_EXPRESS_AD = "CSJ_EXPRESS_AD"
const val YLH_EXPRESS_AD = "YLH_EXPRESS_AD"
const val KS_EXPRESS_AD = "KS_EXPRESS_AD"
// 游戏类型
const val EVENT_TYPE_CLICK = "CLICK"
const val EVENT_TYPE_TIME = "TIME"
......
package com.mints.goodmoney.manager
import android.app.Application
import com.ireader.ireadersdk.Config
import com.ireader.ireadersdk.IreaderApi
import com.mints.goodmoney.MintsApplication
import java.lang.Exception
......@@ -14,24 +15,28 @@ object ZhangyueManager {
private const val APPID = "10054"
fun onCreateIreader(application: Application) {
try {
IreaderApi.onCreate(application)
val config = Config.Builder()
.setZYAppId(APPID)
.setOaId(MintsApplication.OAID)
.setSupportCSJ(true)
.setSupportGDT(true)
.build()
IreaderApi.attachBaseContext(application, config)
} catch (e: Exception) {
e.printStackTrace()
}
// try {
// IreaderApi.onCreate(application)
// val config = Config.Builder()
// .setZYAppId(APPID)
// .setOaId(MintsApplication.OAID)
// .setSupportCSJ(true)
// .setSupportGDT(true)
// .build()
// IreaderApi.attachBaseContext(application, config)
// IreaderApi.attachBaseContext(application)
// IreaderApi.onCreate(application, APPID)
// } catch (e: Exception) {
// e.printStackTrace()
// }
try {
IreaderApi.attachBaseContext(application)
IreaderApi.onCreate(application, APPID)
} catch (e: Exception) {
e.printStackTrace()
}
fun onDestory() {
IreaderApi.onAppExit()
}
}
\ No newline at end of file
......@@ -315,9 +315,7 @@ class DrawNativeVideoActivity : BaseActivity(),
}
kylVideoPresenter.detachView()
if (mLayoutManager != null) {
mLayoutManager!!.setOnViewPagerListener(null)
}
mLayoutManager?.setOnViewPagerListener(null)
}
/**
......
......@@ -73,10 +73,11 @@ class KuYinYuePageFragment(private val targetid: String) : LazyLoadBaseFragment(
val index = position % PAGE_SIZE // 余数
for (i in position until PAGE_SIZE * curPage) {
val curVedioIndex = index / PAGE_SIZE + i
dataList.add(DrawVideoBean(DrawNativeVideoActivity.TYPE_COMMON_ITEM, null,
kylData[index / PAGE_SIZE + i].vedioId,
kylData[index / PAGE_SIZE + i].url,
kylData[index / PAGE_SIZE + i].pvurl))
kylData[curVedioIndex].vedioId,
kylData[curVedioIndex].url,
kylData[curVedioIndex].pvurl))
}
val bundle = Bundle()
......
......@@ -288,6 +288,8 @@ class MyFragment : BaseFragment(),
}
override fun onRefresh(refreshLayout: RefreshLayout) {
onDestoryBroadcastReceiver()
if (userManager.userID.isNotEmpty()) {
myPresenter.getAutoUserHallBaseMsg()
} else {
......
......@@ -8,6 +8,7 @@ import com.ireader.ireadersdk.IreaderApi
import com.mints.goodmoney.R
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.ZhangyueManager
import com.mints.goodmoney.mvp.presenters.BookPresenter
import com.mints.goodmoney.mvp.views.BookView
import com.mints.goodmoney.ui.activitys.AwardActivity
......@@ -52,28 +53,11 @@ class MyZhangyueFragment : LazyLoadBaseFragment(), BookView, IreaderApi.OnReadCh
}
}
override fun onReadStart() {
}
override fun onReadEnd(time: Long) {
// LogUtil.d(TAG, "onReadEnd time:" + time)
// LogUtil.d(TAG, "onReadEnd time(Int):" + (time/1000).toInt())
val seconds = (time / 1000).toInt()
// 阅读5秒以上 保存时长
if (seconds > 5) {
bookPresenter.addReadSeconds(seconds)
}
}
override fun onReadPage(time: Long) {
}
override fun onDestroy() {
super.onDestroy()
IreaderApi.setReadChangeListener(null)
ZhangyueManager.onDestory()
bookPresenter.detachView()
}
......@@ -100,31 +84,31 @@ class MyZhangyueFragment : LazyLoadBaseFragment(), BookView, IreaderApi.OnReadCh
}
}
// override fun addBookShelf(p0: Bundle?) {
// TODO("Not yet implemented")
// }
//
// override fun onReadStart(p0: Bundle?) {
// TODO("Not yet implemented")
// }
//
// override fun onReadEnd(p0: Bundle?) {
// val seconds = (p0!!.getLong(IreaderApi.BOOK_TIME).toLong() / 1000).toInt()
// // 阅读5秒以上 保存时长
// if (seconds > 5) {
// bookPresenter.addReadSeconds(seconds)
// }
// }
//
// override fun onDeleteBook(p0: String?) {
// TODO("Not yet implemented")
// }
//
// override fun onReadPage(p0: Bundle?) {
// TODO("Not yet implemented")
// }
//
// override fun onChangeNight(p0: Boolean) {
// TODO("Not yet implemented")
// }
override fun addBookShelf(p0: Bundle?) {
TODO("Not yet implemented")
}
override fun onReadStart(p0: Bundle?) {
TODO("Not yet implemented")
}
override fun onReadEnd(p0: Bundle?) {
val seconds = (p0!!.getLong(IreaderApi.BOOK_TIME) / 1000).toInt()
// 阅读5秒以上 保存时长
if (seconds > 5) {
bookPresenter.addReadSeconds(seconds)
}
}
override fun onDeleteBook(p0: String?) {
TODO("Not yet implemented")
}
override fun onReadPage(p0: Bundle?) {
TODO("Not yet implemented")
}
override fun onChangeNight(p0: Boolean) {
TODO("Not yet implemented")
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import com.ireader.ireadersdk.IreaderApi
import com.mints.goodmoney.R
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.ZhangyueManager
import com.mints.goodmoney.mvp.presenters.BookPresenter
import com.mints.goodmoney.mvp.views.BookView
import com.mints.goodmoney.ui.activitys.AwardActivity
......@@ -55,25 +56,26 @@ class ZhangyueFragment : LazyLoadBaseFragment(), BookView, IreaderApi.OnReadChan
super.onDestroy()
IreaderApi.setReadChangeListener(null)
ZhangyueManager.onDestory()
bookPresenter.detachView()
}
override fun onReadStart() {
}
override fun onReadEnd(time: Long) {
// LogUtil.d(TAG, "onReadEnd time:" + time)
// LogUtil.d(TAG, "onReadEnd time(Int):" + (time/1000).toInt())
val seconds = (time / 1000).toInt()
// 阅读5秒以上 保存时长
if (seconds > 5) {
bookPresenter.addReadSeconds(seconds)
}
}
override fun onReadPage(time: Long) {
}
// override fun onReadStart() {
// }
//
// override fun onReadEnd(time: Long) {
//// LogUtil.d(TAG, "onReadEnd time:" + time)
//// LogUtil.d(TAG, "onReadEnd time(Int):" + (time/1000).toInt())
//
// val seconds = (time / 1000).toInt()
// // 阅读5秒以上 保存时长
// if (seconds > 5) {
// bookPresenter.addReadSeconds(seconds)
// }
// }
//
// override fun onReadPage(time: Long) {
// }
override fun readSecondsSuc(coin: Int) {
......@@ -99,29 +101,29 @@ class ZhangyueFragment : LazyLoadBaseFragment(), BookView, IreaderApi.OnReadChan
}
}
// override fun addBookShelf(p0: Bundle?) {
// }
//
// override fun onReadStart(p0: Bundle?) {
// }
//
// override fun onReadEnd(p0: Bundle?) {
// // LogUtil.d(TAG, "onReadEnd time:" + time)
//// LogUtil.d(TAG, "onReadEnd time(Int):" + (time/1000).toInt())
//
// val seconds = (p0!!.getLong(IreaderApi.BOOK_TIME).toLong() / 1000).toInt()
// // 阅读5秒以上 保存时长
// if (seconds > 5) {
// bookPresenter.addReadSeconds(seconds)
// }
// }
//
// override fun onDeleteBook(p0: String?) {
// }
//
// override fun onReadPage(p0: Bundle?) {
// }
//
// override fun onChangeNight(p0: Boolean) {
// }
override fun addBookShelf(p0: Bundle?) {
}
override fun onReadStart(p0: Bundle?) {
}
override fun onReadEnd(p0: Bundle?) {
// LogUtil.d(TAG, "onReadEnd time:" + time)
// LogUtil.d(TAG, "onReadEnd time(Int):" + (time/1000).toInt())
val seconds = (p0!!.getLong(IreaderApi.BOOK_TIME).toLong() / 1000).toInt()
// 阅读5秒以上 保存时长
if (seconds > 5) {
bookPresenter.addReadSeconds(seconds)
}
}
override fun onDeleteBook(p0: String?) {
}
override fun onReadPage(p0: Bundle?) {
}
override fun onChangeNight(p0: Boolean) {
}
}
\ 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