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 223bc07 commit 9471710
Show file tree
Hide file tree
Showing 56 changed files with 532 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Created by 王朋飞 on 2022/7/6.
*/
public interface BindD2VHelper<VH, V, Data> {
public interface BindD2VHHelper<VH, V, Data> {

void initView(@Nullable VH viewHolder, @NonNull V view, @NonNull Data data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
public @interface BindData2View {
@IdRes int id() default Constants.NO_RES_ID;

Class<? extends BindD2VHelper> helper() default BindD2VHelper.class;
Class<? extends BindD2VHHelper> helper() default BindD2VHHelper.class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
2 changes: 2 additions & 0 deletions QuickBind/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
45 changes: 30 additions & 15 deletions QuickBind/src/main/java/com/wpf/app/quickbind/QuickBind.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<KClass<out Annotation>, BasePlugin> = LinkedHashMap()
val bindPlugin: MutableMap<KClass<out Annotation>, BasePlugin> =
linkedMapOf(Pair(BindData2View::class, BindData2ViewPlugin()))
private val plugins: ArrayMap<KClass<out Annotation>, BasePlugin> = ArrayMap()
val bindPlugin = arrayMapOf<KClass<out Annotation>, BasePlugin>(Pair(BindData2View::class, BindData2ViewPlugin()))

fun <T : BasePlugin> registerPlugin(ann: KClass<out Annotation>, plugin: T) {
override fun getRegisterPlugins(): MutableMap<KClass<out Annotation>, BasePlugin> {
return plugins
}

override fun getBindPlugin(): MutableMap<KClass<out Annotation>, BasePlugin> {
return bindPlugin
}

override fun <T : BasePlugin> registerPlugin(ann: KClass<out Annotation>, plugin: T) {
plugins[ann] = plugin
}

override fun <T : BasePlugin> registerPlugin(index: Int, ann: KClass<out Annotation>, plugin: T) {
plugins.put(ann, plugin)
}

init {
//顺序不能乱
registerPlugin(BindView::class, BindViewPlugin())
Expand All @@ -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 <T : Bind> bind(bind: T) {
override fun <T : Bind> bind(bind: T) {
bind.getView()?.let {
bindBinder(bind, bind.getView()!!)
}
Expand Down Expand Up @@ -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<KClass<out Annotation>, BasePlugin>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<V : View, Data : Any> :
BindD2VHHelper<RecyclerView.ViewHolder, V, Data> {

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

fun initView(view: V, data: Data)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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.
*
*/
object BindData2ViewHelper {

fun <Data: Any, V : View, Helper : BindD2VHHelper<V, Data>> bind(
fun <Data: Any, V : View, Helper : BindD2VHelper<V, Data>> bind(
view: V,
data: Data,
helper: Helper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextView, Int> {
object Color2TextView: BindD2VHelper<TextView, Int> {

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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<View, Int> {
object Color2View: BindD2VHelper<View, Int> {

override fun initView(viewHolder: RecyclerView.ViewHolder?, view: View, @DrawableRes data: Int) {
override fun initView(view: View, @DrawableRes data: Int) {
view.setBackgroundColor(data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageView, Int> {
object Drawable2ImageView : BindD2VHelper<ImageView, Int> {

override fun initView(viewHolder: RecyclerView.ViewHolder?, view: ImageView, data: Int) {
override fun initView(view: ImageView, data: Int) {
if (data != 0) {
view.setImageResource(data)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View, Int> {
object DrawableRes2View: BindD2VHelper<View, Int> {

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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<View, Int> {
object Height2View : BindD2VHelper<View, Int> {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View, View.OnClickListener> {
object ItemClick : BindD2VHelper<View, View.OnClickListener> {

override fun initView(
viewHolder: RecyclerView.ViewHolder?,
view: View,
data: View.OnClickListener
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CheckBox, Boolean> {
object Select2CheckBox : BindD2VHelper<CheckBox, Boolean> {

override fun initView(viewHolder: RecyclerView.ViewHolder?, view: CheckBox, aBoolean: Boolean) {
view.isChecked = aBoolean
override fun initView(view: CheckBox, data: Boolean) {
view.isChecked = data
}
}
Loading

0 comments on commit 9471710

Please sign in to comment.