Skip to content

Commit

Permalink
add attachContentView function and findView
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdi-khosravi-sh committed Jan 21, 2022
1 parent 00f3ffa commit 49f802f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion arrowpanel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -411,7 +412,7 @@ open class ArrowPanel(context: Context) : Panel(context) {
return arrowLayout
}

open fun findView(id: Int): View {
open fun <T : View> findView(@IdRes id: Int): T {
return arrowLayout.findViewById(id)
}

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

Expand All @@ -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
Expand Down

0 comments on commit 49f802f

Please sign in to comment.