From bb81c7e63aa68398638d2a2efc630d55f3d9f74a Mon Sep 17 00:00:00 2001 From: AngelSuarez03 Date: Tue, 19 Mar 2024 22:53:48 -0600 Subject: [PATCH] Final Commit --- .../example/pantallacompra/ChairAdapter.kt | 13 ++++--- .../com/example/pantallacompra/ChairList.kt | 11 +++--- .../example/pantallacompra/MainActivity.kt | 17 ++++++++- .../java/com/example/pantallacompra/compra.kt | 35 ++++++++++++++++-- .../main/res/layout/activity_chair_list.xml | 13 +++---- app/src/main/res/layout/pantallacompra.xml | 36 ++++++------------- 6 files changed, 79 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/com/example/pantallacompra/ChairAdapter.kt b/app/src/main/java/com/example/pantallacompra/ChairAdapter.kt index f152658..80061f7 100644 --- a/app/src/main/java/com/example/pantallacompra/ChairAdapter.kt +++ b/app/src/main/java/com/example/pantallacompra/ChairAdapter.kt @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.RecyclerView import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase -class ChairAdapter (private val item : ArrayList): RecyclerView.Adapter() { +class ChairAdapter (private val item : ArrayList, private val asientoNombre : String?): RecyclerView.Adapter() { private lateinit var mListener : onItemClickListener private lateinit var database: FirebaseDatabase @@ -22,7 +22,7 @@ class ChairAdapter (private val item : ArrayList): RecyclerView.Adapter var asiento=item[position].noAsiento.toString() database = FirebaseDatabase.getInstance() - var myRef = database.getReference("Asientos/$asiento/status") + var myRef = database.getReference("$asientoNombre/$asiento/status") val asientoprueba = item[position] val asientoNo = asientoprueba.noAsiento.toString() @@ -68,9 +68,14 @@ class ChairAdapter (private val item : ArrayList): RecyclerView.Adapter val item = item[position] chair.text= item.noAsiento.toString() - if (selectedItems.contains(position)) { - itemView.setBackgroundColor(Color.RED) + if (item.status == "Ocupado") { + itemView.setBackgroundColor(Color.RED) // Color para elementos ocupados + } else if (selectedItems.contains(position)) { + itemView.setBackgroundColor(Color.BLUE) + selectedItems.add(position) + } else { + selectedItems.remove(position) itemView.setBackgroundColor(Color.parseColor("#4a8a9e")) } } diff --git a/app/src/main/java/com/example/pantallacompra/ChairList.kt b/app/src/main/java/com/example/pantallacompra/ChairList.kt index 2669235..2e8f5f8 100644 --- a/app/src/main/java/com/example/pantallacompra/ChairList.kt +++ b/app/src/main/java/com/example/pantallacompra/ChairList.kt @@ -48,7 +48,7 @@ class ChairList : AppCompatActivity() { eventList = arrayListOf() // chairs= arrayListOf() - getEvents() + getEvents(nombreEvento) btnComprar.setOnClickListener{ val adapter = recycleView.adapter as ChairAdapter val asientosOcupados = adapter.getOccupiedSeats() @@ -57,6 +57,7 @@ class ChairList : AppCompatActivity() { val montoTotal = asientosOcupados.size * 50 intent.putStringArrayListExtra("asientosSeleccionados", ArrayList(asientosOcupados)) intent.putExtra("montoTotal", montoTotal) + intent.putExtra("nombreEvento",nombreEvento.toString()) startActivity(intent) val mensajeToast = if (asientosOcupados.isNotEmpty()) { @@ -73,8 +74,8 @@ class ChairList : AppCompatActivity() { } } - private fun getEvents(){ - dbreference= FirebaseDatabase.getInstance().getReference("Asientos") + private fun getEvents(nombreEvento: String?){ + dbreference= FirebaseDatabase.getInstance().getReference("$nombreEvento") dbreference.addValueEventListener(object : ValueEventListener { override fun onDataChange(snapshot: DataSnapshot) { if(snapshot.exists()){ @@ -83,7 +84,7 @@ class ChairList : AppCompatActivity() { val item=event.getValue(Asiento::class.java) eventList.add(item!!) } - var adapter=ChairAdapter(eventList) + var adapter=ChairAdapter(eventList, "$nombreEvento") recycleView.adapter=adapter adapter.setOnItemClickListener(object : ChairAdapter.onItemClickListener{ @@ -93,7 +94,7 @@ class ChairList : AppCompatActivity() { }) // total= adapter.getTotal() - + adapter.notifyDataSetChanged() } } diff --git a/app/src/main/java/com/example/pantallacompra/MainActivity.kt b/app/src/main/java/com/example/pantallacompra/MainActivity.kt index 2f60229..596c475 100644 --- a/app/src/main/java/com/example/pantallacompra/MainActivity.kt +++ b/app/src/main/java/com/example/pantallacompra/MainActivity.kt @@ -15,15 +15,30 @@ class MainActivity : AppCompatActivity() { private lateinit var eventosReferences : DatabaseReference private lateinit var salasReference: 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?) { super.onCreate(savedInstanceState) binding= ActivityMainBinding.inflate(layoutInflater) eventosReferences= FirebaseDatabase.getInstance().getReference("Eventos") salasReference= FirebaseDatabase.getInstance().getReference("Salas") 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) - cargarAsientos(asientosReference) + cargarAsientos(europaReference) + cargarAsientos(potrosReference) + val boton = findViewById