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/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
}
-
-
})
}
}