Skip to content

Basic API implementation#4

Open
BonaOQuinn wants to merge 1 commit into
masterfrom
BonaOQuinn-API
Open

Basic API implementation#4
BonaOQuinn wants to merge 1 commit into
masterfrom
BonaOQuinn-API

Conversation

@BonaOQuinn
Copy link
Copy Markdown
Collaborator

-dependency added for internet connection

  • thread created for API endpoint which has request GET method as well as repsonse code in JSON form via Gson

-dependency added for internet connection 
- thread created for API endpoint which has request GET method
@BonaOQuinn BonaOQuinn requested a review from Arjun-S19 October 15, 2025 23:06
@Arjun-S19 Arjun-S19 requested a review from Copilot October 15, 2025 23:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Implements a basic network call for fetching recipes and sets up the main activity with Compose UI.

  • Add MainActivity with a fetchRecipes() method using HttpURLConnection and Gson
  • Add INTERNET permission in AndroidManifest

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 10 comments.

File Description
MainActivity.kt Adds Compose UI scaffolding and a background-threaded network call parsing JSON via Gson
AndroidManifest.xml Declares INTERNET permission and app/activity configuration (contains unresolved merge conflict)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread AndroidManifest.xml
Comment on lines +4 to +12
<<<<<<< HEAD

//dependecy added for internent connection
<uses-permission android:name="android.permission.INTERNET" />


=======
<uses-permission android:name="android.permission.INTERNET"/>
>>>>>>> 2adbb52ebf87dfede19d67b9789c30621982a91e
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolved merge conflict markers (<<<<<<<, =======, >>>>>>>) are present and will break the build. Also, the // comment is invalid in XML and the INTERNET permission is duplicated. Resolve the conflict, remove the invalid comment, and keep a single <uses-permission android:name="android.permission.INTERNET" /> line.

Suggested change
<<<<<<< HEAD
//dependecy added for internent connection
<uses-permission android:name="android.permission.INTERNET" />
=======
<uses-permission android:name="android.permission.INTERNET"/>
>>>>>>> 2adbb52ebf87dfede19d67b9789c30621982a91e
<uses-permission android:name="android.permission.INTERNET" />

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
Comment on lines +18 to +23
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both setContentView and setContent are called, which mixes ViewBinding and Compose rendering paths in the same Activity. If you're using Compose, remove setContentView/binding and do all UI in setContent (or, alternatively, remove setContent and use only view binding).

Suggested change
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
//API endpoint
val url = URL("https://api.spoonacular.com/recipes/random?number=10&apiKey=YOUR_API_KEY")

val connection = HttpURLConnection = url.openConnection() as HttpURLConnection
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid Kotlin and shadows the HttpURLConnection type. It should be assigning the result of openConnection to a variable: val connection = url.openConnection() as HttpURLConnection.

Suggested change
val connection = HttpURLConnection = url.openConnection() as HttpURLConnection
val connection = url.openConnection() as HttpURLConnection

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.easychef.ui.theme.EasyChefTheme
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required imports for the networking and parsing code are missing, causing compilation errors. Add imports for java.net.URL, java.net.HttpURLConnection, java.io.BufferedReader, java.io.InputStreamReader, com.google.gson.Gson, and your view binding type (com.example.easychef.databinding.ActivityMainBinding).

Suggested change
import com.example.easychef.ui.theme.EasyChefTheme
import com.example.easychef.ui.theme.EasyChefTheme
import java.net.URL
import java.net.HttpURLConnection
import java.io.BufferedReader
import java.io.InputStreamReader
import com.google.gson.Gson
import com.example.easychef.databinding.ActivityMainBinding

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
Comment on lines +49 to +67
if (responseCode == HttpURLConnection.HTTP_OK) {
val inputStream = connection.inputStream
//Read and print the response data
val reader : BufferedReader = BufferedReader(InputStreamReader(inputStream))
val response = StringBuilder()
var line: String?
while (reader.readLine().also { line = it } != null) {
response.append(line)
}

//close connections
reader.close()
inputStream.close()
connection.disconnect()

//JSON response via Gson
val jsonResponse = response.toString()
val gson = Gson()
val recipeResponse = gson.fromJson(jsonResponse, RecipeResponse::class.java)
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streams and the connection are only closed on the success path; failures or exceptions will leak resources. Wrap I/O in use blocks and disconnect in a finally block, e.g., reader.use { ... } and always call connection.disconnect() in finally.

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
private fun fetchRecipes(): Thread{
return Thread{
//API endpoint
val url = URL("https://api.spoonacular.com/recipes/random?number=10&apiKey=YOUR_API_KEY")
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hardcoding API keys in source code. Store secrets outside the repo (e.g., local.properties/Gradle) and read at runtime via BuildConfig or from encrypted storage.

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
Comment on lines +37 to +41
private fun fetchRecipes(): Thread{
return Thread{
//API endpoint
val url = URL("https://api.spoonacular.com/recipes/random?number=10&apiKey=YOUR_API_KEY")

Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Prefer Kotlin coroutines (Dispatchers.IO) and a modern HTTP client (OkHttp/Retrofit) over manually managing Thread and HttpURLConnection; this simplifies cancellation, error handling, and lifecycle awareness. Consider making this a suspend function and calling it from lifecycleScope.

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
val connection = HttpURLConnection = url.openConnection() as HttpURLConnection

//Request GET Method
connection.requestMethod = "GET"
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Prefer Kotlin coroutines (Dispatchers.IO) and a modern HTTP client (OkHttp/Retrofit) over manually managing Thread and HttpURLConnection; this simplifies cancellation, error handling, and lifecycle awareness. Consider making this a suspend function and calling it from lifecycleScope.

Copilot uses AI. Check for mistakes.
Comment thread MainActivity.kt
Comment on lines +37 to +38
private fun fetchRecipes(): Thread{
return Thread{
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchRecipes returns a Thread but is never called, and the returned thread is not started. Either start the thread where needed, or refactor to a suspend function and invoke it from a scoped coroutine.

Copilot uses AI. Check for mistakes.
Comment thread AndroidManifest.xml
Comment on lines +4 to +12
<<<<<<< HEAD

//dependecy added for internent connection
<uses-permission android:name="android.permission.INTERNET" />


=======
<uses-permission android:name="android.permission.INTERNET"/>
>>>>>>> 2adbb52ebf87dfede19d67b9789c30621982a91e
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling.

Suggested change
<<<<<<< HEAD
//dependecy added for internent connection
<uses-permission android:name="android.permission.INTERNET" />
=======
<uses-permission android:name="android.permission.INTERNET"/>
>>>>>>> 2adbb52ebf87dfede19d67b9789c30621982a91e
<!-- Dependency added for internet connection -->
<uses-permission android:name="android.permission.INTERNET" />

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants