Skip to content

Commit 85855de

Browse files
committed
Fix UI alignment, icon, and add timeout
1 parent 3989bdc commit 85855de

6 files changed

Lines changed: 51 additions & 40 deletions

File tree

app/src/main/java/com/example/DiseaseScannerScreen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import android.content.ContentValues
4242
import android.provider.MediaStore
4343
import android.widget.Toast
4444
import androidx.compose.material.icons.Icons
45-
import androidx.compose.material.icons.automirrored.filled.ArrowBack
45+
import androidx.compose.material.icons.filled.ArrowBack
4646
import androidx.compose.material.icons.filled.Download
4747

4848
enum class ScanMode { CROP, SOIL }
@@ -307,7 +307,7 @@ fun CameraScanner(modifier: Modifier, scanMode: ScanMode, onBack: () -> Unit) {
307307
Modifier.fillMaxWidth().background(Color(0xDD0D1208)).statusBarsPadding().padding(4.dp),
308308
verticalAlignment = Alignment.CenterVertically
309309
) {
310-
IconButton(onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back", tint = NuKropText) }
310+
IconButton(onBack) { Icon(Icons.Default.ArrowBack, contentDescription = "Back", tint = NuKropText) }
311311
Column {
312312
Text(if (scanMode == ScanMode.CROP) "Crop Disease & Pest Scan" else "Soil Health Analysis",
313313
fontSize = 15.sp, fontWeight = FontWeight.Bold, color = NuKropText)
@@ -419,7 +419,7 @@ fun ScanResultView(modifier: Modifier, raw: String, mode: ScanMode, accent: Colo
419419
Column(modifier.fillMaxSize().background(NuKropDark).verticalScroll(scroll)) {
420420
// Header
421421
Row(Modifier.fillMaxWidth().background(NuKropSurface).statusBarsPadding().padding(8.dp), verticalAlignment = Alignment.CenterVertically) {
422-
IconButton(onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back", tint = NuKropText) }
422+
IconButton(onBack) { Icon(Icons.Default.ArrowBack, contentDescription = "Back", tint = NuKropText) }
423423
Column {
424424
Text("AI Analysis Complete", fontSize = 16.sp, fontWeight = FontWeight.Bold, color = NuKropText)
425425
Text("Results powered by NuKrop Vision AI", fontSize = 10.sp, color = NuKropTextMuted)
@@ -456,7 +456,7 @@ fun ScanResultView(modifier: Modifier, raw: String, mode: ScanMode, accent: Colo
456456
Row(Modifier.fillMaxWidth(), Arrangement.spacedBy(12.dp)) {
457457
OutlinedButton(onBack, Modifier.weight(1f).height(50.dp), shape = RoundedCornerShape(25.dp),
458458
border = BorderStroke(1.dp, NuKropTextDim)) {
459-
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back", tint = NuKropTextMuted, modifier = Modifier.size(18.dp))
459+
Icon(Icons.Default.ArrowBack, contentDescription = "Back", tint = NuKropTextMuted, modifier = Modifier.size(18.dp))
460460
Spacer(Modifier.width(6.dp))
461461
Text("Back", color = NuKropTextMuted)
462462
}

app/src/main/java/com/example/GeminiVisionService.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ object GeminiVisionService {
3636
"llama-3.1-8b-instant"
3737
)
3838

39-
private val VISION_MODELS = listOf(
40-
"qwen/qwen3.6-27b",
41-
"llama-3.2-11b-vision-preview"
42-
)
39+
private val VISION_MODELS = listOf("llama-3.2-11b-vision-preview")
4340

4441
private fun parseText(body: String): String {
4542
if (body.isBlank()) return "API Error: Empty response from Groq server"

app/src/main/java/com/example/HomeScreen.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ fun HomeScreen(
221221
QuickActionTile(Modifier.weight(1f), Icons.Filled.AccountBalance, "Loan & Subsidy", "Govt Schemes Matcher", Color(0xFFFFB74D), onNavigateToFinance)
222222
QuickActionTile(Modifier.weight(1f), Icons.Filled.Navigation, "Field Navigator", "GPS Route & Coverage", Color(0xFFE57373), onNavigateToAutopilot)
223223
}
224+
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
225+
QuickActionTile(Modifier.weight(1f), Icons.Filled.Download, "Saved Reports", "View downloaded files", NuKropBadgeGreen, {
226+
try {
227+
context.startActivity(android.content.Intent(android.app.DownloadManager.ACTION_VIEW_DOWNLOADS))
228+
} catch (e: Exception) { }
229+
})
230+
Spacer(Modifier.weight(1f))
231+
}
224232
}
225233

226234
Spacer(Modifier.height(20.dp))
@@ -333,6 +341,7 @@ fun HomeScreen(
333341
)
334342
tips.forEach { (icon, title, desc) -> TipCard(icon, title, desc); Spacer(Modifier.height(8.dp)) }
335343

344+
Spacer(Modifier.height(180.dp))
336345
}
337346
}
338347
}
@@ -426,7 +435,7 @@ fun QuickActionTile(modifier: Modifier, icon: ImageVector, title: String, subtit
426435
}
427436
Spacer(Modifier.height(10.dp))
428437
Text(title, fontSize = 13.sp, fontWeight = FontWeight.Bold, color = NuKropText)
429-
Text(subtitle, fontSize = 10.sp, color = NuKropTextMuted, lineHeight = 14.sp)
438+
Text(subtitle, fontSize = 10.sp, color = NuKropTextMuted, lineHeight = 14.sp, minLines = 2, maxLines = 2, overflow = TextOverflow.Ellipsis)
430439
}
431440
}
432441
}

app/src/main/java/com/example/MandiApiService.kt

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,38 +142,42 @@ object MandiApiService {
142142

143143
// PATH 1: Try backend Redis cache (ultra-fast)
144144
try {
145-
val stateEnc = URLEncoder.encode(state.trim(), "UTF-8")
146-
val commEnc = URLEncoder.encode(commodity.trim(), "UTF-8")
147-
val url = "$BACKEND_URL?state=$stateEnc&commodity=$commEnc"
148-
val request = Request.Builder().url(url).build()
149-
150-
val responseBody = client.newCall(request).execute().use { response ->
151-
if (response.isSuccessful) response.body?.string() else null
152-
}
153-
154-
if (!responseBody.isNullOrBlank()) {
155-
val root = json.parseToJsonElement(responseBody).jsonObject
156-
val recordsArray = root["records"]?.jsonArray
157-
if (recordsArray != null) {
158-
val records = recordsArray.mapNotNull { el ->
159-
runCatching {
160-
val obj = el.jsonObject
161-
MandiRecord(
162-
state = obj["state"]?.jsonPrimitive?.content ?: "",
163-
district = obj["district"]?.jsonPrimitive?.content ?: "",
164-
market = obj["market"]?.jsonPrimitive?.content ?: "",
165-
commodity = obj["commodity"]?.jsonPrimitive?.content ?: "",
166-
variety = obj["variety"]?.jsonPrimitive?.content ?: "",
167-
minPrice = obj["minPrice"]?.jsonPrimitive?.doubleOrNull ?: 0.0,
168-
maxPrice = obj["maxPrice"]?.jsonPrimitive?.doubleOrNull ?: 0.0,
169-
modalPrice = obj["modalPrice"]?.jsonPrimitive?.doubleOrNull ?: 0.0,
170-
arrivalDate = obj["arrivalDate"]?.jsonPrimitive?.content ?: ""
171-
)
172-
}.getOrNull()
145+
val backendResult = kotlinx.coroutines.withTimeoutOrNull(1000L) {
146+
val stateEnc = URLEncoder.encode(state.trim(), "UTF-8")
147+
val commEnc = URLEncoder.encode(commodity.trim(), "UTF-8")
148+
val url = "$BACKEND_URL?state=$stateEnc&commodity=$commEnc"
149+
val request = Request.Builder().url(url).build()
150+
151+
val responseBody = client.newCall(request).execute().use { response ->
152+
if (response.isSuccessful) response.body?.string() else null
153+
}
154+
155+
if (!responseBody.isNullOrBlank()) {
156+
val root = json.parseToJsonElement(responseBody).jsonObject
157+
val recordsArray = root["records"]?.jsonArray
158+
if (recordsArray != null) {
159+
val records = recordsArray.mapNotNull { el ->
160+
runCatching {
161+
val obj = el.jsonObject
162+
MandiRecord(
163+
state = obj["state"]?.jsonPrimitive?.content ?: "",
164+
district = obj["district"]?.jsonPrimitive?.content ?: "",
165+
market = obj["market"]?.jsonPrimitive?.content ?: "",
166+
commodity = obj["commodity"]?.jsonPrimitive?.content ?: "",
167+
variety = obj["variety"]?.jsonPrimitive?.content ?: "",
168+
minPrice = obj["minPrice"]?.jsonPrimitive?.doubleOrNull ?: 0.0,
169+
maxPrice = obj["maxPrice"]?.jsonPrimitive?.doubleOrNull ?: 0.0,
170+
modalPrice = obj["modalPrice"]?.jsonPrimitive?.doubleOrNull ?: 0.0,
171+
arrivalDate = obj["arrivalDate"]?.jsonPrimitive?.content ?: ""
172+
)
173+
}.getOrNull()
174+
}
175+
if (records.isNotEmpty()) return@withTimeoutOrNull Result.success(records)
173176
}
174-
if (records.isNotEmpty()) return@withContext Result.success(records)
175177
}
178+
null
176179
}
180+
if (backendResult != null) return@withContext backendResult
177181
} catch (_: Exception) {
178182
// Backend not reachable (physical device without local server) — fall through to gov API
179183
}

app/src/main/java/com/example/MarketScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fun MarketScreen(modifier: Modifier = Modifier) {
133133
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {
134134
Icon(Icons.Filled.LocationOn, contentDescription = null, tint = NuKropAccent, modifier = Modifier.size(14.dp))
135135
val locText = if (userMandi.isNotEmpty()) "$userMandi, $userState" else if (userState.isNotEmpty()) userState else AppStrings.get("auto_detect", lang)
136-
Text(locText, fontSize = 11.sp, color = if (userState.isNotEmpty()) NuKropAccent else NuKropTextMuted, fontWeight = FontWeight.Bold)
136+
Text(locText, fontSize = 11.sp, color = if (userState.isNotEmpty()) NuKropAccent else NuKropTextMuted, fontWeight = FontWeight.Bold, maxLines = 1, overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis, modifier = Modifier.widthIn(max = 120.dp))
137137
}
138138
}
139139
}
@@ -265,6 +265,7 @@ fun MarketScreen(modifier: Modifier = Modifier) {
265265
MandiLiveCard(record, lang, context)
266266
}
267267
}
268+
Spacer(Modifier.height(180.dp))
268269
}
269270
}
270271
}

app/src/main/java/com/example/ProfileScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fun ProfileScreen(modifier: Modifier = Modifier, onSignOut: (() -> Unit)? = null
237237
Text("Sign Out", color = NuKropError, fontWeight = FontWeight.SemiBold)
238238
}
239239

240-
Spacer(modifier = Modifier.height(100.dp))
240+
Spacer(modifier = Modifier.height(180.dp))
241241
}
242242
}
243243

0 commit comments

Comments
 (0)