Add retrofit service and remove activity main
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.navi.medici.android_customer_app.api
|
||||
|
||||
import retrofit2.Converter
|
||||
import retrofit2.Retrofit
|
||||
|
||||
object RetrofitService {
|
||||
fun build(baseURL: String, converterFactory: Converter.Factory): Retrofit {
|
||||
val retrofitBuilder = Retrofit.Builder().baseUrl(baseURL)
|
||||
return retrofitBuilder.addConverterFactory(converterFactory).build()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.navi.medici.android_customer_app
|
||||
package com.navi.medici.android_customer_app.api
|
||||
|
||||
import retrofit2.Response
|
||||
import java.io.IOException
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.navi.medici.android_customer_app.login
|
||||
|
||||
import com.navi.medici.android_customer_app.api.RetrofitService
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import retrofit2.http.GET
|
||||
|
||||
private const val BASE_URL = "https://jsonplaceholder.typicode.com/"
|
||||
|
||||
private val retrofit = Retrofit
|
||||
.Builder()
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.baseUrl(BASE_URL)
|
||||
.build()
|
||||
private val gsonConverterFactory = GsonConverterFactory.create()
|
||||
|
||||
interface LoginApi {
|
||||
@GET("posts/1")
|
||||
@@ -19,7 +14,8 @@ interface LoginApi {
|
||||
|
||||
companion object {
|
||||
operator fun invoke(): LoginApi {
|
||||
return retrofit.create(LoginApi::class.java)
|
||||
return RetrofitService.build(BASE_URL, gsonConverterFactory)
|
||||
.create(LoginApi::class.java)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.navi.medici.android_customer_app.login
|
||||
|
||||
import com.navi.medici.android_customer_app.SafeApiRequest
|
||||
import com.navi.medici.android_customer_app.api.SafeApiRequest
|
||||
|
||||
class LoginRepository(private val loginApi: LoginApi) : SafeApiRequest() {
|
||||
suspend fun submitPhoneNumber(phoneNumber: String) = apiRequest { loginApi.submitPhoneNumber() }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.navi.medici.android_customer_app.login
|
||||
|
||||
data class LoginResponse(
|
||||
val id: Int,
|
||||
val title: String,
|
||||
val body: String,
|
||||
val userId: Int
|
||||
val id: Int?,
|
||||
val title: String?,
|
||||
val body: String?,
|
||||
val userId: Int?
|
||||
)
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user