Created
December 28, 2017 11:27
-
-
Save MarcinMoskala/db8e182ecc526868149114fc6d088bd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.google.firebase.udacity.friendlychat | |
import com.google.firebase.database.ChildEventListener | |
import com.google.firebase.database.DataSnapshot | |
import com.google.firebase.database.DatabaseError | |
class _ChildEventListener( | |
private val _onCancelled: (DatabaseError) -> Unit, | |
private val _onChildMoved: (DataSnapshot, String?) -> Unit, | |
private val _onChildChanged: (DataSnapshot, String?) -> Unit, | |
private val _onChildAdded: (DataSnapshot, String?) -> Unit, | |
private val _onChildRemoved: (DataSnapshot) -> Unit | |
) : ChildEventListener { | |
override fun onCancelled(p0: DatabaseError) { | |
_onCancelled(p0) | |
} | |
override fun onChildMoved(p0: DataSnapshot, p1: String?) { | |
_onChildMoved(p0, p1) | |
} | |
override fun onChildChanged(p0: DataSnapshot, p1: String?) { | |
_onChildChanged(p0, p1) | |
} | |
override fun onChildAdded(p0: DataSnapshot, p1: String?) { | |
_onChildAdded(p0, p1) | |
} | |
override fun onChildRemoved(p0: DataSnapshot) { | |
_onChildRemoved(p0) | |
} | |
} | |
class _ChildEventListenerConfig { | |
private var _onCancelled: (DatabaseError) -> Unit = {} | |
private var _onChildMoved: (DataSnapshot, String?) -> Unit = { _, _ -> } | |
private var _onChildChanged: (DataSnapshot, String?) -> Unit = { _, _ -> } | |
private var _onChildAdded: (DataSnapshot, String?) -> Unit = { _, _ -> } | |
private var _onChildRemoved: (DataSnapshot) -> Unit = {} | |
fun onCancelled(f: (DatabaseError) -> Unit) { | |
_onCancelled = f | |
} | |
fun onChildMoved(f: (DataSnapshot, String?) -> Unit) { | |
_onChildMoved = f | |
} | |
fun onChildChanged(f: (DataSnapshot, String?) -> Unit) { | |
_onChildChanged = f | |
} | |
fun onChildAdded(f: (DataSnapshot, String?) -> Unit) { | |
_onChildAdded = f | |
} | |
fun onChildRemoved(f: (DataSnapshot) -> Unit) { | |
_onChildRemoved = f | |
} | |
fun build() = _ChildEventListener(_onCancelled, _onChildMoved, _onChildChanged, _onChildAdded, _onChildRemoved) | |
} | |
fun childEventListener(configure: _ChildEventListenerConfig.() -> Unit): ChildEventListener { | |
val config = _ChildEventListenerConfig() | |
config.configure() | |
return config.build() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment