Skip to content

Commit

Permalink
hot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hantrungkien committed Jul 20, 2018
1 parent 0e1cd46 commit 98bcfb2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class BubblePicker : GLSurfaceView {
}

override fun onResume() {
if (!isStarted && renderer.items.isNotEmpty()) {
if (!isStarted && renderer.items != null && renderer.items!!.isNotEmpty()) {
super.onResume()
isStarted = true
}
}

override fun onPause() {
if (isStarted && renderer.items.isNotEmpty()) {
if (isStarted && renderer.items!!.isNotEmpty()) {
super.onPause()
isStarted = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,24 @@ class PickerRenderer(val glView: View) : GLSurfaceView.Renderer {
}

var backgroundColor: Color? = null

var maxSelectedCount: Int? = null
set(value) {
Engine.maxSelectedCount = value
}

var bubbleSize = 50
set(value) {
Engine.radius = value
}

var listener: BubblePickerListener? = null
var items: List<PickerItem> = ArrayList()

var items: List<PickerItem> ?= null

val selectedItems: List<PickerItem?>
get() = Engine.selectedBodies.map { circles.firstOrNull { circle -> circle.circleBody == it }?.pickerItem }

var centerImmediately = false
set(value) {
field = value
Expand All @@ -60,8 +66,10 @@ class PickerRenderer(val glView: View) : GLSurfaceView.Renderer {

private val scaleX: Float
get() = if (glView.width < glView.height) glView.height.toFloat() / glView.width.toFloat() else 1f

private val scaleY: Float
get() = if (glView.width < glView.height) 1f else glView.width.toFloat() / glView.height.toFloat()

private val circles = ArrayList<Item>()

override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
Expand All @@ -82,17 +90,28 @@ class PickerRenderer(val glView: View) : GLSurfaceView.Renderer {
}

private fun initialize() {
if(items == null){
return
}

clear()

Engine.centerImmediately = centerImmediately
Engine.build(items.size, scaleX, scaleY).forEachIndexed { index, body ->
circles.add(Item(WeakReference(glView.context), items[index], body, isAlwaysSelected))

Engine.build(items!!.size, scaleX, scaleY)
.forEachIndexed { index, body ->
circles.add(Item(WeakReference(glView.context), items!![index], body, isAlwaysSelected))
}

items!!.forEach {
if (circles.isNotEmpty() && (it.isSelected || isAlwaysSelected)) {
Engine.resize(circles.first { circle -> circle.pickerItem == it })
}
}
items.forEach {
if (it.isSelected || isAlwaysSelected) Engine.resize(circles.first { circle ->
circle.pickerItem == it
})

if (textureIds == null) {
textureIds = IntArray(circles.size * 2)
}
if (textureIds == null) textureIds = IntArray(circles.size * 2)
initializeArrays()
}

Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

buildscript {
ext.kotlin_version = '1.2.51'
ext.kotlin_version = '1.2.30'
repositories {
google()
jcenter()
Expand Down

0 comments on commit 98bcfb2

Please sign in to comment.