Commit 0b13b4f4 authored by jyx's avatar jyx

代码优化

parent 28fdfa5c
......@@ -49,7 +49,7 @@ class WatchRecordPresenter : BasePresenter<WatchRecordView>() {
fun collect(videoId: String) {
val vo = HashMap<String, Any>()
vo["videoId"] = videoId
vo["vedioId"] = videoId
AppHttpManager.getInstance(loanApplication)
.call(loanService.collect(vo), object : BaseSubscriber<BaseResponse<JsonObject>>() {
override fun onCompleted() {
......@@ -87,7 +87,7 @@ class WatchRecordPresenter : BasePresenter<WatchRecordView>() {
fun cancelCollect(videoId: String) {
val vo = HashMap<String, Any>()
vo["videoId"] = videoId
vo["vedioId"] = videoId
AppHttpManager.getInstance(loanApplication)
.call(
loanService.cancelCollect(vo),
......
......@@ -50,13 +50,19 @@ class WatchRecordActivity : BaseActivity(), WatchRecordView {
datas[position]
)
}
mWatchRecordAdapter?.setOnItemChildClickListener { adapter, view, position ->
if (datas[position].collect == 0) {
watchRecordPresenter.collect("" + datas[position].vedioId)
} else {
watchRecordPresenter.cancelCollect("" + datas[position].vedioId)
mWatchRecordAdapter?.setOnItemCollectClickListener(object :
WatchRecordAdapter.OnItemCollectClickListener {
override fun onItemCollectClick(position: Int) {
if (datas[position].collect == 0) {
datas[position].collect = 1
watchRecordPresenter.collect("" + datas[position].vedioId)
} else {
datas[position].collect = 0
watchRecordPresenter.cancelCollect("" + datas[position].vedioId)
}
mWatchRecordAdapter?.notifyItemChanged(position)
}
}
})
rv_watch_record.layoutManager = LinearLayoutManager(this)
rv_watch_record.addItemDecoration(StickHeaderDecoration(this))
rv_watch_record.adapter = mWatchRecordAdapter
......
......@@ -37,8 +37,10 @@ class WatchRecordAdapter :
holder.getView<View>(R.id.ll_collect).setOnClickListener {
if (item.collect == 0) {
mOnItemCollectClickListener?.onItemCollectClick(holder.adapterPosition)
playCollectAnim(holder.getView(R.id.iv_collect))
} else {
mOnItemCollectClickListener?.onItemCollectClick(holder.adapterPosition)
playCancelCollectAnim(holder.getView(R.id.iv_collect))
}
}
......@@ -97,4 +99,15 @@ class WatchRecordAdapter :
view.setImageDrawable(lottieDrawable)
}
private var mOnItemCollectClickListener: OnItemCollectClickListener? = null
fun setOnItemCollectClickListener(onItemCollectClickListener: OnItemCollectClickListener) {
this.mOnItemCollectClickListener = onItemCollectClickListener
}
interface OnItemCollectClickListener {
fun onItemCollectClick(position: Int)
}
}
\ No newline at end of file
......@@ -8,28 +8,28 @@
<include layout="@layout/header_layout" />
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/srlMainPage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:srlAccentColor="@color/black">
<!-- <com.scwang.smartrefresh.layout.SmartRefreshLayout-->
<!-- android:id="@+id/srlMainPage"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- android:layout_weight="1"-->
<!-- app:srlAccentColor="@color/black">-->
<com.scwang.smartrefresh.header.MaterialHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- <com.scwang.smartrefresh.header.MaterialHeader-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content" />-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_watch_record"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlAccentColor="@color/black"
app:srlPrimaryColor="@color/color_FDFDFD" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<!-- <com.scwang.smartrefresh.layout.footer.ClassicsFooter-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:srlAccentColor="@color/black"-->
<!-- app:srlPrimaryColor="@color/color_FDFDFD" />-->
<!-- </com.scwang.smartrefresh.layout.SmartRefreshLayout>-->
</LinearLayout>
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