fun lastCarpetId( ) {
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
val res1 = StringBuffer()
db.collection("carpets")
.orderBy("carpetid")
.limit(1)
.get()
.addOnCompleteListener {
if (it.isSuccessful) {
for (document in it.result!!) {
res1.append(document.data.getValue("carpetid")).append("")
}
}
}
}
lastCarpetId { value ->
//value получен
}
fun lastCarpetId(callback: (String) -> Unit) {
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
db.collection("carpets")
.orderBy("carpetid")
.limit(1)
.get()
.addOnCompleteListener {
if (it.isSuccessful) {
for (document in it.result!!) {
callback(document.data.getValue("carpetid"))
}
}
}
}