Skip to content

Commit

Permalink
日常提交:2022-11-09.
Browse files Browse the repository at this point in the history
Signed-off-by: 王朋飞 <walgr1010>
  • Loading branch information
王朋飞 committed Nov 9, 2022
1 parent 968220f commit 72d94f9
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 178 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.wpf.app.quickbind.bindview

import android.view.View
import androidx.annotation.LayoutRes
import com.wpf.app.quickbind.QuickBind
import com.wpf.app.quickutil.bind.Bind

open class QuickRequestData @JvmOverloads constructor(
@LayoutRes open val layoutId: Int = 0,
@Transient open val layoutView: View? = null
) : Bind {

@Transient
private var mView: View? = null

open fun onCreateView(view: View) {
mView = view
QuickBind.bind(this)
}

override fun getView(): View? {
return mView
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wpf.app.quickbind.helper.binddatahelper

import android.view.View
import com.wpf.app.quickbind.bindview.QuickRequestData
import com.wpf.app.quickbind.annotations.BindD2VHelper
import com.wpf.app.quickbind.interfaces.Request2ViewWithView
import com.wpf.app.quickutil.Callback

object Request2View: BindD2VHelper<View, Request2ViewWithView<out QuickRequestData, out View>> {

override fun initView(view: View, data: Request2ViewWithView<out QuickRequestData, out View>) {
(data as Request2ViewWithView<QuickRequestData, View>).requestAndCallback(view, callback = object : Callback<QuickRequestData> {
override fun callback(data: QuickRequestData?) {
data?.onCreateView(view)
}

})
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.wpf.app.quickbind.interfaces

import android.view.View
import com.wpf.app.quickbind.bindview.QuickRequestData
import com.wpf.app.quickutil.Callback


interface Request2View<Data : QuickRequestData>: Request2ViewWithView<Data, View> {

/**
* 接口请求
*/
fun requestAndCallback(callback: Callback<Data>)

override fun requestAndCallback(view: View, callback: Callback<Data>) {
requestAndCallback(callback)
}
}

interface Request2ViewWithView<Data : QuickRequestData, View> {

/**
* 接口请求
*/
fun requestAndCallback(view: View, callback: Callback<Data>)
}

fun <Data : QuickRequestData> request2View(
callbackF: (callback: Callback<Data>) -> Unit
) = object : Request2View<Data> {

override fun requestAndCallback(callback: Callback<Data>) {
callbackF.invoke(callback)
}
}

fun <Data : QuickRequestData, View> request2ViewWithView(
callbackF: (view: View, callback: Callback<Data>) -> Unit
) = object : Request2ViewWithView<Data, View> {

override fun requestAndCallback(view: View, callback: Callback<Data>) {
callbackF.invoke(view, callback)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import android.util.AttributeSet
import com.wpf.app.quickrecyclerview.data.QuickItemData
import com.wpf.app.quickrecyclerview.data.RequestData
import com.wpf.app.quickrecyclerview.listeners.RefreshView
import com.wpf.app.quickrecyclerview.listeners.RequestDataAndCallbackWithView
import com.wpf.app.quickutil.Callback
import com.wpf.app.quickrecyclerview.listeners.Request2ListWithView
import com.wpf.app.quickutil.CallbackList

/**
* Created by 王朋飞 on 2022/7/13.
Expand All @@ -26,17 +26,17 @@ open class QuickRefreshRecyclerView @JvmOverloads constructor(
@JvmField
var mRequestData = RequestData(0)

private var mDataChangeListener: RequestDataAndCallbackWithView<out RequestData, out QuickItemData, QuickRefreshRecyclerView>? =
private var mDataChangeListener: Request2ListWithView<out RequestData, out QuickItemData, QuickRefreshRecyclerView>? =
null

fun <Request : RequestData, Data : QuickItemData> setDataChangeListener(dataChangeListener: RequestDataAndCallbackWithView<Request, Data, QuickRefreshRecyclerView>) {
fun <Request : RequestData, Data : QuickItemData> setDataChangeListener(dataChangeListener: Request2ListWithView<Request, Data, QuickRefreshRecyclerView>) {
mDataChangeListener = dataChangeListener
}

override fun onRefresh() {
mRequestData.refresh()
(mDataChangeListener as? RequestDataAndCallbackWithView<RequestData, QuickItemData, QuickRefreshRecyclerView>)
?.requestAndCallback(this, mRequestData, object : Callback<QuickItemData> {
(mDataChangeListener as? Request2ListWithView<RequestData, QuickItemData, QuickRefreshRecyclerView>)
?.requestAndCallback(this, mRequestData, object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
setNewData(data)
mRequestData.loadDataSize(data?.size ?: 0)
Expand All @@ -49,8 +49,8 @@ open class QuickRefreshRecyclerView @JvmOverloads constructor(

override fun onLoadMore() {
mRequestData.loadMore()
(mDataChangeListener as? RequestDataAndCallbackWithView<RequestData, QuickItemData, QuickRefreshRecyclerView>)
?.requestAndCallback(this, mRequestData, object : Callback<QuickItemData> {
(mDataChangeListener as? Request2ListWithView<RequestData, QuickItemData, QuickRefreshRecyclerView>)
?.requestAndCallback(this, mRequestData, object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
appendList(data)
mRequestData.loadDataSize(data?.size ?: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ import com.wpf.app.quickrecyclerview.QuickRefreshRecyclerView
import com.wpf.app.quickrecyclerview.data.QuickItemData
import com.wpf.app.quickrecyclerview.data.RequestData
import com.wpf.app.quickrecyclerview.listeners.RefreshView
import com.wpf.app.quickrecyclerview.listeners.RequestDataAndCallbackWithView
import com.wpf.app.quickutil.Callback
import com.wpf.app.quickrecyclerview.listeners.Request2ListWithView
import com.wpf.app.quickutil.CallbackList
import java.lang.reflect.ParameterizedType

object Request2RefreshView :
BindD2VHelper<View, RequestDataAndCallbackWithView<out RequestData, out QuickItemData, out RefreshView>> {
BindD2VHelper<View, Request2ListWithView<out RequestData, out QuickItemData, out RefreshView>> {

override fun initView(
view: View,
data: RequestDataAndCallbackWithView<out RequestData, out QuickItemData, out RefreshView>
data: Request2ListWithView<out RequestData, out QuickItemData, out RefreshView>
) {
if (view is QuickRefreshRecyclerView) {
view.setDataChangeListener(data as RequestDataAndCallbackWithView<RequestData, QuickItemData, QuickRefreshRecyclerView>)
view.setDataChangeListener(data as Request2ListWithView<RequestData, QuickItemData, QuickRefreshRecyclerView>)
} else if (view is RefreshView && view.getAdapter() is QuickAdapter) {
val quickAdapter = view.getAdapter() as QuickAdapter
val requestData: RequestData = try {
((data.javaClass.genericInterfaces[0] as ParameterizedType).actualTypeArguments[0] as Class<*>).newInstance() as RequestData
} catch (ignore: Exception) {
RequestData()
}
val realData = data as RequestDataAndCallbackWithView<RequestData, QuickItemData, RefreshView>
val realData = data as Request2ListWithView<RequestData, QuickItemData, RefreshView>
view.refreshView = object : RefreshView {
override var refreshView: RefreshView? = this

override fun onRefresh() {
super.onRefresh()
requestData.refresh()
realData.requestAndCallback(view, requestData, object : Callback<QuickItemData> {
realData.requestAndCallback(view, requestData, object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
quickAdapter.mDataList?.clear()
quickAdapter.appendList(data)
Expand All @@ -50,7 +50,7 @@ object Request2RefreshView :
override fun onLoadMore() {
super.onLoadMore()
requestData.loadMore()
realData.requestAndCallback(view, requestData, object : Callback<QuickItemData> {
realData.requestAndCallback(view, requestData, object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
quickAdapter.appendList(data)
requestData.loadDataSize(data?.size ?: 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.wpf.app.quickrecyclerview.listeners

import com.wpf.app.quickrecyclerview.data.QuickItemData
import com.wpf.app.quickrecyclerview.data.RequestData
import com.wpf.app.quickutil.CallbackList

/**
* Created by 王朋飞 on 2022/7/13.
*
*/

interface Request2List<Request : RequestData, Data : QuickItemData>: Request2ListWithView<Request, Data, Any> {

/**
* 接口请求
*/
fun requestAndCallback(requestData: Request, callback: CallbackList<Data>)

override fun requestAndCallback(view: Any, requestData: Request, callback: CallbackList<Data>) {
requestAndCallback(requestData, callback)
}
}

interface Request2ListWithView<Request : RequestData, Data : QuickItemData, View> {

/**
* 接口请求
*/
fun requestAndCallback(view: View, requestData: Request, callback: CallbackList<Data>)

/**
* 刷新结束
* 返回true表示刷新结束后自己刷新adapter
*/
fun refreshFinish(): Boolean { return false }

/**
* 加载结束
* 返回true表示刷新结束后自己刷新adapter
*/
fun loadMoreFinish(): Boolean { return false }
}

fun <Request : RequestData, Data : QuickItemData> requestData2List(
callbackF: (requestData: Request, callback: CallbackList<Data>) -> Unit
) = object : Request2List<Request, Data> {

override fun requestAndCallback(requestData: Request, callback: CallbackList<Data>) {
callbackF.invoke(requestData, callback)
}
}

fun <Request : RequestData, Data : QuickItemData, View> requestData2ListWithView(
callbackF: (view: View, requestData: Request, callback: CallbackList<Data>) -> Unit
) = object : Request2ListWithView<Request, Data, View> {

override fun requestAndCallback(view: View, requestData: Request, callback: CallbackList<Data>) {
callbackF.invoke(view, requestData, callback)
}
}

fun <Data : QuickItemData> request2List(
callbackF: (requestData: RequestData, callback: CallbackList<Data>) -> Unit
) = object : Request2List<RequestData, Data> {

override fun requestAndCallback(requestData: RequestData, callback: CallbackList<Data>) {
callbackF.invoke(requestData, callback)
}
}

fun <Data : QuickItemData, View> request2ListWithView(
callbackF: (view: View, requestData: RequestData, callback: CallbackList<Data>) -> Unit
) = object : Request2ListWithView<RequestData, Data, View> {

override fun requestAndCallback(view: View, requestData: RequestData, callback: CallbackList<Data>) {
callbackF.invoke(view, requestData, callback)
}
}

This file was deleted.

Loading

0 comments on commit 72d94f9

Please sign in to comment.