Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.realestatemobileapplicationmae.screen
- import android.annotation.SuppressLint
- import android.content.Context
- import android.content.Intent
- import android.widget.Toast
- import androidx.compose.foundation.background
- import androidx.compose.foundation.layout.*
- import androidx.compose.foundation.lazy.LazyColumn
- import androidx.compose.foundation.lazy.itemsIndexed
- import androidx.compose.material.Card
- import androidx.compose.material.ExperimentalMaterialApi
- import androidx.compose.material.Text
- import androidx.compose.runtime.Composable
- import androidx.compose.runtime.mutableStateListOf
- import androidx.compose.runtime.snapshots.SnapshotStateList
- import androidx.compose.ui.Alignment
- import androidx.compose.ui.Modifier
- import androidx.compose.ui.graphics.Color
- import androidx.compose.ui.platform.LocalContext
- import androidx.compose.ui.text.TextStyle
- import androidx.compose.ui.text.style.TextAlign
- import androidx.compose.ui.unit.dp
- import androidx.compose.ui.unit.sp
- import androidx.navigation.NavController
- import androidx.navigation.NavHostController
- import com.example.realestatemobileapplicationmae.model.Property
- import com.google.firebase.firestore.FirebaseFirestore
- @SuppressLint("UnrememberedMutableState")
- @Composable
- fun PropertyDetailScreen(navController: NavController){
- val ctx = LocalContext.current
- Column(
- modifier = Modifier.padding(20.dp),
- verticalArrangement = Arrangement.Center,
- horizontalAlignment = Alignment.CenterHorizontally,
- ){
- val propertyList = mutableStateListOf<Property?>()
- val db: FirebaseFirestore = FirebaseFirestore.getInstance()
- db.collection("Property").get().addOnSuccessListener { queryDocumentSnapshots ->
- if (!queryDocumentSnapshots.isEmpty) {
- val list = queryDocumentSnapshots.documents
- for (d in list) {
- val p: Property? = d.toObject(Property::class.java)
- p?.propertyID = d.id
- propertyList.add(p)
- }
- } else {
- Toast.makeText(
- ctx,
- "No data found in database",
- Toast.LENGTH_SHORT
- ).show()
- }
- }
- .addOnFailureListener {
- Toast.makeText(
- ctx,
- "Fail to get the data.",
- Toast.LENGTH_SHORT
- ).show()
- }
- firebaseUI(LocalContext.current, propertyList)
- }
- }
- @OptIn(ExperimentalMaterialApi::class)
- @Composable
- fun firebaseUI(context: Context,propertyList: SnapshotStateList<Property?>){
- Column(
- modifier = Modifier
- .fillMaxHeight()
- .fillMaxWidth()
- .background(Color.White),
- verticalArrangement = Arrangement.Top,
- horizontalAlignment = Alignment.CenterHorizontally
- ){
- LazyColumn {
- itemsIndexed(propertyList) { index, item ->
- Card(
- onClick = {
- val i = Intent(context, UpdateProperty::class.java)
- i.putExtra("propertyTitle",item?.propertyTitle)
- i.putExtra("propertyType",item?.propertyType)
- i.putExtra("Address",item?.address)
- i.putExtra("Price",item?.price)
- i.putExtra("propertyID",item?.propertyID)
- context.startActivity(i)
- },
- modifier = Modifier.padding(8.dp),
- elevation = 6.dp
- )
- {
- Column(
- modifier = Modifier
- .padding(8.dp)
- .fillMaxWidth()
- ) {
- Spacer(modifier = Modifier.width(5.dp))
- propertyList[index]?.propertyTitle?.let {
- Text(
- text = it,
- modifier = Modifier.padding(4.dp),
- color = Color.Black,
- textAlign = TextAlign.Center,
- style = TextStyle(fontSize = 15.sp)
- )
- }
- Spacer(modifier = Modifier.height(5.dp))
- propertyList[index]?.propertyType?.let{
- Text(
- text = it,
- modifier = Modifier.padding(4.dp),
- color = Color.Black,
- textAlign = TextAlign.Center,
- style = TextStyle(
- fontSize = 15.sp
- )
- )
- }
- Spacer(modifier = Modifier.width(5.dp))
- propertyList[index]?.price?.let{
- Text(
- text = "it",
- modifier = Modifier.padding(4.dp),
- color = Color.Black,
- textAlign = TextAlign.Center,
- style = TextStyle(fontSize = 15.sp)
- )
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement