diff --git a/arrowpanel/build.gradle b/arrowpanel/build.gradle index 17e3d83..af965a0 100644 --- a/arrowpanel/build.gradle +++ b/arrowpanel/build.gradle @@ -6,7 +6,7 @@ plugins { def LIB_GROUP_ID = 'com.mahdikh.vision' def LIB_ARTIFACT_ID = 'arrowpanel' -def LIB_VERSION = '4.0.8' +def LIB_VERSION = '4.1.0' android { compileSdk 30 diff --git a/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/ArrowPanel.kt b/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/ArrowPanel.kt index 4633c95..a862001 100644 --- a/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/ArrowPanel.kt +++ b/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/ArrowPanel.kt @@ -13,6 +13,7 @@ import android.view.View.OnLongClickListener import android.view.WindowManager.LayoutParams import androidx.annotation.CallSuper import androidx.annotation.ColorInt +import androidx.annotation.IdRes import androidx.annotation.LayoutRes import androidx.fragment.app.FragmentActivity import com.mahdikh.vision.arrowpanel.animator.BaseAnimator @@ -411,7 +412,7 @@ open class ArrowPanel(context: Context) : Panel(context) { return arrowLayout } - open fun findView(id: Int): View { + open fun findView(@IdRes id: Int): T { return arrowLayout.findViewById(id) } @@ -528,6 +529,10 @@ open class ArrowPanel(context: Context) : Panel(context) { private val panelParams = PanelParams() private val arrowPanel = ArrowPanel(context) + fun attachContentView() { + panelParams.attachContentView(arrowPanel) + } + fun setContentView(view: View): Builder { panelParams.mView = view panelParams.mViewLayoutResId = 0 diff --git a/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/PanelParams.kt b/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/PanelParams.kt index d8a1bfa..1514f87 100644 --- a/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/PanelParams.kt +++ b/arrowpanel/src/main/java/com/mahdikh/vision/arrowpanel/widget/PanelParams.kt @@ -3,7 +3,7 @@ package com.mahdikh.vision.arrowpanel.widget import android.view.View class PanelParams { - var mViewLayoutResId: Int = 0 + var mViewLayoutResId: Int = -1 var mView: View? = null var targetView: View? = null @@ -12,11 +12,31 @@ class PanelParams { var clickIds: IntArray? = null var longClickIds: IntArray? = null + var isAttachedContentView = false + + fun attachContentView(panel: ArrowPanel) { + val instance = mView + if (instance != null) { + isAttachedContentView = true + panel.setContentView(instance) + } else { + if (mViewLayoutResId != -1) { + isAttachedContentView = true + panel.setContentView(mViewLayoutResId) + return + } + throw NullPointerException() + } + } + fun apply(panel: ArrowPanel) { - mView?.let { - panel.setContentView(it) - } ?: kotlin.run { - panel.setContentView(mViewLayoutResId) + if (!isAttachedContentView) { + val instance = mView + if (instance != null) { + panel.setContentView(instance) + } else { + panel.setContentView(mViewLayoutResId) + } } val cIds = clickIds