Commit de5584d9 authored by jyx's avatar jyx

我的页面添加Banner轮播

parent 28a54830
......@@ -7,6 +7,7 @@ import com.bytedance.sdk.openadsdk.TTAdNative
import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.manager.TtCsjAdManager
import com.mints.goodmoney.ui.widgets.seekbar.BubbleUtils
import com.mints.goodmoney.utils.LogUtil
/**
......@@ -35,6 +36,11 @@ object BannerManager {
return pxWidth / density + 0.5f
}
private fun getViewHeight(): Float {
var pxHeight = BubbleUtils.dp2px(150)
return pxHeight.toFloat()
}
/**
* 获取穿山甲banner
*/
......@@ -45,7 +51,7 @@ object BannerManager {
when (codeId) {
TtCsjAdManager.TT_AD_BANNER_MY -> {
expressViewAcceptedSizeWidth = getViewWidth()
expressViewAcceptedSizeHeight = 0f
expressViewAcceptedSizeHeight = getViewHeight()
}
}
......
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
import java.util.List;
public class RotationChartBean implements Serializable {
/**
* show : true
* position : 0
* list : [{"imgUrl":"https://mints-gs2.oss-cn-beijing.aliyuncs.com/activities/jizhun_shuff.jpg","title":"测试","pkg":"com.mints.boxing","url":"http://tuiluck.cn/ssp-hd-h5/activities/rmw58h63","sid":"rotationrotationJzad"},{"imgUrl":"https://yun.tuitiger.com/mami-media/img/qnceuoe04m.png","title":"每日大礼包","pkg":"com.mints.asdfasf","url":"https://engine.tuicoco.com/index/activity?appKey=3JqPn4Kc11qYkuT5jX8nuJSKHJTv&adslotId=340257","sid":"rotationrcBigGift"}]
*/
private boolean show;
private int position;
private List<ListBean> list;
public boolean isShow() {
return show;
}
public void setShow(boolean show) {
this.show = show;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public List<ListBean> getList() {
return list;
}
public void setList(List<ListBean> list) {
this.list = list;
}
public static class ListBean {
/**
* imgUrl : https://mints-gs2.oss-cn-beijing.aliyuncs.com/activities/jizhun_shuff.jpg
* title : 测试
* pkg : com.mints.boxing
* url : http://tuiluck.cn/ssp-hd-h5/activities/rmw58h63
* sid : rotationrotationJzad
*/
private String imgUrl;
private String title;
private String pkg;
private String url;
private String sid;
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPkg() {
return pkg;
}
public void setPkg(String pkg) {
this.pkg = pkg;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
}
}
package com.mints.goodmoney.mvp.presenters
import android.text.TextUtils
import com.google.gson.JsonObject
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.common.DeviceInfo
......@@ -247,7 +248,7 @@ open class MyPresenter : BasePresenter<MyView>() {
}
fun setHighTaskType(carrierType: String, value: String) {
this.setHighTaskType(carrierType,value,"")
this.setHighTaskType(carrierType, value, "")
}
/**
......@@ -309,4 +310,28 @@ open class MyPresenter : BasePresenter<MyView>() {
})
}
fun myRotationChart() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.myRotationChart(),
object : BaseSubscriber<BaseResponse<RotationChartBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
}
override fun onNext(baseResponse: BaseResponse<RotationChartBean>) {
if (isLinkView) return
val code = baseResponse.getStatus()
when (code) {
200 -> view.getMyRotationChartSuc(baseResponse.data)
}
}
})
}
}
\ No newline at end of file
package com.mints.goodmoney.mvp.views
import com.mints.goodmoney.mvp.model.BannerBean
import com.mints.goodmoney.mvp.model.MyInfo
import com.mints.goodmoney.mvp.model.SignCardBean
import com.mints.goodmoney.mvp.model.UserTaskMsgBean
import com.google.gson.JsonObject
import com.mints.goodmoney.mvp.model.*
interface MyView : BaseView {
......@@ -35,4 +33,6 @@ interface MyView : BaseView {
fun userLoginSuc()
fun getHallBaseMsgSuc(data: UserTaskMsgBean)
fun getMyRotationChartSuc(data: RotationChartBean)
}
......@@ -19,6 +19,7 @@ import com.mints.goodmoney.mvp.model.MainVideoMsgBean;
import com.mints.goodmoney.mvp.model.MealBean;
import com.mints.goodmoney.mvp.model.MorningClockBean;
import com.mints.goodmoney.mvp.model.MyInfo;
import com.mints.goodmoney.mvp.model.RotationChartBean;
import com.mints.goodmoney.mvp.model.SignCardBean;
import com.mints.goodmoney.mvp.model.TaskCpdBean;
import com.mints.goodmoney.mvp.model.TurnBean;
......@@ -580,6 +581,7 @@ public interface LoanService {
Observable<BaseResponse<JsonObject>> reportErrornterface(@Body Map<String, Object> vo);
/**
* <<<<<<< Updated upstream
* 获取大转盘信息
*
* @return
......@@ -611,6 +613,14 @@ public interface LoanService {
@POST("api/turn/addTurnToOtherMsg")
Observable<BaseResponse<Object>> addTurnToOtherMsg(@Body Map<String, Object> vo);
/**
*
* 我的页面Banner
* @return
*/
@POST("api/myRotationChart")
Observable<BaseResponse<RotationChartBean>> myRotationChart();
/**
* 默认http工厂
*/
......
......@@ -3,16 +3,22 @@ package com.mints.goodmoney.ui.activitys
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import com.bytedance.hume.readapk.HumeSDK
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.ad.banner.BannerManager
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.TtCsjAdManager
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.adapter.AdBannerAdapter
import com.mints.goodmoney.utils.ToastUtil
import com.mints.library.utils.CommonUtils
import com.mints.library.utils.ConstantUtil
import kotlinx.android.synthetic.main.activity_aboutus.*
import kotlinx.android.synthetic.main.fragment_main_my.*
import kotlinx.android.synthetic.main.header_layout.*
/**
......
package com.mints.goodmoney.ui.adapter;
import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.mints.goodmoney.R;
import com.mints.goodmoney.ad.banner.BannerManager;
import com.mints.goodmoney.manager.TtCsjAdManager;
import com.mints.goodmoney.mvp.model.RotationChartBean;
import com.mints.library.utils.GlideUtils;
/**
* 描述:轮播图Adapter
* 作者:孟崔广
* 时间:2018/5/13 16:36
* 邮箱:mengcg@xiaojinqb.cn
*/
public class AdBannerAdapter extends BannerBaseAdapter<RotationChartBean.ListBean> {
private Context mContext;
private int mCurrentPostion = 0;
public AdBannerAdapter(Context context) {
super(context);
this.mContext = context;
}
public void setAdPosition(int position) {
mCurrentPostion = position;
}
@Override
protected int getLayoutResID() {
return R.layout.item_banner_ad;
}
@Override
protected void convert(View convertView, RotationChartBean.ListBean listBean, int currentPostion) {
FrameLayout container = getView(R.id.ad_container);
if (currentPostion == mCurrentPostion) {
BannerManager.INSTANCE.getTtBanner(TtCsjAdManager.TT_AD_BANNER_MY, container);
} else {
ImageView iv = getView(R.id.iv_banner_ad);
iv.setVisibility(View.VISIBLE);
GlideUtils.loadImageView(mContext, listBean.getImgUrl(), iv);
iv.setOnClickListener(v -> {
if (mOnPageClickListener != null) {
mOnPageClickListener.onPageClick(currentPostion);
}
});
}
}
private OnPageClickListener mOnPageClickListener;
public void setOnPageClickListener(OnPageClickListener onPageClickListener) {
mOnPageClickListener = onPageClickListener;
}
public interface OnPageClickListener {
void onPageClick(int position);
}
}
......@@ -30,7 +30,7 @@ public class BannerAdapter extends BannerBaseAdapter<BannerBean.ListBean> {
}
@Override
protected void convert(View convertView, BannerBean.ListBean data) {
protected void convert(View convertView, BannerBean.ListBean data,int currentPostion) {
if (TextUtils.isEmpty(data.getImgUrl())) {
setImage(R.id.pageImage, 0);
} else {
......
......@@ -75,7 +75,7 @@ public abstract class BannerBaseAdapter<T> extends PagerAdapter {
if (mDatas != null) {
// 处理视图和数据
convert(mConvertView, getItem(position));
convert(mConvertView, getItem(position), position);
}
final int finalPosition = position;
......@@ -163,7 +163,7 @@ public abstract class BannerBaseAdapter<T> extends PagerAdapter {
// 绑定视图和数据
protected abstract int getLayoutResID();
protected abstract void convert(View convertView, T data);
protected abstract void convert(View convertView, T data, int position);
public void setOnPageTouchListener(OnPageTouchListener<T> listener) {
this.mListener = listener;
......
......@@ -34,9 +34,7 @@ import com.mints.goodmoney.mvp.presenters.MyPresenter
import com.mints.goodmoney.mvp.views.MyView
import com.mints.goodmoney.service.AppInstallService
import com.mints.goodmoney.ui.activitys.*
import com.mints.goodmoney.ui.adapter.GvMyAdapter
import com.mints.goodmoney.ui.adapter.MainMyAdapter
import com.mints.goodmoney.ui.adapter.ViewPagerAdapter
import com.mints.goodmoney.ui.adapter.*
import com.mints.goodmoney.ui.adapter.listener.OnItemChildClickListener
import com.mints.goodmoney.ui.fragment.base.BaseFragment
import com.mints.goodmoney.ui.widgets.ShareDialog
......@@ -78,7 +76,7 @@ class MyFragment : BaseFragment(),
OnItemChildClickListener,
OnRefreshListener,
View.OnClickListener,
AdapterView.OnItemClickListener {
AdapterView.OnItemClickListener, AdBannerAdapter.OnPageClickListener {
companion object {
const val HOT_PAGE_SIZE = 8
......@@ -109,6 +107,10 @@ class MyFragment : BaseFragment(),
private val dataList: MutableList<MyInfo.AutoListBean> = mutableListOf()
private var mainMyAdapter: MainMyAdapter? = null
// Banner
private var mAdBannerAdapter: AdBannerAdapter? = null
private var mBannerData: RotationChartBean? = null
// 高额任务
private var mCurrentPkg: String? = null
private var mReceiverBroadcastReceiver: BroadcastReceiver? = null
......@@ -125,6 +127,13 @@ class MyFragment : BaseFragment(),
initManager()
initView()
initRecy()
initBanner()
}
private fun initBanner() {
mAdBannerAdapter = AdBannerAdapter(activity)
mAdBannerAdapter?.setOnPageClickListener(this)
banner_view.setAdapter(mAdBannerAdapter)
}
override fun onHiddenChanged(hidden: Boolean) {
......@@ -155,9 +164,11 @@ class MyFragment : BaseFragment(),
myPresenter.userLogin()
}
myPresenter.myRotationChart()
// 防止banner刷新太快
if (AntiShake.check(fl_my_banner?.id)) return
BannerManager.getTtBanner(TtCsjAdManager.TT_AD_BANNER_MY, fl_my_banner)
// if (AntiShake.check(fl_my_banner?.id)) return
// BannerManager.getTtBanner(TtCsjAdManager.TT_AD_BANNER_MY, fl_my_banner)
// 刷新喜马拉雅信息流
TTPreLoadExpressXmlyManager.getInstance().loadTtFrameLayout()
......@@ -345,6 +356,21 @@ class MyFragment : BaseFragment(),
}
}
/**
* 设置Banner
*/
override fun getMyRotationChartSuc(data: RotationChartBean) {
banner_view.visibility = View.VISIBLE
mBannerData = data
mAdBannerAdapter?.let {
val list = mBannerData?.list
list?.add(data.position, null)
it.setData(list)
it.setAdPosition(data.position)
it.notifyDataSetChanged()
}
}
override fun onRefresh(refreshLayout: RefreshLayout) {
onDestroyBroadcastReceiver()
......@@ -1466,4 +1492,23 @@ class MyFragment : BaseFragment(),
}
}
}
/**
* Banner点击事件
*/
override fun onPageClick(position: Int) {
mBannerData?.let {
val pkg = it.list[position].pkg
if (!TextUtils.isEmpty(pkg) && AppUtil.checkPackInfo(activity!!, pkg)) {
AppTryPlayManager.toTryPlay(pkg)
} else {
//未安装
val bundle = Bundle()
bundle.putString(WebActivity.WEB_TITLE, it.list[position].title)
bundle.putString(WebActivity.WEB_URL, it.list[position].url)
readyGo(WebActivity::class.java, bundle)
}
}
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.widgets;
/**
/*
* Author: renjinlong
* Email: chinarenlong@foxmail.com
* Date: 2017/8/15
......@@ -113,24 +113,21 @@ public class BannerView extends FrameLayout {
params.gravity = Gravity.CENTER;
mViewPager.setLayoutParams(params);
mViewPager.setPageMargin(pageMargin);
mViewPager.setPageTransformer(false, new BannerPageTransformer());
// mViewPager.setPageTransformer(false, new BannerPageTransformer());
// mViewPager.setOffscreenPageLimit(1);
}
private void initEvent() {
mViewPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
if (isAutoScroll) stopAutoScroll();
break;
case MotionEvent.ACTION_UP:
if (isAutoScroll) startAutoScroll();
break;
}
return false;
mViewPager.setOnTouchListener((view, motionEvent) -> {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
if (isAutoScroll) stopAutoScroll();
break;
case MotionEvent.ACTION_UP:
if (isAutoScroll) startAutoScroll();
break;
}
return false;
});
// 父亲将触摸事件交给孩子处理
......@@ -199,12 +196,9 @@ public class BannerView extends FrameLayout {
mField.setAccessible(true);
Scroller mScroller = new Scroller(getContext(),
// 动画效果与ViewPager的一致
new Interpolator() {
@Override
public float getInterpolation(float t) {
t -= 1.0f;
return t * t * t * t * t + 1.0f;
}
t -> {
t -= 1.0f;
return t * t * t * t * t + 1.0f;
}) {
@Override
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
......
......@@ -51,6 +51,16 @@
<include layout="@layout/item_divider_gray" />
<com.mints.goodmoney.ui.widgets.BannerView
android:id="@+id/banner_view"
android:layout_width="match_parent"
android:layout_height="150dp"
android:visibility="gone"
app:bannerAnimScroll="false"
app:bannerAutoScroll="true"
app:bannerPageMargin="0dp"
app:bannerPagePercent="1" />
<include layout="@layout/view_title" />
<androidx.recyclerview.widget.RecyclerView
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ad_container"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@color/color_0000">
<ImageView
android:visibility="gone"
android:id="@+id/iv_banner_ad"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
\ 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