From 926e19d44df6a869283053c1c42f0192178c517c Mon Sep 17 00:00:00 2001 From: sebastiancc27 Date: Mon, 11 Mar 2024 23:11:30 -0600 Subject: [PATCH] Hala Madrid --- .idea/.name | 1 + app/build.gradle.kts | 6 ++ app/google-services.json | 49 +++++++++++++ .../com/example/pantallacompra/Asiento.kt | 5 ++ .../example/pantallacompra/ChairAdapter.kt | 41 +++++++++++ .../com/example/pantallacompra/ChairList.kt | 73 +++++++++++++++++++ .../java/com/example/pantallacompra/Event.kt | 5 ++ .../com/example/pantallacompra/EventList.kt | 68 +++++++++++++++++ .../example/pantallacompra/MainActivity.kt | 4 +- .../com/example/pantallacompra/MyAdapter.kt | 49 +++++++++++++ .../java/com/example/pantallacompra/Sala.kt | 5 ++ app/src/main/res/drawable/boton_redondo.xml | 6 ++ app/src/main/res/layout/chair_item.xml | 16 ++++ build.gradle.kts | 5 ++ 14 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 .idea/.name create mode 100644 app/google-services.json create mode 100644 app/src/main/java/com/example/pantallacompra/Asiento.kt create mode 100644 app/src/main/java/com/example/pantallacompra/ChairAdapter.kt create mode 100644 app/src/main/java/com/example/pantallacompra/ChairList.kt create mode 100644 app/src/main/java/com/example/pantallacompra/Event.kt create mode 100644 app/src/main/java/com/example/pantallacompra/EventList.kt create mode 100644 app/src/main/java/com/example/pantallacompra/MyAdapter.kt create mode 100644 app/src/main/java/com/example/pantallacompra/Sala.kt create mode 100644 app/src/main/res/drawable/boton_redondo.xml create mode 100644 app/src/main/res/layout/chair_item.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..6c9ca6f --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +pantallaCompra \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5a50e99..66b9083 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.android.application") id("org.jetbrains.kotlin.android") + id("com.google.gms.google-services") } android { @@ -33,6 +34,10 @@ android { kotlinOptions { jvmTarget = "1.8" } + buildFeatures { + viewBinding = true + } + } dependencies { @@ -41,6 +46,7 @@ dependencies { implementation("androidx.appcompat:appcompat:1.6.1") 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") 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/google-services.json b/app/google-services.json new file mode 100644 index 0000000..aa03fd0 --- /dev/null +++ b/app/google-services.json @@ -0,0 +1,49 @@ +{ + "project_info": { + "project_number": "466470867685", + "firebase_url": "https://playpal-853fb-default-rtdb.firebaseio.com", + "project_id": "playpal-853fb", + "storage_bucket": "playpal-853fb.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:466470867685:android:0ff8f84509e25132ae3a0c", + "android_client_info": { + "package_name": "com.example.pantallacompra" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyDq4DgG2Re5v10N9-xJAKiiSQ6OphC7uKM" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:466470867685:android:1205ac64994853dfae3a0c", + "android_client_info": { + "package_name": "com.example.teatro2" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyDq4DgG2Re5v10N9-xJAKiiSQ6OphC7uKM" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/app/src/main/java/com/example/pantallacompra/Asiento.kt b/app/src/main/java/com/example/pantallacompra/Asiento.kt new file mode 100644 index 0000000..a2571d0 --- /dev/null +++ b/app/src/main/java/com/example/pantallacompra/Asiento.kt @@ -0,0 +1,5 @@ +package com.example.pantallacompra + +data class Asiento(val noAsiento : String?=null, val precio : Int?=null, val tipo : String ?=null, val status : String?=null, val nSala : Int?=null){ + +} diff --git a/app/src/main/java/com/example/pantallacompra/ChairAdapter.kt b/app/src/main/java/com/example/pantallacompra/ChairAdapter.kt new file mode 100644 index 0000000..7d7d452 --- /dev/null +++ b/app/src/main/java/com/example/pantallacompra/ChairAdapter.kt @@ -0,0 +1,41 @@ +package com.example.pantallacompra + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView + +class ChairAdapter (private val item : ArrayList): RecyclerView.Adapter() { + + private lateinit var mListener : onItemClickListener + + interface onItemClickListener{ + fun onItemClick(position: Int) + } + + fun setOnItemClickListener(listener: onItemClickListener){ + mListener=listener + } + + class ViewHolder(itemView: View, listener: onItemClickListener): RecyclerView.ViewHolder(itemView){ + val chair : TextView = itemView.findViewById(R.id.chair) + init { + itemView.setOnClickListener{ + listener.onItemClick(adapterPosition) + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.chair_item,parent,false),mListener) + } + + override fun getItemCount(): Int { + return item.size + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.chair.text=item[position].noAsiento.toString() + } +} \ 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 new file mode 100644 index 0000000..6843e77 --- /dev/null +++ b/app/src/main/java/com/example/pantallacompra/ChairList.kt @@ -0,0 +1,73 @@ +package com.example.pantallacompra + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.TextView +import android.widget.Toast +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 +import com.google.firebase.database.DatabaseReference +import com.google.firebase.database.FirebaseDatabase +import com.google.firebase.database.ValueEventListener + +class ChairList : AppCompatActivity() { + private lateinit var dbreference : DatabaseReference + private lateinit var recycleView: RecyclerView + private lateinit var eventList : ArrayList + + override fun onCreate(savedInstanceState: Bundle?) { + + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_chair_list) + + //SE GUARDA EL NOMBRE DEL EVENTO + val bundle= intent.extras + val nombreEvento=bundle?.getString("nombreEvento") + val noSala=bundle?.getString("sala") + + val nEvento:TextView =findViewById(R.id.eventoText) + nEvento.text=nombreEvento + + val nSala:TextView=findViewById(R.id.noSalaText) + nSala.text=noSala + + recycleView = findViewById(R.id.chairRecycleView) + recycleView.layoutManager = GridLayoutManager(this,2) + recycleView.setHasFixedSize(true) + + eventList = arrayListOf() + getEvents() + + } + private fun getEvents(){ + dbreference= FirebaseDatabase.getInstance().getReference("Asientos") + dbreference.addValueEventListener(object : ValueEventListener { + override fun onDataChange(snapshot: DataSnapshot) { + if(snapshot.exists()){ + + for(event in snapshot.children){ + val item=event.getValue(Asiento::class.java) + eventList.add(item!!) + } + 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() + } + + }) + + } + } + + override fun onCancelled(error: DatabaseError) { + TODO("Not yet implemented") + } + + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/pantallacompra/Event.kt b/app/src/main/java/com/example/pantallacompra/Event.kt new file mode 100644 index 0000000..4b13032 --- /dev/null +++ b/app/src/main/java/com/example/pantallacompra/Event.kt @@ -0,0 +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){ + +} diff --git a/app/src/main/java/com/example/pantallacompra/EventList.kt b/app/src/main/java/com/example/pantallacompra/EventList.kt new file mode 100644 index 0000000..500c2c0 --- /dev/null +++ b/app/src/main/java/com/example/pantallacompra/EventList.kt @@ -0,0 +1,68 @@ +package com.example.pantallacompra + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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 EventList : AppCompatActivity() { + private lateinit var dbreference : DatabaseReference + private lateinit var recycleView: RecyclerView + private lateinit var eventList : ArrayList + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_event_list) + + recycleView = findViewById(R.id.eventRecycleView) + recycleView.layoutManager = LinearLayoutManager(this) + recycleView.setHasFixedSize(true) + + eventList = arrayListOf() + getEvents() + } + + private fun getEvents(){ + dbreference= FirebaseDatabase.getInstance().getReference("Eventos") + dbreference.addValueEventListener(object : ValueEventListener { + override fun onDataChange(snapshot: DataSnapshot) { + if(snapshot.exists()){ + for(event in snapshot.children){ + val item=event.getValue(Event::class.java) + eventList.add(item!!) + } + //recycleView.adapter=MyAdapter(eventList) + var adapter=MyAdapter(eventList) + recycleView.adapter=adapter + adapter.setOnItemClickListener(object : MyAdapter.onItemClickListener{ + override fun onItemClick(position: Int) { + //Toast.makeText(this@EventList,"${eventList[position].nombre.toString()}", Toast.LENGTH_LONG).show() + val nombreEvento: String= eventList[position].nombre.toString() + var salaEvento:String?=null + when(nombreEvento){ + "Champions"-> salaEvento = "1" + "Los caligaris"->salaEvento="2" + } + val intent = Intent(this@EventList, ChairList::class.java) + intent.putExtra("nombreEvento",nombreEvento)//CLAVE : VALOR + intent.putExtra("sala",salaEvento) + startActivity(intent) + } + + }) + + } + } + + override fun onCancelled(error: DatabaseError) { + TODO("Not yet implemented") + } + + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/pantallacompra/MainActivity.kt b/app/src/main/java/com/example/pantallacompra/MainActivity.kt index 85f1242..729bf7a 100644 --- a/app/src/main/java/com/example/pantallacompra/MainActivity.kt +++ b/app/src/main/java/com/example/pantallacompra/MainActivity.kt @@ -6,13 +6,15 @@ import android.os.Bundle import android.widget.Button import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.example.pantallacompra.databinding.ActivityMainBinding +import com.google.firebase.database.DatabaseReference +import com.google.firebase.database.FirebaseDatabase class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private lateinit var eventosReferences : DatabaseReference private lateinit var salasReference: DatabaseReference private lateinit var asientosReference: DatabaseReference - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding= ActivityMainBinding.inflate(layoutInflater) diff --git a/app/src/main/java/com/example/pantallacompra/MyAdapter.kt b/app/src/main/java/com/example/pantallacompra/MyAdapter.kt new file mode 100644 index 0000000..b6fd52a --- /dev/null +++ b/app/src/main/java/com/example/pantallacompra/MyAdapter.kt @@ -0,0 +1,49 @@ +package com.example.pantallacompra + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView + +class MyAdapter (private val eventList : ArrayList) : RecyclerView.Adapter(){ + + private lateinit var mListener : onItemClickListener + + interface onItemClickListener{ + fun onItemClick(position: Int) + } + + fun setOnItemClickListener(listener: onItemClickListener){ + mListener=listener + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { + val itemView= LayoutInflater.from(parent.context).inflate(R.layout.event_item,parent,false) + return MyViewHolder(itemView, mListener) + } + + override fun getItemCount(): Int { + return eventList.size + } + + override fun onBindViewHolder(holder: MyViewHolder, position: Int) { + val list= eventList[position] + holder.nombre.text="Evento:" +list.nombre + holder.tipo.text="Tipo: "+list.tipo + holder.duracion.text="DuraciĆ³n: "+list.duracion.toString()+" min" + + } + + class MyViewHolder(itemView : View, listener: onItemClickListener): RecyclerView.ViewHolder(itemView){ + val nombre : TextView = itemView.findViewById(R.id.eventName) + val tipo: TextView = itemView.findViewById(R.id.eventType) + val duracion: TextView =itemView.findViewById(R.id.eventDuration) + init { + itemView.setOnClickListener{ + listener.onItemClick(adapterPosition) + } + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/pantallacompra/Sala.kt b/app/src/main/java/com/example/pantallacompra/Sala.kt new file mode 100644 index 0000000..ad73b54 --- /dev/null +++ b/app/src/main/java/com/example/pantallacompra/Sala.kt @@ -0,0 +1,5 @@ +package com.example.pantallacompra + +data class Sala(val n0Sala : Int?=null, val nombreEvento : String ?=null){ + +} diff --git a/app/src/main/res/drawable/boton_redondo.xml b/app/src/main/res/drawable/boton_redondo.xml new file mode 100644 index 0000000..4ef9c75 --- /dev/null +++ b/app/src/main/res/drawable/boton_redondo.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/chair_item.xml b/app/src/main/res/layout/chair_item.xml new file mode 100644 index 0000000..c24e95c --- /dev/null +++ b/app/src/main/res/layout/chair_item.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 53f4a67..523fa72 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,8 @@ +buildscript { + dependencies { + classpath("com.google.gms:google-services:4.4.1") + } +} // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id("com.android.application") version "8.2.2" apply false