-
-
Save anandrex5/3c9b405976ff577d0ba5288ecc127324 to your computer and use it in GitHub Desktop.
Retrofit Get In Kotlin
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.example.kotlintutorial | |
import okhttp3.OkHttpClient | |
import okhttp3.logging.HttpLoggingInterceptor | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
class ApiClient { | |
val BASE_URL: String = "http://14.142.204.101:9900/" | |
var retrofit: Retrofit? = null | |
fun getApiClient(): Retrofit? { | |
if (retrofit == null) { | |
val interceptor = HttpLoggingInterceptor() | |
interceptor.level = HttpLoggingInterceptor.Level.BODY | |
val builder = OkHttpClient.Builder() | |
.addInterceptor(interceptor) | |
.addInterceptor { chain -> | |
val request = chain.request().newBuilder() | |
.addHeader("AUTH_TOKEN", "C7jGJZho7/ptHX+vbYGt+A==") | |
.addHeader("Content-Type", "application/json") | |
.addHeader("DEVICE_ID", "dUwTB2fzTjKDdDTdW69lrc") | |
.addHeader("ANDROID_DEVICE_ID", "5b39185c0342d9f9") | |
.addHeader("COUNTRY", "India") | |
.addHeader("CITY", "Noida") | |
.addHeader("LANGUAGE", "EN") | |
.addHeader("ANDROID_DEVICE_ID", "5b39185c0342d9f9") | |
.build() | |
chain.proceed(request) | |
} | |
retrofit = Retrofit.Builder() | |
.baseUrl(BASE_URL) | |
.client(builder.build()) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build() | |
} | |
return retrofit | |
} | |
} | |
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.example.kotlintutorial | |
import retrofit2.Call | |
import retrofit2.http.GET | |
interface ApiInterface { | |
@GET("cans/tt/rest/api/sec/v6/Coupons.json/All") | |
fun getBanner(): Call<BannerPojo> | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<androidx.appcompat.widget.AppCompatImageView | |
android:id="@+id/banner_image" | |
android:layout_width="match_parent" | |
android:layout_height="200dp" | |
android:layout_marginTop="10dp" | |
android:scaleType="fitXY" | |
android:layout_marginHorizontal="10dp" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
/> | |
<androidx.appcompat.widget.AppCompatTextView | |
android:id="@+id/banner_Name" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Name" | |
android:textSize="20dp" | |
android:textColor="@color/white" | |
android:layout_marginVertical="5dp" | |
android:layout_marginHorizontal="10dp" | |
android:background="#5565F6" | |
android:gravity="center_horizontal" | |
android:textStyle="bold" | |
app:layout_constraintTop_toBottomOf="@+id/banner_image" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
/> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment