当前位置: 首页 > news >正文

注册了域名后怎么设计网站只做自己网站

注册了域名后怎么设计网站,只做自己网站,甘肃县门户网站建设方案,零食进货渠道网背景 项目中首页列表页需要统计每个item的曝光情况#xff0c;给产品运营提供数据报表分析用户行为#xff0c;于是封装了一个通用的列表Item曝光工具#xff0c;方便曝光埋点上报 源码分析 核心就是监听RecyclerView的滚动#xff0c;在滚动状态为SCROLL_STATE_IDLE的时…背景 项目中首页列表页需要统计每个item的曝光情况给产品运营提供数据报表分析用户行为于是封装了一个通用的列表Item曝光工具方便曝光埋点上报 源码分析 核心就是监听RecyclerView的滚动在滚动状态为SCROLL_STATE_IDLE的时候开始计算哪些item是可见的 private fun calculateVisibleItemInternal() {if (!isRecording) {return}val lastRange currVisibleRangeval currRange findItemVisibleRange()val newVisibleItemPosList createCurVisiblePosList(lastRange, currRange)visibleItemCheckTasks.forEach {it.updateVisibleRange(currRange)}if (newVisibleItemPosList.isNotEmpty()) {VisibleCheckTimerTask(newVisibleItemPosList, this, threshold).also {visibleItemCheckTasks.add(it)}.execute()}currVisibleRange currRange}根据LayoutManager找出当前可见item的范围剔除掉显示不到80%的item private fun findItemVisibleRange(): IntRange {return when (val lm currRecyclerView?.layoutManager) {is GridLayoutManager - {val first lm.findFirstVisibleItemPosition()val last lm.findLastVisibleItemPosition()return fixCurRealVisibleRange(first, last)}is LinearLayoutManager - {val first lm.findFirstVisibleItemPosition()val last lm.findLastVisibleItemPosition()return fixCurRealVisibleRange(first, last)}is StaggeredGridLayoutManager - {val firstItems IntArray(lm.spanCount)lm.findFirstVisibleItemPositions(firstItems)val lastItems IntArray(lm.spanCount)lm.findLastVisibleItemPositions(lastItems)val first when (RecyclerView.NO_POSITION) {firstItems[0] - {firstItems[lm.spanCount - 1]}firstItems[lm.spanCount - 1] - {firstItems[0]}else - {min(firstItems[0], firstItems[lm.spanCount - 1])}}val last when (RecyclerView.NO_POSITION) {lastItems[0] - {lastItems[lm.spanCount - 1]}lastItems[lm.spanCount - 1] - {lastItems[0]}else - {max(lastItems[0], lastItems[lm.spanCount - 1])}}return fixCurRealVisibleRange(first, last)}else - {IntRange.EMPTY}}}对可见的item进行分组形成一个位置列表上一次和这一次的分开组队 private fun createCurVisiblePosList(lastRange: IntRange, currRange: IntRange): ListInt {val result mutableListOfInt()currRange.forEach { pos -if (pos !in lastRange) {result.add(pos)}}return result}将分组好的列表装进一个定时的task在延迟一个阈值的时间后执行onVisibleCheck class VisibleCheckTimerTask(input: ListInt,private val callback: VisibleCheckCallback,private val delay: Long ) : Runnable {private val visibleList mutableListOfInt()private var isExecuted falseinit {visibleList.addAll(input)}fun updateVisibleRange(keyRange: IntRange) {val iterator visibleList.iterator()while (iterator.hasNext()) {val entry iterator.next()if (entry !in keyRange) {iterator.remove()}}}override fun run() {callback.onVisibleCheck( this, visibleList)}fun execute() {if (isExecuted) {return}mHandler.postDelayed(this, delay)isExecuted true}fun cancel() {mHandler.removeCallbacks(this)}interface VisibleCheckCallback {fun onVisibleCheck(task: VisibleCheckTimerTask, visibleList: ListInt)} }达到阈值后再获取一遍可见item的范围对于仍然可见的item回调onItemShow override fun onVisibleCheck(task: VisibleCheckTimerTask, visibleList: ListInt) {val visibleRange findItemVisibleRange()visibleList.forEach {if (it in visibleRange) {notifyItemShow(it)}}visibleItemCheckTasks.remove(task)}完整源码 val mHandler Handler(Looper.getMainLooper())class ListItemExposeUtil(private val threshold: Long 100): RecyclerView.OnScrollListener(), VisibleCheckTimerTask.VisibleCheckCallback {private var currRecyclerView: RecyclerView? nullprivate var isRecording falseprivate var currVisibleRange: IntRange IntRange.EMPTYprivate val visibleItemCheckTasks mutableListOfVisibleCheckTimerTask()private val itemShowListeners mutableListOfOnItemShowListener()fun attachTo(recyclerView: RecyclerView) {recyclerView.addOnScrollListener(this)currRecyclerView recyclerView}fun start() {isRecording truecurrRecyclerView?.post {calculateVisibleItemInternal()}}fun stop() {visibleItemCheckTasks.forEach {it.cancel()}visibleItemCheckTasks.clear()currVisibleRange IntRange.EMPTYisRecording false}fun detach() {if (isRecording) {stop()}itemShowListeners.clear()currRecyclerView?.removeOnScrollListener(this)currRecyclerView null}override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {if (newState RecyclerView.SCROLL_STATE_IDLE) {calculateVisibleItemInternal()}}private fun calculateVisibleItemInternal() {if (!isRecording) {return}val lastRange currVisibleRangeval currRange findItemVisibleRange()val newVisibleItemPosList createCurVisiblePosList(lastRange, currRange)visibleItemCheckTasks.forEach {it.updateVisibleRange(currRange)}if (newVisibleItemPosList.isNotEmpty()) {VisibleCheckTimerTask(newVisibleItemPosList, this, threshold).also {visibleItemCheckTasks.add(it)}.execute()}currVisibleRange currRange}private fun findItemVisibleRange(): IntRange {return when (val lm currRecyclerView?.layoutManager) {is GridLayoutManager - {val first lm.findFirstVisibleItemPosition()val last lm.findLastVisibleItemPosition()return fixCurRealVisibleRange(first, last)}is LinearLayoutManager - {val first lm.findFirstVisibleItemPosition()val last lm.findLastVisibleItemPosition()return fixCurRealVisibleRange(first, last)}is StaggeredGridLayoutManager - {val firstItems IntArray(lm.spanCount)lm.findFirstVisibleItemPositions(firstItems)val lastItems IntArray(lm.spanCount)lm.findLastVisibleItemPositions(lastItems)val first when (RecyclerView.NO_POSITION) {firstItems[0] - {firstItems[lm.spanCount - 1]}firstItems[lm.spanCount - 1] - {firstItems[0]}else - {min(firstItems[0], firstItems[lm.spanCount - 1])}}val last when (RecyclerView.NO_POSITION) {lastItems[0] - {lastItems[lm.spanCount - 1]}lastItems[lm.spanCount - 1] - {lastItems[0]}else - {max(lastItems[0], lastItems[lm.spanCount - 1])}}return fixCurRealVisibleRange(first, last)}else - {IntRange.EMPTY}}}/*** 检查该item是否真实可见* view区域80%显示出来就算*/private fun checkItemCurrRealVisible(pos: Int): Boolean {val holder currRecyclerView?.findViewHolderForAdapterPosition(pos)return if (holder null) {false} else {val rect Rect()holder.itemView.getGlobalVisibleRect(rect)if (holder.itemView.width 0 holder.itemView.height 0) {return (rect.width() * rect.height() / (holder.itemView.width * holder.itemView.height).toFloat()) 0.8f} else {return false}}}/*** 双指针寻找真实可见的item的范围有一些item没显示完整剔除*/private fun fixCurRealVisibleRange(first: Int, last: Int): IntRange {return if (first 0 last 0) {var realFirst firstwhile (!checkItemCurrRealVisible(realFirst) realFirst last) {realFirst}var realLast lastwhile (!checkItemCurrRealVisible(realLast) realLast realFirst) {realLast--}if (realFirst realLast) {realFirst..realLast} else {IntRange.EMPTY}} else {IntRange.EMPTY}}/*** 创建当前可见的item位置列表*/private fun createCurVisiblePosList(lastRange: IntRange, currRange: IntRange): ListInt {val result mutableListOfInt()currRange.forEach { pos -if (pos !in lastRange) {result.add(pos)}}return result}/*** 达到阈值后再获取一遍可见item的范围对于仍然可见的item回调onItemShow*/override fun onVisibleCheck(task: VisibleCheckTimerTask, visibleList: ListInt) {val visibleRange findItemVisibleRange()visibleList.forEach {if (it in visibleRange) {notifyItemShow(it)}}visibleItemCheckTasks.remove(task)}private fun notifyItemShow(pos: Int) {itemShowListeners.forEach {it.onItemShow(pos)}}fun addItemShowListener(listener: OnItemShowListener) {itemShowListeners.add(listener)} }interface OnItemShowListener {fun onItemShow(pos: Int) }class VisibleCheckTimerTask(input: ListInt,private val callback: VisibleCheckCallback,private val delay: Long) : Runnable {private val visibleList mutableListOfInt()private var isExecuted falseinit {visibleList.addAll(input)}fun updateVisibleRange(keyRange: IntRange) {val iterator visibleList.iterator()while (iterator.hasNext()) {val entry iterator.next()if (entry !in keyRange) {iterator.remove()}}}override fun run() {callback.onVisibleCheck(this, visibleList)}fun execute() {if (isExecuted) {return}mHandler.postDelayed(this, delay)isExecuted true}fun cancel() {mHandler.removeCallbacks(this)}interface VisibleCheckCallback {fun onVisibleCheck(task: VisibleCheckTimerTask, visibleList: ListInt)} }测试代码 运行结果
http://www.hkea.cn/news/14575292/

相关文章:

  • 企业建网站的好处哪里培训做网站
  • 电子商务网站开发是指京东网上商城手机
  • 佛山龙江做网站的全部列表支持安卓浏览器软件下载
  • 凡科网建站系统源码网站备份与恢复
  • 开发网站服务器黄岩区信誉好高端网站设计
  • 交易网站seo怎么做公关策划是做什么的
  • 新的网站建设一般多少钱长沙城乡住房建设厅网站
  • 长春高端网站制作wordpress伪静态不跳转404
  • 低价网站建设制作设计公司1月初达到感染高峰
  • 吉安网站推广投资做个app要多少钱
  • 瑞安做网站的公司微信小程序怎么制作自己的程序
  • 专业的网站设计公司有没有女的做任务的网站
  • 四川省城乡和住房建设厅官方网站wordpress微博图床优点缺点
  • 网站标题 关键字零基础编程入门自学
  • 户外网站设计建站之星模板的使用
  • 企业网站营销实现方式淄博 网站seo优化
  • 中华室内设计网招聘网站内部代码优化
  • 飞凡网站建设为什么谷歌浏览器打不开网页
  • 设计网站多少费用多少平台期什么意思
  • 网站建设明确细节网页设计与网站建设考试名词解释
  • 网站数据库多大合适wordpress开发教程 pdf
  • 做网站用框架衡阳退休职工做面膜网站
  • 做网站好的网站建设公司网页制作第一步
  • 自己做一元购网站常见的系统优化软件
  • 长沙网站列表珠海商城网站建设
  • 上海智能网站建设设计保洁公司在哪个网站做推广比较好
  • 南通网站建设有限公司网站设计的任务
  • 电商网站seo公司做h5的免费软件
  • 慧聪网seo页面优化百度seo外包
  • 济南小程序网站制作哪家公司建别墅好