inner class GoodsItemHolder(itemView: View) : View.OnClickListener {
override fun onClick(v: View?) {
var isAdd: Boolean = false
when (v?.id) {
R.id.ib_add -> {
isAdd = true
doAddOperation()
}
R.id.ib_minus -> doMinusOperation()
}
processRedDotCount(isAdd)
}
private fun processRedDotCount(isAdd: Boolean) {
//找到此商品属于的类别
val typeId = goodsInfo.typeId
//找到此类别在左侧列表中的位置(遍历)
val typePosition = goodsFragment.goodsFragmentPresenter.getTypePositionByTypeId(typeId)
//最后找出tvRedDotCount
val goodsTypeInfo = goodsFragment.goodsFragmentPresenter.goodstypeList.get(typePosition)
var redDotCount = goodsTypeInfo.redDotCount
if (isAdd) {
redDotCount++
} else {
redDotCount–
}
goodsTypeInfo.redDotCount = redDotCount
//刷新左侧列表
goodsFragment.goodsTypeAdapter.notifyDataSetChanged()
}
private fun doMinusOperation() {
//改变count值
var count = goodsInfo.count
if (count == 1) {
//最后一次点击减号执行动画集
val hideAnimationSet: AnimationSet = getHideAnimation()
tvCount.startAnimation(hideAnimationSet)
btnMinus.startAnimation(hideAnimationSet)
//删除缓存
// TakeoutApp.sInstance.deleteCacheSelectedInfo(goodsInfo.id)
}else{
//更新缓存
// TakeoutApp.sInstance.updateCacheSelectedInfo(goodsInfo.id, Constants.MINUS)
}
count–
//改变数据层
goodsInfo.count = count
notifyDataSetChanged()
}
private fun doAddOperation() {
//改变count值
var count = goodsInfo.count
if (count == 0) {
//第一次点击加号执行动画集
val showAnimationSet: AnimationSet = getShowAnimation()
tvCount.startAnimation(showAnimationSet)
btnMinus.startAnimation(showAnimationSet)
//添加缓存
// TakeoutApp.sInstance.addCacheSelectedInfo(CacheSelectedInfo(goodsInfo.sellerId,goodsInfo.typeId,goodsInfo.id,1))
}else{
//更新缓存
// TakeoutApp.sInstance.updateCacheSelectedInfo(goodsInfo.id, Constants.ADD)
}
count++
//改变数据层
goodsInfo.count = count
notifyDataSetChanged()
//抛物线
//1.克隆+号,并且添加到acitivty上
var ib = ImageButton(context)
//大小,位置、背景全部相同
ib.setBackgroundResource(R.mipmap.button_add)
// btnAdd.width
val srcLocation = IntArray(2)
btnAdd.getLocatio