Skip to content

Commit 42e230d

Browse files
committed
feat: Complete Material You Plantix-Style Redesign with Onboarding, Crop Picker, Calculators, and Curved Bottom Bar
1 parent 91dd7bd commit 42e230d

10 files changed

Lines changed: 2535 additions & 534 deletions

File tree

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

Lines changed: 397 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
package com.example
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.clickable
6+
import androidx.compose.foundation.layout.*
7+
import androidx.compose.foundation.lazy.LazyColumn
8+
import androidx.compose.foundation.lazy.LazyRow
9+
import androidx.compose.foundation.lazy.items
10+
import androidx.compose.foundation.shape.CircleShape
11+
import androidx.compose.foundation.shape.RoundedCornerShape
12+
import androidx.compose.material.icons.Icons
13+
import androidx.compose.material.icons.filled.*
14+
import androidx.compose.material3.*
15+
import androidx.compose.runtime.*
16+
import androidx.compose.ui.Alignment
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.draw.clip
19+
import androidx.compose.ui.graphics.Color
20+
import androidx.compose.ui.text.font.FontWeight
21+
import androidx.compose.ui.unit.dp
22+
import androidx.compose.ui.unit.sp
23+
import com.example.ui.theme.*
24+
25+
data class CommunityPost(
26+
val postId: String,
27+
val authorName: String,
28+
val location: String,
29+
val cropName: String,
30+
val cropEmoji: String,
31+
val timeAgo: String,
32+
val questionText: String,
33+
val translatedText: String? = null,
34+
val verifiedSolution: String? = null,
35+
val upvotesCount: Int,
36+
val answersCount: Int
37+
)
38+
39+
@Composable
40+
fun CommunityScreen(
41+
onNavigateToChat: () -> Unit = {}
42+
) {
43+
var selectedCropFilter by remember { mutableStateOf("All") }
44+
var translatedPostIds by remember { mutableStateOf(setOf<String>()) }
45+
46+
val cropFilters = listOf("All", "Cotton", "Rice / Paddy", "Chilli", "Tomato", "Wheat", "Tobacco")
47+
48+
val samplePosts = remember {
49+
listOf(
50+
CommunityPost(
51+
postId = "POST-1",
52+
authorName = "Suresh Reddy",
53+
location = "Guntur, Andhra Pradesh",
54+
cropName = "Chilli",
55+
cropEmoji = "🌶️",
56+
timeAgo = "2 hours ago",
57+
questionText = "మిరప ఆకుల అడుగున నల్లటి మచ్చలు వస్తున్నాయి. పురుగు మందు ఏమి కొట్టాలి?",
58+
translatedText = "Black spots appearing under chilli leaves. Which pesticide spray should I use?",
59+
verifiedSolution = "Agri-Expert Solution: This is Cercospora Leaf Spot. Spray Azoxystrobin + Difenoconazole @ 1ml/L during morning hours.",
60+
upvotesCount = 24,
61+
answersCount = 7
62+
),
63+
CommunityPost(
64+
postId = "POST-2",
65+
authorName = "Gurpreet Singh",
66+
location = "Bathinda, Punjab",
67+
cropName = "Cotton",
68+
cropEmoji = "🌾",
69+
timeAgo = "5 hours ago",
70+
questionText = "कपास के पत्तों में पीलापन और मुड़ाव आ रहा है। क्या यह सफेद मक्खी का प्रकोप है?",
71+
translatedText = "Cotton leaves turning yellow and curling. Is this Whitefly attack?",
72+
verifiedSolution = "Agri-Expert Solution: Yes, Cotton Leaf Curl Virus spread by Whitefly. Install Yellow Sticky Traps @ 10/acre and spray Neemastra (5%).",
73+
upvotesCount = 42,
74+
answersCount = 12
75+
),
76+
CommunityPost(
77+
postId = "POST-3",
78+
authorName = "Ramesh Patil",
79+
location = "Nashik, Maharashtra",
80+
cropName = "Tomato",
81+
cropEmoji = "🍅",
82+
timeAgo = "1 day ago",
83+
questionText = "टोमॅटो फळांवर काळे डाग पडत आहेत. कॅल्शियमची कमतरता आहे का?",
84+
translatedText = "Black spots on bottom of tomato fruits. Is this calcium deficiency?",
85+
verifiedSolution = "Agri-Expert Solution: Blossom End Rot caused by calcium deficiency and irregular watering. Apply Calcium Nitrate @ 5g/L as foliar spray.",
86+
upvotesCount = 19,
87+
answersCount = 5
88+
)
89+
)
90+
}
91+
92+
val filteredPosts = if (selectedCropFilter == "All") samplePosts else samplePosts.filter { it.cropName.contains(selectedCropFilter) }
93+
94+
Scaffold(
95+
containerColor = PlantixBackground,
96+
floatingActionButton = {
97+
ExtendedFloatingActionButton(
98+
onClick = onNavigateToChat,
99+
containerColor = PlantixPrimary,
100+
contentColor = Color.White,
101+
shape = RoundedCornerShape(24.dp),
102+
modifier = Modifier.padding(bottom = 80.dp)
103+
) {
104+
Icon(Icons.Filled.Edit, contentDescription = null, modifier = Modifier.size(18.dp))
105+
Spacer(Modifier.width(8.dp))
106+
Text("Ask Community", fontWeight = FontWeight.Bold, fontSize = 13.sp)
107+
}
108+
}
109+
) { innerPadding ->
110+
Column(
111+
modifier = Modifier
112+
.fillMaxSize()
113+
.padding(innerPadding)
114+
) {
115+
// Header
116+
Row(
117+
modifier = Modifier
118+
.fillMaxWidth()
119+
.background(Color.White)
120+
.statusBarsPadding()
121+
.padding(horizontal = 16.dp, vertical = 12.dp),
122+
horizontalArrangement = Arrangement.SpaceBetween,
123+
verticalAlignment = Alignment.CenterVertically
124+
) {
125+
Column {
126+
Text("Farmer Community Feed", fontSize = 20.sp, fontWeight = FontWeight.Bold, color = PlantixText)
127+
Text("Connect, ask questions & learn from verified experts", fontSize = 12.sp, color = PlantixTextMuted)
128+
}
129+
IconButton(onClick = { /* Search */ }) {
130+
Icon(Icons.Default.Search, contentDescription = "Search", tint = PlantixTextMuted)
131+
}
132+
}
133+
134+
// Crop Filter Chips Horizontal Row
135+
LazyRow(
136+
modifier = Modifier
137+
.fillMaxWidth()
138+
.background(Color.White)
139+
.padding(horizontal = 16.dp, vertical = 8.dp),
140+
horizontalArrangement = Arrangement.spacedBy(8.dp)
141+
) {
142+
items(cropFilters) { filter ->
143+
val isSelected = selectedCropFilter == filter
144+
Box(
145+
modifier = Modifier
146+
.clip(RoundedCornerShape(20.dp))
147+
.background(if (isSelected) PlantixPrimary else Color(0xFFEFF3EF))
148+
.clickable { selectedCropFilter = filter }
149+
.padding(horizontal = 14.dp, vertical = 6.dp)
150+
) {
151+
Text(
152+
filter,
153+
fontSize = 12.sp,
154+
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium,
155+
color = if (isSelected) Color.White else PlantixText
156+
)
157+
}
158+
}
159+
}
160+
161+
HorizontalDivider(color = PlantixBorder)
162+
163+
// Posts Feed
164+
LazyColumn(
165+
modifier = Modifier.fillMaxSize(),
166+
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 14.dp, bottom = 120.dp),
167+
verticalArrangement = Arrangement.spacedBy(14.dp)
168+
) {
169+
items(filteredPosts) { post ->
170+
val isTranslated = translatedPostIds.contains(post.postId)
171+
Card(
172+
modifier = Modifier.fillMaxWidth(),
173+
shape = RoundedCornerShape(16.dp),
174+
colors = CardDefaults.cardColors(containerColor = Color.White),
175+
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
176+
) {
177+
Column(Modifier.padding(16.dp)) {
178+
// Author & Location Header
179+
Row(
180+
modifier = Modifier.fillMaxWidth(),
181+
horizontalArrangement = Arrangement.SpaceBetween,
182+
verticalAlignment = Alignment.CenterVertically
183+
) {
184+
Row(verticalAlignment = Alignment.CenterVertically) {
185+
Box(
186+
modifier = Modifier
187+
.size(40.dp)
188+
.clip(CircleShape)
189+
.background(PlantixBadgeGreen),
190+
contentAlignment = Alignment.Center
191+
) {
192+
Text(post.cropEmoji, fontSize = 20.sp)
193+
}
194+
Spacer(Modifier.width(10.dp))
195+
Column {
196+
Text(post.authorName, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = PlantixText)
197+
Text("${post.location}${post.timeAgo}", fontSize = 11.sp, color = PlantixTextMuted)
198+
}
199+
}
200+
Box(
201+
modifier = Modifier
202+
.clip(RoundedCornerShape(8.dp))
203+
.background(Color(0xFFEFF3EF))
204+
.padding(horizontal = 8.dp, vertical = 4.dp)
205+
) {
206+
Text(post.cropName, fontSize = 10.sp, fontWeight = FontWeight.Bold, color = PlantixPrimary)
207+
}
208+
}
209+
210+
Spacer(Modifier.height(12.dp))
211+
212+
// Question Text
213+
Text(
214+
text = if (isTranslated && post.translatedText != null) post.translatedText else post.questionText,
215+
fontSize = 14.sp,
216+
color = PlantixText,
217+
lineHeight = 20.sp
218+
)
219+
220+
// Translate Button
221+
if (post.translatedText != null) {
222+
Spacer(Modifier.height(4.dp))
223+
Text(
224+
text = if (isTranslated) "Show Original Language" else "Translate to English",
225+
fontSize = 11.sp,
226+
color = PlantixActionBlue,
227+
fontWeight = FontWeight.Bold,
228+
modifier = Modifier.clickable {
229+
translatedPostIds = if (isTranslated) translatedPostIds - post.postId else translatedPostIds + post.postId
230+
}
231+
)
232+
}
233+
234+
// Verified Solution Card
235+
post.verifiedSolution?.let { sol ->
236+
Spacer(Modifier.height(10.dp))
237+
Box(
238+
modifier = Modifier
239+
.fillMaxWidth()
240+
.clip(RoundedCornerShape(12.dp))
241+
.background(Color(0xFFE8F5E9))
242+
.border(1.dp, PlantixPrimary.copy(alpha = 0.3f), RoundedCornerShape(12.dp))
243+
.padding(12.dp)
244+
) {
245+
Row {
246+
Icon(Icons.Filled.Verified, contentDescription = null, tint = PlantixPrimary, modifier = Modifier.size(16.dp))
247+
Spacer(Modifier.width(6.dp))
248+
Text(sol, fontSize = 12.sp, color = PlantixDarkGreen, lineHeight = 17.sp)
249+
}
250+
}
251+
}
252+
253+
Spacer(Modifier.height(12.dp))
254+
HorizontalDivider(color = PlantixBorder)
255+
Spacer(Modifier.height(8.dp))
256+
257+
// Action footer (Upvotes, Answers, Share)
258+
Row(
259+
modifier = Modifier.fillMaxWidth(),
260+
horizontalArrangement = Arrangement.SpaceBetween,
261+
verticalAlignment = Alignment.CenterVertically
262+
) {
263+
Row(verticalAlignment = Alignment.CenterVertically) {
264+
Icon(Icons.Filled.ThumbUp, contentDescription = null, tint = PlantixTextMuted, modifier = Modifier.size(16.dp))
265+
Spacer(Modifier.width(4.dp))
266+
Text("${post.upvotesCount} Helpful", fontSize = 11.sp, color = PlantixTextMuted)
267+
}
268+
Row(verticalAlignment = Alignment.CenterVertically) {
269+
Icon(Icons.Filled.ChatBubbleOutline, contentDescription = null, tint = PlantixTextMuted, modifier = Modifier.size(16.dp))
270+
Spacer(Modifier.width(4.dp))
271+
Text("${post.answersCount} Answers", fontSize = 11.sp, color = PlantixTextMuted)
272+
}
273+
Row(verticalAlignment = Alignment.CenterVertically) {
274+
Icon(Icons.Filled.Share, contentDescription = null, tint = PlantixTextMuted, modifier = Modifier.size(16.dp))
275+
Spacer(Modifier.width(4.dp))
276+
Text("Share", fontSize = 11.sp, color = PlantixTextMuted)
277+
}
278+
}
279+
}
280+
}
281+
}
282+
}
283+
}
284+
}
285+
}

0 commit comments

Comments
 (0)