From 629d7db949109e55d0c104a63c95ecc1fd4f4d9f Mon Sep 17 00:00:00 2001 From: TanishMoral11 Date: Fri, 9 Aug 2024 23:09:34 +0530 Subject: [PATCH] Added Comments --- .../java/com/example/randommemes/ApiInterface.kt | 7 +++++-- .../com/example/randommemes/RetrofitInstance.kt | 13 +++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/example/randommemes/ApiInterface.kt b/app/src/main/java/com/example/randommemes/ApiInterface.kt index 327a18c..8400c7d 100644 --- a/app/src/main/java/com/example/randommemes/ApiInterface.kt +++ b/app/src/main/java/com/example/randommemes/ApiInterface.kt @@ -3,7 +3,10 @@ package com.example.randommemes import retrofit2.Call import retrofit2.http.GET +// Interface to define the API endpoints interface ApiInterface { + + // A GET request to the endpoint "gimme" which returns a Call object containing a response of type `responseDataclass` @GET("gimme") - fun getData() : Call -} \ No newline at end of file + fun getData(): Call +} diff --git a/app/src/main/java/com/example/randommemes/RetrofitInstance.kt b/app/src/main/java/com/example/randommemes/RetrofitInstance.kt index 9296f37..93c14bf 100644 --- a/app/src/main/java/com/example/randommemes/RetrofitInstance.kt +++ b/app/src/main/java/com/example/randommemes/RetrofitInstance.kt @@ -5,15 +5,16 @@ import retrofit2.converter.gson.GsonConverterFactory object RetrofitInstance { - //lazy meaning that it is not initialized until it is accessed for the first time + // Lazy initialization of Retrofit instance. It's created when accessed for the first time private val retrofit by lazy { - Retrofit.Builder().baseUrl("https://meme-api.com/") - .addConverterFactory(GsonConverterFactory.create()) + Retrofit.Builder() + .baseUrl("https://meme-api.com/") // Base URL for the API + .addConverterFactory(GsonConverterFactory.create()) // Convert JSON data to Kotlin objects using Gson .build() } - val apiInterface by lazy{ + // Lazy initialization of the ApiInterface + val apiInterface by lazy { retrofit.create(ApiInterface::class.java) } - -} \ No newline at end of file +}