Commit cfb783b7 authored by jyx's avatar jyx

优化添加广告导致下标错误问题,添加平滑滚动

parent 3db770b5
......@@ -138,7 +138,6 @@ class DrawExpressManager {
}
mTTFeedAd = it[0]
isLoadSuccess = 2
showAd()
}
}
......@@ -228,30 +227,15 @@ class DrawExpressManager {
Log.i(TAG, "express dislike 点击了取消")
}
})
isLoadSuccess = 2
it.adView?.let { view ->
if (view.parent != null) {
(view.parent as ViewGroup).removeView(view)
}
frameLayout?.addView(view)
}
// val view: FrameLayout = frameLayout!!
// val frameLayout = FrameLayout(MintsApplication.getContext())
// frameLayout.addView(view)
viewCache.add(frameLayout)
// mExpressAdCallback?.let {
// if (it.renderSuccess(viewCache.lastElement())) {
// LogUtil.d(
// TAG,
// "gromore信息流 onRenderSuccess -> showAd->$isShowAd \n adcode->$adcode ecpm->$ecpm"
// )
//
// isLoadSuccess = 0
// isShowAd = true
// adShowTime = System.currentTimeMillis()
// }
// }
// mExpressAdCallback = null
}
override fun onRenderFail(p0: View?, p1: String?, p2: Int) {
......
......@@ -22,6 +22,7 @@ import com.mints.helivideo.mvp.model.VedioBean;
import com.mints.helivideo.mvp.model.VideoMultiItemEntity;
import com.mints.helivideo.video.tx.adapter.TxVideoAdapter;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
......@@ -83,7 +84,7 @@ public class SuperShortVideoView extends RelativeLayout {
mSnapHelper.attachToRecyclerView(mRecyclerView);
mAdapter = new TxVideoAdapter();
mAdapter.setNewInstance(mList);
mAdapter.setOnVideoEndListener(() -> onItemClick(mCurrentPosition + 1));
mAdapter.setOnVideoEndListener(() -> onItemClick(mCurrentPosition + 1, true));
mLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false) {
@Override
protected int getExtraLayoutSpace(RecyclerView.State state) {
......@@ -117,9 +118,9 @@ public class SuperShortVideoView extends RelativeLayout {
if (position == mCurrentPosition || position == RecyclerView.NO_POSITION)
return;
Log.i(TAG, "[SCROLL_STATE_IDLE] mLastPositionInIDLE " + mLastPositionInIDLE + " position " + position);
mCurrentPosition = position;
addAdView(position);
onPageSelectedMethod(position);
if (isLuckPosition(position)) {
......@@ -220,16 +221,37 @@ public class SuperShortVideoView extends RelativeLayout {
}
public void onItemClick(final int position) {
onItemClick(position, false);
}
public void onItemClick(final int position, boolean isVideoEnd) {
if (mList == null || position >= mList.size()) return;
mRecyclerView.scrollToPosition(position);
mRecyclerView.post(() -> {
Log.i(TAG, "onItemClick");
mCurrentPosition = position;
if (isVideoEnd) {
changeLayoutPosition(position);
// 执行 onScrollListener
mRecyclerView.smoothScrollToPosition(position);
} else {
mRecyclerView.scrollToPosition(position);
mRecyclerView.post(() -> {
Log.i(TAG, "onItemClick");
mCurrentPosition = position;
addAdView(mCurrentPosition);
onPageSelectedMethod(position);
});
}
}
addAdView(mCurrentPosition);
onPageSelectedMethod(position);
});
private void changeLayoutPosition(int position) {
try {
Class<LinearLayoutManager> lm = LinearLayoutManager.class;
Field mPendingScrollPosition = lm.getDeclaredField("mPendingScrollPosition");
mPendingScrollPosition.setAccessible(true);
mPendingScrollPosition.set(mLayoutManager, position);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
public List<VideoMultiItemEntity> getData() {
......
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