Advertisement
backlight0815

Untitled

Mar 2nd, 2023
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. package com.example.realestatemobileapplicationmae.screen
  2.  
  3. import android.annotation.SuppressLint
  4. import android.content.Context
  5. import android.content.Intent
  6. import android.widget.Toast
  7. import androidx.compose.foundation.background
  8. import androidx.compose.foundation.layout.*
  9. import androidx.compose.foundation.lazy.LazyColumn
  10. import androidx.compose.foundation.lazy.itemsIndexed
  11. import androidx.compose.material.Card
  12. import androidx.compose.material.ExperimentalMaterialApi
  13. import androidx.compose.material.Text
  14. import androidx.compose.runtime.Composable
  15. import androidx.compose.runtime.mutableStateListOf
  16. import androidx.compose.runtime.snapshots.SnapshotStateList
  17. import androidx.compose.ui.Alignment
  18. import androidx.compose.ui.Modifier
  19. import androidx.compose.ui.graphics.Color
  20. import androidx.compose.ui.platform.LocalContext
  21. import androidx.compose.ui.text.TextStyle
  22. import androidx.compose.ui.text.style.TextAlign
  23. import androidx.compose.ui.unit.dp
  24. import androidx.compose.ui.unit.sp
  25. import androidx.navigation.NavController
  26. import androidx.navigation.NavHostController
  27.  
  28. import com.example.realestatemobileapplicationmae.model.Property
  29. import com.google.firebase.firestore.FirebaseFirestore
  30.  
  31. @SuppressLint("UnrememberedMutableState")
  32. @Composable
  33. fun PropertyDetailScreen(navController: NavController){
  34. val ctx = LocalContext.current
  35.  
  36. Column(
  37. modifier = Modifier.padding(20.dp),
  38. verticalArrangement = Arrangement.Center,
  39. horizontalAlignment = Alignment.CenterHorizontally,
  40.  
  41.  
  42. ){
  43.  
  44. val propertyList = mutableStateListOf<Property?>()
  45. val db: FirebaseFirestore = FirebaseFirestore.getInstance()
  46.  
  47. db.collection("Property").get().addOnSuccessListener { queryDocumentSnapshots ->
  48.  
  49. if (!queryDocumentSnapshots.isEmpty) {
  50. val list = queryDocumentSnapshots.documents
  51. for (d in list) {
  52. val p: Property? = d.toObject(Property::class.java)
  53. p?.propertyID = d.id
  54. propertyList.add(p)
  55. }
  56. } else {
  57. Toast.makeText(
  58. ctx,
  59. "No data found in database",
  60. Toast.LENGTH_SHORT
  61. ).show()
  62. }
  63. }
  64. .addOnFailureListener {
  65. Toast.makeText(
  66. ctx,
  67. "Fail to get the data.",
  68. Toast.LENGTH_SHORT
  69. ).show()
  70. }
  71.  
  72. firebaseUI(LocalContext.current, propertyList)
  73.  
  74.  
  75. }
  76. }
  77.  
  78.  
  79.  
  80. @OptIn(ExperimentalMaterialApi::class)
  81. @Composable
  82. fun firebaseUI(context: Context,propertyList: SnapshotStateList<Property?>){
  83.  
  84. Column(
  85. modifier = Modifier
  86. .fillMaxHeight()
  87. .fillMaxWidth()
  88. .background(Color.White),
  89.  
  90. verticalArrangement = Arrangement.Top,
  91. horizontalAlignment = Alignment.CenterHorizontally
  92.  
  93. ){
  94. LazyColumn {
  95. itemsIndexed(propertyList) { index, item ->
  96.  
  97. Card(
  98. onClick = {
  99. val i = Intent(context, UpdateProperty::class.java)
  100. i.putExtra("propertyTitle",item?.propertyTitle)
  101. i.putExtra("propertyType",item?.propertyType)
  102. i.putExtra("Address",item?.address)
  103. i.putExtra("Price",item?.price)
  104. i.putExtra("propertyID",item?.propertyID)
  105.  
  106. context.startActivity(i)
  107.  
  108.  
  109.  
  110. },
  111. modifier = Modifier.padding(8.dp),
  112. elevation = 6.dp
  113.  
  114. )
  115.  
  116. {
  117. Column(
  118. modifier = Modifier
  119. .padding(8.dp)
  120. .fillMaxWidth()
  121. ) {
  122. Spacer(modifier = Modifier.width(5.dp))
  123.  
  124. propertyList[index]?.propertyTitle?.let {
  125. Text(
  126. text = it,
  127.  
  128. modifier = Modifier.padding(4.dp),
  129.  
  130. color = Color.Black,
  131. textAlign = TextAlign.Center,
  132. style = TextStyle(fontSize = 15.sp)
  133. )
  134. }
  135. Spacer(modifier = Modifier.height(5.dp))
  136.  
  137. propertyList[index]?.propertyType?.let{
  138. Text(
  139. text = it,
  140. modifier = Modifier.padding(4.dp),
  141. color = Color.Black,
  142. textAlign = TextAlign.Center,
  143. style = TextStyle(
  144. fontSize = 15.sp
  145. )
  146. )
  147. }
  148. Spacer(modifier = Modifier.width(5.dp))
  149.  
  150. propertyList[index]?.price?.let{
  151. Text(
  152. text = "it",
  153. modifier = Modifier.padding(4.dp),
  154. color = Color.Black,
  155. textAlign = TextAlign.Center,
  156. style = TextStyle(fontSize = 15.sp)
  157. )
  158. }
  159. }
  160. }
  161. }
  162.  
  163. }
  164. }
  165.  
  166.  
  167.  
  168.  
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement