Final Commit

This commit is contained in:
AngelSuarez03 2024-03-19 22:53:48 -06:00
parent bc572854f5
commit bb81c7e63a
6 changed files with 79 additions and 46 deletions

View File

@ -9,7 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.database.DatabaseReference import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase import com.google.firebase.database.FirebaseDatabase
class ChairAdapter (private val item : ArrayList<Asiento>): RecyclerView.Adapter<ChairAdapter.ViewHolder>() { class ChairAdapter (private val item : ArrayList<Asiento>, private val asientoNombre : String?): RecyclerView.Adapter<ChairAdapter.ViewHolder>() {
private lateinit var mListener : onItemClickListener private lateinit var mListener : onItemClickListener
private lateinit var database: FirebaseDatabase private lateinit var database: FirebaseDatabase
@ -22,7 +22,7 @@ class ChairAdapter (private val item : ArrayList<Asiento>): RecyclerView.Adapter
var asiento=item[position].noAsiento.toString() var asiento=item[position].noAsiento.toString()
database = FirebaseDatabase.getInstance() database = FirebaseDatabase.getInstance()
var myRef = database.getReference("Asientos/$asiento/status") var myRef = database.getReference("$asientoNombre/$asiento/status")
val asientoprueba = item[position] val asientoprueba = item[position]
val asientoNo = asientoprueba.noAsiento.toString() val asientoNo = asientoprueba.noAsiento.toString()
@ -68,9 +68,14 @@ class ChairAdapter (private val item : ArrayList<Asiento>): RecyclerView.Adapter
val item = item[position] val item = item[position]
chair.text= item.noAsiento.toString() chair.text= item.noAsiento.toString()
if (selectedItems.contains(position)) { if (item.status == "Ocupado") {
itemView.setBackgroundColor(Color.RED) itemView.setBackgroundColor(Color.RED) // Color para elementos ocupados
} else if (selectedItems.contains(position)) {
itemView.setBackgroundColor(Color.BLUE)
selectedItems.add(position)
} else { } else {
selectedItems.remove(position)
itemView.setBackgroundColor(Color.parseColor("#4a8a9e")) itemView.setBackgroundColor(Color.parseColor("#4a8a9e"))
} }
} }

View File

@ -48,7 +48,7 @@ class ChairList : AppCompatActivity() {
eventList = arrayListOf<Asiento>() eventList = arrayListOf<Asiento>()
// chairs= arrayListOf<String>() // chairs= arrayListOf<String>()
getEvents() getEvents(nombreEvento)
btnComprar.setOnClickListener{ btnComprar.setOnClickListener{
val adapter = recycleView.adapter as ChairAdapter val adapter = recycleView.adapter as ChairAdapter
val asientosOcupados = adapter.getOccupiedSeats() val asientosOcupados = adapter.getOccupiedSeats()
@ -57,6 +57,7 @@ class ChairList : AppCompatActivity() {
val montoTotal = asientosOcupados.size * 50 val montoTotal = asientosOcupados.size * 50
intent.putStringArrayListExtra("asientosSeleccionados", ArrayList(asientosOcupados)) intent.putStringArrayListExtra("asientosSeleccionados", ArrayList(asientosOcupados))
intent.putExtra("montoTotal", montoTotal) intent.putExtra("montoTotal", montoTotal)
intent.putExtra("nombreEvento",nombreEvento.toString())
startActivity(intent) startActivity(intent)
val mensajeToast = if (asientosOcupados.isNotEmpty()) { val mensajeToast = if (asientosOcupados.isNotEmpty()) {
@ -73,8 +74,8 @@ class ChairList : AppCompatActivity() {
} }
} }
private fun getEvents(){ private fun getEvents(nombreEvento: String?){
dbreference= FirebaseDatabase.getInstance().getReference("Asientos") dbreference= FirebaseDatabase.getInstance().getReference("$nombreEvento")
dbreference.addValueEventListener(object : ValueEventListener { dbreference.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) { override fun onDataChange(snapshot: DataSnapshot) {
if(snapshot.exists()){ if(snapshot.exists()){
@ -83,7 +84,7 @@ class ChairList : AppCompatActivity() {
val item=event.getValue(Asiento::class.java) val item=event.getValue(Asiento::class.java)
eventList.add(item!!) eventList.add(item!!)
} }
var adapter=ChairAdapter(eventList) var adapter=ChairAdapter(eventList, "$nombreEvento")
recycleView.adapter=adapter recycleView.adapter=adapter
adapter.setOnItemClickListener(object : ChairAdapter.onItemClickListener{ adapter.setOnItemClickListener(object : ChairAdapter.onItemClickListener{
@ -93,7 +94,7 @@ class ChairList : AppCompatActivity() {
}) })
// total= adapter.getTotal() // total= adapter.getTotal()
adapter.notifyDataSetChanged()
} }
} }

View File

@ -15,15 +15,30 @@ class MainActivity : AppCompatActivity() {
private lateinit var eventosReferences : DatabaseReference private lateinit var eventosReferences : DatabaseReference
private lateinit var salasReference: DatabaseReference private lateinit var salasReference: DatabaseReference
private lateinit var asientosReference: DatabaseReference private lateinit var asientosReference: DatabaseReference
private lateinit var champinosReference: DatabaseReference
private lateinit var caligarisReference: DatabaseReference
private lateinit var rhianaReference: DatabaseReference
private lateinit var mjReference: DatabaseReference
private lateinit var potrosReference: DatabaseReference
private lateinit var europaReference: DatabaseReference
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding= ActivityMainBinding.inflate(layoutInflater) binding= ActivityMainBinding.inflate(layoutInflater)
eventosReferences= FirebaseDatabase.getInstance().getReference("Eventos") eventosReferences= FirebaseDatabase.getInstance().getReference("Eventos")
salasReference= FirebaseDatabase.getInstance().getReference("Salas") salasReference= FirebaseDatabase.getInstance().getReference("Salas")
asientosReference= FirebaseDatabase.getInstance().getReference("Asientos") asientosReference= FirebaseDatabase.getInstance().getReference("Asientos")
champinosReference= FirebaseDatabase.getInstance().getReference("Champions")
rhianaReference= FirebaseDatabase.getInstance().getReference("Rhiana Show")
mjReference= FirebaseDatabase.getInstance().getReference("Michael Jackson")
caligarisReference= FirebaseDatabase.getInstance().getReference("Los caligaris")
potrosReference= FirebaseDatabase.getInstance().getReference("Potros Furiosos")
europaReference= FirebaseDatabase.getInstance().getReference("Europa League")
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
cargarAsientos(asientosReference) cargarAsientos(europaReference)
cargarAsientos(potrosReference)
val boton = findViewById<Button>(R.id.nextBtn) val boton = findViewById<Button>(R.id.nextBtn)

View File

@ -4,13 +4,21 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.widget.Button import android.widget.Button
import android.widget.EditText import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
class compra: AppCompatActivity() { class compra: AppCompatActivity() {
private lateinit var dbreference : DatabaseReference
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.pantallacompra) setContentView(R.layout.pantallacompra)
@ -27,10 +35,33 @@ class compra: AppCompatActivity() {
// Obtener la lista de asientos seleccionados del intent // Obtener la lista de asientos seleccionados del intent
val asientosSeleccionados = intent.getStringArrayListExtra("asientosSeleccionados") val asientosSeleccionados = intent.getStringArrayListExtra("asientosSeleccionados")
val bundle = intent.extras
var nombreEvento=bundle?.getString("nombreEvento")
var imageEvent : ImageView = findViewById(R.id.imgEvento)
// Mostrar la lista de asientos seleccionados en el TextView // Mostrar la lista de asientos seleccionados en el TextView
textViewAsientos.text = asientosSeleccionados?.joinToString(", ") textViewAsientos.text = asientosSeleccionados?.joinToString(", ")
textViewMontoTotal.text = "$montoTotal pesos" textViewMontoTotal.text = "$ $montoTotal"
dbreference= FirebaseDatabase.getInstance().getReference("Eventos/$nombreEvento")
dbreference.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()) {
val imageUrl = dataSnapshot.child("urlImage").value.toString()
// Cargar la imagen en el ImageView usando una biblioteca como Glide o Picasso
Glide.with(this@compra)
.load(imageUrl)
.into(imageEvent)
} else {
// Manejar el caso en que no se encuentre la imagen
println("No se encontró la URL de la imagen en la base de datos")
}
}
override fun onCancelled(databaseError: DatabaseError) {
// Manejar cualquier error de base de datos
println("Error al obtener la URL de la imagen: ${databaseError.message}")
}
})
btnComprar.setOnClickListener { btnComprar.setOnClickListener {
val nombre = editTextNombre.text.toString() val nombre = editTextNombre.text.toString()

View File

@ -34,11 +34,10 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/chairRecycleView" android:id="@+id/chairRecycleView"
android:layout_width="375dp" android:layout_width="309dp"
android:layout_height="299dp" android:layout_height="155dp"
android:layout_marginTop="76dp" android:layout_marginTop="176dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.444"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventTextTitle" /> app:layout_constraintTop_toBottomOf="@+id/eventTextTitle" />
@ -49,12 +48,10 @@
android:text="N0. Sala" android:text="N0. Sala"
android:textAlignment="center" android:textAlignment="center"
android:textSize="30sp" android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/chairRecycleView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/logoCamion" />
app:layout_constraintVertical_bias="1.0" />
<TextView <TextView
android:id="@+id/eventoText" android:id="@+id/eventoText"
@ -118,7 +115,7 @@
android:id="@+id/textView8" android:id="@+id/textView8"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="130dp" android:layout_height="130dp"
android:layout_marginTop="16dp" android:layout_marginTop="56dp"
android:background="#612020" android:background="#612020"
android:fontFamily="@font/cinepolis" android:fontFamily="@font/cinepolis"
android:gravity="center" android:gravity="center"

View File

@ -67,7 +67,7 @@
app:layout_constraintTop_toBottomOf="@+id/top_layout"> app:layout_constraintTop_toBottomOf="@+id/top_layout">
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imgEvento"
android:layout_width="345dp" android:layout_width="345dp"
android:layout_height="328dp" android:layout_height="328dp"
android:scaleType="centerCrop" android:scaleType="centerCrop"
@ -87,7 +87,7 @@
android:background="#297880" android:background="#297880"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/top_layout" app:layout_constraintEnd_toEndOf="@+id/top_layout"
app:layout_constraintHorizontal_bias="1.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/top_layout" app:layout_constraintStart_toStartOf="@+id/top_layout"
app:layout_constraintTop_toBottomOf="@+id/second_layout"> app:layout_constraintTop_toBottomOf="@+id/second_layout">
@ -106,26 +106,18 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fecha y hora: "
android:textColor="#FFFFFF"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/textView3"
app:layout_constraintTop_toBottomOf="@id/textView3" />
<!-- TextView para "Asientos seleccionados" --> <!-- TextView para "Asientos seleccionados" -->
<TextView <TextView
android:id="@+id/textView5" android:id="@+id/textView5"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:text="Asientos seleccionados: " android:text="Asientos seleccionados: "
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/textView3" app:layout_constraintStart_toStartOf="@id/textView3"
app:layout_constraintTop_toBottomOf="@id/textView4" /> app:layout_constraintTop_toBottomOf="@+id/textView3" />
<!-- TextView para "Monto total" --> <!-- TextView para "Monto total" -->
<TextView <TextView
@ -148,25 +140,16 @@
app:layout_constraintStart_toStartOf="@id/textView6" app:layout_constraintStart_toStartOf="@id/textView6"
app:layout_constraintTop_toBottomOf="@id/textView6" /> app:layout_constraintTop_toBottomOf="@id/textView6" />
<TextView
android:id="@+id/textView4Result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13 de Noviembre, 4:00 AM"
android:textColor="#4CAF50"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="@id/textView4"
app:layout_constraintTop_toTopOf="@id/textView4" />
<TextView <TextView
android:id="@+id/textView5Result" android:id="@+id/textView5Result"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:text="A1, B2 " android:text="A1, B2 "
android:textColor="#4CAF50" android:textColor="#4CAF50"
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintStart_toEndOf="@id/textView5" app:layout_constraintStart_toEndOf="@id/textView5"
app:layout_constraintTop_toTopOf="@id/textView5" /> app:layout_constraintTop_toBottomOf="@+id/textView3" />
<TextView <TextView
android:id="@+id/textView6Result" android:id="@+id/textView6Result"
@ -214,13 +197,14 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:backgroundTint="#D9D9D9" android:backgroundTint="#D9D9D9"
android:text="Cancelar"
android:fontFamily="@font/cinepolis" android:fontFamily="@font/cinepolis"
android:text="Cancelar"
android:textColor="#000000" android:textColor="#000000"
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/buttonComprar" app:layout_constraintStart_toEndOf="@id/buttonComprar"
app:layout_constraintTop_toBottomOf="@id/editTextTelefono" /> app:layout_constraintTop_toBottomOf="@id/editTextTelefono" />
<Button <Button
android:id="@+id/buttonComprar" android:id="@+id/buttonComprar"
android:layout_width="0dp" android:layout_width="0dp"
@ -228,8 +212,8 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:backgroundTint="#D9D9D9" android:backgroundTint="#D9D9D9"
android:text="Comprar"
android:fontFamily="@font/cinepolis" android:fontFamily="@font/cinepolis"
android:text="Comprar"
android:textColor="#000000" android:textColor="#000000"
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintEnd_toStartOf="@id/buttonCancelar" app:layout_constraintEnd_toStartOf="@id/buttonCancelar"