Commit 8d8d5930 authored by mengcuiguang's avatar mengcuiguang

优化banner

parent 4ec161d4
......@@ -8,6 +8,7 @@ import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.manager.TtCsjAdManager
import com.mints.goodmoney.utils.LogUtil
import com.mints.library.utils.DensityUtils
/**
* banner管理
......@@ -19,19 +20,35 @@ object BannerManager {
fun init() {
adNative = TtCsjAdManager.get().createAdNative(MintsApplication.getContext())
// 权限请求
TtCsjAdManager.get().requestPermissionIfNecessary(MintsApplication.getContext())
}
/**
* 获取穿山甲banner
*/
fun getTtBanner(codeId: String, frameLayout: FrameLayout?, viewWidth: Float, viewHeight: Float) {
fun getTtBanner(codeId: String, frameLayout: FrameLayout?) {
var expressViewAcceptedSizeWidth: Float = 380f
var expressViewAcceptedSizeHeight: Float = 280f
var imageAcceptedSizeWidth: Int = 600
var imageAcceptedSizeHeight: Int = 500
when (codeId) {
TtCsjAdManager.TT_AD_BANNER_MY -> {
expressViewAcceptedSizeWidth = 380f
expressViewAcceptedSizeHeight = 280f
imageAcceptedSizeWidth = 600
imageAcceptedSizeHeight = 500
}
}
adNative?.let {
val adSlot = AdSlot.Builder()
.setCodeId(codeId) //广告位id
.setSupportDeepLink(true)
.setAdCount(1) //请求广告数量为1到3条
.setExpressViewAcceptedSize(viewWidth, viewHeight) //期望模板广告view的size,单位dp
.setImageAcceptedSize(viewWidth.toInt(), viewHeight.toInt()) //这个参数设置即可,不影响模板广告的size
.setExpressViewAcceptedSize(expressViewAcceptedSizeWidth, expressViewAcceptedSizeHeight) //期望模板广告view的size,单位dp
.setImageAcceptedSize(imageAcceptedSizeWidth, imageAcceptedSizeHeight) //这个参数设置即可,不影响模板广告的size
.build()
it.loadBannerExpressAd(adSlot, object : TTAdNative.NativeExpressAdListener {
override fun onNativeExpressAdLoad(ads: MutableList<TTNativeExpressAd>?) {
......@@ -43,7 +60,7 @@ object BannerManager {
}
override fun onError(code: Int, msg: String) {
LogUtil.d("BannerManager","onError code:${code} msg:${msg}")
LogUtil.d("BannerManager", "onError code:${code} msg:${msg}")
// frameLayout?.removeAllViews()
}
})
......@@ -63,7 +80,7 @@ object BannerManager {
override fun onRenderSuccess(view: View, p1: Float, p2: Float) {
frameLayout?.let {
it.visibility=View.VISIBLE
it.visibility = View.VISIBLE
it.removeAllViews()
it.addView(view)
}
......
......@@ -28,6 +28,7 @@ import com.mints.goodmoney.ui.fragment.base.BaseFragment
import com.mints.goodmoney.ui.widgets.CustomDialogAsApple
import com.mints.goodmoney.ui.widgets.DialogListener
import com.mints.goodmoney.ui.widgets.ShareDialog
import com.mints.goodmoney.utils.LogUtil
import com.mints.goodmoney.utils.QQJumpUtil
import com.mints.goodmoney.utils.SpanUtils
import com.mints.library.net.netstatus.NetUtils
......@@ -56,6 +57,8 @@ import kotlin.concurrent.schedule
@SuppressLint("SetTextI18n")
class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshListener, View.OnClickListener, AdapterView.OnItemClickListener {
private val TAG = MyFragment::class.java.simpleName
private val ps by lazy { AppPreferences(context) }
private val myPresenter by lazy { MyPresenter() }
private val userManager by lazy { UserManager.getInstance() }
......@@ -87,50 +90,9 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
myPresenter.attachView(this)
srl_my.setOnRefreshListener(this)
BannerManager.init()
vedioAdingManager = VedioAdingManager.getInstance(activity)
initManager()
initView()
initRecy()
if (!TextUtils.isEmpty(userManager.userID)) {
// 登录成功的用户初始化鱼丸盒子
if (userManager.userIsLogin()) {
YwhzManager.init(baseApplication)
}
}
}
private fun initView() {
tv_title.text = "个人中心"
view_title.text = "每日任务"
iv_right_icon.visibility = View.VISIBLE
iv_right_icon.setImageResource(R.mipmap.ic_settings)
iv_right_icon2.visibility = View.VISIBLE
iv_right_icon2.setImageResource(R.mipmap.icon_customer_service)
iv_right_icon2.setOnClickListener(this)
item_title_id.setOnClickListener(this)
iv_right_icon.setOnClickListener(this)
btn_withdraw.setOnClickListener(this)
btn_coinRecord.setOnClickListener(this)
item_title_invitecode.setOnClickListener(this)
item_title_invitecode_copy.setOnClickListener(this)
ll_my_login.setOnClickListener(this)
item_customer_service.setOnClickListener(this)
item_promotions_egv.onItemClickListener = this
}
/**
* 初始化Recyclerview
*/
private fun initRecy() {
recy_my.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recy_my.setItemViewCacheSize(10)
mainMyAdapter = MainMyAdapter(mContext, dataList)
recy_my.adapter = mainMyAdapter
mainMyAdapter?.setOnItemChildClickListener(this)
}
override fun onHiddenChanged(hidden: Boolean) {
......@@ -160,7 +122,7 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
// 防止banner刷新太快
if (AntiShake.check(fl_my_banner?.id)) return
BannerManager.getTtBanner(TtCsjAdManager.TT_AD_BANNER_MY, fl_my_banner, 600f, 500f)
BannerManager.getTtBanner(TtCsjAdManager.TT_AD_BANNER_MY, fl_my_banner)
}
}
......@@ -245,6 +207,8 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
return
}
initAdWeight(data)
// 新人福利
if (data.userMsg.firstGiveCoin > 0) {
val bundle = Bundle()
......@@ -820,4 +784,62 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
})
shareDialog.show()
}
private fun initManager() {
BannerManager.init()
vedioAdingManager = VedioAdingManager.getInstance(activity)
if (!TextUtils.isEmpty(userManager.userID)) {
// 登录成功的用户初始化鱼丸盒子
if (userManager.userIsLogin()) {
YwhzManager.init(baseApplication)
}
}
}
private fun initView() {
tv_title.text = "个人中心"
view_title.text = "每日任务"
iv_right_icon.visibility = View.VISIBLE
iv_right_icon.setImageResource(R.mipmap.ic_settings)
iv_right_icon2.visibility = View.VISIBLE
iv_right_icon2.setImageResource(R.mipmap.icon_customer_service)
iv_right_icon2.setOnClickListener(this)
item_title_id.setOnClickListener(this)
iv_right_icon.setOnClickListener(this)
btn_withdraw.setOnClickListener(this)
btn_coinRecord.setOnClickListener(this)
item_title_invitecode.setOnClickListener(this)
item_title_invitecode_copy.setOnClickListener(this)
ll_my_login.setOnClickListener(this)
item_customer_service.setOnClickListener(this)
item_promotions_egv.onItemClickListener = this
}
/**
* 初始化Recyclerview
*/
private fun initRecy() {
recy_my.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recy_my.setItemViewCacheSize(10)
mainMyAdapter = MainMyAdapter(mContext, dataList)
recy_my.adapter = mainMyAdapter
mainMyAdapter?.setOnItemChildClickListener(this)
}
/**
* 设置视频权重
*/
private fun initAdWeight(data: UserTaskMsgBean) {
vedioAdingManager?.initAdWeight(data.vedioRules.csJ_VEDIO.rate, data.vedioRules.ylH_VEDIO.rate, data.vedioRules.sdhZ_VEDIO.rate)
LogUtil.d(TAG, "首页权重值:csjWeight:${data.vedioRules.csJ_VEDIO.rate} ylhWeight:${data.vedioRules.ylH_VEDIO.rate} sdhzWeight:${data.vedioRules.sdhZ_VEDIO.rate}")
// 广告视频数
AppConfig.csjVedioAdCount = data.vedioRules.csJ_VEDIO.surplus
AppConfig.ylhAdCount = data.vedioRules.ylH_VEDIO.surplus
AppConfig.wnVedioAdCount = data.vedioRules.sdhZ_VEDIO.surplus
LogUtil.d(TAG, "首页视频数:csjCount:${AppConfig.csjVedioAdCount} ylhCount:${AppConfig.ylhAdCount} sdhzCount:${AppConfig.wnVedioAdCount}")
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.widgets
import android.app.Activity
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.wechat.friends.Wechat
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.login.LoginApi
import com.mints.goodmoney.login.OnLoginListener
import com.mints.goodmoney.mvp.model.DrawcashBean
import com.mints.goodmoney.mvp.model.WXInfo
import com.mints.goodmoney.mvp.presenters.SettingsPresenter
import com.mints.goodmoney.mvp.views.SettingsView
import com.mints.goodmoney.ui.activitys.AccountMergeActivity
import com.mints.goodmoney.ui.activitys.AwardActivity
import com.mints.goodmoney.utils.ToastUtil
import com.mints.library.utils.json.JsonUtil
import com.mints.library.utils.nodoubleclick.AntiShake
import java.util.*
/**
* 微信授权弹窗
*/
class BindWxDialog(context: Activity) :
Dialog(context, R.style.dialog), OnLoginListener, SettingsView, View.OnClickListener {
private var loginApi: LoginApi? = null
private var settingsPresenter: SettingsPresenter? = null
private var wxInfo: WXInfo? = null
init {
setContentView(R.layout.dialog_bindwx)
// 设置window属性
val lp = window!!.attributes
lp.gravity = Gravity.CENTER
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.windowAnimations = R.style.DialogAnimBottom
window!!.attributes = lp
// 设置外部不可关闭
setCancelable(false)
setCanceledOnTouchOutside(false)
setOnKeyListener { _, i, _ ->
i == KeyEvent.KEYCODE_BACK
}
findViewById<View>(R.id.btn_dialogper_next).setOnClickListener(this)
loginApi = LoginApi()
settingsPresenter = SettingsPresenter()
settingsPresenter?.attachView(this)
}
override fun dismiss() {
super.dismiss()
loginApi?.setOnLoginListener(null)
settingsPresenter?.detachView()
}
override fun onClick(v: View) {
if (AntiShake.check(v?.id)) return
when (v.id) {
R.id.btn_dialogper_next -> {
val wechat = ShareSDK.getPlatform(Wechat.NAME)
if (!wechat.isClientValid) {
showToast("请先安装微信")
return
}
loginApi?.let {
it.setOnLoginListener(this)
it.setPlatform(Wechat.NAME)
it.login(context)
}
}
}
}
override fun onLogin(platform: String?, res: HashMap<String, Any>): Boolean {
try {
wxInfo = WXInfo()
wxInfo?.let {
it.setUnionid(res["unionid"].toString() + "")
it.setOpenid(res["openid"].toString() + "")
it.setProvince(res["province"].toString() + "")
it.setCity(res["city"].toString() + "")
it.setCountry(res["country"].toString() + "")
it.setHeadimgurl(res["headimgurl"].toString() + "")
it.setNickname(res["nickname"].toString() + "")
it.setSex((res["sex"].toString() + "").toInt())
}
settingsPresenter?.editUserMsg(res["openid"].toString(), JsonUtil.toJson(wxInfo))
} catch (e: Exception) {
e.printStackTrace()
}
return false
}
override fun mergeAccount(mobile: String, wxOpenId: String, key: String) {
val bundle = Bundle()
bundle.putString(Constant.MERGE_MOBILE, mobile)
bundle.putString(Constant.MERGE_WXOPENID, wxOpenId)
bundle.putString(Constant.MERGE_KEY, key)
readyGo(AccountMergeActivity::class.java, bundle)
}
protected fun readyGo(clazz: Class<*>?, bundle: Bundle?) {
val intent = Intent(context, clazz)
if (null != bundle) {
intent.putExtras(bundle)
}
context.startActivity(intent)
}
override fun editUserMsgSuc() {
ToastUtil.show(context, "微信绑定成功")
dismiss()
}
override fun getUserTaskMsgSuc(data: DrawcashBean) {
}
override fun showLoading(msg: String?) {
}
override fun showToast(msg: String?) {
ToastUtil.showLong(context, msg)
}
override fun hideLoading() {
}
override fun getBaseApplication(): MintsApplication {
return MintsApplication.getContext() as MintsApplication
}
}
\ No newline at end of file
<?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">
<LinearLayout
android:layout_width="420dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="@drawable/shape_bg_write"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text="温馨提示"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:background="#E1E1E1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="为了保证您的账户安全\n请先绑定微信"
android:textColor="@color/gray"
android:textSize="14sp" />
<ImageView
android:layout_width="50dp"
android:src="@mipmap/ic_share_wx"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_height="50dp"/>
<TextView
android:id="@+id/btn_dialogper_next"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:layout_marginBottom="20dp"
android:background="@drawable/shape_green"
android:text="去绑定"
android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
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