Commit f7efdcbd by Miguel Do Carmo

bueno se agregaron cositas para recibir adecuadamente y de manera mas ordenada…

bueno se agregaron cositas para recibir adecuadamente y de manera mas ordenada los eventos utilizados\n Al acceder en la sala de juego se me cierra la coneccion y no encuentro manera de levantar aun
parent e7d65461
TolucaGraphics
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
package com.example.tolucagraphics
import android.view.View
import android.widget.TextView
import okhttp3.WebSocket
import okhttp3.WebSocketListener
class ClassRandom :WebSocketListener() {
override fun onMessage(webSocket: WebSocket, text: String) {
super.onMessage(webSocket, text)
var view : View?=null
view?.findViewById<TextView>(R.id.textID)
}
}
\ No newline at end of file
package com.example.tolucagraphics
object KeysWebSocket {
const val commandResponse = "COMMAND_RESPONSE"
const val trucoRoomEvent = "TRUCO_ROOM_EVENT"
const val trucoTableEvent = "TRUCO_TABLE_EVENT"
const val tablePositionSetted = "TABLE_POSITION_SETTED"
const val roomUserJoined = "ROOM_USER_JOINED"
const val roomLeftRoom = "USER_LEFT_ROOM"
const val roomTableCreated = "ROOM_TABLE_CREATED"
const val roomTableUserJoined = "ROOM_TABLE_USER_JOINED"
const val commandGetRooms = "get_rooms"
const val commandJoinRoom = "join_room"
const val commandCreateRoomTable = "create_room_table"
}
\ No newline at end of file
...@@ -8,7 +8,7 @@ import android.view.View ...@@ -8,7 +8,7 @@ import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.example.tolucagraphics.datas.GetRooms import com.example.tolucagraphics.datas.GetRooms
import com.example.tolucagraphics.events.Events import com.example.tolucagraphics.events.EventGetRoom
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_lobby.* import kotlinx.android.synthetic.main.activity_lobby.*
import okhttp3.* import okhttp3.*
...@@ -16,12 +16,10 @@ import java.util.concurrent.TimeUnit ...@@ -16,12 +16,10 @@ import java.util.concurrent.TimeUnit
class LobbyActivity : AppCompatActivity(){ class LobbyActivity : AppCompatActivity(){
val conection = Conection val conection = Socket
private val SERVER_PATH = "ws://3.222.70.21:5000/ws?" private val SERVER_PATH = "ws://3.222.70.21:5000/ws?"
lateinit var webSocket : WebSocket
var username : String? = null var username : String? = null
private val gson = Gson() private val gson = Gson()
var eventReceived : Events?= null
lateinit var campoIDroom : TextView lateinit var campoIDroom : TextView
lateinit var campotestNameRoom : TextView lateinit var campotestNameRoom : TextView
...@@ -77,12 +75,12 @@ class LobbyActivity : AppCompatActivity(){ ...@@ -77,12 +75,12 @@ class LobbyActivity : AppCompatActivity(){
Log.d("request", "Receiving : $text") Log.d("request", "Receiving : $text")
val gsonreceived = Gson() val gsonreceived = Gson()
runOnUiThread { runOnUiThread {
eventReceived = gsonreceived.fromJson(text, Events::class.java) val eventReceived = gsonreceived.fromJson(text, EventGetRoom::class.java)
campoIDroom = findViewById(R.id.campoID) campoIDroom = findViewById(R.id.campoID)
campotestNameRoom = findViewById(R.id.campoNAME) campotestNameRoom = findViewById(R.id.campoNAME)
if (eventReceived != null) { if (eventReceived != null) {
campoIDroom.text = eventReceived?.data?.rooms?.get(0)?.id ?: "0" campoIDroom.text = eventReceived.data?.rooms?.get(0)?.id ?: "0"
campotestNameRoom.text = eventReceived?.data?.rooms?.get(0)?.name ?: "-" campotestNameRoom.text = eventReceived.data?.rooms?.get(0)?.name ?: "-"
} }
} }
} }
...@@ -93,23 +91,4 @@ class LobbyActivity : AppCompatActivity(){ ...@@ -93,23 +91,4 @@ class LobbyActivity : AppCompatActivity(){
Log.d("request","Error : " + t.message) Log.d("request","Error : " + t.message)
} }
} }
object Conection{
var username: String?= null
var SERVER_PATH: String?= null
val client = OkHttpClient.Builder()
.readTimeout(1, TimeUnit.SECONDS)
.build()
var request : Request?=null
var listener : WebSocketListener?=null
fun realizarConex() {
request = Request.Builder()
.url(SERVER_PATH + username)
.build()
}
var webSocketSingle : WebSocket?=null
fun conectarconWS(){
webSocketSingle = client.newWebSocket(request!!, listener!!)
}
}
} }
\ No newline at end of file
package com.example.tolucagraphics
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.gson.Gson
import okhttp3.Response
import okhttp3.WebSocket
import okhttp3.WebSocketListener
class MesaEnJuego : AppCompatActivity() {
val single = Socket
val gson = Gson()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mesa_en_juego)
val intentJoin = intent.getStringExtra("join")!!
Log.d("TAG", "Join from Intent: $intentJoin")
//single.listener = Listener2()
single.conectarconWS()
}
fun mensajeRecibido(text : String){
Log.d("TAG", text)
}
inner class Listener2 : WebSocketListener(){
@SuppressLint("SetTextI18n")
override fun onMessage(webSocket: WebSocket, text: String) {
super.onMessage(webSocket, text)
runOnUiThread {
Log.d("TAG", "Undefined text -> $text")
/*if (text.contains(KeysWebSocket.commandResponse,true) && text.contains(KeysWebSocket.commandGetRooms)){
}*/
mensajeRecibido(text)
}
}
override fun onOpen(webSocket: WebSocket, response: Response) {
super.onOpen(webSocket, response)
Log.d("TAG", "established connection! Table Game!!! <3")
}
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
super.onClosing(webSocket, code, reason)
Log.d("TAG", "$code $reason")
}
}
}
package com.example.tolucagraphics package com.example.tolucagraphics
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.tolucagraphics.adapters.JugadoresAdapter import com.example.tolucagraphics.adapters.JugadoresAdapter
import com.example.tolucagraphics.datas.Data import com.example.tolucagraphics.adapters.MesaAdapter
import com.example.tolucagraphics.datas.JoinData import com.example.tolucagraphics.datas.CreateTable
import com.example.tolucagraphics.datas.JoinTable import com.example.tolucagraphics.datas.GetRooms
import com.example.tolucagraphics.events.Events import com.example.tolucagraphics.datas.JoinRoom
import com.example.tolucagraphics.events.UserElement import com.example.tolucagraphics.events.*
import com.example.tolucagraphics.models.ModelForTables
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_mesas_players.* import kotlinx.android.synthetic.main.activity_mesas_players.*
import okhttp3.Response import okhttp3.Response
import okhttp3.WebSocket import okhttp3.WebSocket
import okhttp3.WebSocketListener import okhttp3.WebSocketListener
import okio.ByteString
class MesasActivity : AppCompatActivity() { class MesasActivity : AppCompatActivity() {
var selector = 1 var selector = 1
val gson = Gson() val gson = Gson()
val decoJson = Gson() val decoJson = Gson()
var eventoRecibido = Events() private val conection = Socket
private val conection2 = LobbyActivity.Conection var yaEntro = false
private lateinit var adapterJugadores : JugadoresAdapter var yaEntroMesaCreada = false
var tamanioJugadores = 0
var tamanioMesas = 0
var listaJugadores = ArrayList<UserElementJoin>()
var listaMesas = ArrayList<EventCreateMesa>()
val listaTables = ArrayList<ModelForTables>()
lateinit var jugadoresAdapter: JugadoresAdapter
lateinit var mesasAdapter: MesaAdapter
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mesas_players) setContentView(R.layout.activity_mesas_players)
conection2.webSocketSingle?.close(1000, "Change Activity") conection.webSocketSingle?.close(1000, "Change Activity")
conection2.listener = TestListener() conection.listener = TestListener()
conection2.conectarconWS() conection.conectarconWS()
conection.webSocketSingle?.send(gson.toJson(GetRooms()))
conection.webSocketSingle?.send(gson.toJson(JoinRoom()))
btnCreaMesa.setOnClickListener {
conection.webSocketSingle?.send(gson.toJson(CreateTable()))
}
/********************PETICION DE MESAS******************/ /********************PETICION DE MESAS******************/
val joinRoom = JoinData("join_room", Data("1")) val joinRoomJSON = gson.toJson(JoinRoom())
val joinRoomJSON = gson.toJson(joinRoom)
Log.d("request",joinRoomJSON) Log.d("request",joinRoomJSON)
conection2.webSocketSingle?.send(joinRoomJSON) conection.webSocketSingle?.send(joinRoomJSON)
btnCreaMesa.setOnClickListener { btnCreaMesa.setOnClickListener {
Log.d("request", "mesnaje a enviar:{\"command\":\"create_room_table\",\"data\":{\"roomId\":\"1\",\"points\":30}} ") Log.d("request", "mesnaje a enviar:{\"command\":\"create_room_table\",\"data\":{\"roomId\":\"1\",\"points\":30}} ")
conection2.webSocketSingle?.send("{\"command\":\"create_room_table\",\"data\":{\"roomId\":\"1\",\"points\":30}}") conection.webSocketSingle?.send(gson.toJson(CreateTable()))
} }
} }
fun iniciarRecyclerJugadores(){
jugadoresAdapter = JugadoresAdapter(listaJugadores)
lista_jugadores.apply {
layoutManager = LinearLayoutManager(this@MesasActivity)
adapter = jugadoresAdapter
}
}
fun iniciarRecyclerMesas(){
mesasAdapter = MesaAdapter(listaMesas){ cadena, join ->
Toast.makeText(this@MesasActivity, cadena, Toast.LENGTH_LONG).show()
val intentJuego = Intent(this@MesasActivity, MesaEnJuego::class.java)
intentJuego.putExtra("join", gson.toJson(join))
startActivity(intentJuego)
}
lista_mesas.apply {
layoutManager = LinearLayoutManager(this@MesasActivity)
adapter = mesasAdapter
}
}
fun agregarTableGetInit(entrada : EventGetRoom){
for (indiceT in entrada.data?.rooms?.get(0)?.tables?.indices!!) {
listaTables.add(ModelForTables(id = entrada.data.rooms[0].tables?.get(indiceT)?.id, state = entrada.data.rooms[0].tables?.get(indiceT)?.status, users = entrada.data.rooms[0].tables?.get(indiceT)?.positions))
}
}
fun agregarTable(entrada : EventCreateMesa){
listaTables.add(ModelForTables(id = entrada.data?.table?.id, state = entrada.data?.table?.status, users = entrada.data?.table?.users as List<OwnerClass>))
}
fun buscarDuplicados(){
/*if(list.removeAll { it == item }) {
println("Lista modificada: ${list}")
} else {
println("El elemento no existe!!")
} */
if (tamanioMesas > 1) {
for (indice in listaMesas.indices) {
if (listaMesas.removeAll { it == listaMesas[indice] }) {
tamanioMesas = listaMesas.size
mesasAdapter.notifyItemRemoved(tamanioMesas)
}
}
}
}
fun contieneId(lista: ArrayList<EventCreateMesa>, idNuevo : String?):Boolean{
var contiene = false
for (indice in lista.indices){
contiene = lista[indice].data?.table?.id != idNuevo
}
return contiene
}
fun adaptarEvento(evento : EventCreateMesa) : EventCreateMesa{
var resultado = EventCreateMesa()
resultado.command = evento.command
resultado.type = evento.type
resultado.data?.user = evento.data?.user
resultado.data?.room = evento.data?.room
resultado.data?.eventName = evento.data?.eventName
resultado.data?.table?.id = evento.data?.table?.id
resultado.data?.table?.owner = evento.data?.table?.owner
resultado.data?.table?.points = evento.data?.table?.points
resultado.data?.table?.privateTable = evento.data?.table?.privateTable
resultado.data?.table?.roomID = evento.data?.table?.roomID
resultado.data?.table?.status = evento.data?.table?.status
resultado.data?.table?.users?.add(evento.data?.table?.users!!.first())
return resultado
}
inner class TestListener : WebSocketListener() { inner class TestListener : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) { override fun onOpen(webSocket: WebSocket, response: Response) {
//Log.d("request", "connection successfully") //Log.d("request", "connection successfully")
...@@ -58,42 +136,92 @@ class MesasActivity : AppCompatActivity() { ...@@ -58,42 +136,92 @@ class MesasActivity : AppCompatActivity() {
override fun onMessage(webSocket: WebSocket, text: String) { override fun onMessage(webSocket: WebSocket, text: String) {
//usernameReceived.text = "cargando Rooms" //usernameReceived.text = "cargando Rooms"
runOnUiThread { runOnUiThread {
Log.d("request", "testRecibe : $text") if (text.contains(KeysWebSocket.commandResponse,true) && text.contains(KeysWebSocket.commandGetRooms)){
//--------eventoRecibido = decoJson.fromJson(text, Events::class.java) Log.d("TAG", "GETROOMS -> $text")
Log.d("request", "evento Jugadores a EventsClass: $eventoRecibido") agregarTableGetInit(gson.fromJson(text, EventGetRoom::class.java))
//------if (eventoRecibido.type == "TRUCO_ROOM_EVENT") { Log.d("TAG", "ListaTables Nueva -> $listaTables")
if (text.contains("TRUCO_ROOM_EVENT", true)) { /**********************************************Parte para el Recycler de Jugadores**************************************/
eventoRecibido = decoJson.fromJson(text, Events::class.java) }else if (text.contains(KeysWebSocket.commandResponse,true) && text.contains(KeysWebSocket.commandJoinRoom)){
Log.d("request", "ENTRO AL ADAPTER!!!") val eventJoinRoom = gson.fromJson(text, EventJoinRoom::class.java)
val jugadores:ArrayList<UserElement?> = eventoRecibido.data?.room?.users as ArrayList<UserElement?> listaJugadores = eventJoinRoom.data?.room?.users!! as ArrayList<UserElementJoin>
Log.d("request", "JUGADORES TIENE ESTO $jugadores") tamanioJugadores = listaJugadores.size
adapterJugadores = JugadoresAdapter(jugadores) iniciarRecyclerJugadores()
lista_jugadores.apply { }else if(text.contains(KeysWebSocket.trucoRoomEvent,true) && text.contains(KeysWebSocket.roomUserJoined)){
layoutManager = LinearLayoutManager(this@MesasActivity) if (yaEntro) {
adapter = adapterJugadores val eventTrucoRoom = gson.fromJson(text, EventJoinRoomTRE::class.java)
listaJugadores.add(UserElementJoin(user = UserUserJoin(eventTrucoRoom.data?.user!!.id, eventTrucoRoom.data.user.username ), online = true))
jugadoresAdapter.notifyItemInserted(tamanioJugadores)
}else yaEntro = true
}else if(text.contains(KeysWebSocket.trucoRoomEvent, true) && text.contains(KeysWebSocket.roomLeftRoom, true)){
val eventLeftTrucoRoom = gson.fromJson(text, EventJoinRoomTRE::class.java)
listaJugadores.remove(UserElementJoin(user = UserUserJoin(eventLeftTrucoRoom.data?.user!!.id, eventLeftTrucoRoom.data.user.username ), online = true))
jugadoresAdapter.notifyItemRemoved(tamanioJugadores)
/************************************************Parte para el Recycler de Mesas ****************************************************/
}else if (text.contains(KeysWebSocket.commandResponse,true) && text.contains(KeysWebSocket.commandCreateRoomTable)){
val eventoCreateTable = gson.fromJson(text, EventCreateMesa::class.java)
listaMesas.add(eventoCreateTable)
tamanioMesas = listaMesas.size
if (yaEntroMesaCreada){
mesasAdapter.notifyItemInserted(tamanioMesas)
}else {
iniciarRecyclerMesas()
buscarDuplicados()
yaEntroMesaCreada = true
} }
//disparaAdapter() }else if(text.contains(KeysWebSocket.trucoRoomEvent,true) && text.contains(KeysWebSocket.roomTableCreated,true)){
val eventoCreateTable = gson.fromJson(text, EventCreateMesa::class.java)
// Users solo tiene el owner size = 1
Log.d("TAG", "MesaCreada-> $eventoCreateTable")
if (listaMesas.isEmpty()){
listaMesas.add(eventoCreateTable)
tamanioMesas = listaMesas.size
iniciarRecyclerMesas()
}else{ }else{
Log.d("request", "MENSAJE: $text")
if (contieneId(listaMesas, eventoCreateTable.data?.table?.id))
listaMesas.add(eventoCreateTable)
tamanioMesas = listaMesas.size
mesasAdapter.notifyItemInserted(tamanioMesas)
} }
}else if(text.contains(KeysWebSocket.trucoRoomEvent, true) && text.contains(KeysWebSocket.roomTableUserJoined, true)){
var eventoJoined = gson.fromJson(text, EventCreateMesa::class.java)
var eventoJoinedAdaptado = adaptarEvento(eventoJoined)
for (indice in listaMesas.indices) {
if (listaMesas[indice].data?.table?.id == eventoJoinedAdaptado.data?.table?.id ) {
listaMesas[indice].data?.table?.users?.get(0)?.id = eventoJoinedAdaptado.data?.user?.id
listaMesas[indice].data?.table?.users?.get(0)?.username = eventoJoinedAdaptado.data?.user?.username
mesasAdapter.notifyItemChanged(indice)
} }
} }
}else if(text.contains(KeysWebSocket.trucoTableEvent,true)&&text.contains(KeysWebSocket.tablePositionSetted,true)){
override fun onMessage(webSocket: WebSocket, bytes: ByteString) { var eventoJoined = gson.fromJson(text, EventTablePositionSetted::class.java)
super.onMessage(webSocket, bytes) Log.d("TAG", "se Unio $eventoJoined")
Log.d("request", "testRecibe : $bytes") Log.d("TAG", "tamanio de la mesa hecha: ${listaMesas.first().data?.table?.users?.size}")
Log.d("TAG", "tamanio de la mesa recibida: ${eventoJoined.data?.table?.positions?.size}")
for (indice in listaMesas.indices) {
if (listaMesas[indice].data?.table?.id == eventoJoined.data?.table?.id ) {
Log.d("TAG", "entra para agregar Player!!!")
listaMesas[indice].data?.table?.users = eventoJoined.data?.table?.positions as ArrayList<User>
//listaMesas[indice].data?.table?.users?.get(eventoJoined.data?.position!!.toInt())?.username = "X"
mesasAdapter.notifyItemChanged(tamanioMesas)
}
}
}else{
Log.d("TAG", "Unidentified-> $text")
}
} }
}
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
Log.d("request","testCierra : $code / $reason") Log.d("request","testCierra : $code / $reason")
} }
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
Log.d("request","Error : " + t.message +response.toString()) Log.d("request","Error : " + t.message +response.toString())
LobbyActivity.Conection.conectarconWS() conection.conectarconWS()
val joinRoom = JoinData("join_room", Data("1")) val joinRoomJSON = gson.toJson(JoinRoom())
val joinRoomJSON = gson.toJson(joinRoom)
Log.d("request",joinRoomJSON) Log.d("request",joinRoomJSON)
LobbyActivity.Conection.webSocketSingle?.send(joinRoomJSON) conection.webSocketSingle?.send(joinRoomJSON)
} }
} }
} }
package com.example.tolucagraphics
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import java.util.concurrent.TimeUnit
object Socket {
var username: String?= null
var SERVER_PATH: String?= null
private val client = OkHttpClient.Builder()
.readTimeout(1, TimeUnit.SECONDS)
.build()
var request : Request?=null
lateinit var listener : WebSocketListener
fun realizarConex() {
request = Request.Builder()
.url(SERVER_PATH + username)
.build()
}
var webSocketSingle : WebSocket?=null
fun conectarconWS(){
webSocketSingle = client.newWebSocket(request!!, listener)
}
}
\ No newline at end of file
...@@ -7,8 +7,9 @@ import android.widget.TextView ...@@ -7,8 +7,9 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.example.tolucagraphics.R import com.example.tolucagraphics.R
import com.example.tolucagraphics.events.UserElement import com.example.tolucagraphics.events.UserElement
import com.example.tolucagraphics.events.UserElementJoin
class JugadoresAdapter (val listaJugadores : ArrayList<UserElement?>) : RecyclerView.Adapter<JugadoresAdapter.MesaHolder>() { class JugadoresAdapter (val listaJugadores : ArrayList<UserElementJoin>) : RecyclerView.Adapter<JugadoresAdapter.MesaHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MesaHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MesaHolder {
var layoutInflate = LayoutInflater.from(parent.context) var layoutInflate = LayoutInflater.from(parent.context)
...@@ -21,7 +22,7 @@ class JugadoresAdapter (val listaJugadores : ArrayList<UserElement?>) : Recycler ...@@ -21,7 +22,7 @@ class JugadoresAdapter (val listaJugadores : ArrayList<UserElement?>) : Recycler
} }
override fun onBindViewHolder(holder: MesaHolder, position: Int) { override fun onBindViewHolder(holder: MesaHolder, position: Int) {
listaJugadores[position]?.let { holder.binder(it) } holder.binder(listaJugadores[position])
} }
class MesaHolder(view: View) : RecyclerView.ViewHolder(view) { class MesaHolder(view: View) : RecyclerView.ViewHolder(view) {
...@@ -29,7 +30,7 @@ class JugadoresAdapter (val listaJugadores : ArrayList<UserElement?>) : Recycler ...@@ -29,7 +30,7 @@ class JugadoresAdapter (val listaJugadores : ArrayList<UserElement?>) : Recycler
private val rank: TextView = view.findViewById(R.id.campoRanking) private val rank: TextView = view.findViewById(R.id.campoRanking)
fun binder(element : UserElement) { fun binder(element : UserElementJoin) {
name.text = element.user?.id.toString() name.text = element.user?.id.toString()
rank.text = element.user?.username.toString() rank.text = element.user?.username.toString()
......
package com.example.tolucagraphics.adapters
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.tolucagraphics.R
import com.example.tolucagraphics.datas.DataJT
import com.example.tolucagraphics.datas.JoinTable
import com.example.tolucagraphics.events.EventCreateMesa
class MesaAdapter(val mesasCreadas: ArrayList<EventCreateMesa>, var callback: (String, JoinTable) -> Unit) : RecyclerView.Adapter<MesaAdapter.JugadoresHolder>() {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): JugadoresHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.modelo_recycler_mesas, parent, false)
return JugadoresHolder(view)
}
override fun getItemCount(): Int {
return mesasCreadas.size
}
override fun onBindViewHolder(holder: JugadoresHolder, position: Int) {
holder.binding(mesasCreadas[position])
holder.itemView.findViewById<Button>(R.id.campoMesaacc).setOnClickListener {
val joinTable = JoinTable()
joinTable.data?.tableID = mesasCreadas[position].data?.table?.id
Log.d("TAG", "LO QUE TIENE TABLA ID ${mesasCreadas[position].data?.table?.id}")
callback("Con mucho amor Hasta aqui llegue ♥", joinTable)
}
}
class JugadoresHolder(view: View):RecyclerView.ViewHolder(view){
var id= view.findViewById<TextView>(R.id.campoMesaId)
var st= view.findViewById<TextView>(R.id.campoMesaEstado)
var s1= view.findViewById<TextView>(R.id.campoMesaS1)
var s2= view.findViewById<TextView>(R.id.campoMesaS2)
var s3= view.findViewById<TextView>(R.id.campoMesaS3)
var s4= view.findViewById<TextView>(R.id.campoMesaS4)
var s5= view.findViewById<TextView>(R.id.campoMesaS5)
var s6= view.findViewById<TextView>(R.id.campoMesaS6)
fun binding(userElementJoin: EventCreateMesa) {
id.text = userElementJoin.data?.table?.id.toString()
st.text = userElementJoin.data?.table?.status.toString()
/*
s1.text = if(userElementJoin.data?.table?.users?.get(0)?.username !=null) userElementJoin.data.table.users?.get(0)?.username else "-"
s2.text = if(userElementJoin.data?.table?.users?.get(1)?.username !=null) userElementJoin.data.table.users?.get(1)?.username else "-"
s3.text = if(userElementJoin.data?.table?.users?.get(2)?.username !=null) userElementJoin.data.table.users?.get(2)?.username else "-"
s4.text = if(userElementJoin.data?.table?.users?.get(3)?.username !=null) userElementJoin.data.table.users?.get(3)?.username else "-"
s5.text = if(userElementJoin.data?.table?.users?.get(4)?.username !=null) userElementJoin.data.table.users?.get(4)?.username else "-"
s6.text = if(userElementJoin.data?.table?.users?.get(5)?.username !=null) userElementJoin.data.table.users?.get(5)?.username else "-"*/
s1.text = "-"
s2.text = "-"
s3.text = "-"
s4.text = "-"
s5.text = "-"
s6.text = "-"
}
}
}
\ No newline at end of file
package com.example.tolucagraphics.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.tolucagraphics.R
import com.example.tolucagraphics.events.UserElement
class MesasAdapter (val listamesa : ArrayList<UserElement>) : RecyclerView.Adapter<MesasAdapter.MesaHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MesaHolder {
var layoutInflate = LayoutInflater.from(parent.context)
.inflate(R.layout.modelo_recycler_mesas, parent, false)
return MesaHolder(layoutInflate)
}
override fun getItemCount(): Int {
return listamesa.size
}
override fun onBindViewHolder(holder: MesaHolder, position: Int) {
holder.vindeando(listamesa[position])
}
class MesaHolder(view: View) : RecyclerView.ViewHolder(view) {
val id = view.findViewById<TextView>(R.id.campoMesaId)
val st = view.findViewById<TextView>(R.id.campoMesaEstado)
val s1 = view.findViewById<TextView>(R.id.campoMesaS1)
val s2 = view.findViewById<TextView>(R.id.campoMesaS2)
val s3 = view.findViewById<TextView>(R.id.campoMesaS3)
val s4 = view.findViewById<TextView>(R.id.campoMesaS4)
val s5 = view.findViewById<TextView>(R.id.campoMesaS5)
val s6 = view.findViewById<TextView>(R.id.campoMesaS6)
fun vindeando(elemento : UserElement) {
}
}
}
package com.example.tolucagraphics.datas
data class CreateTable (
val command: String = "create_room_table",
val data: DataCreate = DataCreate("1", 30)
)
data class DataCreate (
val roomId: String? = null,
val points: Long? = null
)
\ No newline at end of file
package com.example.tolucagraphics.datas
data class UsernameData (
val username: String? = null,
val id: String? = null
)
data class Data (
val roomId: String? = null,
val points: String? = null
)
data class GetRooms(
val command: String? =null
)
data class JoinData (
val command: String? = null,
val data: Data? = null
)
data class JoinTable (
val command: String? = null,
val data: Data? = null
)
data class ModeloJugadores(
val jugadorNombre: String?= null,
val jugadorRanking: String?= null
)
\ No newline at end of file
package com.example.tolucagraphics.datas
data class GetRooms(
val command: String = "get_rooms"
)
\ No newline at end of file
package com.example.tolucagraphics.datas
data class JoinRoom (
val command: String = "join_room",
val data: Data = Data("1")
)
data class Data (
val roomId: String?=null
)
\ No newline at end of file
package com.example.tolucagraphics.datas
data class JoinTable (
val command: String = "join_room_table",
val data: DataJT? = null
)
data class DataJT (
val roomID: String = "1",
var tableID: String? = null
)
\ No newline at end of file
package com.example.tolucagraphics.events
data class EventCreateMesa (
var type: String? = null,
var command: String? = null,
val data: DataECT? = null
)
data class DataECT (
var eventName: String? = null,
var user: User? = null,
var room: RoomECT? = null,
val table: Table? = null
)
data class RoomECT (
val id: String? = null,
val name: String? = null
)
data class Table (
var id: String? = null,
var status: String? = null,
var roomID: String? = null,
var points: Long? = null,
var owner: User? = null,
var privateTable: Boolean? = null,
var users : ArrayList<User>? = null
)
data class User (
var id: String? = null,
var username: String? = null
)
\ No newline at end of file
package com.example.tolucagraphics.events
data class EventCreateMesaTRE (
val type: String? = null,
val data: DataCRTRE? = null
)
data class DataCRTRE (
val eventName: String? = null,
val user: User? = null,
val room: RoomCRTRE? = null,
val table: TableCRTRE? = null
)
data class RoomCRTRE (
val id: String? = null,
val name: String? = null
)
data class TableCRTRE (
val id: String? = null,
val status: String? = null,
val roomID: String? = null,
val points: Long? = null,
val owner: UserCRTRE? = null,
val privateTable: Boolean? = null,
val users: List<UserCRTRE>? = null
)
data class UserCRTRE (
val id: String? = null,
val username: String? = null
)
package com.example.tolucagraphics.events
data class EventGetRoom (
val type: String? = null,
val command: String? = null,
val data: Data? = null
)
data class Data (
val eventName: String? = null,
val user: UserUser? = null,
val rooms: List<Room>? = null
)
data class Room (
val id: String? = null,
val name: String? = null,
val users: List<UserElement>? = null,
val tables: List<TableGR>? = null
)
data class UserElement (
val user: UserUser? = null,
val online: Boolean? = null
)
data class UserUser (
val id: String? = null,
val username: String? = null
)
data class TableGR (
val id: String? = null,
val status: String? = null,
val roomID: String? = null,
val points: Long? = null,
val owner: OwnerClass? = null,
val privateTable: Boolean? = null,
val users: List<OwnerClass>? = null,
val positions: List<OwnerClass>? = null
)
data class OwnerClass (
val id: String? = null,
val username: String? = null
)
\ No newline at end of file
package com.example.tolucagraphics.events
data class EventJoinRoom (
val type: String? = null,
val command: String? = null,
val data: DataJoin? = null
)
data class DataJoin (
val eventName: String? = null,
val message: String? = null,
val user: UserUser? = null,
val room: RoomJoin? = null
)
data class RoomJoin (
val id: String? = null,
val name: String? = null,
val users: List<UserElementJoin>? = null,
val tables: List<Any?>? = null
)
data class UserElementJoin (
val user: UserUserJoin? = null,
val online: Boolean? = null
)
data class UserUserJoin (
val id: String? = null,
val username: String? = null
)
package com.example.tolucagraphics.events
data class EventJoinRoomTRE (
val type: String? = null,
val data: DataJRTRE? = null
)
data class DataJRTRE (
val eventName: String? = null,
val message: String? = null,
val user: UserUserJRTRE? = null,
val room: RoomJRTRE? = null
)
data class RoomJRTRE (
val id: String? = null,
val name: String? = null,
val users: List<UserElementJRTRE>? = null,
val tables: List<Any?>? = null
)
data class UserElementJRTRE (
val user: UserUserJRTRE? = null,
val online: Boolean? = null
)
data class UserUserJRTRE (
val id: String? = null,
val username: String? = null
)
\ No newline at end of file
package com.example.tolucagraphics.events
data class EventTablePositionSetted (
val type: String? = null,
val data: DataETPS? = null
)
data class DataETPS (
val eventName: String? = null,
val message: String? = null,
val roomID: String? = null,
val user: User? = null,
val tableID: String? = null,
val position: Long? = null,
val table: TableETPS? = null
)
data class TableETPS (
val id: String? = null,
val status: String? = null,
val roomID: String? = null,
val points: Long? = null,
val owner: UserETPS? = null,
val privateTable: Boolean? = null,
val positions: ArrayList<UserETPS?>? = null
)
data class UserETPS (
val id: String? = null,
val username: String? = null
)
package com.example.tolucagraphics.events
data class Events (
val type: String? = null,
val command: String? = null,
val data: Data? = null
)
data class Data (
val eventName: String? = null,
val user: UserUser? = null,
val message: String? = null,
val room: Room? = null,
val rooms: Array<Room>? = null
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Data
if (eventName != other.eventName) return false
if (user != other.user) return false
if (rooms != null) {
if (other.rooms == null) return false
if (!rooms.contentEquals(other.rooms)) return false
} else if (other.rooms != null) return false
return true
}
override fun hashCode(): Int {
var result = eventName?.hashCode() ?: 0
result = 31 * result + (user?.hashCode() ?: 0)
result = 31 * result + (rooms?.contentHashCode() ?: 0)
return result
}
}
data class Room (
val id: String? = null,
val name: String? = null,
val users: List<UserElement>? = null,
val tables: List<Any?>? = null
)
data class UserElement (
val user: UserUser? = null,
val online: Boolean? = null
)
data class UserUser (
val id: String? = null,
val username: String? = null
)
\ No newline at end of file
package com.example.tolucagraphics.models
import com.example.tolucagraphics.events.OwnerClass
data class ModelForTables(
val id : String?= null,
val state:String?=null,
var users : List<OwnerClass>?=null
)
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/blue" />
<corners android:radius="20dp" />
</shape>
</item>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MesaEnJuego">
<TextView
android:id="@+id/textoPuntajeLocal"
android:text="@string/puntajes_local"
android:textColor="@color/black"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/textoPuntajeVisitante"/>
<TextView
android:id="@+id/textoPuntajeVisitante"
android:text="@string/puntajes_visitante"
android:textColor="@color/black"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/textoPuntajeLocal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/layoutVisitante"/>
<TextView
android:id="@+id/puntajeLocal"
android:text="@string/_00"
android:textColor="@color/black"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toTopOf="@id/textoPuntajeLocal"
app:layout_constraintStart_toEndOf="@id/textoPuntajeLocal"
android:layout_marginStart="10dp" />
<TextView
android:id="@+id/puntajeVisitante"
android:text="@string/_00"
android:textColor="@color/black"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toTopOf="@id/textoPuntajeVisitante"
app:layout_constraintStart_toEndOf="@id/textoPuntajeVisitante"
android:layout_marginStart="10dp" />
<!-- Layout de Jugador Visitante -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutVisitante"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/puntajeVisitante">
<ImageView
android:id="@+id/cartaVisitante1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:background="@drawable/carta_oculta"
app:layout_constraintEnd_toStartOf="@id/cartaVisitante2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/cartaoculta" />
<ImageView
android:id="@+id/cartaVisitante2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/carta_oculta"
app:layout_constraintEnd_toStartOf="@id/cartaVisitante3"
app:layout_constraintStart_toEndOf="@id/cartaVisitante1"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/cartaoculta" />
<ImageView
android:id="@+id/cartaVisitante3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/carta_oculta"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/cartaVisitante2"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/cartaoculta" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:text="@string/esperando_oponente"
android:id="@+id/empezarJuego"
android:focusable="false"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/layoutVisitante"
app:layout_constraintBottom_toTopOf="@id/layoutLocal"/>
<!-- Layout de Jugador Visitante -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutLocal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<ImageView
android:id="@+id/cartaLocal1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:background="@drawable/carta_oculta"
app:layout_constraintEnd_toStartOf="@id/cartaLocal2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/cartaoculta" />
<ImageView
android:id="@+id/cartaLocal2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/carta_oculta"
app:layout_constraintEnd_toStartOf="@id/cartaLocal3"
app:layout_constraintStart_toEndOf="@id/cartaLocal1"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/cartaoculta" />
<ImageView
android:id="@+id/cartaLocal3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/carta_oculta"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/cartaLocal2"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/cartaoculta" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -6,4 +6,9 @@ ...@@ -6,4 +6,9 @@
<string name="ranking">Ranking</string> <string name="ranking">Ranking</string>
<string name="crear_mesa">Crear Mesa</string> <string name="crear_mesa">Crear Mesa</string>
<string name="volver">Volver</string> <string name="volver">Volver</string>
<string name="cartaoculta">CartaOculta</string>
<string name="puntajes_visitante">Puntajes Visitante:</string>
<string name="puntajes_local">Puntajes Local:</string>
<string name="_00">00</string>
<string name="esperando_oponente">Esperando Oponente</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment