From 395e5e65dd59ec5b470135156e02ae5ce253c1ad Mon Sep 17 00:00:00 2001 From: AngelSuarez03 Date: Mon, 18 Mar 2024 13:37:00 -0600 Subject: [PATCH] Conexion pantallas (Principal -> Sala -> Compra) --- app/build.gradle.kts | 2 + app/src/main/AndroidManifest.xml | 2 +- .../example/pantallacompra/ChairAdapter.kt | 31 ++++++++++++- .../com/example/pantallacompra/ChairList.kt | 25 +++++++++-- .../java/com/example/pantallacompra/Event.kt | 2 +- .../com/example/pantallacompra/EventList.kt | 2 +- .../example/pantallacompra/MainActivity.kt | 7 +++ .../com/example/pantallacompra/MyAdapter.kt | 10 ++++- .../java/com/example/pantallacompra/compra.kt | 11 +++++ app/src/main/res/drawable/boton_redondo.xml | 4 +- .../main/res/layout/activity_chair_list.xml | 45 +++++++++++++++++-- .../main/res/layout/activity_event_list.xml | 6 ++- app/src/main/res/layout/chair_item.xml | 1 + app/src/main/res/layout/pantallacompra.xml | 35 +++++++++------ 14 files changed, 151 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/com/example/pantallacompra/compra.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 66b9083..3e45975 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,6 +47,8 @@ dependencies { implementation("com.google.android.material:material:1.11.0") implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("com.google.firebase:firebase-database:20.3.1") + implementation ("com.github.bumptech.glide:glide:4.12.0") + annotationProcessor ("com.github.bumptech.glide:compiler:4.12.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 766f0c7..1187fdc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ android:name=".ChairList" android:screenOrientation="portrait" android:exported="false" /> - ): RecyclerView.Adapter() { private lateinit var mListener : onItemClickListener + private val selectedItems = ArrayList() + + fun toggleSelection(position: Int) { + if (selectedItems.contains(position)) { + selectedItems.remove(position) + } else { + selectedItems.add(position) + } + notifyItemChanged(position) + } interface onItemClickListener{ fun onItemClick(position: Int) @@ -22,7 +33,10 @@ class ChairAdapter (private val item : ArrayList): RecyclerView.Adapter val chair : TextView = itemView.findViewById(R.id.chair) init { itemView.setOnClickListener{ - listener.onItemClick(adapterPosition) + val position=adapterPosition + if(position!=RecyclerView.NO_POSITION){ + (itemView.context as? ChairAdapter) ?.toggleSelection((position)) + } } } } @@ -36,6 +50,19 @@ class ChairAdapter (private val item : ArrayList): RecyclerView.Adapter } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.chair.text=item[position].noAsiento.toString() + //holder.chair.text=item[position].noAsiento.toString() + // val chair = item[position] + holder.chair.text = item[position].noAsiento.toString() + + if (selectedItems.contains(position)) { + holder.itemView.setBackgroundColor(Color.RED) + } else { + holder.itemView.setBackgroundColor(Color.parseColor("#225c6e")) + } + + holder.itemView.setOnClickListener { + toggleSelection(position) + } } + } \ No newline at end of file diff --git a/app/src/main/java/com/example/pantallacompra/ChairList.kt b/app/src/main/java/com/example/pantallacompra/ChairList.kt index 6843e77..8d02676 100644 --- a/app/src/main/java/com/example/pantallacompra/ChairList.kt +++ b/app/src/main/java/com/example/pantallacompra/ChairList.kt @@ -1,11 +1,13 @@ package com.example.pantallacompra -import androidx.appcompat.app.AppCompatActivity +import android.content.Intent import android.os.Bundle +import android.view.View +import android.widget.Button import android.widget.TextView import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.GridLayoutManager -import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.firebase.database.DataSnapshot import com.google.firebase.database.DatabaseError @@ -17,6 +19,7 @@ class ChairList : AppCompatActivity() { private lateinit var dbreference : DatabaseReference private lateinit var recycleView: RecyclerView private lateinit var eventList : ArrayList + private lateinit var seleccionados : ArrayList override fun onCreate(savedInstanceState: Bundle?) { @@ -34,13 +37,26 @@ class ChairList : AppCompatActivity() { val nSala:TextView=findViewById(R.id.noSalaText) nSala.text=noSala + val btnConfirmar:Button = findViewById(R.id.btnConfirmar) + val btnCancelar:Button = findViewById(R.id.btncancelar) + recycleView = findViewById(R.id.chairRecycleView) - recycleView.layoutManager = GridLayoutManager(this,2) + recycleView.layoutManager = GridLayoutManager(this,4) recycleView.setHasFixedSize(true) eventList = arrayListOf() getEvents() + btnConfirmar.setOnClickListener(View.OnClickListener() { + val intent = Intent(this, compra::class.java) + startActivity(intent) + }) + + btnCancelar.setOnClickListener(View.OnClickListener() { + val intent = Intent(this, EventList::class.java) + startActivity(intent) + }) + } private fun getEvents(){ dbreference= FirebaseDatabase.getInstance().getReference("Asientos") @@ -54,9 +70,10 @@ class ChairList : AppCompatActivity() { } var adapter=ChairAdapter(eventList) recycleView.adapter=adapter + adapter.setOnItemClickListener(object : ChairAdapter.onItemClickListener{ override fun onItemClick(position: Int) { - //Toast.makeText(this@ChairList,"Has hecho click", Toast.LENGTH_LONG).show() + adapter.toggleSelection(position) } }) diff --git a/app/src/main/java/com/example/pantallacompra/Event.kt b/app/src/main/java/com/example/pantallacompra/Event.kt index 4b13032..86fc88b 100644 --- a/app/src/main/java/com/example/pantallacompra/Event.kt +++ b/app/src/main/java/com/example/pantallacompra/Event.kt @@ -1,5 +1,5 @@ package com.example.pantallacompra -data class Event(val nombre : String ?=null, val genero : String ?=null, val duracion : Int ?=null, val tipo : String ?=null){ +data class Event(val nombre : String ?=null, val genero : String ?=null, val duracion : Int ?=null, val tipo : String ?=null, val urlImage : String ?=null){ } diff --git a/app/src/main/java/com/example/pantallacompra/EventList.kt b/app/src/main/java/com/example/pantallacompra/EventList.kt index 500c2c0..df4c4f5 100644 --- a/app/src/main/java/com/example/pantallacompra/EventList.kt +++ b/app/src/main/java/com/example/pantallacompra/EventList.kt @@ -37,7 +37,7 @@ class EventList : AppCompatActivity() { eventList.add(item!!) } //recycleView.adapter=MyAdapter(eventList) - var adapter=MyAdapter(eventList) + var adapter=MyAdapter(eventList, this@EventList) recycleView.adapter=adapter adapter.setOnItemClickListener(object : MyAdapter.onItemClickListener{ override fun onItemClick(position: Int) { diff --git a/app/src/main/java/com/example/pantallacompra/MainActivity.kt b/app/src/main/java/com/example/pantallacompra/MainActivity.kt index 729bf7a..2f60229 100644 --- a/app/src/main/java/com/example/pantallacompra/MainActivity.kt +++ b/app/src/main/java/com/example/pantallacompra/MainActivity.kt @@ -23,6 +23,7 @@ class MainActivity : AppCompatActivity() { asientosReference= FirebaseDatabase.getInstance().getReference("Asientos") setContentView(R.layout.activity_main) + cargarAsientos(asientosReference) val boton = findViewById