Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp") version "1.9.24-1.0.20"
}

android {
Expand Down Expand Up @@ -101,8 +102,15 @@ dependencies {
implementation("com.google.ai.client.generativeai:generativeai:0.9.0")
implementation("io.coil-kt:coil-compose:2.7.0")

val room_version = "2.6.1"
implementation("androidx.room:room-runtime:$room_version")
implementation("androidx.room:room-ktx:$room_version")
ksp("androidx.room:room-compiler:$room_version")

implementation("com.github.jeziellago:compose-markdown:0.5.2")

testImplementation("junit:junit:4.13.2")
testImplementation("io.mockk:mockk:1.13.12")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
testImplementation("androidx.arch.core:core-testing:2.2.0")
}
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".FreeAiRockApplication"
android:allowBackup="true"
android:label="FREE AI ROCK"
android:supportsRtl="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sayanthrock.freeairock

import android.app.Application

class FreeAiRockApplication : Application() {
override fun onCreate() {
super.onCreate()
}
}
277 changes: 5 additions & 272 deletions app/src/main/java/com/sayanthrock/freeairock/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,57 +1,23 @@
package com.sayanthrock.freeairock

import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import com.sayanthrock.freeairock.data.ai.CodeAnalysisState
import com.sayanthrock.freeairock.data.github.GitHubApiService
import com.sayanthrock.freeairock.data.storage.SecureStorageManager
import com.sayanthrock.freeairock.ui.AboutScreen
import com.sayanthrock.freeairock.ui.AppViewModel
import com.sayanthrock.freeairock.ui.AppViewModelFactory
import com.sayanthrock.freeairock.ui.HomeScaffold
import com.sayanthrock.freeairock.ui.ImageViewModel
import com.sayanthrock.freeairock.ui.PlaceholderPanel
import com.sayanthrock.freeairock.ui.ImageStudioScreen
import com.sayanthrock.freeairock.data.ai.PollinationsApiService
import retrofit2.converter.scalars.ScalarsConverterFactory
import com.sayanthrock.freeairock.ui.ReviewScreen
import com.sayanthrock.freeairock.ui.ReviewViewModel
import com.sayanthrock.freeairock.ui.ThemeMode
import com.sayanthrock.freeairock.ui.chat.ChatScreen
import com.sayanthrock.freeairock.ui.theme.FreeAiRockTheme
import com.sayanthrock.freeairock.data.ai.PollinationsApiService
import retrofit2.converter.scalars.ScalarsConverterFactory
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
Expand All @@ -67,7 +33,7 @@ class MainActivity : ComponentActivity() {
val token = secureStorage.getGitHubToken()

if (!token.isNullOrBlank()) {
requestBuilder.header("Authorization", "Bearer $token")
requestBuilder.header("Authorization", "Bearer \$token")
}

chain.proceed(requestBuilder.build())
Expand All @@ -84,7 +50,6 @@ class MainActivity : ComponentActivity() {
.create(GitHubApiService::class.java)
}


private val pollinationsApiService by lazy {
Retrofit.Builder()
.baseUrl("https://text.pollinations.ai/")
Expand All @@ -107,14 +72,6 @@ class MainActivity : ComponentActivity() {
viewModelProvider[AppViewModel::class.java]
}

private val reviewViewModel: ReviewViewModel by lazy {
viewModelProvider[ReviewViewModel::class.java]
}

private val imageViewModel: ImageViewModel by lazy {
viewModelProvider[ImageViewModel::class.java]
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -127,231 +84,7 @@ class MainActivity : ComponentActivity() {
}

FreeAiRockTheme(darkTheme = darkTheme) {
HomeScaffold(
codeContent = { modifier ->
CodeAnalyzerScreen(
uiState = appViewModel.analysisState.collectAsState().value,
onSave = { githubToken ->
appViewModel.saveKeys(githubToken)
imageViewModel.refreshRenderer()
},
onAnalyze = appViewModel::analyzeCodeFile,
onReset = appViewModel::resetAnalysis,
modifier = modifier
)
},
reviewContent = { modifier ->
ReviewScreen(
viewModel = reviewViewModel,
modifier = modifier
)
},
studioContent = { modifier ->
ImageStudioScreen(modifier = modifier)
},
aboutContent = { modifier ->
AboutScreen(
currentTheme = appTheme,
onThemeChange = { appTheme = it },
modifier = modifier
)
}
)
}
}
}
}

@Composable
private fun CodeAnalyzerScreen(
uiState: CodeAnalysisState,
onSave: (githubToken: String) -> Unit,
onAnalyze: (fileName: String, downloadUrl: String?) -> Unit,
onReset: () -> Unit,
modifier: Modifier = Modifier
) {
var githubToken by remember { mutableStateOf("") }

var fileName by remember { mutableStateOf("MainActivity.kt") }
var fileUrl by remember { mutableStateOf("") }
var savedMessage by remember { mutableStateOf<String?>(null) }
val clipboardManager = LocalClipboardManager.current
val context = LocalContext.current

Surface(
modifier = modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(24.dp)
) {
Text(
text = "FREE-AI-ROCK",
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.primary
)

Spacer(modifier = Modifier.height(12.dp))

Text(
text = "Secure setup for GitHub file analysis and AI code summaries.",
color = MaterialTheme.colorScheme.onBackground
)

Spacer(modifier = Modifier.height(24.dp))

OutlinedTextField(
value = githubToken,
onValueChange = { githubToken = it },
label = { Text("GitHub token") },
visualTransformation = PasswordVisualTransformation(),
modifier = Modifier.fillMaxWidth(),
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(
onDone = {
if (githubToken.isNotBlank()) {
onSave(githubToken)
savedMessage = "Saved securely on this device"
}
}
)
)



Spacer(modifier = Modifier.height(16.dp))

Button(
onClick = {
onSave(githubToken)
savedMessage = "Saved securely on this device"
},
modifier = Modifier.fillMaxWidth()
) {
Text("Save Securely")
}

savedMessage?.let {
Spacer(modifier = Modifier.height(12.dp))
Text(
text = it,
color = MaterialTheme.colorScheme.onBackground
)
}

Spacer(modifier = Modifier.height(28.dp))

Text(
text = "Code AI",
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.primary
)

Spacer(modifier = Modifier.height(12.dp))

OutlinedTextField(
value = fileName,
onValueChange = { fileName = it },
label = { Text("File name") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
)

Spacer(modifier = Modifier.height(12.dp))

OutlinedTextField(
value = fileUrl,
onValueChange = { url ->
fileUrl = url
if (url.isNotBlank()) {
val cleanUrl = url.substringBefore("?").substringBefore("#")
val parts = cleanUrl.split('/')
val lastPart = parts.lastOrNull()
if (!lastPart.isNullOrBlank() && lastPart.contains('.')) {
fileName = lastPart
}
}
},
label = { Text("GitHub raw/blob file URL") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
keyboardActions = KeyboardActions(
onSearch = {
if (uiState !is CodeAnalysisState.Loading && fileUrl.isNotBlank()) {
onAnalyze(fileName, fileUrl)
}
}
)
)

Spacer(modifier = Modifier.height(16.dp))

Button(
onClick = { onAnalyze(fileName, fileUrl) },
enabled = uiState !is CodeAnalysisState.Loading && fileUrl.isNotBlank(),
modifier = Modifier.fillMaxWidth()
) {
Text(if (uiState is CodeAnalysisState.Loading) "Analyzing..." else "Summarize Code with AI")
}

Spacer(modifier = Modifier.height(20.dp))

when (uiState) {
CodeAnalysisState.Idle -> Text(
text = "Paste a GitHub raw URL or normal blob URL, then run the analyzer.",
color = MaterialTheme.colorScheme.onBackground
)

CodeAnalysisState.Loading -> CircularProgressIndicator(
color = MaterialTheme.colorScheme.primary
)

is CodeAnalysisState.Success -> {
Surface(
color = MaterialTheme.colorScheme.surface,
shape = MaterialTheme.shapes.medium,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = uiState.result,
modifier = Modifier.padding(16.dp),
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodyMedium
)
}

Spacer(modifier = Modifier.height(12.dp))

OutlinedButton(
onClick = {
clipboardManager.setText(AnnotatedString(uiState.result))
Toast.makeText(context, "Result copied to clipboard", Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth()
) {
Text("Copy Result")
}

Spacer(modifier = Modifier.height(8.dp))

OutlinedButton(
onClick = onReset,
modifier = Modifier.fillMaxWidth()
) {
Text("Reset")
}
}

is CodeAnalysisState.Error -> Text(
text = "Error: ${uiState.message}",
color = MaterialTheme.colorScheme.error
)
ChatScreen(viewModel = appViewModel)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The activity now renders only ChatScreen, so the existing PR review flow is no longer reachable from the application. Restore navigation or expose ReviewScreen alongside the new chat UI so users can still submit and analyze pull requests. [incomplete implementation]

Severity Level: Critical 🚨
- ❌ Launcher activity hides the pull-request review workflow.
- ❌ Users cannot submit PR numbers for analysis.
- ⚠️ Existing `HomeScaffold` navigation is unreachable.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** app/src/main/java/com/sayanthrock/freeairock/MainActivity.kt
**Line:** 87:87
**Comment:**
	*Incomplete Implementation: The activity now renders only `ChatScreen`, so the existing PR review flow is no longer reachable from the application. Restore navigation or expose `ReviewScreen` alongside the new chat UI so users can still submit and analyze pull requests.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sayanthrock.freeairock.data.ai

import kotlinx.coroutines.flow.Flow

interface AiProvider {
suspend fun generateResponse(prompt: String): String
fun streamResponse(prompt: String): Flow<String>
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/sayanthrock/freeairock/data/chat/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.sayanthrock.freeairock.data.chat

// Directory placeholder
Loading
Loading