Commit ecf43840 authored by jyx's avatar jyx

Merge branch 'dev_kyl' into dev_ad

parents 6fb2b3a3 69c52606
......@@ -269,6 +269,9 @@ dependencies {
// 快手
implementation(name: 'kssdk-ad-3.3.6-publishRelease', ext: 'aar')
// 抖音滑动LayoutManager
implementation(name: 'LayoutManagerGroup', ext: 'aar')
// testImplementation 'junit:junit:4.13'
// androidTestImplementation 'androidx.test.ext:junit:1.1.2'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
......
......@@ -222,6 +222,9 @@
<activity
android:name=".ui.activitys.TaskCpdActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activitys.DrawNativeVideoActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activitys.KylVideoActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
......
......@@ -10,7 +10,6 @@ import com.downloader.PRDownloader
import com.downloader.PRDownloaderConfig
import com.mints.goodmoney.manager.BxmManager.initBxm
import com.mob.MobSDK
import com.tencent.mm.opensdk.openapi.WXAPIFactory
/**
* 子线程初始化SDK
......
package com.mints.goodmoney.ad.draw
import android.app.Activity
import com.bytedance.sdk.openadsdk.AdSlot
import com.bytedance.sdk.openadsdk.TTAdNative
import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.bytedance.sdk.openadsdk.TTRewardVideoAd
import com.mints.goodmoney.manager.TTNativeExpressManager
import com.mints.goodmoney.manager.TtCsjAdManager
import com.mints.goodmoney.utils.LogUtil
import com.mints.goodmoney.utils.UIUtils
class CsjDrawAdManager private constructor(activity: Activity) {
companion object {
private var _inst: CsjDrawAdManager? = null
fun getInstance(activity: Activity): CsjDrawAdManager? {
return if (_inst != null) {
_inst
} else {
_inst = CsjDrawAdManager(activity)
_inst
}
}
}
private var activity: Activity? = null
private var ttAdNative: TTAdNative? = null
private var mttRewardVideoAd: TTRewardVideoAd? = null
private var csjDrawAdListener: CsjDrawAdListener? = null
init {
this.activity = activity
val ttNativeExpressManager = TTNativeExpressManager()
ttAdNative = ttNativeExpressManager.initTTAd(false)
}
fun loadDrawNativeAd(activity: Activity, adCount: Int) {
this.activity = activity
//step3:创建广告请求参数AdSlot,具体参数含义参考文档
val expressViewWidth: Float = UIUtils.getScreenWidthDp(activity)
val expressViewHeight: Float = UIUtils.getHeight(activity)
val adSlot = AdSlot.Builder()
.setCodeId(TtCsjAdManager.TT_AD_EXPRESS_DRAW)
.setExpressViewAcceptedSize(expressViewWidth, expressViewHeight)
.setAdCount(adCount) //请求广告数量为1到3条
.build()
mttRewardVideoAd?.setRewardAdInteractionListener(null)
//step4:请求广告,对请求回调的广告作渲染处理
ttAdNative?.loadExpressDrawFeedAd(adSlot, object : TTAdNative.NativeExpressAdListener {
override fun onError(p0: Int, p1: String?) {
// ToastUtil.show(activity, p1)
LogUtil.d(p1)
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail()
}
override fun onNativeExpressAdLoad(p0: MutableList<TTNativeExpressAd>?) {
if (p0 == null || p0.isEmpty()) {
// ToastUtil.show(activity, "未请求到广告")
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail()
LogUtil.d("未请求到广告")
return
}
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdSuccess(p0)
}
})
}
fun setCsjDrawAdListener(csjDrawAdListener: CsjDrawAdListener?) {
this.csjDrawAdListener = csjDrawAdListener
}
interface CsjDrawAdListener {
fun csjDrawAdFail()
fun csjDrawAdSuccess(data: MutableList<TTNativeExpressAd>?)
}
fun onDestroy() {
this.csjDrawAdListener = null
mttRewardVideoAd?.setRewardAdInteractionListener(null)
activity = null
}
}
\ No newline at end of file
......@@ -108,7 +108,9 @@ object DownloadApkManager {
.build()
.setOnProgressListener { progress ->
if (activity != null && !activity!!.isFinishing) {
downloadProgressDialog?.setProgress(progress)
activity!!.runOnUiThread {
downloadProgressDialog?.setProgress(progress)
}
}
}
.start(object : OnDownloadListener {
......@@ -126,7 +128,7 @@ object DownloadApkManager {
}
override fun onError(error: Error) {
if (activity != null && !activity!!.isFinishing()) {
if (activity != null && !activity!!.isFinishing) {
downloadProgressDialog?.dismiss()
CacheUtil.clearAllCache()
}
......
package com.mints.goodmoney.manager;
import android.content.Context;
import android.text.TextUtils;
import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.mints.goodmoney.BuildConfig;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.common.AppConfig;
import com.mints.goodmoney.common.Constant;
import com.mints.goodmoney.mvp.model.AdcodeBean;
import com.mints.goodmoney.mvp.model.UserMsgBean;
import com.mints.library.utils.CommonUtils;
/**
......@@ -59,6 +56,9 @@ public class TtCsjAdManager {
public static String TT_AD_INSERT_LOADING_ID_LIEBAO = "945608874";//猎豹游戏加载时
public static String TT_AD_INSERT_LOADING_ID_JULEYUN = "945675533";//聚乐云
/*全屏Draw信息流*/
public static String TT_AD_EXPRESS_DRAW = "945858858";//讯飞信息流
private static boolean sInit;
public static com.bytedance.sdk.openadsdk.TTAdManager get() {
......
package com.mints.goodmoney.mvp.model;
import android.os.Parcel;
import android.os.Parcelable;
import com.bytedance.sdk.openadsdk.TTNativeExpressAd;
public class DrawVideoBean implements Parcelable {
public int type = 0;
public TTNativeExpressAd ad;
public String videoId;
public String videoUrl;
public String ImgId;
public DrawVideoBean(int type, TTNativeExpressAd ad, String videoId, String videoUrl, String imgId) {
this.type = type;
this.ad = ad;
this.videoId = videoId;
this.videoUrl = videoUrl;
ImgId = imgId;
}
protected DrawVideoBean(Parcel in) {
type = in.readInt();
videoId = in.readString();
videoUrl = in.readString();
ImgId = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(type);
dest.writeString(videoId);
dest.writeString(videoUrl);
dest.writeString(ImgId);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<DrawVideoBean> CREATOR = new Creator<DrawVideoBean>() {
@Override
public DrawVideoBean createFromParcel(Parcel in) {
return new DrawVideoBean(in);
}
@Override
public DrawVideoBean[] newArray(int size) {
return new DrawVideoBean[size];
}
};
}
......@@ -3,6 +3,7 @@ package com.mints.goodmoney.mvp.presenters
import com.google.gson.JsonObject
import com.mints.goodmoney.manager.AppHttpManager
import com.mints.goodmoney.mvp.model.BaseResponse
import com.mints.goodmoney.mvp.model.KylBean
import com.mints.goodmoney.mvp.views.KylVideoView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
......@@ -10,6 +11,36 @@ import java.util.*
class KylVideoPresenter : BasePresenter<KylVideoView>() {
fun getXfPageMsg(targetid:String,page: Int,pageCount: Int) {
val vo = HashMap<String, Any>()
vo["targetid"] = targetid
vo["page"] = page
vo["size"] = pageCount
AppHttpManager.getInstance(loanApplication)
.call(loanService.getXfPageMsg(vo),
object : BaseSubscriber<BaseResponse<KylBean>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.getXfPageMsgFail()
}
override fun onNext(baseResponse: BaseResponse<KylBean>) {
if (isLinkView) return
val code = baseResponse.getStatus()
when (code) {
200 -> {
view.getXfPageMsgSuc(baseResponse.data)
}
else -> view.showToast(baseResponse.getMessage())
}
}
})
}
fun addReadSeconds(seconds: Int) {
val vo = HashMap<String, Any>()
vo["seconds"] = seconds
......
package com.mints.goodmoney.mvp.views
import com.mints.goodmoney.mvp.model.KylBean
interface KylVideoView : BaseView {
interface KylVideoView : BaseView {
fun getXfPageMsgSuc(data: KylBean)
fun getXfPageMsgFail()
}
\ No newline at end of file
......@@ -374,9 +374,14 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
}
override fun onDestroy() {
super.onDestroy()
AppConfig.isSuperTask = false
if (mReceiverBroadcastReceiver != null) {
mContext.stopService(Intent(context, AppInstallService::class.java))
mContext.unregisterReceiver(mReceiverBroadcastReceiver)
mReceiverBroadcastReceiver = null
}
awardPresenter.setHighTaskType("0")
mTimer?.stop()
......@@ -395,14 +400,9 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
videoAdingManager.setVideoAdingListener(null)
videoAdingManager.onDestory()
if (mReceiverBroadcastReceiver != null) {
mContext.stopService(Intent(context, AppInstallService::class.java))
mContext.unregisterReceiver(mReceiverBroadcastReceiver)
mReceiverBroadcastReceiver = null
}
awardPresenter.detachView()
super.onDestroy()
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
......
package com.mints.goodmoney.ui.activitys
import android.Manifest
import android.content.Context
import android.content.ContextWrapper
import android.media.MediaPlayer
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.VideoView
import androidx.recyclerview.widget.OrientationHelper
import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.dingmouren.layoutmanagergroup.viewpager.OnViewPagerListener
import com.dingmouren.layoutmanagergroup.viewpager.ViewPagerLayoutManager
import com.downloader.Error
import com.downloader.OnDownloadListener
import com.downloader.PRDownloader
import com.mints.goodmoney.R
import com.mints.goodmoney.ad.draw.CsjDrawAdManager
import com.mints.goodmoney.ad.video.VideoAdingManager
import com.mints.goodmoney.call.business.VideoDBHelper
import com.mints.goodmoney.call.detail.DetailApplyActivity
import com.mints.goodmoney.call.permission.PermissionActivity
import com.mints.goodmoney.call.permission.PermissionManager
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.DrawVideoBean
import com.mints.goodmoney.mvp.model.KylBean
import com.mints.goodmoney.mvp.model.VideoAdingBean
import com.mints.goodmoney.mvp.presenters.KylVideoPresenter
import com.mints.goodmoney.mvp.views.KylVideoView
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.adapter.DrawVideoAdapter
import com.mints.goodmoney.utils.MD5
import com.mints.goodmoney.utils.ToastUtil
import com.tbruyelle.rxpermissions.RxPermissions
import kotlinx.android.synthetic.main.activity_draw_native_video.*
private const val TAG = "DrawNativeVideoActivity"
/**
* 描述:讯飞彩铃展示
*
*/
class DrawNativeVideoActivity : BaseActivity(),
View.OnClickListener,
CsjDrawAdManager.CsjDrawAdListener,
KylVideoView {
override fun getContentViewLayoutID() = R.layout.activity_draw_native_video
override fun isApplyKitKatTranslucency() = false
companion object {
const val TYPE_COMMON_ITEM = 1
const val TYPE_AD_ITEM = 2
// 当前数据page
const val CURRENT_PAGE = "CURRENT_PAGE"
// 传递过来的数据
const val VIDEO_DATA = "VIDEO_DATA"
// 请求视频的target_id
const val TARGET_ID = "TARGET_ID"
// 广告插入数值
const val AD_INSERT_INDEX = 3
// 来电秀跳转地址
const val WEB_VIDEO_URL = "https://vring.kuyin123.com/friend/94aa83142f7f5c98?videoId="
}
// 列表页面播放page
private var mCurrentPage = 0
// 当前播放视频下标
private var mCurrentPlayIndex = 0
// 当前播放视频数据源
private val drawDatas: MutableList<DrawVideoBean> = mutableListOf()
// 广告请求次数
private var mAdPage = 0
// targerId 视频类别
private var targerId = ""
private val kylVideoPresenter by lazy { KylVideoPresenter() }
private lateinit var videoAdingManager: VideoAdingManager
private var downloadVedioSucFlag = false // 下载视频成功
private var videoPathName = "" // 视频下载名称
private var downloadId: Int = -1 // video下载id
private var loadVideoFailCount = 0
private var mDrawVideoAdapter: DrawVideoAdapter? = null
private var mLayoutManager: ViewPagerLayoutManager? = null
private var mCsjDrawAdManager: CsjDrawAdManager? = null
override fun getBundleExtras(extras: Bundle?) {
super.getBundleExtras(extras)
mCurrentPage = extras?.getInt(CURRENT_PAGE, 0)!!
targerId = extras.getString(TARGET_ID, "")
val parcelableArrayList = extras.getParcelableArrayList<DrawVideoBean>(VIDEO_DATA)
if (parcelableArrayList != null) {
drawDatas.addAll(parcelableArrayList)
}
}
override fun initViewsAndEvents() {
kylVideoPresenter.attachView(this)
mCsjDrawAdManager = CsjDrawAdManager.getInstance(this)
mCsjDrawAdManager?.setCsjDrawAdListener(this)
mLayoutManager = ViewPagerLayoutManager(this, OrientationHelper.VERTICAL)
mDrawVideoAdapter = DrawVideoAdapter(this, drawDatas)
recy_draw_native.layoutManager = mLayoutManager
recy_draw_native.adapter = mDrawVideoAdapter
videoAdingManager = VideoAdingManager.getInstance(this)
// 第一次加载广告
if (drawDatas.size > AD_INSERT_INDEX) {
mCsjDrawAdManager?.loadDrawNativeAd(this, 2)
} else {
mCsjDrawAdManager?.loadDrawNativeAd(this, 1)
}
initListener()
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.ivBack -> finish()
R.id.ivVedio -> {
val bundle = Bundle()
bundle.putString(WebActivity.WEB_TITLE, "开通视频彩铃")
bundle.putString(WebActivity.WEB_URL, WEB_VIDEO_URL + drawDatas[mCurrentPlayIndex].videoId)
readyGo(WebActivity::class.java, bundle)
}
R.id.ivSetting -> {
if (downloadVedioSucFlag) {
readyGo()
return
}
RxPermissions(this)
.request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
.subscribe { granted: Boolean ->
if (granted) {
downloadVideoToCacheFile()
awardVideo()
} else {
showMissingPermissionDialog("存储")
}
}
}
}
}
private fun playVideo(position: Int) {
if (isFinishing) {
return
}
val itemView: View = recy_draw_native.getChildAt(0) ?: return
val videoLayout = itemView.findViewById<FrameLayout>(R.id.video_layout)
val view = videoLayout.getChildAt(0)
if (view !is VideoView) {
Log.e(TAG, "view not instanceof VideoView")
return
}
val videoView = videoLayout.getChildAt(0) as VideoView
val imgPlay = itemView.findViewById<ImageView>(R.id.img_play)
val imgThumb = itemView.findViewById<ImageView>(R.id.img_thumb)
val mediaPlayer = arrayOfNulls<MediaPlayer>(1)
videoView.start()
videoView.setOnInfoListener { mp, what, extra ->
mediaPlayer[0] = mp
Log.e(TAG, "onInfo")
mp.isLooping = true
imgThumb.animate().alpha(0f).setDuration(200).start()
false
}
videoView.setOnPreparedListener { Log.e(TAG, "onPrepared") }
videoView.setOnClickListener(object : View.OnClickListener {
var isPlaying = true
override fun onClick(v: View) {
isPlaying = if (videoView.isPlaying) {
Log.e(TAG, "isPlaying:" + videoView.isPlaying)
imgPlay.animate().alpha(1f).start()
videoView.pause()
false
} else {
Log.e(TAG, "isPlaying:" + videoView.isPlaying)
imgPlay.animate().alpha(0f).start()
videoView.start()
true
}
}
})
}
private fun downloadVideoToCacheFile() {
downloadVedioSucFlag = false
val videoPath: String = try {
getExternalFilesDir(null)!!.absolutePath + "/video/"
} catch (e: java.lang.Exception) {
filesDir.absolutePath + "/video/"
}
val videoName = MD5.GetMD5Code(System.currentTimeMillis().toString() +
UserManager.getInstance().userID + drawDatas[mCurrentPlayIndex].videoId) + ".mp4"
videoPathName = videoPath + videoName
downloadId = PRDownloader.download(drawDatas[mCurrentPlayIndex].videoUrl, videoPath, videoName)
.build()
.start(object : OnDownloadListener {
override fun onDownloadComplete() {
downloadVedioSucFlag = true
}
override fun onError(error: Error) {
}
})
}
private fun releaseVideo(index: Int) {
if (isFinishing) {
return
}
val itemView: View = recy_draw_native.getChildAt(index)
val videoLayout = itemView.findViewById<FrameLayout>(R.id.video_layout) ?: return
val view = videoLayout.getChildAt(0)
if (view is VideoView) {
val videoView = videoLayout.getChildAt(0) as VideoView
val imgThumb = itemView.findViewById<ImageView>(R.id.img_thumb)
val imgPlay = itemView.findViewById<ImageView>(R.id.img_play)
videoView.stopPlayback()
imgThumb.animate().alpha(1f).start()
imgPlay.animate().alpha(0f).start()
}
}
private fun initListener() {
ivBack.setOnClickListener(this)
ivVedio.setOnClickListener(this)
ivSetting.setOnClickListener(this)
mLayoutManager?.setOnViewPagerListener(object : OnViewPagerListener {
override fun onInitComplete() {
onLayoutComplete()
}
override fun onPageRelease(isNext: Boolean, position: Int) {
Log.e(TAG, "释放位置:$position 下一页:$isNext")
val index: Int = if (isNext) {
0
} else {
1
}
if (drawDatas[position].type == TYPE_COMMON_ITEM) {
releaseVideo(index)
}
}
override fun onPageSelected(position: Int, isBottom: Boolean) {
Log.e(TAG, "选中位置:$position 是否是滑动到底部:$isBottom")
mCurrentPlayIndex = position
if (drawDatas[position].type == TYPE_COMMON_ITEM) {
playVideo(0)
changeBottomTopLayoutVisibility(true)
} else {
changeBottomTopLayoutVisibility(false)
}
if (isBottom) {
loadMoreData()
}
}
private fun onLayoutComplete() {
if (drawDatas[0].type == TYPE_COMMON_ITEM) {
playVideo(0)
changeBottomTopLayoutVisibility(true)
} else {
changeBottomTopLayoutVisibility(false)
}
}
})
}
private fun loadMoreData() {
mCurrentPage++
kylVideoPresenter.getXfPageMsg(targerId, mCurrentPage, 3)
}
private fun changeBottomTopLayoutVisibility(visibility: Boolean) {
ivVedio.visibility = if (visibility) View.VISIBLE else View.GONE
ivSetting.visibility = if (visibility) View.VISIBLE else View.GONE
}
override fun onDestroy() {
mCsjDrawAdManager?.onDestroy()
videoAdingManager.setVideoAdingListener(null)
videoAdingManager.onDestory()
releaseVideo(mCurrentPlayIndex)
super.onDestroy()
if (downloadId != -1) {
PRDownloader.cancel(downloadId)
}
kylVideoPresenter.detachView()
if (mLayoutManager != null) {
mLayoutManager!!.setOnViewPagerListener(null)
}
}
/**
* 获取激励视频
*/
private fun awardVideo() {
if (videoAdingManager.videoFinishFlag) {
showToast("今日视频已看完,请明天再来吧")
return
}
loadVideoFailCount = 0
showLoading("加载中...")
val bean = VideoAdingBean()
bean.carrierType = Constant.CARRIER_KUYINYUE_VEDIO
loadVideo(videoAdingManager, bean, true)
}
/**
* 加载激励视频
*/
private fun loadVideo(videoAdingManager: VideoAdingManager, bean: VideoAdingBean, isFirstLoad: Boolean) {
videoAdingManager.setVideoAdingListener(object : VideoAdingManager.VideoAdingListener {
override fun videoAdingListenerError(adType: String) {
showToast("加载超时,请休息一下")
hideLoading()
}
override fun videoAdingListenerFail(adType: String) {
loadVideoFailCount++
if (loadVideoFailCount >= 2) {
hideLoading()
showToast("加载失败,请稍后重试!")
} else {
loadVideo(videoAdingManager, bean, false)
}
}
override fun videoAdingListenerSuccess(adType: String) {
hideLoading()
vedioAdingSuccess(adType)
}
})
if (isFirstLoad) {
// 首页按权重加载
videoAdingManager.loadAding(this, bean)
} else {
// 失败按优先级加载
videoAdingManager.loadFailAding(this, bean)
}
}
private fun vedioAdingSuccess(adType: String) {
if (!downloadVedioSucFlag || TextUtils.isEmpty(videoPathName)) {
showToast("视频处理中,请稍候")
return
}
readyGo()
}
private fun readyGo() {
if (PermissionManager.getInstance().checkEssential(this)) {
VideoDBHelper.getInstance().setSelectVideo(this, VideoDBHelper.UNKNOWN_NUMBER, videoPathName)
DetailApplyActivity.startSelf(this, videoPathName, true)
} else {
PermissionActivity.startSelf(this)
}
}
override fun csjDrawAdFail() {
showToast("加载失败,请稍候再试")
finish()
}
override fun csjDrawAdSuccess(ads: MutableList<TTNativeExpressAd>?) {
if (ads == null || ads.isEmpty()) {
ToastUtil.show(this, "请求广告为空")
return
}
for (ad in ads) {
//点击监听器必须在getAdView之前调
ad.setVideoAdListener(object : TTNativeExpressAd.ExpressVideoAdListener {
override fun onVideoLoad() {
}
override fun onVideoError(p0: Int, p1: Int) {
}
override fun onVideoAdStartPlay() {
}
override fun onVideoAdPaused() {
}
override fun onVideoAdContinuePlay() {
}
override fun onProgressUpdate(p0: Long, p1: Long) {
}
override fun onVideoAdComplete() {
}
override fun onClickRetry() {
}
})
ad.setCanInterruptVideoPlay(true)
ad.setExpressInteractionListener(object : TTNativeExpressAd.ExpressAdInteractionListener {
override fun onAdClicked(p0: View?, p1: Int) {
}
override fun onAdShow(p0: View?, p1: Int) {
}
override fun onRenderFail(p0: View?, p1: String?, p2: Int) {
}
override fun onRenderSuccess(p0: View?, p1: Float, p2: Float) {
// 数据源每次刷新添加3个视频加1个广告 则需+1
var index = drawDatas.size / (AD_INSERT_INDEX + 1) + mAdPage * AD_INSERT_INDEX
if (index == 0) {
index++
}
drawDatas.add(index, DrawVideoBean(TYPE_AD_ITEM, ad, "", "", ""))
// 列表只展示当前数据
mDrawVideoAdapter?.notifyItemInserted(mCurrentPlayIndex + 1)
mAdPage++
}
})
ad.render()
}
}
override fun getXfPageMsgSuc(data: KylBean) {
for (data in data.data) {
drawDatas.add(DrawVideoBean(TYPE_COMMON_ITEM, null, data.vedioId, data.url, data.pvurl))
}
mCsjDrawAdManager?.loadDrawNativeAd(this, 1)
}
override fun getXfPageMsgFail() {
showToast("加载失败,请稍候再试")
finish()
}
override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase)
// 处理VideoView setVideoPath方法中 AudioManager对Activity持有强引用,导致内存泄漏
object : ContextWrapper(newBase) {
override fun getSystemService(name: String): Any {
if (Context.AUDIO_SERVICE == name)
return applicationContext.getSystemService(name)
return super.getSystemService(name)
}
}
}
}
......@@ -16,6 +16,7 @@ import com.mints.goodmoney.call.permission.PermissionActivity
import com.mints.goodmoney.call.permission.PermissionManager
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.KylBean
import com.mints.goodmoney.mvp.model.VideoAdingBean
import com.mints.goodmoney.mvp.presenters.KylVideoPresenter
import com.mints.goodmoney.mvp.views.KylVideoView
......@@ -133,11 +134,10 @@ class KylVideoActivity : BaseActivity(), View.OnClickListener, KylVideoView {
private fun downloadVedioToCacheFile() {
downloadVedioSucFlag = false
var vedioPath = ""
try {
vedioPath = getExternalFilesDir(null)!!.absolutePath + "/video/"
var vedioPath: String = try {
getExternalFilesDir(null)!!.absolutePath + "/video/"
} catch (e: java.lang.Exception) {
vedioPath = filesDir.absolutePath + "/video/"
filesDir.absolutePath + "/video/"
}
val vedioName = MD5.GetMD5Code(System.currentTimeMillis().toString() + UserManager.getInstance().userID + videoUrl) + ".mp4"
vedioPathName = vedioPath + vedioName
......@@ -225,4 +225,10 @@ class KylVideoActivity : BaseActivity(), View.OnClickListener, KylVideoView {
PermissionActivity.startSelf(this)
}
}
override fun getXfPageMsgSuc(data: KylBean) {
}
override fun getXfPageMsgFail() {
}
}
package com.mints.goodmoney.ui.adapter
import android.content.Context
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import com.mints.goodmoney.R
import com.mints.goodmoney.call.widget.CustomVideoView
import com.mints.goodmoney.mvp.model.DrawVideoBean
import com.mints.goodmoney.ui.activitys.DrawNativeVideoActivity
import com.mints.goodmoney.ui.adapter.listener.OnItemClickListener
import com.mints.library.utils.GlideUtils
class DrawVideoAdapter(context: Context, datas: List<DrawVideoBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var mContext: Context = context
private var mDrawVideoData: List<DrawVideoBean> = datas
private var mOnItemClickListener: OnItemClickListener? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(mContext).inflate(R.layout.item_view_pager, parent, false)
return ViewHolder(view)
}
override fun getItemViewType(position: Int): Int {
return mDrawVideoData[position].type
}
override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {
val holder = viewHolder as ViewHolder
var view: View? = View(mContext)
val item: DrawVideoBean? = mDrawVideoData[position]
if (item?.type == DrawNativeVideoActivity.TYPE_COMMON_ITEM) {
GlideUtils.loadImageView(mContext, item.ImgId, holder.img_thumb)
view = getView()
(view as VideoView).setVideoURI(Uri.parse(mDrawVideoData[position].videoUrl))
} else if (item?.type == DrawNativeVideoActivity.TYPE_AD_ITEM && item.ad != null) {
view = item.ad.expressAdView
}
holder.videoLayout.removeAllViews()
if (view?.parent != null) {
(view.parent as ViewGroup).removeView(view)
}
holder.videoLayout.addView(view)
if (item != null) {
changeUIVisibility(holder, item.type)
}
}
private fun changeUIVisibility(holder: ViewHolder, type: Int) {
var visibilable = true
if (type == DrawNativeVideoActivity.TYPE_AD_ITEM) {
visibilable = false
}
holder.img_play.visibility = if (visibilable) View.VISIBLE else View.GONE
holder.img_thumb.visibility = if (visibilable) View.VISIBLE else View.GONE
}
private fun getView(): View {
val videoView = CustomVideoView(mContext)
val layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
videoView.layoutParams = layoutParams
return videoView
}
override fun getItemCount(): Int {
return mDrawVideoData.size
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val img_thumb: ImageView = itemView.findViewById(R.id.img_thumb)
val img_play: ImageView = itemView.findViewById(R.id.img_play)
val rootView: RelativeLayout = itemView.findViewById(R.id.root_view)
val videoLayout: FrameLayout = itemView.findViewById(R.id.video_layout)
}
fun setOnItemClickListener(listener: OnItemClickListener) {
mOnItemClickListener = listener
}
}
\ No newline at end of file
......@@ -168,14 +168,15 @@ class KylPageAdapter(val kylPageList: MutableList<KylBean.Data>) :
private fun bindDislikeCustom(dislike: View, ad: TTFeedAd) {
val ttAdDislike = ad.getDislikeDialog(context as Activity?)
if (ttAdDislike != null) {
ad.getDislikeDialog(context as Activity?).setDislikeInteractionCallback(object : DislikeInteractionCallback {
override fun onSelected(position: Int, value: String) {
}
override fun onCancel() {}
override fun onRefuse() {}
})
}
// if (ttAdDislike != null) {
// ad.getDislikeDialog(context as Activity?).setDislikeInteractionCallback(object : DislikeInteractionCallback {
// override fun onSelected(position: Int, value: String) {
// }
// override fun onCancel() {}
// override fun onRefuse() {}
// })
// }
dislike.setOnClickListener { ttAdDislike!!.showDislikeDialog() }
}
......
......@@ -5,10 +5,11 @@ import androidx.recyclerview.widget.GridLayoutManager
import com.bytedance.sdk.openadsdk.*
import com.mints.goodmoney.R
import com.mints.goodmoney.manager.TtCsjAdManager
import com.mints.goodmoney.mvp.model.DrawVideoBean
import com.mints.goodmoney.mvp.model.KylBean
import com.mints.goodmoney.mvp.presenters.KuYinYuePagePresenter
import com.mints.goodmoney.mvp.views.KuYinYuePageView
import com.mints.goodmoney.ui.activitys.KylVideoActivity
import com.mints.goodmoney.ui.activitys.DrawNativeVideoActivity
import com.mints.goodmoney.ui.adapter.KylPageAdapter
import com.mints.goodmoney.ui.fragment.base.LazyLoadBaseFragment
import com.mints.goodmoney.utils.LogUtil
......@@ -62,11 +63,27 @@ class KuYinYuePageFragment(private val targetid: String) : LazyLoadBaseFragment(
}
override fun onItemClick(position: Int) {
if (kylData != null && kylData.size > 0) {
if (kylData.size > 0) {
// val bundle = Bundle()
// bundle.putString(KylVideoActivity.VIDEO_URL, kylData[position].url)
// bundle.putString(KylVideoActivity.VIDEO_ID, kylData[position].vedioId)
// readyGo(KylVideoActivity::class.java, bundle)
val dataList = arrayListOf<DrawVideoBean>()
val index = position % PAGE_SIZE // 余数
for (i in position until PAGE_SIZE * curPage) {
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))
}
val bundle = Bundle()
bundle.putString(KylVideoActivity.VIDEO_URL, kylData[position].url)
bundle.putString(KylVideoActivity.VIDEO_ID, kylData[position].vedioId)
readyGo(KylVideoActivity::class.java, bundle)
bundle.putParcelableArrayList(DrawNativeVideoActivity.VIDEO_DATA, dataList)
bundle.putInt(DrawNativeVideoActivity.CURRENT_PAGE, curPage)
bundle.putString(DrawNativeVideoActivity.TARGET_ID, targetid)
readyGo(DrawNativeVideoActivity::class.java, bundle)
}
}
......@@ -156,7 +173,7 @@ class KuYinYuePageFragment(private val targetid: String) : LazyLoadBaseFragment(
}
override fun onFeedAdLoad(ads: List<TTFeedAd>) {
if (ads == null || ads.isEmpty()) {
if (ads.isEmpty()) {
getXfPageMsg()
return
}
......
......@@ -652,7 +652,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
mRedBoxTimer?.setOnCountDownTimerListener(object : OnCountDownTimerListener {
override fun onTick(millisUntilFinished: Long) {
if (isAdded && !requireActivity().isFinishing) {
stopRedbox()
// stopRedbox()
tv_fragment_main_redbox.text = TimeRender.ms2MS(millisUntilFinished.toInt())
}
}
......
......@@ -10,7 +10,6 @@ import android.widget.ImageView
import android.widget.TextView
import com.downloader.PRDownloader
import com.downloader.Progress
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.utils.CacheUtil
import com.mints.goodmoney.utils.Utils
......
package com.mints.goodmoney.utils;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.DisplayCutout;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created by bytedance on 2019/9/5.
*/
public class UIUtils {
public static float getScreenWidthDp(Context context){
final float scale = context.getResources().getDisplayMetrics().density;
float width = context.getResources().getDisplayMetrics().widthPixels;
return width / (scale <= 0 ? 1 : scale) + 0.5f;
}
//全面屏、刘海屏适配
public static float getHeight(Activity activity) {
hideBottomUIMenu(activity);
float height;
int realHeight = getRealHeight(activity);
if (UIUtils.hasNotchScreen(activity)) {
height = px2dip(activity, realHeight - getStatusBarHeight(activity));
}else {
height = px2dip(activity, realHeight);
}
return height;
}
public static void hideBottomUIMenu(Activity activity) {
if (activity == null) {
return;
}
try {
//隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = activity.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = activity.getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
// | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE;
decorView.setSystemUiVisibility(uiOptions);
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
} catch (Exception e) {
e.printStackTrace();
}
}
//获取屏幕真实高度,不包含下方虚拟导航栏
public static int getRealHeight(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
display.getRealMetrics(dm);
} else {
display.getMetrics(dm);
}
int realHeight = dm.heightPixels;
return realHeight;
}
//获取状态栏高度
public static float getStatusBarHeight(Context context) {
float height = 0;
int resourceId = context.getApplicationContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
height = context.getApplicationContext().getResources().getDimensionPixelSize(resourceId);
}
return height;
}
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / (scale <= 0 ? 1 : scale) + 0.5f);
}
/**
* 判断是否是刘海屏
* @return
*/
public static boolean hasNotchScreen(Activity activity){
return isAndroidPHasNotch(activity)
|| getInt("ro.miui.notch", activity) == 1
|| hasNotchAtHuawei(activity)
|| hasNotchAtOPPO(activity)
|| hasNotchAtVivo(activity);
}
/**
* Android P 刘海屏判断
* @param activity
* @return
*/
public static boolean isAndroidPHasNotch(Activity activity){
boolean result = false;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
DisplayCutout displayCutout = null;
try {
WindowInsets windowInsets = activity.getWindow().getDecorView().getRootWindowInsets();
if (windowInsets != null) {
displayCutout = windowInsets.getDisplayCutout();
}
if (displayCutout != null) {
result = true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
/**
* 小米刘海屏判断.
* @return 0 if it is not notch ; return 1 means notch
* @throws IllegalArgumentException if the key exceeds 32 characters
*/
public static int getInt(String key, Activity activity) {
int result = 0;
if (isMiui()){
try {
ClassLoader classLoader = activity.getClassLoader();
@SuppressWarnings("rawtypes")
Class SystemProperties = classLoader.loadClass("android.os.SystemProperties");
//参数类型
@SuppressWarnings("rawtypes")
Class[] paramTypes = new Class[2];
paramTypes[0] = String.class;
paramTypes[1] = int.class;
Method getInt = SystemProperties.getMethod("getInt", paramTypes);
//参数
Object[] params = new Object[2];
params[0] = new String(key);
params[1] = new Integer(0);
result = (Integer) getInt.invoke(SystemProperties, params);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
return result;
}
/**
* 华为刘海屏判断
* @return
*/
public static boolean hasNotchAtHuawei(Context context) {
boolean ret = false;
try {
ClassLoader classLoader = context.getClassLoader();
Class HwNotchSizeUtil = classLoader.loadClass("com.huawei.android.util.HwNotchSizeUtil");
Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");
ret = (boolean) get.invoke(HwNotchSizeUtil);
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (Exception e) {
} finally {
return ret;
}
}
public static final int VIVO_NOTCH = 0x00000020;//是否有刘海
public static final int VIVO_FILLET = 0x00000008;//是否有圆角
/**
* VIVO刘海屏判断
* @return
*/
public static boolean hasNotchAtVivo(Context context) {
boolean ret = false;
try {
ClassLoader classLoader = context.getClassLoader();
Class FtFeature = classLoader.loadClass("android.util.FtFeature");
Method method = FtFeature.getMethod("isFeatureSupport", int.class);
ret = (boolean) method.invoke(FtFeature, VIVO_NOTCH);
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (Exception e) {
} finally {
return ret;
}
}
/**
* O-P-P-O刘海屏判断
* @return
*/
public static boolean hasNotchAtOPPO(Context context) {
String temp = "com.kllk.feature.screen.heteromorphism";
String name = getKllkDecryptString(temp);
return context.getPackageManager().hasSystemFeature(name);
}
public static boolean isMiui() {
boolean sIsMiui = false;
try {
Class<?> clz = Class.forName("miui.os.Build");
if (clz != null) {
sIsMiui = true;
//noinspection ConstantConditions
return sIsMiui;
}
} catch (Exception e) {
// ignore
}
return sIsMiui;
}
/**
*用于o-p-p-o 版本隐私协议
*/
public static String getKllkDecryptString(String encryptionString) {
if (TextUtils.isEmpty(encryptionString)) {
return "";
}
String decryptTag = "";
String decryptCapitalized = "O" + "P" + "P" + "O";
String decrypt = "o" + "p" + "p" + "o";
if (encryptionString.contains("KLLK")) {
decryptTag = encryptionString.replace("KLLK", decryptCapitalized);
} else if (encryptionString.contains("kllk")) {
decryptTag = encryptionString.replace("kllk", decrypt);
}
return decryptTag;
}
public static void setViewSize(View view, int width, int height) {
if (view.getParent() instanceof FrameLayout) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) view.getLayoutParams();
lp.width = width;
lp.height = height;
view.setLayoutParams(lp);
view.requestLayout();
} else if (view.getParent() instanceof RelativeLayout) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) view.getLayoutParams();
lp.width = width;
lp.height = height;
view.setLayoutParams(lp);
view.requestLayout();
} else if (view.getParent() instanceof LinearLayout) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) view.getLayoutParams();
lp.width = width;
lp.height = height;
view.setLayoutParams(lp);
view.requestLayout();
}
}
}
......@@ -26,9 +26,11 @@ import androidx.core.content.ContextCompat;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.DisplayCutout;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
......
<vector android:alpha="0.61" android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#99ffffff" android:pathData="M8,5v14l11,-7z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recy_draw_native"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ivBack"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:padding="12dp"
android:src="@mipmap/ic_left_arrow" />
<TextView
android:id="@+id/ivVedio"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="100dp"
android:background="@drawable/shape_tv_gold"
android:gravity="center"
android:text="设为视频彩铃"
android:textColor="@color/white" />
<TextView
android:id="@+id/ivSetting"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="40dp"
android:background="@drawable/shape_tv_gold"
android:gravity="center"
android:text="看广告设置来电秀"
android:textColor="@color/white" />
</RelativeLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<FrameLayout
android:id="@+id/video_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false" />
<ImageView
android:id="@+id/img_play"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:alpha="0"
android:clickable="false"
android:focusable="false"
android:src="@drawable/play_arrow" />
<ImageView
android:id="@+id/img_thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:scaleType="fitXY" />
</RelativeLayout>
\ 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