diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 32522c1..0897082 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,5 +1,6 @@
+
\ No newline at end of file
diff --git a/.idea/other.xml b/.idea/other.xml
index 0d3a1fb..4604c44 100644
--- a/.idea/other.xml
+++ b/.idea/other.xml
@@ -179,17 +179,6 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3d31dbb..a5fb73c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -9,9 +9,9 @@
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
- android:icon="@mipmap/ic_launcher"
+ android:icon="@drawable/logo"
android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
+ android:roundIcon="@drawable/logo"
android:supportsRtl="true"
android:theme="@style/Theme.Randommemes"
tools:targetApi="31">
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/MainActivity.kt b/app/src/main/java/com/example/randommemes/MainActivity.kt
index 5530a6f..f42b3c7 100644
--- a/app/src/main/java/com/example/randommemes/MainActivity.kt
+++ b/app/src/main/java/com/example/randommemes/MainActivity.kt
@@ -15,51 +15,60 @@ import retrofit2.Response
class MainActivity : AppCompatActivity() {
- //https://meme-api.com/gimme
+ // Declaring a lateinit variable for View Binding
lateinit var binding: ActivityMainBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
enableEdgeToEdge()
setContentView(binding.root)
+
+ // Handling window insets for edge-to-edge display
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
+
+ // Fetch the first meme on activity creation
getData()
+ // Set an onClickListener to fetch a new meme when the button is clicked
binding.btnNewMeme.setOnClickListener {
getData()
}
}
+ // Function to fetch meme data using Retrofit
private fun getData() {
-
val progressDialog = ProgressDialog(this)
progressDialog.setMessage("Please wait...")
progressDialog.show()
-
+ // Making a network request using Retrofit
RetrofitInstance.apiInterface.getData().enqueue(object : Callback {
override fun onResponse(
call: Call,
response: Response
) {
-
- binding.memeAuthor.text = response.body()?.author
+ // Set the meme author and title text views
+ binding.memeAuthor.text = response.body()?.author
binding.memeTitle.text = response.body()?.title
- Glide.with(this@MainActivity).load(response.body()?.url).into(binding.memeImage);
+ // Load the meme image using Glide
+ Glide.with(this@MainActivity)
+ .load(response.body()?.url)
+ .into(binding.memeImage)
+ // Dismiss the progress dialog
progressDialog.dismiss()
}
override fun onFailure(call: Call, t: Throwable) {
- Toast.makeText(this@MainActivity, "${t.localizedMessage}", Toast.LENGTH_SHORT)
- .show()
+ // Show a toast message if the request fails
+ Toast.makeText(this@MainActivity, "${t.localizedMessage}", Toast.LENGTH_SHORT).show()
+ progressDialog.dismiss() // Dismiss the progress dialog on failure as well
}
-
-
})
}
}
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
+}
diff --git a/app/src/main/res/drawable/logo.png b/app/src/main/res/drawable/logo.png
new file mode 100644
index 0000000..df39859
Binary files /dev/null and b/app/src/main/res/drawable/logo.png differ