diff --git a/app/src/main/java/com/kienht/bubble_picker/MainActivity.kt b/app/src/main/java/com/kienht/bubble_picker/MainActivity.kt index b5ebfa8..6e7d29e 100644 --- a/app/src/main/java/com/kienht/bubble_picker/MainActivity.kt +++ b/app/src/main/java/com/kienht/bubble_picker/MainActivity.kt @@ -56,9 +56,7 @@ class MainActivity : AppCompatActivity() { override fun onResume() { super.onResume() - if (picker.isStarted) { - picker.onResume() - } + picker.onResume() } override fun onPause() { diff --git a/bubblepicker/src/main/java/com/kienht/bubblepicker/rendering/BubblePicker.kt b/bubblepicker/src/main/java/com/kienht/bubblepicker/rendering/BubblePicker.kt index 76b2b09..cfc1e1f 100755 --- a/bubblepicker/src/main/java/com/kienht/bubblepicker/rendering/BubblePicker.kt +++ b/bubblepicker/src/main/java/com/kienht/bubblepicker/rendering/BubblePicker.kt @@ -5,6 +5,7 @@ import android.graphics.PixelFormat import android.opengl.GLSurfaceView import android.support.annotation.ColorInt import android.util.AttributeSet +import android.util.Log import android.view.MotionEvent import com.kienht.bubblepicker.BubblePickerListener import com.kienht.bubblepicker.R @@ -16,6 +17,7 @@ import com.kienht.bubblepicker.model.PickerItem * Created by irinagalata on 1/19/17. */ class BubblePicker : GLSurfaceView { + val renderer = PickerRenderer(this) @ColorInt var background: Int = 0 @@ -24,14 +26,28 @@ class BubblePicker : GLSurfaceView { renderer.backgroundColor = Color(value) } - var datas: List? = null + var isStarted: Boolean = false + + var datas: List = ArrayList() set(value) { field = value - renderer.items = value ?: ArrayList() + renderer.items = value onResume() } - val isStarted: Boolean = datas != null + override fun onResume() { + if (!isStarted && renderer.items.isNotEmpty()) { + super.onResume() + isStarted = true + } + } + + override fun onPause() { + if (isStarted && renderer.items.isNotEmpty()) { + super.onPause() + isStarted = false + } + } var adapter: BubblePickerAdapter? = null set(value) { @@ -42,20 +58,24 @@ class BubblePicker : GLSurfaceView { onResume() } } + var maxSelectedCount: Int? = null set(value) { renderer.maxSelectedCount = value } + var listener: BubblePickerListener? = null set(value) { renderer.listener = value } + var bubbleSize = 50 set(value) { if (value in 1..100) { renderer.bubbleSize = value } } + val selectedItems: List get() = renderer.selectedItems @@ -65,7 +85,6 @@ class BubblePicker : GLSurfaceView { renderer.centerImmediately = value } - val renderer = PickerRenderer(this) private var startX = 0f private var startY = 0f private var previousX = 0f