Actualizaciones en la pantalla Compra
This commit is contained in:
parent
add78b3a4a
commit
2d9e334a0f
|
@ -6,17 +6,34 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.google.firebase.database.DatabaseReference
|
||||||
|
import com.google.firebase.database.FirebaseDatabase
|
||||||
|
|
||||||
class ChairAdapter (private val item : ArrayList<Asiento>): RecyclerView.Adapter<ChairAdapter.ViewHolder>() {
|
class ChairAdapter (private val item : ArrayList<Asiento>): RecyclerView.Adapter<ChairAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private lateinit var mListener : onItemClickListener
|
private lateinit var mListener : onItemClickListener
|
||||||
private val selectedItems = ArrayList<Int>()
|
private lateinit var database: FirebaseDatabase
|
||||||
|
//private lateinit var myRef: DatabaseReference
|
||||||
|
private val selectedItems = HashSet<Int>()
|
||||||
|
private val occupiedSeats = ArrayList<String>()
|
||||||
|
|
||||||
fun toggleSelection(position: Int) {
|
fun toggleSelection(position: Int) {
|
||||||
|
|
||||||
|
var asiento=item[position].noAsiento.toString()
|
||||||
|
database = FirebaseDatabase.getInstance()
|
||||||
|
var myRef = database.getReference("Asientos/$asiento/status")
|
||||||
|
|
||||||
|
val asientoprueba = item[position]
|
||||||
|
val asientoNo = asientoprueba.noAsiento.toString()
|
||||||
|
|
||||||
if (selectedItems.contains(position)) {
|
if (selectedItems.contains(position)) {
|
||||||
|
actulizarValor("Libre", myRef)
|
||||||
selectedItems.remove(position)
|
selectedItems.remove(position)
|
||||||
|
occupiedSeats.remove(asientoNo)
|
||||||
} else {
|
} else {
|
||||||
|
actulizarValor("Ocupado", myRef)
|
||||||
selectedItems.add(position)
|
selectedItems.add(position)
|
||||||
|
occupiedSeats.add(asientoNo)
|
||||||
}
|
}
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
|
@ -29,16 +46,28 @@ class ChairAdapter (private val item : ArrayList<Asiento>): RecyclerView.Adapter
|
||||||
mListener=listener
|
mListener=listener
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewHolder(itemView: View, listener: onItemClickListener): RecyclerView.ViewHolder(itemView){
|
inner class ViewHolder(itemView: View, listener: onItemClickListener): RecyclerView.ViewHolder(itemView){
|
||||||
val chair : TextView = itemView.findViewById(R.id.chair)
|
val chair : TextView = itemView.findViewById(R.id.chair)
|
||||||
init {
|
init {
|
||||||
itemView.setOnClickListener{
|
itemView.setOnClickListener{
|
||||||
val position=adapterPosition
|
val position=adapterPosition
|
||||||
if(position!=RecyclerView.NO_POSITION){
|
if(position!=RecyclerView.NO_POSITION){
|
||||||
(itemView.context as? ChairAdapter) ?.toggleSelection((position))
|
toggleSelection(position)
|
||||||
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun bind(position: Int){
|
||||||
|
val item = item[position]
|
||||||
|
chair.text= item.noAsiento.toString()
|
||||||
|
|
||||||
|
if (selectedItems.contains(position)) {
|
||||||
|
itemView.setBackgroundColor(Color.RED)
|
||||||
|
} else {
|
||||||
|
itemView.setBackgroundColor(Color.parseColor("#4a8a9e"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
@ -49,20 +78,16 @@ class ChairAdapter (private val item : ArrayList<Asiento>): RecyclerView.Adapter
|
||||||
return item.size
|
return item.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
//holder.chair.text=item[position].noAsiento.toString()
|
|
||||||
// val chair = item[position]
|
|
||||||
holder.chair.text = item[position].noAsiento.toString()
|
holder.chair.text = item[position].noAsiento.toString()
|
||||||
|
holder.bind(position)
|
||||||
if (selectedItems.contains(position)) {
|
}
|
||||||
holder.itemView.setBackgroundColor(Color.RED)
|
fun actulizarValor(status : String, reference: DatabaseReference){
|
||||||
} else {
|
reference.setValue(status)
|
||||||
holder.itemView.setBackgroundColor(Color.parseColor("#225c6e"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.itemView.setOnClickListener {
|
fun getOccupiedSeats(): List<String> {
|
||||||
toggleSelection(position)
|
return occupiedSeats
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -19,7 +19,9 @@ class ChairList : AppCompatActivity() {
|
||||||
private lateinit var dbreference : DatabaseReference
|
private lateinit var dbreference : DatabaseReference
|
||||||
private lateinit var recycleView: RecyclerView
|
private lateinit var recycleView: RecyclerView
|
||||||
private lateinit var eventList : ArrayList<Asiento>
|
private lateinit var eventList : ArrayList<Asiento>
|
||||||
public lateinit var seleccionados : ArrayList<String>
|
// private lateinit var chairs : ArrayList<String>
|
||||||
|
//var arraySillas = arrayListOf<String>()
|
||||||
|
var total : Int =0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
||||||
|
@ -30,6 +32,8 @@ class ChairList : AppCompatActivity() {
|
||||||
val bundle= intent.extras
|
val bundle= intent.extras
|
||||||
val nombreEvento=bundle?.getString("nombreEvento")
|
val nombreEvento=bundle?.getString("nombreEvento")
|
||||||
val noSala=bundle?.getString("sala")
|
val noSala=bundle?.getString("sala")
|
||||||
|
val btnComprar : Button = findViewById(R.id.btnConfirmar)
|
||||||
|
val btnSalir : Button = findViewById(R.id.btncancelar)
|
||||||
|
|
||||||
val nEvento:TextView =findViewById(R.id.eventoText)
|
val nEvento:TextView =findViewById(R.id.eventoText)
|
||||||
nEvento.text=nombreEvento
|
nEvento.text=nombreEvento
|
||||||
|
@ -37,25 +41,33 @@ class ChairList : AppCompatActivity() {
|
||||||
val nSala:TextView=findViewById(R.id.noSalaText)
|
val nSala:TextView=findViewById(R.id.noSalaText)
|
||||||
nSala.text=noSala
|
nSala.text=noSala
|
||||||
|
|
||||||
val btnConfirmar:Button = findViewById(R.id.btnConfirmar)
|
|
||||||
val btnCancelar:Button = findViewById(R.id.btncancelar)
|
|
||||||
|
|
||||||
recycleView = findViewById(R.id.chairRecycleView)
|
recycleView = findViewById(R.id.chairRecycleView)
|
||||||
recycleView.layoutManager = GridLayoutManager(this,4)
|
recycleView.layoutManager = GridLayoutManager(this,2)
|
||||||
recycleView.setHasFixedSize(true)
|
recycleView.setHasFixedSize(true)
|
||||||
|
|
||||||
eventList = arrayListOf<Asiento>()
|
eventList = arrayListOf<Asiento>()
|
||||||
|
// chairs= arrayListOf<String>()
|
||||||
|
|
||||||
getEvents()
|
getEvents()
|
||||||
|
btnComprar.setOnClickListener{
|
||||||
btnConfirmar.setOnClickListener(View.OnClickListener() {
|
val adapter = recycleView.adapter as ChairAdapter
|
||||||
|
val asientosOcupados = adapter.getOccupiedSeats()
|
||||||
val intent = Intent(this, compra::class.java)
|
val intent = Intent(this, compra::class.java)
|
||||||
|
intent.putStringArrayListExtra("asientosSeleccionados", ArrayList(asientosOcupados))
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
})
|
|
||||||
|
|
||||||
btnCancelar.setOnClickListener(View.OnClickListener() {
|
val mensajeToast = if (asientosOcupados.isNotEmpty()) {
|
||||||
|
"Asientos ocupados: ${asientosOcupados.joinToString(", ")}"
|
||||||
|
} else {
|
||||||
|
"No hay asientos ocupados."
|
||||||
|
}
|
||||||
|
Toast.makeText(this@ChairList, mensajeToast, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
btnSalir.setOnClickListener{
|
||||||
val intent = Intent(this, EventList::class.java)
|
val intent = Intent(this, EventList::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
})
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private fun getEvents(){
|
private fun getEvents(){
|
||||||
|
@ -73,11 +85,11 @@ class ChairList : AppCompatActivity() {
|
||||||
|
|
||||||
adapter.setOnItemClickListener(object : ChairAdapter.onItemClickListener{
|
adapter.setOnItemClickListener(object : ChairAdapter.onItemClickListener{
|
||||||
override fun onItemClick(position: Int) {
|
override fun onItemClick(position: Int) {
|
||||||
Toast.makeText(this@ChairList,"No deja",Toast.LENGTH_SHORT).show()
|
|
||||||
adapter.toggleSelection(position)
|
adapter.toggleSelection(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
// total= adapter.getTotal()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,4 +100,6 @@ class ChairList : AppCompatActivity() {
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ 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.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
|
||||||
|
@ -18,6 +19,14 @@ class compra: AppCompatActivity() {
|
||||||
val editTextNombre: EditText = findViewById(R.id.editTextNombre)
|
val editTextNombre: EditText = findViewById(R.id.editTextNombre)
|
||||||
val editTextTelefono: EditText = findViewById(R.id.editTextTelefono)
|
val editTextTelefono: EditText = findViewById(R.id.editTextTelefono)
|
||||||
|
|
||||||
|
val textViewAsientos: TextView = findViewById(R.id.textView5Result) // Este es tu TextView
|
||||||
|
|
||||||
|
// Obtener la lista de asientos seleccionados del intent
|
||||||
|
val asientosSeleccionados = intent.getStringArrayListExtra("asientosSeleccionados")
|
||||||
|
|
||||||
|
// Mostrar la lista de asientos seleccionados en el TextView
|
||||||
|
textViewAsientos.text = asientosSeleccionados?.joinToString(", ")
|
||||||
|
|
||||||
btnComprar.setOnClickListener {
|
btnComprar.setOnClickListener {
|
||||||
val nombre = editTextNombre.text.toString()
|
val nombre = editTextNombre.text.toString()
|
||||||
val telefono = editTextTelefono.text.toString()
|
val telefono = editTextTelefono.text.toString()
|
||||||
|
@ -40,9 +49,15 @@ class compra: AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mostrarMensaje(mensaje: String) {
|
private fun mostrarMensaje(mensaje: String) {
|
||||||
|
val asientosSeleccionados = intent.getStringArrayListExtra("asientosSeleccionados")
|
||||||
|
|
||||||
|
val mensajeAsientos = asientosSeleccionados?.joinToString(", ") ?: "Ningún asiento seleccionado"
|
||||||
|
|
||||||
|
val mensajeCompleto = "$mensaje\n\nAsientos seleccionados:\n$mensajeAsientos"
|
||||||
|
|
||||||
val builder = AlertDialog.Builder(this)
|
val builder = AlertDialog.Builder(this)
|
||||||
builder.setTitle("Datos de la compra")
|
builder.setTitle("Datos de la compra")
|
||||||
builder.setMessage(mensaje)
|
builder.setMessage(mensajeCompleto)
|
||||||
builder.setPositiveButton("Aceptar", null)
|
builder.setPositiveButton("Aceptar", null)
|
||||||
val dialog = builder.create()
|
val dialog = builder.create()
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|
Loading…
Reference in New Issue