Skip to content

Commit

Permalink
日常提交:2022-11-14.
Browse files Browse the repository at this point in the history
Signed-off-by: 王朋飞 <walgr1010>
  • Loading branch information
王朋飞 committed Nov 14, 2022
1 parent 051e554 commit 70bce1d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 29 deletions.
55 changes: 45 additions & 10 deletions Quick/src/main/java/com/wpf/app/quick/helper/AdapterHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ import com.wpf.app.quickbind.interfaces.request2View
import com.wpf.app.quicknetwork.base.BaseResponseI
import com.wpf.app.quicknetwork.call.RealCall
import com.wpf.app.quicknetwork.requestCls
import com.wpf.app.quickrecyclerview.data.QuickItemData
import com.wpf.app.quickrecyclerview.data.RequestData
import com.wpf.app.quickrecyclerview.helper.Request2RefreshView
import com.wpf.app.quickrecyclerview.listeners.RefreshView
import com.wpf.app.quickrecyclerview.listeners.Request2ListWithView
import com.wpf.app.quickrecyclerview.listeners.request2List
import com.wpf.app.quickutil.LogUtil
import java.lang.reflect.Type

/**
* Created by 王朋飞 on 2022/5/18.
Expand Down Expand Up @@ -61,25 +66,55 @@ fun onViewCheck(view: View, onChange: CompoundButton.OnCheckedChangeListener?) {
}

@BindingAdapter(value = ["apiClass", "methodName", "parameters"], requireAll = false)
fun <T> View.request2This(apiCls: Class<T>, methodName: String, parameters: List<Any>?) {
fun <T> View.request2View(apiCls: Class<T>, methodName: String, parameters: List<Any>?) {
if (!apiCls.isInterface) return
val parameterTypes : Array<Class<*>> = parameters?.map {
val parameterTypes: Array<Class<*>> = parameters?.map {
if (it.javaClass == Integer::class.java) Int::class.java else it.javaClass
}?.toTypedArray() ?: arrayOf()
val method = apiCls.getMethod(methodName, *parameterTypes)
val api: (T.() -> RealCall<BaseResponseI<out QuickRequestData, Any>, Any>) = object : (T) -> RealCall<BaseResponseI<out QuickRequestData, Any>, Any> {
override fun invoke(p1: T): RealCall<BaseResponseI<out QuickRequestData, Any>, Any> {
return method.invoke(p1, *(parameters?.toTypedArray() ?: arrayOf())) as RealCall<BaseResponseI<out QuickRequestData, Any>, Any>
val api: (T.() -> RealCall<BaseResponseI<out QuickRequestData, Any>, Any>) =
object : (T) -> RealCall<BaseResponseI<out QuickRequestData, Any>, Any> {
override fun invoke(p1: T): RealCall<BaseResponseI<out QuickRequestData, Any>, Any> {
return method.invoke(
p1,
*(parameters?.toTypedArray() ?: arrayOf())
) as RealCall<BaseResponseI<out QuickRequestData, Any>, Any>
}
}
}
val request2View = request2View { callback ->
requestCls(apiCls) {
api()
}.success {
callback.backData(it?.dataI)
}.fail {
LogUtil.e("请求出错-${it.toString()}")
}
} as Request2ViewWithView<out QuickRequestData, out View>
BindData2ViewHelper.bind(this, request2View, Request2View)
}
}

//@Deprecated("暂未开放")
//@BindingAdapter(value = ["apiClass", "methodName", "parameters"], requireAll = false)
//fun <T> View.request2List(apiCls: Class<T>, methodName: String, parameters: List<Any>?) {
// if (this !is RefreshView) return
// if (!apiCls.isInterface) return
// val parameterTypes: Array<Class<*>> = parameters?.map {
// if (it.javaClass == Integer::class.java) Int::class.java else it.javaClass
// }?.toTypedArray() ?: arrayOf()
// val method = apiCls.getMethod(methodName, *parameterTypes)
// val api: (T.() -> RealCall<BaseResponseI<out QuickItemData, Any>, Any>) =
// object : (T) -> RealCall<BaseResponseI<out QuickItemData, Any>, Any> {
// override fun invoke(p1: T): RealCall<BaseResponseI<out QuickItemData, Any>, Any> {
// return method.invoke(
// p1,
// *(parameters?.toTypedArray() ?: arrayOf())
// ) as RealCall<BaseResponseI<out QuickItemData, Any>, Any>
// }
// }
// val request2List = request2List { _, callback ->
// requestCls(apiCls) {
// api()
// }.success {
// callback.backData(arrayListOf())
// }
// } as Request2ListWithView<RequestData, QuickItemData, RefreshView>
// BindData2ViewHelper.bind(this, request2List, Request2RefreshView)
//}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.wpf.app.quickbind.annotations

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.wpf.app.quick.annotations.BindD2VHHelper

/**
* Created by 王朋飞 on 2022/9/5.
*
*/
interface BindD2VHelper<V : View, Data : Any> :
BindD2VHHelper<RecyclerView.ViewHolder, V, Data> {
interface BindD2VHelper<View : Any, Data : Any> :
BindD2VHHelper<RecyclerView.ViewHolder, View, Data> {

override fun initView(viewHolder: RecyclerView.ViewHolder?, view: V, data: Data) {
override fun initView(viewHolder: RecyclerView.ViewHolder?, view: View, data: Data) {
initView(view, data)
}

fun initView(view: V, data: Data)
fun initView(view: View, data: Data)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wpf.app.quickbind.helper.binddatahelper

import android.view.View
import com.wpf.app.quickbind.annotations.BindD2VHelper

/**
Expand All @@ -9,8 +8,8 @@ import com.wpf.app.quickbind.annotations.BindD2VHelper
*/
object BindData2ViewHelper {

fun <Data: Any, V : View, Helper : BindD2VHelper<V, Data>> bind(
view: V,
fun <Data: Any, View, Helper : BindD2VHelper<View, Data>> bind(
view: View,
data: Data,
helper: Helper
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class QuickRefreshRecyclerView @JvmOverloads constructor(

@JvmField
val refreshCallback = object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
override fun backData(data: List<QuickItemData>?) {
getQuickAdapter().mDataList?.clear()
getQuickAdapter().appendList(data)
mRequestData.loadDataSize(data?.size ?: 0)
Expand All @@ -40,7 +40,7 @@ open class QuickRefreshRecyclerView @JvmOverloads constructor(

@JvmField
val loadMoreCallback = object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
override fun backData(data: List<QuickItemData>?) {
appendList(data)
mRequestData.loadDataSize(data?.size ?: 0)
if (mDataChangeListener?.loadMoreFinish() != true) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wpf.app.quickrecyclerview.helper

import android.view.View
import com.wpf.app.quickbind.annotations.BindD2VHelper
import com.wpf.app.quickrecyclerview.QuickAdapter
import com.wpf.app.quickrecyclerview.QuickRefreshRecyclerView
Expand All @@ -12,15 +11,15 @@ import com.wpf.app.quickutil.CallbackList
import java.lang.reflect.ParameterizedType

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

override fun initView(
view: View,
view: RefreshView,
data: Request2ListWithView<out RequestData, out QuickItemData, out RefreshView>
) {
if (view is QuickRefreshRecyclerView) {
view.setDataChangeListener(data as Request2ListWithView<RequestData, QuickItemData, QuickRefreshRecyclerView>)
} else if (view is RefreshView && view.getAdapter() is QuickAdapter) {
} else if (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
Expand All @@ -31,7 +30,7 @@ object Request2RefreshView :
realData.view = view
realData.requestData = requestData
val refreshCallback = object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
override fun backData(data: List<QuickItemData>?) {
quickAdapter.mDataList?.clear()
quickAdapter.appendList(data)
requestData.loadDataSize(data?.size ?: 0)
Expand All @@ -42,7 +41,7 @@ object Request2RefreshView :
}
realData.refreshCallback = refreshCallback
val loadMoreCallback = object : CallbackList<QuickItemData> {
override fun callback(data: List<QuickItemData>?) {
override fun backData(data: List<QuickItemData>?) {
quickAdapter.appendList(data)
requestData.loadDataSize(data?.size ?: 0)
if (!realData.loadMoreFinish()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ package com.wpf.app.quickutil
*/
interface CallbackList<Data> {

fun callback(data: List<Data>?)
fun backData(data: List<Data>?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RefreshListTestActivity : QuickActivity(R.layout.activity_refresh_list, ti
request {
首页文章列表(requestData.page)
}.success {
callback.callback(it?.data?.datas)
callback.backData(it?.data?.datas)
}.after {
if (requestData.isRefresh) {
mSmartRefreshLayout?.finishRefresh()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android.nonTransitiveRClass=true

#android.disableAutomaticComponentCreation=true

IS_REMOTE=false
IS_REMOTE=true
GROUP=com.wpf.app.quick
VERSION_NAME=0.5.7

Expand Down

0 comments on commit 70bce1d

Please sign in to comment.