@@ -28,6 +28,7 @@ import androidx.compose.ui.unit.sp
2828import com.example.ui.theme.*
2929
3030data class EquipmentItem (
31+ val id : String = java.util.UUID .randomUUID().toString(),
3132 val name : String ,
3233 val category : String ,
3334 val rate : String ,
@@ -41,52 +42,55 @@ data class EquipmentItem(
4142@Composable
4243fun EquipmentRentalScreen (
4344 onNavigateBack : () -> Unit ,
44- onNavigateToChat : () -> Unit
45+ onNavigateToPeerChat : (name: String , info: String , phone: String ) -> Unit
4546) {
4647 val context = LocalContext .current
4748 val scrollState = rememberScrollState()
49+ var showAddDialog by remember { mutableStateOf(false ) }
4850
49- val equipmentList = remember {
50- listOf (
51- EquipmentItem (
52- name = " Mahindra 575 DI Tractor (45 HP)" ,
53- category = " Tractor & Tillage" ,
54- rate = " ₹450 / Hour" ,
55- owner = " Verma Farms (Rajesh Verma)" ,
56- distance = " 3.2 km away" ,
57- phone = " 9876543210" ,
58- isAvailable = true ,
59- icon = " 🚜"
60- ),
61- EquipmentItem (
62- name = " DJI Agras T40 Spraying Drone" ,
63- category = " Pesticide Drone Spraying" ,
64- rate = " ₹350 / Acre" ,
65- owner = " AgriTech Kisan Co-op" ,
66- distance = " 5.0 km away" ,
67- phone = " 9812345678" ,
68- isAvailable = true ,
69- icon = " 🛸"
70- ),
71- EquipmentItem (
72- name = " CLAAS Crop Combine Harvester" ,
73- category = " Harvester" ,
74- rate = " ₹1,200 / Hour" ,
75- owner = " Suresh Patel" ,
76- distance = " 8.5 km away" ,
77- phone = " 9765432109" ,
78- isAvailable = false ,
79- icon = " ⚙️"
80- ),
81- EquipmentItem (
82- name = " Solar Drip Irrigation Pump (5 HP)" ,
83- category = " Irrigation Pump" ,
84- rate = " ₹150 / Day" ,
85- owner = " Ramesh Singh" ,
86- distance = " 2.1 km away" ,
87- phone = " 9988776655" ,
88- isAvailable = true ,
89- icon = " 💧"
51+ var equipmentList by remember {
52+ mutableStateOf(
53+ listOf (
54+ EquipmentItem (
55+ name = " Mahindra 575 DI Tractor (45 HP)" ,
56+ category = " Tractor & Tillage" ,
57+ rate = " ₹450 / Hour" ,
58+ owner = " Verma Farms (Rajesh Verma)" ,
59+ distance = " 3.2 km away" ,
60+ phone = " 9876543210" ,
61+ isAvailable = true ,
62+ icon = " 🚜"
63+ ),
64+ EquipmentItem (
65+ name = " DJI Agras T40 Spraying Drone" ,
66+ category = " Pesticide Drone Spraying" ,
67+ rate = " ₹350 / Acre" ,
68+ owner = " AgriTech Kisan Co-op" ,
69+ distance = " 5.0 km away" ,
70+ phone = " 9812345678" ,
71+ isAvailable = true ,
72+ icon = " 🛸"
73+ ),
74+ EquipmentItem (
75+ name = " CLAAS Crop Combine Harvester" ,
76+ category = " Harvester" ,
77+ rate = " ₹1,200 / Hour" ,
78+ owner = " Suresh Patel" ,
79+ distance = " 8.5 km away" ,
80+ phone = " 9765432109" ,
81+ isAvailable = false ,
82+ icon = " ⚙️"
83+ ),
84+ EquipmentItem (
85+ name = " Solar Drip Irrigation Pump (5 HP)" ,
86+ category = " Irrigation Pump" ,
87+ rate = " ₹150 / Day" ,
88+ owner = " Ramesh Singh" ,
89+ distance = " 2.1 km away" ,
90+ phone = " 9988776655" ,
91+ isAvailable = true ,
92+ icon = " 💧"
93+ )
9094 )
9195 )
9296 }
@@ -103,15 +107,29 @@ fun EquipmentRentalScreen(
103107 .background(Color (0xCC141A0A ))
104108 .statusBarsPadding()
105109 .padding(horizontal = 8 .dp, vertical = 8 .dp),
106- verticalAlignment = Alignment .CenterVertically
110+ verticalAlignment = Alignment .CenterVertically ,
111+ horizontalArrangement = Arrangement .SpaceBetween
107112 ) {
108- IconButton (onClick = onNavigateBack) {
109- Icon (Icons .AutoMirrored .Filled .ArrowBack , contentDescription = " Back" , tint = NuKropText )
113+ Row (verticalAlignment = Alignment .CenterVertically ) {
114+ IconButton (onClick = onNavigateBack) {
115+ Icon (Icons .AutoMirrored .Filled .ArrowBack , contentDescription = " Back" , tint = NuKropText )
116+ }
117+ Spacer (Modifier .width(4 .dp))
118+ Column {
119+ Text (" P2P Equipment & Drone Rental" , fontSize = 16 .sp, fontWeight = FontWeight .Bold , color = NuKropText )
120+ Text (" Rent tractors, drones & machinery directly" , fontSize = 11 .sp, color = NuKropTextMuted )
121+ }
110122 }
111- Spacer (Modifier .width(4 .dp))
112- Column {
113- Text (" P2P Equipment & Drone Rental" , fontSize = 18 .sp, fontWeight = FontWeight .Bold , color = NuKropText )
114- Text (" Rent nearby tractors, drones & harvesters directly" , fontSize = 11 .sp, color = NuKropTextMuted )
123+
124+ Button (
125+ onClick = { showAddDialog = true },
126+ colors = ButtonDefaults .buttonColors(containerColor = NuKropAccent ),
127+ contentPadding = PaddingValues (horizontal = 10 .dp, vertical = 4 .dp),
128+ shape = RoundedCornerShape (8 .dp)
129+ ) {
130+ Icon (Icons .Default .Add , null , tint = NuKropDark , modifier = Modifier .size(14 .dp))
131+ Spacer (Modifier .width(4 .dp))
132+ Text (" List Mine" , color = NuKropDark , fontSize = 11 .sp, fontWeight = FontWeight .Bold )
115133 }
116134 }
117135
@@ -141,17 +159,91 @@ fun EquipmentRentalScreen(
141159 }
142160
143161 equipmentList.forEach { item ->
144- EquipmentCard (item = item, onChatClick = onNavigateToChat, onCallClick = {
145- try {
146- val intent = Intent (Intent .ACTION_DIAL , Uri .parse(" tel:${item.phone} " ))
147- context.startActivity(intent)
148- } catch (_: Exception ) {}
149- })
162+ EquipmentCard (
163+ item = item,
164+ onChatClick = { onNavigateToPeerChat(item.owner, item.name, item.phone) },
165+ onCallClick = {
166+ try {
167+ val intent = Intent (Intent .ACTION_DIAL , Uri .parse(" tel:${item.phone} " ))
168+ context.startActivity(intent)
169+ } catch (_: Exception ) {}
170+ }
171+ )
150172 }
151173
152174 Spacer (Modifier .height(80 .dp))
153175 }
154176 }
177+
178+ if (showAddDialog) {
179+ var nameInput by remember { mutableStateOf(" " ) }
180+ var categoryInput by remember { mutableStateOf(" Tractor" ) }
181+ var rateInput by remember { mutableStateOf(" " ) }
182+ var phoneInput by remember { mutableStateOf(" " ) }
183+ var locationInput by remember { mutableStateOf(" Pune, Maharashtra" ) }
184+
185+ AlertDialog (
186+ onDismissRequest = { showAddDialog = false },
187+ containerColor = NuKropCard ,
188+ title = { Text (" List Vehicle / Equipment" , color = NuKropText , fontWeight = FontWeight .Bold ) },
189+ text = {
190+ Column (verticalArrangement = Arrangement .spacedBy(10 .dp)) {
191+ OutlinedTextField (
192+ value = nameInput,
193+ onValueChange = { nameInput = it },
194+ label = { Text (" Vehicle Name (e.g. Swaraj 744 FE)" , color = NuKropTextMuted ) },
195+ colors = OutlinedTextFieldDefaults .colors(focusedTextColor = NuKropText , unfocusedTextColor = NuKropText )
196+ )
197+ OutlinedTextField (
198+ value = rateInput,
199+ onValueChange = { rateInput = it },
200+ label = { Text (" Rental Rate (e.g. ₹400 / Hour)" , color = NuKropTextMuted ) },
201+ colors = OutlinedTextFieldDefaults .colors(focusedTextColor = NuKropText , unfocusedTextColor = NuKropText )
202+ )
203+ OutlinedTextField (
204+ value = phoneInput,
205+ onValueChange = { phoneInput = it },
206+ label = { Text (" Phone Number" , color = NuKropTextMuted ) },
207+ colors = OutlinedTextFieldDefaults .colors(focusedTextColor = NuKropText , unfocusedTextColor = NuKropText )
208+ )
209+ OutlinedTextField (
210+ value = locationInput,
211+ onValueChange = { locationInput = it },
212+ label = { Text (" Location / District" , color = NuKropTextMuted ) },
213+ colors = OutlinedTextFieldDefaults .colors(focusedTextColor = NuKropText , unfocusedTextColor = NuKropText )
214+ )
215+ }
216+ },
217+ confirmButton = {
218+ Button (
219+ onClick = {
220+ if (nameInput.isNotBlank() && rateInput.isNotBlank()) {
221+ val newItem = EquipmentItem (
222+ name = nameInput.trim(),
223+ category = categoryInput,
224+ rate = rateInput.trim(),
225+ owner = " My Listed Vehicle" ,
226+ distance = locationInput,
227+ phone = if (phoneInput.isBlank()) " 9876543210" else phoneInput.trim(),
228+ isAvailable = true ,
229+ icon = if (categoryInput.contains(" Drone" , ignoreCase = true )) " 🛸" else " 🚜"
230+ )
231+ equipmentList = listOf (newItem) + equipmentList
232+ }
233+ showAddDialog = false
234+ },
235+ colors = ButtonDefaults .buttonColors(containerColor = NuKropAccent )
236+ ) {
237+ Text (" Publish Listing" , color = NuKropDark , fontWeight = FontWeight .Bold )
238+ }
239+ },
240+ dismissButton = {
241+ TextButton (onClick = { showAddDialog = false }) {
242+ Text (" Cancel" , color = NuKropTextMuted )
243+ }
244+ }
245+ )
246+ }
155247}
156248
157249@Composable
0 commit comments