Skip to content

Commit

Permalink
Open constructor without container and setContainer in ZoomEngine (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeemakr committed Dec 12, 2020
1 parent 373da27 commit d9d0d1b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt
Expand Up @@ -35,10 +35,11 @@ import kotlin.math.min
open class ZoomEngine
/**
* Constructs an helper instance.
* The creator has to ensure that [setContainer] is called before any other operation is performed.
*
* @param context a valid context
*/
internal constructor(context: Context) : ZoomApi {
constructor(context: Context) : ZoomApi {

/**
* Constructs an helper instance.
Expand Down Expand Up @@ -351,6 +352,10 @@ internal constructor(context: Context) : ZoomApi {
*
*/
fun addListener(listener: Listener) {
// fail fast if the engine is not initialized properly
if (!::container.isInitialized) {
error("container is not initialized.")
}
dispatcher.addListener(listener)
}

Expand Down Expand Up @@ -531,11 +536,15 @@ internal constructor(context: Context) : ZoomApi {

/**
* Set a container to perform transformations on.
* This method should only be called once at initialization time.
* This method can only be called once at initialization time. It throws an exception if
* it is called twice.
*
* @param container view
*/
internal fun setContainer(container: View) {
fun setContainer(container: View) {
if(this::container.isInitialized) {
error("container already set")
}
this.container = container
this.container.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(view: View) {
Expand Down

0 comments on commit d9d0d1b

Please sign in to comment.