Skip to content

Instantly share code, notes, and snippets.

class ApiClient {
fun getUserFromApi(requestCallback: (isSuccess: Boolean, response: UserResponse?,message: String?) -> (Unit)) {
RetrofitClient.getApi()
.create(ApiHelper::class.java)
.getUser()
.enqueue(object : Callback<UserResponse> {
override fun onFailure(call: Call<UserResponse>, t: Throwable) {
requestCallback(false,null,t.localizedMessage)
interface ApiHelper {
@GET("(default)/documents/user")
fun getUser(): Call<UserResponse>
}
class RetrofitClient {
companion object {
const val baseUrl = "https://firestore.googleapis.com/v1/projects/firestorerestapi/databases/"
fun getApi(): Retrofit {
return Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
data class Value(
@field:SerializedName("stringValue")
val stringValue: String? = null
)
data class Fields(
@field:SerializedName("surname")
val surname: Value? = null,
@field:SerializedName("name")
val name: Value? = null
)
data class DocumentsItem(
@field:SerializedName("createTime")
val createTime: String? = null,
@field:SerializedName("name")
val name: String? = null,
@field:SerializedName("updateTime")
val updateTime: String? = null,
data class UserResponse(
@field:SerializedName("documents")
val documents: List<DocumentsItem?>? = null
)
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
private fun processFaceResult(faces: MutableList<FirebaseVisionFace>) {
faces.forEach {
val bounds = it.boundingBox
val rectOverLay = RectOverlay(graphic_overlay, bounds)
graphic_overlay.add(rectOverLay)
}
alertDialog.dismiss()
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"