diff --git a/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindD2VHelper.java b/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindD2VHHelper.java similarity index 85% rename from Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindD2VHelper.java rename to Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindD2VHHelper.java index 601ae588..c3a7b3df 100644 --- a/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindD2VHelper.java +++ b/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindD2VHHelper.java @@ -8,7 +8,7 @@ /** * Created by 王朋飞 on 2022/7/6. */ -public interface BindD2VHelper { +public interface BindD2VHHelper { void initView(@Nullable VH viewHolder, @NonNull V view, @NonNull Data data); } diff --git a/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindData2View.java b/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindData2View.java index 5500a056..b7c1e62f 100644 --- a/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindData2View.java +++ b/Quick-annotations/src/main/java/com/wpf/app/quick/annotations/BindData2View.java @@ -17,5 +17,5 @@ public @interface BindData2View { @IdRes int id() default Constants.NO_RES_ID; - Class helper() default BindD2VHelper.class; + Class helper() default BindD2VHHelper.class; } diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindGroup.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindGroup.kt index cc591aa0..04e15621 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindGroup.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindGroup.kt @@ -2,13 +2,12 @@ package com.wpf.app.quick.widgets.quickview import android.content.Context import android.util.AttributeSet -import android.view.View import android.view.ViewGroup import androidx.annotation.CallSuper import androidx.annotation.LayoutRes import com.wpf.app.quickbind.QuickBind import com.wpf.app.quickbind.QuickBind.dealInPlugins -import com.wpf.app.quickbind.interfaces.Bind +import com.wpf.app.quickutil.bind.Bind /** * Created by 王朋飞 on 2022/7/13. diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindView.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindView.kt index 77211e6b..7caf0e59 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindView.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickBindView.kt @@ -1,15 +1,11 @@ package com.wpf.app.quick.widgets.quickview import android.content.Context -import android.graphics.Canvas import android.util.AttributeSet import android.view.View -import android.view.ViewGroup import androidx.annotation.CallSuper import androidx.annotation.LayoutRes import com.wpf.app.quickbind.QuickBind -import com.wpf.app.quickbind.QuickBind.dealInPlugins -import com.wpf.app.quickbind.interfaces.Bind import com.wpf.app.quickbind.interfaces.RunOnContext /** @@ -35,7 +31,7 @@ open class QuickBindView @JvmOverloads constructor( @CallSuper override fun onBindViewHolder(position: Int) { if (dealBind) { - dealInPlugins(this, null, QuickBind.bindPlugin) + QuickBind.dealInPlugins(this, null, QuickBind.bindPlugin) } } diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemGroup.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemGroup.kt index 848fd33b..a238c97c 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemGroup.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemGroup.kt @@ -5,8 +5,7 @@ import android.util.AttributeSet import android.view.View import android.view.ViewGroup import androidx.annotation.LayoutRes -import com.wpf.app.quick.R -import com.wpf.app.quickbind.interfaces.Bind +import com.wpf.app.quickutil.bind.Bind import kotlin.math.abs /** diff --git a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemView.kt b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemView.kt index 184f12d9..e7edaf8d 100644 --- a/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemView.kt +++ b/Quick/src/main/java/com/wpf/app/quick/widgets/quickview/QuickItemView.kt @@ -6,8 +6,8 @@ import android.util.AttributeSet import android.view.View import android.view.ViewGroup import androidx.annotation.LayoutRes -import com.wpf.app.quickbind.interfaces.Bind import com.wpf.app.quickbind.interfaces.RunOnContext +import com.wpf.app.quickutil.bind.Bind import kotlin.math.abs /** diff --git a/QuickBind/build.gradle b/QuickBind/build.gradle index ff69e22a..5c4234ea 100644 --- a/QuickBind/build.gradle +++ b/QuickBind/build.gradle @@ -47,8 +47,10 @@ dependencies { if (IS_REMOTE.toBoolean()) { api deps.quickbind.runtime + api deps.quickbind.network } else { api project(":Quick-runtime") + api project(":QuickNetwork") } } diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/QuickBind.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/QuickBind.kt index 842e76de..a9c84e2a 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/QuickBind.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/QuickBind.kt @@ -2,8 +2,10 @@ package com.wpf.app.quickbind import android.app.Activity import android.app.Dialog +import android.util.ArrayMap import android.view.View import androidx.annotation.UiThread +import androidx.collection.arrayMapOf import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModel import androidx.recyclerview.widget.RecyclerView @@ -12,9 +14,11 @@ import com.wpf.app.quick.annotations.BindView import com.wpf.app.quick.annotations.GroupView import com.wpf.app.quick.runtime.Databinder import com.wpf.app.quickbind.annotations.* -import com.wpf.app.quickbind.interfaces.Bind import com.wpf.app.quickbind.plugins.* import com.wpf.app.quickbind.utils.ReflectHelper +import com.wpf.app.quickutil.bind.Bind +import com.wpf.app.quickutil.bind.QuickBindI +import com.wpf.app.quickutil.bind.plugins.BasePlugin import java.lang.reflect.Constructor import java.lang.reflect.Field import java.lang.reflect.InvocationTargetException @@ -24,17 +28,28 @@ import kotlin.reflect.KClass * Created by 王朋飞 on 2022/7/13. * */ -object QuickBind { +object QuickBind: QuickBindI { private var bindSpFileName = "QuickViewSpBindFile" - private val plugins: MutableMap, BasePlugin> = LinkedHashMap() - val bindPlugin: MutableMap, BasePlugin> = - linkedMapOf(Pair(BindData2View::class, BindData2ViewPlugin())) + private val plugins: ArrayMap, BasePlugin> = ArrayMap() + val bindPlugin = arrayMapOf, BasePlugin>(Pair(BindData2View::class, BindData2ViewPlugin())) - fun registerPlugin(ann: KClass, plugin: T) { + override fun getRegisterPlugins(): MutableMap, BasePlugin> { + return plugins + } + + override fun getBindPlugin(): MutableMap, BasePlugin> { + return bindPlugin + } + + override fun registerPlugin(ann: KClass, plugin: T) { plugins[ann] = plugin } + override fun registerPlugin(index: Int, ann: KClass, plugin: T) { + plugins.put(ann, plugin) + } + init { //顺序不能乱 registerPlugin(BindView::class, BindViewPlugin()) @@ -49,37 +64,37 @@ object QuickBind { registerPlugin(BindData2View::class, BindData2ViewPlugin()) } - fun bind(activity: Activity) { + override fun bind(activity: Activity) { bind(activity, null) } - fun bind(activity: Activity, viewModel: ViewModel?) { + override fun bind(activity: Activity, viewModel: ViewModel?) { bindBinder(viewModel ?: activity, activity.window.decorView) dealInPlugins(activity, viewModel) } - fun bind(fragment: Fragment) { + override fun bind(fragment: Fragment) { bind(fragment, null) } - fun bind(fragment: Fragment, viewModel: ViewModel?) { + override fun bind(fragment: Fragment, viewModel: ViewModel?) { fragment.view?.let { bindBinder(viewModel ?: fragment, it) } dealInPlugins(fragment, viewModel) } - fun bind(viewHolder: RecyclerView.ViewHolder) { + override fun bind(viewHolder: RecyclerView.ViewHolder) { bindBinder(viewHolder, viewHolder.itemView) dealInPlugins(viewHolder, null) } - fun bind(dialog: Dialog) { + override fun bind(dialog: Dialog) { bindBinder(dialog, dialog.window!!.decorView) dealInPlugins(dialog, null) } - fun bind(bind: T) { + override fun bind(bind: T) { bind.getView()?.let { bindBinder(bind, bind.getView()!!) } @@ -140,11 +155,11 @@ object QuickBind { return bindingCtor } - fun dealInPlugins(obj: Any?, viewModel: ViewModel?) { + override fun dealInPlugins(obj: Any?, viewModel: ViewModel?) { dealInPlugins(obj, viewModel, plugins) } - fun dealInPlugins( + override fun dealInPlugins( obj: Any?, viewModel: ViewModel?, plugins: MutableMap, BasePlugin> diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/annotations/BindD2VHHelper.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/annotations/BindD2VHHelper.kt deleted file mode 100644 index ee634ad3..00000000 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/annotations/BindD2VHHelper.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.wpf.app.quickbind.annotations - -import android.view.View -import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quick.annotations.BindD2VHelper - -/** - * Created by 王朋飞 on 2022/9/5. - * - */ -interface BindD2VHHelper : BindD2VHelper { - - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: V, data: Data) -} \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/annotations/BindD2VHelper.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/annotations/BindD2VHelper.kt new file mode 100644 index 00000000..53560dae --- /dev/null +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/annotations/BindD2VHelper.kt @@ -0,0 +1,19 @@ +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 : + BindD2VHHelper { + + override fun initView(viewHolder: RecyclerView.ViewHolder?, view: V, data: Data) { + initView(view, data) + } + + fun initView(view: V, data: Data) +} \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/BindData2ViewHelper.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/BindData2ViewHelper.kt index d156a715..8164b9e2 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/BindData2ViewHelper.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/BindData2ViewHelper.kt @@ -1,7 +1,7 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.view.View -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/20. @@ -9,7 +9,7 @@ import com.wpf.app.quickbind.annotations.BindD2VHHelper */ object BindData2ViewHelper { - fun > bind( + fun > bind( view: V, data: Data, helper: Helper diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2TextView.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2TextView.kt index 10bb620b..65e32b92 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2TextView.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2TextView.kt @@ -4,15 +4,15 @@ import android.widget.TextView import androidx.annotation.ColorRes import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/21. * */ -object Color2TextView: BindD2VHHelper { +object Color2TextView: BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: TextView, @ColorRes data: Int) { + override fun initView(view: TextView, @ColorRes data: Int) { view.setTextColor(ContextCompat.getColor(view.context, data)) } } \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2View.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2View.kt index b20c1a75..88b66cdb 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2View.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Color2View.kt @@ -3,16 +3,16 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.view.View import androidx.annotation.DrawableRes import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/20. * */ -object Color2View: BindD2VHHelper { +object Color2View: BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: View, @DrawableRes data: Int) { + override fun initView(view: View, @DrawableRes data: Int) { view.setBackgroundColor(data) } } \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Drawable2ImageView.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Drawable2ImageView.kt index aaaf93be..561b3316 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Drawable2ImageView.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Drawable2ImageView.kt @@ -2,15 +2,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.widget.ImageView import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/19. * */ -object Drawable2ImageView : BindD2VHHelper { +object Drawable2ImageView : BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: ImageView, data: Int) { + override fun initView(view: ImageView, data: Int) { if (data != 0) { view.setImageResource(data) } diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/DrawableRes2View.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/DrawableRes2View.kt index 161de38e..a891f048 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/DrawableRes2View.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/DrawableRes2View.kt @@ -4,16 +4,16 @@ import android.view.View import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/20. * */ -object DrawableRes2View: BindD2VHHelper { +object DrawableRes2View: BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: View, @DrawableRes data: Int) { + override fun initView(view: View, @DrawableRes data: Int) { view.background = ContextCompat.getDrawable(view.context, data) } } \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Height2View.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Height2View.kt index 1caa22b4..33c73709 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Height2View.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Height2View.kt @@ -3,15 +3,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/20. * */ -object Height2View : BindD2VHHelper { +object Height2View : BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: View, data: Int) { + override fun initView(view: View, data: Int) { view.layoutParams?.let { it.height = data view.layoutParams = it diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/ItemClick.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/ItemClick.kt index b10fa1a6..5fd12630 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/ItemClick.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/ItemClick.kt @@ -2,16 +2,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.view.View import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/13. * */ -object ItemClick : BindD2VHHelper { +object ItemClick : BindD2VHelper { override fun initView( - viewHolder: RecyclerView.ViewHolder?, view: View, data: View.OnClickListener ) { diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Select2CheckBox.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Select2CheckBox.kt index c6cf9170..9a5b848a 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Select2CheckBox.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Select2CheckBox.kt @@ -1,16 +1,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.widget.CheckBox -import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/13. * */ -object Select2CheckBox : BindD2VHHelper { +object Select2CheckBox : BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: CheckBox, aBoolean: Boolean) { - view.isChecked = aBoolean + override fun initView(view: CheckBox, data: Boolean) { + view.isChecked = data } } \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Size2TextView.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Size2TextView.kt index c5d2678a..aad01cdb 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Size2TextView.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Size2TextView.kt @@ -2,16 +2,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.widget.TextView import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/13. * */ -object Size2TextView : BindD2VHHelper { +object Size2TextView : BindD2VHelper { override fun initView( - viewHolder: RecyclerView.ViewHolder?, view: TextView, data: Float ) { diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Text2TextView.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Text2TextView.kt index 37682301..034d113c 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Text2TextView.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Text2TextView.kt @@ -2,16 +2,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.widget.TextView import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/13. * */ -object Text2TextView : BindD2VHHelper { +object Text2TextView : BindD2VHelper { override fun initView( - viewHolder: RecyclerView.ViewHolder?, view: TextView, data: CharSequence ) { diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Url2ImageView.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Url2ImageView.kt index 091bcb3f..8ad12730 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Url2ImageView.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Url2ImageView.kt @@ -4,15 +4,15 @@ import android.widget.ImageView import androidx.fragment.app.FragmentActivity import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/13. * */ -object Url2ImageView : BindD2VHHelper { +object Url2ImageView : BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: ImageView, data: String) { + override fun initView(view: ImageView, data: String) { if (view.context == null || data.isEmpty()) return val activity = view.context as FragmentActivity if (activity.isDestroyed || activity.isFinishing) return diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Visibility2View.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Visibility2View.kt index 99c9d384..78a92109 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Visibility2View.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Visibility2View.kt @@ -2,16 +2,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.view.View import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/20. * */ -object Visibility2View : BindD2VHHelper { +object Visibility2View : BindD2VHelper { override fun initView( - viewHolder: RecyclerView.ViewHolder?, view: View, data: Int ) { diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Width2View.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Width2View.kt index 4fb0652c..e0c900c9 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Width2View.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/helper/binddatahelper/Width2View.kt @@ -3,15 +3,15 @@ package com.wpf.app.quickbind.helper.binddatahelper import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/20. * */ -object Width2View : BindD2VHHelper { +object Width2View : BindD2VHelper { - override fun initView(viewHolder: RecyclerView.ViewHolder?, view: View, data: Int) { + override fun initView(view: View, data: Int) { view.layoutParams?.let { it.width = data view.layoutParams = it diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/AutoGetPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/AutoGetPlugin.kt index 77609e52..07dac25c 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/AutoGetPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/AutoGetPlugin.kt @@ -13,7 +13,7 @@ import java.lang.reflect.ParameterizedType * Created by 王朋飞 on 2022/7/12. * */ -class AutoGetPlugin : BasePlugin { +class AutoGetPlugin : BindBasePlugin { override fun dealField(obj: Any, viewModel: ViewModel?, field: Field) { var objTemp = obj diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindBasePlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindBasePlugin.kt new file mode 100644 index 00000000..78fa4e0c --- /dev/null +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindBasePlugin.kt @@ -0,0 +1,44 @@ +package com.wpf.app.quickbind.plugins + +import androidx.annotation.NonNull +import androidx.annotation.Nullable +import androidx.lifecycle.ViewModel +import com.wpf.app.quick.runtime.Databinder +import com.wpf.app.quickbind.QuickBind +import com.wpf.app.quickutil.bind.plugins.BasePlugin +import java.lang.reflect.Field + +/** + * Created by 王朋飞 on 2022/7/12. + * + */ +interface BindBasePlugin: BasePlugin { + + fun getSaveId( + @NonNull obj: Any, + @Nullable viewModel: ViewModel?, + @NonNull field: Field, + id: Int + ): Int { + val dataBinder: Databinder = + QuickBind.BINDEDMAP[getRealObj(obj, viewModel).javaClass] ?: return id + val value: Any? = dataBinder.getFieldValue(field.name + "BindViewId") + return if (value is Int) { + value + } else id + } + + @Nullable + fun getSaveIdList( + @NonNull obj: Any, + @Nullable viewModel: ViewModel?, + @NonNull field: Field + ): ArrayList? { + val dataBinder: Databinder = + QuickBind.BINDEDMAP[getRealObj(obj, viewModel).javaClass] ?: return null + val value: Any? = dataBinder.getFieldValue(field.name) + return if (value is ArrayList<*>) { + value as ArrayList + } else null + } +} \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindData2ViewPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindData2ViewPlugin.kt index 185a0bae..50b4b1ec 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindData2ViewPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindData2ViewPlugin.kt @@ -1,15 +1,11 @@ package com.wpf.app.quickbind.plugins -import android.util.Log import android.view.View import androidx.lifecycle.ViewModel import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quick.annotations.BindD2VHelper +import com.wpf.app.quick.annotations.BindD2VHHelper import com.wpf.app.quick.annotations.BindData2View import com.wpf.app.quick.annotations.internal.Constants -import com.wpf.app.quickbind.annotations.BindD2VHHelper -import com.wpf.app.quickbind.interfaces.RunOnContext -import com.wpf.app.quickbind.interfaces.RunOnHolder import com.wpf.app.quickbind.interfaces.RunOnHolderWithSelf import com.wpf.app.quickbind.utils.ReflectHelper import java.lang.reflect.Field @@ -18,7 +14,7 @@ import java.lang.reflect.Field * Created by 王朋飞 on 2022/7/13. * */ -class BindData2ViewPlugin : BasePlugin { +class BindData2ViewPlugin : BindBasePlugin { override fun dealField( obj: Any, @@ -29,7 +25,7 @@ class BindData2ViewPlugin : BasePlugin { val bindData2View = field.getAnnotation(BindData2View::class.java) ?: return val bindId: Int = bindData2View.id - val helper = bindData2View.helper.java as Class> + val helper = bindData2View.helper.java as Class> var viewParent: Any? = obj var findView: View? = getRootView(obj) if (parentClassIs(obj.javaClass, "QuickBindData")) { @@ -46,13 +42,10 @@ class BindData2ViewPlugin : BasePlugin { field.isAccessible = true val value = field[getRealObj(obj, viewModel)] if (findView == null || value == null) return -// Log.e("onBindViewHolder","-----" + obj) - var bindBaseHelper: BindD2VHelper? + var bindBaseHelper: BindD2VHHelper? try { - helper.fields.find { - it.name == "INSTANCE" - }.let { - bindBaseHelper = it?.get(getRealObj(obj, viewModel)) as? BindD2VHelper + helper.getField("INSTANCE").let { + bindBaseHelper = it.get(getRealObj(obj, viewModel)) as? BindD2VHHelper } } catch (ignore: Exception) { bindBaseHelper = helper.newInstance() @@ -73,7 +66,7 @@ class BindData2ViewPlugin : BasePlugin { return } - fun parentClassIs(cur: Class<*>, parentName: String): Boolean { + private fun parentClassIs(cur: Class<*>, parentName: String): Boolean { var cur = cur while (parentName != cur.simpleName) { cur = cur.superclass diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragment2Plugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragment2Plugin.kt index e7159d5f..1b5c5e44 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragment2Plugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragment2Plugin.kt @@ -6,15 +6,15 @@ import androidx.fragment.app.FragmentActivity import androidx.lifecycle.ViewModel import androidx.viewpager2.widget.ViewPager2 import com.wpf.app.quickbind.annotations.BindFragment2 -import com.wpf.app.quickbind.interfaces.Bind import com.wpf.app.quickbind.interfaces.BindBaseFragment import com.wpf.app.quickbind.interfaces.BindViewModel import com.wpf.app.quickbind.utils.getViewContext import com.wpf.app.quickbind.viewpager2.ViewPagerSize2 import com.wpf.app.quickbind.viewpager2.adapter.FragmentStateAdapter +import com.wpf.app.quickutil.bind.Bind import java.lang.reflect.Field -class BindFragment2Plugin : BasePlugin { +class BindFragment2Plugin : BindBasePlugin { override fun dealField(obj: Any, viewModel: ViewModel?, field: Field) { try { diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentPlugin.kt index a29b4609..f22b39b2 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentPlugin.kt @@ -10,18 +10,18 @@ import androidx.fragment.app.FragmentStatePagerAdapter import androidx.lifecycle.ViewModel import androidx.viewpager.widget.ViewPager import com.wpf.app.quickbind.annotations.BindFragment -import com.wpf.app.quickbind.interfaces.Bind import com.wpf.app.quickbind.interfaces.BindBaseFragment import com.wpf.app.quickbind.interfaces.BindViewModel import com.wpf.app.quickbind.utils.getViewContext import com.wpf.app.quickbind.viewpager.ViewPagerSize +import com.wpf.app.quickutil.bind.Bind import java.lang.reflect.Field /** * Created by 王朋飞 on 2022/7/13. * */ -class BindFragmentPlugin : BasePlugin { +class BindFragmentPlugin : BindBasePlugin { override fun dealField( obj: Any, diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragments2Plugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragments2Plugin.kt index bc65ac65..8177be0c 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragments2Plugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragments2Plugin.kt @@ -15,7 +15,7 @@ import kotlin.reflect.KClass * Created by 王朋飞 on 2022/7/13. * */ -class BindFragments2Plugin : BasePlugin { +class BindFragments2Plugin : BindBasePlugin { override fun dealField( obj: Any, diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentsPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentsPlugin.kt index 414307b4..70cef4ae 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentsPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindFragmentsPlugin.kt @@ -17,7 +17,7 @@ import kotlin.reflect.KClass * Created by 王朋飞 on 2022/7/13. * */ -class BindFragmentsPlugin : BasePlugin { +class BindFragmentsPlugin : BindBasePlugin { override fun dealField( obj: Any, diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindSp2ViewPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindSp2ViewPlugin.kt index d6357679..702ae18c 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindSp2ViewPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindSp2ViewPlugin.kt @@ -14,7 +14,7 @@ import java.lang.reflect.Field * Created by 王朋飞 on 2022/7/13. * */ -class BindSp2ViewPlugin : BasePlugin { +class BindSp2ViewPlugin : BindBasePlugin { override fun dealField( obj: Any, diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindViewPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindViewPlugin.kt index bd0518ee..95146268 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindViewPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BindViewPlugin.kt @@ -8,7 +8,7 @@ import java.lang.reflect.Field * Created by 王朋飞 on 2022/7/13. * */ -class BindViewPlugin : BasePlugin { +class BindViewPlugin : BindBasePlugin { override fun dealField( obj: Any, diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/GroupViewPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/GroupViewPlugin.kt index fb177c42..51a03e8e 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/GroupViewPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/GroupViewPlugin.kt @@ -9,7 +9,7 @@ import java.lang.reflect.Field * Created by 王朋飞 on 2022/7/13. * */ -class GroupViewPlugin : BasePlugin { +class GroupViewPlugin : BindBasePlugin { override fun dealField( obj: Any, diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/LoadSpPlugin.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/LoadSpPlugin.kt index 8e3d6cb5..52a0bbd3 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/LoadSpPlugin.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/LoadSpPlugin.kt @@ -12,7 +12,7 @@ import java.lang.reflect.Field * Created by 王朋飞 on 2022/7/13. * */ -class LoadSpPlugin : BasePlugin { +class LoadSpPlugin : BindBasePlugin { override fun dealField( obj: Any, diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/viewpager2/adapter/FragmentStateAdapter.kt b/QuickBind/src/main/java/com/wpf/app/quickbind/viewpager2/adapter/FragmentStateAdapter.kt index 5bbabe7c..1a8ccac7 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/viewpager2/adapter/FragmentStateAdapter.kt +++ b/QuickBind/src/main/java/com/wpf/app/quickbind/viewpager2/adapter/FragmentStateAdapter.kt @@ -7,11 +7,11 @@ import androidx.fragment.app.FragmentActivity import androidx.lifecycle.ViewModel import androidx.viewpager2.adapter.FragmentStateAdapter import com.wpf.app.quickbind.annotations.BindFragment2 -import com.wpf.app.quickbind.interfaces.Bind import com.wpf.app.quickbind.interfaces.BindBaseFragment import com.wpf.app.quickbind.interfaces.BindViewModel import com.wpf.app.quickbind.utils.getViewContext import com.wpf.app.quickbind.viewpager2.ViewPagerSize2 +import com.wpf.app.quickutil.bind.Bind class FragmentStateAdapter : FragmentStateAdapter, ViewPagerSize2 { diff --git a/QuickNetwork/src/main/java/com/wpf/app/quicknetwork/base/ListRequest.kt b/QuickNetwork/src/main/java/com/wpf/app/quicknetwork/base/ListRequest.kt new file mode 100644 index 00000000..1bff70e0 --- /dev/null +++ b/QuickNetwork/src/main/java/com/wpf/app/quicknetwork/base/ListRequest.kt @@ -0,0 +1,6 @@ +package com.wpf.app.quicknetwork.base + +abstract class ListRequest : BaseRequest() { + //是否是刷新 + var isRefresh = true +} \ No newline at end of file diff --git a/QuickRecyclerView/build.gradle b/QuickRecyclerView/build.gradle index d1a886f3..4648d3e8 100644 --- a/QuickRecyclerView/build.gradle +++ b/QuickRecyclerView/build.gradle @@ -37,9 +37,11 @@ dependencies { if (IS_REMOTE.toBoolean()) { api deps.quickbind.util api deps.quickbind.bind + api deps.quickbind.network } else { api project(":QuickUtil") api project(":QuickBind") + api project(":QuickNetwork") } } diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/QuickRefreshRecyclerView.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/QuickRefreshRecyclerView.kt index a5e75631..7b418282 100644 --- a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/QuickRefreshRecyclerView.kt +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/QuickRefreshRecyclerView.kt @@ -2,9 +2,12 @@ package com.wpf.app.quickrecyclerview import android.content.Context import android.util.AttributeSet +import androidx.recyclerview.widget.LinearLayoutManager import com.wpf.app.quickrecyclerview.data.QuickItemData import com.wpf.app.quickrecyclerview.data.RequestData -import com.wpf.app.quickrecyclerview.listeners.DataChangeOnListener +import com.wpf.app.quickrecyclerview.listeners.RefreshView +import com.wpf.app.quickrecyclerview.listeners.RequestAndCallback +import com.wpf.app.quickrecyclerview.listeners.RequestAndCallbackWithView import com.wpf.app.quickutil.Callback /** @@ -15,38 +18,40 @@ open class QuickRefreshRecyclerView @JvmOverloads constructor( mContext: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : QuickRecyclerView(mContext, attrs, defStyleAttr) { +) : QuickRecyclerView(mContext, attrs, defStyleAttr), RefreshView { + override var refreshView: RefreshView? = null @JvmField var mRequestData = RequestData(0) - private var mDataChangeListener: DataChangeOnListener? = null + private var mDataChangeListener: RequestAndCallbackWithView? = + null - fun setDataChangeListener(dataChangeListener: DataChangeOnListener) { + fun setDataChangeListener(dataChangeListener: RequestAndCallbackWithView) { mDataChangeListener = dataChangeListener } - fun onRefresh() { + override fun onRefresh() { mRequestData.refresh() - (mDataChangeListener as? DataChangeOnListener)?.onRefresh( - mRequestData, object : Callback { + (mDataChangeListener as? RequestAndCallbackWithView) + ?.requestAndCallback(this, mRequestData, object : Callback { override fun callback(data: List?) { setNewData(data) + mRequestData.loadDataSize(data?.size ?: 0) adapter.notifyDataSetChanged() } }) mDataChangeListener?.refreshFinish() - } - fun onLoadMore() { + override fun onLoadMore() { mRequestData.loadMore() - (mDataChangeListener as? DataChangeOnListener)?.onLoadMore( - mRequestData, - object : Callback { + (mDataChangeListener as? RequestAndCallbackWithView) + ?.requestAndCallback(this, mRequestData, object : Callback { override fun callback(data: List?) { appendList(data) + mRequestData.loadDataSize(data?.size ?: 0) adapter.notifyItemRangeInserted( size() - (data?.size ?: 0), (data?.size ?: 0) ) diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt index 172dfe48..0cebd4e5 100644 --- a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/QuickBindData.kt @@ -6,9 +6,8 @@ import androidx.annotation.CallSuper import androidx.annotation.LayoutRes import com.wpf.app.quickrecyclerview.QuickAdapter import com.wpf.app.quickrecyclerview.holder.QuickViewHolder -import com.wpf.app.quickbind.QuickBind -import com.wpf.app.quickbind.QuickBind.dealInPlugins -import com.wpf.app.quickbind.interfaces.Bind +import com.wpf.app.quickutil.bind.Bind +import com.wpf.app.quickutil.bind.QuickBindWrap /** * Created by 王朋飞 on 2022/7/13. @@ -17,7 +16,7 @@ import com.wpf.app.quickbind.interfaces.Bind open class QuickBindData @JvmOverloads constructor( @LayoutRes open val layoutId: Int = 0, @Transient open val layoutView: View? = null, - override val isSuspension: Boolean = false, //View是否悬浮置顶 + isSuspension: Boolean = false, //View是否悬浮置顶 ) : QuickItemData(isSuspension = isSuspension), Bind { @Transient @@ -34,7 +33,7 @@ open class QuickBindData @JvmOverloads constructor( open fun onCreateViewHolder(itemView: View) { this.mView = itemView if (dealBind) { - QuickBind.bind(this) + QuickBindWrap.bind(this) } } @@ -55,7 +54,9 @@ open class QuickBindData @JvmOverloads constructor( onCreateViewHolder(itemView = viewHolder.itemView) } if (dealBind) { - dealInPlugins(this, null, QuickBind.bindPlugin) + QuickBindWrap.getBindPlugin()?.let { + QuickBindWrap.dealInPlugins(this, null, it) + } } isFirstLoad = false } diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/RequestData.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/RequestData.kt index 42045fad..2f7a00f0 100644 --- a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/RequestData.kt +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/data/RequestData.kt @@ -1,18 +1,35 @@ package com.wpf.app.quickrecyclerview.data +import androidx.annotation.CallSuper + /** * Created by 王朋飞 on 2022/7/13. * */ -open class RequestData( +open class RequestData @JvmOverloads constructor( open var page: Int = 0, open var pageSize: Int = 10 ) { + + var isRefresh = true + //刷新偏移量 + var offset: Int = 0 open fun refresh() { page = 0 + isRefresh = true + offset = 0 } open fun loadMore() { page++ + isRefresh = false + } + + /** + * 每次刷新或加载更多的数量 + */ + @CallSuper + open fun loadDataSize(size: Int) { + offset += size } } \ No newline at end of file diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2LinearLayout.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2LinearLayout.kt index 419927b5..5a25d312 100644 --- a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2LinearLayout.kt +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2LinearLayout.kt @@ -1,8 +1,7 @@ package com.wpf.app.quickrecyclerview.helper import android.widget.LinearLayout -import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper import com.wpf.app.quickrecyclerview.QuickAdapter import com.wpf.app.quickrecyclerview.data.QuickItemData @@ -11,10 +10,9 @@ import com.wpf.app.quickrecyclerview.data.QuickItemData * Created by 王朋飞 on 2022/7/20. * */ -object List2LinearLayout : BindD2VHHelper> { +object List2LinearLayout : BindD2VHelper> { override fun initView( - viewHolder: RecyclerView.ViewHolder?, view: LinearLayout, data: List ) { diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2RecyclerView.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2RecyclerView.kt index 05cc638e..f305c805 100644 --- a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2RecyclerView.kt +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/List2RecyclerView.kt @@ -1,19 +1,17 @@ package com.wpf.app.quickrecyclerview.helper -import androidx.recyclerview.widget.RecyclerView import com.wpf.app.quickrecyclerview.data.QuickItemData import com.wpf.app.quickrecyclerview.QuickRecyclerView -import com.wpf.app.quickbind.annotations.BindD2VHHelper +import com.wpf.app.quickbind.annotations.BindD2VHelper /** * Created by 王朋飞 on 2022/7/20. * */ -object List2RecyclerView: BindD2VHHelper> { +object List2RecyclerView: BindD2VHelper> { override fun initView( - viewHolder: RecyclerView.ViewHolder?, view: QuickRecyclerView, data: List ) { diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/Request2RefreshView.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/Request2RefreshView.kt new file mode 100644 index 00000000..5ada612f --- /dev/null +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/helper/Request2RefreshView.kt @@ -0,0 +1,70 @@ +package com.wpf.app.quickrecyclerview.helper + +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import com.wpf.app.quickbind.annotations.BindD2VHelper +import com.wpf.app.quickrecyclerview.QuickAdapter +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.RequestAndCallbackWithView +import com.wpf.app.quickutil.Callback +import java.lang.reflect.ParameterizedType + +object Request2RefreshView : + BindD2VHelper> { + + override fun initView( + view: View, + data: RequestAndCallbackWithView + ) { + if (view is QuickRefreshRecyclerView) { + view.setDataChangeListener(data as RequestAndCallbackWithView) + } else if (view is RecyclerView && view is RefreshView && view.adapter is QuickAdapter) { + val quickAdapter = view.adapter 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 RequestAndCallbackWithView + view.refreshView = object : RefreshView { + override var refreshView: RefreshView? = this + + override fun onRefresh() { + super.onRefresh() + requestData.refresh() + realData.requestAndCallback(view, requestData, object : Callback { + override fun callback(data: List?) { + quickAdapter.mDataList?.clear() + quickAdapter.appendList(data) + requestData.loadDataSize(data?.size ?: 0) + if (!realData.refreshFinish()) { + quickAdapter.notifyDataSetChanged() + } + } + }) + realData.refreshFinish() + } + + override fun onLoadMore() { + super.onLoadMore() + requestData.loadMore() + realData.requestAndCallback(view, requestData, object : Callback { + override fun callback(data: List?) { + quickAdapter.appendList(data) + requestData.loadDataSize(data?.size ?: 0) + if (!realData.loadMoreFinish()) { + quickAdapter.notifyDataSetChanged() + } + } + }) + realData.loadMoreFinish() + } + } + } else { + //是普通RecyclerView + } + } +} \ No newline at end of file diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/DataChangeOnListener.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/DataChangeOnListener.kt deleted file mode 100644 index bfad8935..00000000 --- a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/DataChangeOnListener.kt +++ /dev/null @@ -1,31 +0,0 @@ -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.Callback - -/** - * Created by 王朋飞 on 2022/7/13. - * - */ -interface DataChangeOnListener { - /** - * 下拉刷新 - */ - fun onRefresh(requestData: Request, callback: Callback) - - /** - * 上拉加载 - */ - fun onLoadMore(requestData: Request, callback: Callback) - - /** - * 刷新结束 - */ - fun refreshFinish() {} - - /** - * 加载结束 - */ - fun loadMoreFinish() {} -} \ No newline at end of file diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RefreshView.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RefreshView.kt new file mode 100644 index 00000000..60301e62 --- /dev/null +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RefreshView.kt @@ -0,0 +1,10 @@ +package com.wpf.app.quickrecyclerview.listeners + +interface RefreshView { + + var refreshView: RefreshView? + + fun onRefresh() {} + + fun onLoadMore() {} +} \ No newline at end of file diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RequestAndCallback.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RequestAndCallback.kt new file mode 100644 index 00000000..8fe6fa33 --- /dev/null +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RequestAndCallback.kt @@ -0,0 +1,77 @@ +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.Callback + +/** + * Created by 王朋飞 on 2022/7/13. + * + */ +interface RequestAndCallback: RequestAndCallbackWithView { + + /** + * 接口请求 + */ + fun requestAndCallback(requestData: Request, callback: Callback) + + override fun requestAndCallback(view: Any, requestData: Request, callback: Callback) { + requestAndCallback(requestData, callback) + } +} + +interface RequestAndCallbackWithView { + + /** + * 接口请求 + */ + fun requestAndCallback(view: View, requestData: Request, callback: Callback) + + /** + * 刷新结束 + * 返回true表示刷新结束后自己刷新adapter + */ + fun refreshFinish(): Boolean { return false } + + /** + * 加载结束 + * 返回true表示刷新结束后自己刷新adapter + */ + fun loadMoreFinish(): Boolean { return false } +} + +fun requestData2List( + callbackF: (requestData: Request, callback: Callback) -> Unit +) = object : RequestAndCallback { + + override fun requestAndCallback(requestData: Request, callback: Callback) { + callbackF.invoke(requestData, callback) + } +} + +fun requestData2ListWithView( + callbackF: (view: View, requestData: Request, callback: Callback) -> Unit +) = object : RequestAndCallbackWithView { + + override fun requestAndCallback(view: View, requestData: Request, callback: Callback) { + callbackF.invoke(view, requestData, callback) + } +} + +fun request2List( + callbackF: (requestData: RequestData, callback: Callback) -> Unit +) = object : RequestAndCallback { + + override fun requestAndCallback(requestData: RequestData, callback: Callback) { + callbackF.invoke(requestData, callback) + } +} + +fun request2ListWithView( + callbackF: (view: View, requestData: RequestData, callback: Callback) -> Unit +) = object : RequestAndCallbackWithView { + + override fun requestAndCallback(view: View, requestData: RequestData, callback: Callback) { + callbackF.invoke(view, requestData, callback) + } +} \ No newline at end of file diff --git a/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RequestAndItemCallback.kt b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RequestAndItemCallback.kt new file mode 100644 index 00000000..7972b309 --- /dev/null +++ b/QuickRecyclerView/src/main/java/com/wpf/app/quickrecyclerview/listeners/RequestAndItemCallback.kt @@ -0,0 +1,10 @@ +package com.wpf.app.quickrecyclerview.listeners + +import com.wpf.app.quickrecyclerview.data.QuickItemData +import com.wpf.app.quickrecyclerview.data.RequestData + +/** + * Created by 王朋飞 on 2022/7/13. + * + */ +interface RequestAndItemCallback: RequestAndCallback \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/interfaces/Bind.kt b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/Bind.kt similarity index 85% rename from QuickBind/src/main/java/com/wpf/app/quickbind/interfaces/Bind.kt rename to QuickUtil/src/main/java/com/wpf/app/quickutil/bind/Bind.kt index f2e2aac5..fc308809 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/interfaces/Bind.kt +++ b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/Bind.kt @@ -1,4 +1,4 @@ -package com.wpf.app.quickbind.interfaces +package com.wpf.app.quickutil.bind import android.os.Bundle import android.view.View diff --git a/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/QuickBindI.kt b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/QuickBindI.kt new file mode 100644 index 00000000..73214957 --- /dev/null +++ b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/QuickBindI.kt @@ -0,0 +1,42 @@ +package com.wpf.app.quickutil.bind + +import android.app.Activity +import android.app.Dialog +import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModel +import androidx.recyclerview.widget.RecyclerView +import com.wpf.app.quickutil.bind.plugins.BasePlugin +import kotlin.reflect.KClass + +interface QuickBindI { + + fun bind(activity: Activity) + + fun bind(activity: Activity, viewModel: ViewModel?) + + fun bind(fragment: Fragment) + + fun bind(fragment: Fragment, viewModel: ViewModel?) + + fun bind(viewHolder: RecyclerView.ViewHolder) + + fun bind(dialog: Dialog) + + fun bind(bind: T) + + fun getRegisterPlugins(): MutableMap, BasePlugin>? + + fun getBindPlugin(): MutableMap, BasePlugin>? + + fun registerPlugin(ann: KClass, plugin: T) + + fun registerPlugin(index: Int, ann: KClass, plugin: T) + + fun dealInPlugins(obj: Any?, viewModel: ViewModel?) + + fun dealInPlugins( + obj: Any?, + viewModel: ViewModel?, + plugins: MutableMap, BasePlugin> + ) +} \ No newline at end of file diff --git a/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/QuickBindWrap.kt b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/QuickBindWrap.kt new file mode 100644 index 00000000..8ab9847d --- /dev/null +++ b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/QuickBindWrap.kt @@ -0,0 +1,77 @@ +package com.wpf.app.quickutil.bind + +import android.app.Activity +import android.app.Dialog +import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModel +import androidx.recyclerview.widget.RecyclerView +import com.wpf.app.quickutil.bind.plugins.BasePlugin +import kotlin.reflect.KClass + +object QuickBindWrap: QuickBindI { + private var quickBindI: QuickBindI? = null + init { + try { + quickBindI = Class.forName("com.wpf.app.quickbind.QuickBind").getField("INSTANCE").get(null) as QuickBindI + } catch (e : Exception) { + e.printStackTrace() + } + } + + override fun bind(activity: Activity) { + quickBindI?.bind(activity) + } + + override fun bind(activity: Activity, viewModel: ViewModel?) { + quickBindI?.bind(activity, viewModel) + } + + override fun bind(fragment: Fragment) { + quickBindI?.bind(fragment) + } + + override fun bind(fragment: Fragment, viewModel: ViewModel?) { + quickBindI?.bind(fragment, viewModel) + } + + override fun bind(viewHolder: RecyclerView.ViewHolder) { + quickBindI?.bind(viewHolder) + } + + override fun bind(dialog: Dialog) { + quickBindI?.bind(dialog) + } + + override fun bind(bind: T) { + quickBindI?.bind(bind) + } + + override fun getRegisterPlugins(): MutableMap, BasePlugin>? { + return quickBindI?.getRegisterPlugins() + } + + override fun getBindPlugin(): MutableMap, BasePlugin>? { + return quickBindI?.getBindPlugin() + } + + override fun registerPlugin(ann: KClass, plugin: T) { + quickBindI?.registerPlugin(ann, plugin) + } + + override fun registerPlugin(index: Int, ann: KClass, plugin: T) { + quickBindI?.registerPlugin(index, ann, plugin) + } + + override fun dealInPlugins(obj: Any?, viewModel: ViewModel?) { + quickBindI?.dealInPlugins(obj, viewModel) + } + + override fun dealInPlugins( + obj: Any?, + viewModel: ViewModel?, + plugins: MutableMap, BasePlugin> + ) { + quickBindI?.dealInPlugins(obj, viewModel, plugins) + } + +} \ No newline at end of file diff --git a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BasePlugin.kt b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/plugins/BasePlugin.kt similarity index 66% rename from QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BasePlugin.kt rename to QuickUtil/src/main/java/com/wpf/app/quickutil/bind/plugins/BasePlugin.kt index 3e88b487..113ac4d7 100644 --- a/QuickBind/src/main/java/com/wpf/app/quickbind/plugins/BasePlugin.kt +++ b/QuickUtil/src/main/java/com/wpf/app/quickutil/bind/plugins/BasePlugin.kt @@ -1,4 +1,4 @@ -package com.wpf.app.quickbind.plugins +package com.wpf.app.quickutil.bind.plugins import android.app.Activity import android.app.Dialog @@ -9,9 +9,7 @@ import androidx.annotation.Nullable import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModel import androidx.recyclerview.widget.RecyclerView -import com.wpf.app.quick.runtime.Databinder -import com.wpf.app.quickbind.QuickBind -import com.wpf.app.quickbind.interfaces.Bind +import com.wpf.app.quickutil.bind.Bind import java.lang.reflect.Field /** @@ -27,34 +25,6 @@ interface BasePlugin { return viewModel ?: obj } - fun getSaveId( - @NonNull obj: Any, - @Nullable viewModel: ViewModel?, - @NonNull field: Field, - id: Int - ): Int { - val dataBinder: Databinder = - QuickBind.BINDEDMAP[getRealObj(obj, viewModel).javaClass] ?: return id - val value: Any? = dataBinder.getFieldValue(field.name + "BindViewId") - return if (value is Int) { - value - } else id - } - - @Nullable - fun getSaveIdList( - @NonNull obj: Any, - @Nullable viewModel: ViewModel?, - @NonNull field: Field - ): ArrayList? { - val dataBinder: Databinder = - QuickBind.BINDEDMAP[getRealObj(obj, viewModel).javaClass] ?: return null - val value: Any? = dataBinder.getFieldValue(field.name) - return if (value is ArrayList<*>) { - value as ArrayList - } else null - } - fun getContext(obj: Any?): Context? { if (obj == null) return null var context: Context? = null diff --git a/app/src/main/java/com/wpf/app/quick/demo/RefreshListTestActivity.kt b/app/src/main/java/com/wpf/app/quick/demo/RefreshListTestActivity.kt index c37088fa..82c0b197 100644 --- a/app/src/main/java/com/wpf/app/quick/demo/RefreshListTestActivity.kt +++ b/app/src/main/java/com/wpf/app/quick/demo/RefreshListTestActivity.kt @@ -3,10 +3,12 @@ package com.wpf.app.quick.demo import android.annotation.SuppressLint import com.scwang.smart.refresh.layout.SmartRefreshLayout import com.wpf.app.quick.activity.QuickActivity +import com.wpf.app.quick.annotations.BindData2View import com.wpf.app.quick.annotations.BindView -import com.wpf.app.quick.demo.model.ListRequest -import com.wpf.app.quick.demo.model.RefreshItem -import com.wpf.app.quickutil.Callback +import com.wpf.app.quick.demo.http.request +import com.wpf.app.quickrecyclerview.QuickRefreshRecyclerView +import com.wpf.app.quickrecyclerview.helper.Request2RefreshView +import com.wpf.app.quickrecyclerview.listeners.request2List /** * Created by 王朋飞 on 2022/7/8. @@ -18,45 +20,28 @@ class RefreshListTestActivity : QuickActivity(R.layout.activity_refresh_list, ti @SuppressLint("NonConstantResourceId") @BindView(R.id.list) - var mRecyclerView: com.wpf.app.quickrecyclerview.QuickRefreshRecyclerView? = null - override fun initView() { - mRecyclerView?.mRequestData = ListRequest(0) - mRecyclerView?.setDataChangeListener(object : - com.wpf.app.quickrecyclerview.listeners.DataChangeOnListener { - override fun onLoadMore(requestData: ListRequest, callback: Callback) { - if (requestData.page > 2) { - mSmartRefreshLayout?.setEnableLoadMore(false) - } - Thread { - try { - Thread.sleep(500) - } catch (e: InterruptedException) { - e.printStackTrace() - } - mSmartRefreshLayout?.post { - mSmartRefreshLayout?.finishLoadMore() - callback.callback(arrayListOf(RefreshItem(), RefreshItem(), RefreshItem(),RefreshItem(), RefreshItem(), RefreshItem(),RefreshItem(), RefreshItem(), RefreshItem())) - } - }.start() - } + var mRecyclerView: QuickRefreshRecyclerView? = null - override fun onRefresh(requestData: ListRequest, callback: Callback) { - Thread { - try { - Thread.sleep(500) - } catch (e: InterruptedException) { - e.printStackTrace() - } - mSmartRefreshLayout?.post { - mSmartRefreshLayout?.finishRefresh() - callback.callback(arrayListOf(RefreshItem(), RefreshItem(),RefreshItem(), RefreshItem(), RefreshItem(),RefreshItem(), RefreshItem(), RefreshItem(),RefreshItem(), RefreshItem(), RefreshItem(), RefreshItem(), RefreshItem(), RefreshItem(),RefreshItem(), RefreshItem(), RefreshItem(),RefreshItem(), RefreshItem(), RefreshItem())) - } - }.start() + @SuppressLint("NonConstantResourceId") + @BindData2View(id = R.id.list, helper = Request2RefreshView::class) + val request2List = request2List { requestData, callback -> + request { + 首页文章列表(requestData.page) + }.success { + callback.callback(it?.data?.datas) + }.after { + if (requestData.isRefresh) { + mSmartRefreshLayout?.finishRefresh() + } else { + mSmartRefreshLayout?.finishLoadMore() } + } + } + - }) + override fun initView() { mSmartRefreshLayout?.setOnRefreshListener { mRecyclerView?.onRefresh() } mSmartRefreshLayout?.setOnLoadMoreListener { mRecyclerView?.onLoadMore() } - mRecyclerView?.onRefresh() + mSmartRefreshLayout?.autoRefresh() } } \ No newline at end of file diff --git a/app/src/main/java/com/wpf/app/quick/demo/adapterholder/MyMessageHolder.kt b/app/src/main/java/com/wpf/app/quick/demo/adapterholder/MyMessageHolder.kt index 716b533a..355af38f 100644 --- a/app/src/main/java/com/wpf/app/quick/demo/adapterholder/MyMessageHolder.kt +++ b/app/src/main/java/com/wpf/app/quick/demo/adapterholder/MyMessageHolder.kt @@ -4,7 +4,6 @@ import android.view.ViewGroup import com.wpf.app.quick.demo.R import com.wpf.app.quick.demo.databinding.HolderMessageMyBinding import com.wpf.app.quick.demo.model.MyMessage -import com.wpf.app.quickrecyclerview.QuickAdapter import com.wpf.app.quickrecyclerview.holder.QuickViewBindingHolder /** diff --git a/app/src/main/java/com/wpf/app/quick/demo/http/TestApi.kt b/app/src/main/java/com/wpf/app/quick/demo/http/TestApi.kt index 2208e34d..bdc13f2d 100644 --- a/app/src/main/java/com/wpf/app/quick/demo/http/TestApi.kt +++ b/app/src/main/java/com/wpf/app/quick/demo/http/TestApi.kt @@ -10,6 +10,6 @@ interface TestApi { @GET("/article/list/{page}/json") fun 首页文章列表( - @Path("page") path: Int + @Path("page") page: Int ): TestCommonCall<首页文章> } \ No newline at end of file diff --git "a/app/src/main/java/com/wpf/app/quick/demo/http/model/\351\246\226\351\241\265\346\226\207\347\253\240.kt" "b/app/src/main/java/com/wpf/app/quick/demo/http/model/\351\246\226\351\241\265\346\226\207\347\253\240.kt" index 39af32ac..db878700 100644 --- "a/app/src/main/java/com/wpf/app/quick/demo/http/model/\351\246\226\351\241\265\346\226\207\347\253\240.kt" +++ "b/app/src/main/java/com/wpf/app/quick/demo/http/model/\351\246\226\351\241\265\346\226\207\347\253\240.kt" @@ -1,10 +1,18 @@ package com.wpf.app.quick.demo.http.model +import android.annotation.SuppressLint +import com.wpf.app.quick.annotations.BindData2View +import com.wpf.app.quick.demo.R +import com.wpf.app.quickbind.helper.binddatahelper.Text2TextView +import com.wpf.app.quickrecyclerview.data.QuickBindData + class 首页文章 { val curPage: Int? = null val datas: List<文章>? = null - class 文章 { + class 文章: QuickBindData(layoutId = R.layout.holder_refresh_item) { + @SuppressLint("NonConstantResourceId") + @BindData2View(id = R.id.title, helper = Text2TextView::class) val title: String?= null } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 3b86e6d8..b26b5e96 100755 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ android.nonTransitiveRClass=true IS_REMOTE=true GROUP=com.wpf.app.quick -VERSION_NAME=0.5.2 +VERSION_NAME=0.5.3 POM_DESCRIPTION=Quick Android.