I am making a mini drawing game app and I made this class to save draw Path with their according color, and now I need to save it so that other users of my app can go fetch that data and see the draw in real
class CustomPath(path: android.graphics.Path, paint: android.graphics.Paint)
But when I do myRefDraw?.push()?.setValue((array))
, where array is a ArrayList I get this error
"E/MessageQueue-JNI: com.google.firebase.database.DatabaseException: Serializing Collections is not supported, please use Lists instead"
Is there any better way to save this ArrayList somewhere where the other players of the game could fetch the data it is holding so that the draw appears on their respective screens?
The code:
class CanvasView(context: Context, attrs:AttributeSet?): View(context,attrs) {
private var mAuth: FirebaseAuth
private var mFirebaseDatabase:FirebaseDatabase
var paint: Paint = Paint()
var path: Path = Path()
var apagar: Boolean = false
var array = arrayListOf<CustomPath>()
private var database: FirebaseDatabase? = null
private var myRefDraw: DatabaseReference? = null
var c = CustomPath(path,paint)
override fun onDraw(canvas: Canvas) {
for (p in array) {
canvas.drawPath(p.getPath(), p.getPaint())
}
super.onDraw(canvas)
}
fun clear(){
array.clear()
invalidate()
}
override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
path = Path()
path.moveTo(event.x, event.y)
c = CustomPath(path,paint)
array.add(c)
myRefDraw?.push()?.setValue((array))
}
MotionEvent.ACTION_MOVE -> {
path.lineTo(event.x, event.y)
invalidate()
}
MotionEvent.ACTION_UP -> {
}
}
return true
}
init {
paint.color = Color.BLACK
paint.style = Paint.Style.STROKE
paint.strokeWidth = 12f
paint.strokeJoin = Paint.Join.ROUND;
paint.strokeCap = Paint.Cap.ROUND;
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRefDraw = mFirebaseDatabase.getReference("pathDraw");
}
}```
and
class CustomPath(path: android.graphics.Path, paint: android.graphics.Paint){
private var path: Path
private var paint: Paint
init {
this.paint = paint
this.path = path
}
fun setPath(path:Path){
this.path = path
}
fun getPath(): Path {
return this.path
}
fun setPaint(paint:Paint){
this.path = path
}
fun getPaint(): Paint {
return this.paint
}
}```