Skip to content

Commit d9d0d1b

Browse files
authored
Open constructor without container and setContainer in ZoomEngine (#193)
1 parent 373da27 commit d9d0d1b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ import kotlin.math.min
3535
open class ZoomEngine
3636
/**
3737
* Constructs an helper instance.
38+
* The creator has to ensure that [setContainer] is called before any other operation is performed.
3839
*
3940
* @param context a valid context
4041
*/
41-
internal constructor(context: Context) : ZoomApi {
42+
constructor(context: Context) : ZoomApi {
4243

4344
/**
4445
* Constructs an helper instance.
@@ -351,6 +352,10 @@ internal constructor(context: Context) : ZoomApi {
351352
*
352353
*/
353354
fun addListener(listener: Listener) {
355+
// fail fast if the engine is not initialized properly
356+
if (!::container.isInitialized) {
357+
error("container is not initialized.")
358+
}
354359
dispatcher.addListener(listener)
355360
}
356361

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

532537
/**
533538
* Set a container to perform transformations on.
534-
* This method should only be called once at initialization time.
539+
* This method can only be called once at initialization time. It throws an exception if
540+
* it is called twice.
535541
*
536542
* @param container view
537543
*/
538-
internal fun setContainer(container: View) {
544+
fun setContainer(container: View) {
545+
if(this::container.isInitialized) {
546+
error("container already set")
547+
}
539548
this.container = container
540549
this.container.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
541550
override fun onViewAttachedToWindow(view: View) {

0 commit comments

Comments
 (0)