|
|
|
@ -1,10 +1,19 @@
|
|
|
|
|
package com.example.mathseduc
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.graphics.Color
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import android.widget.ArrayAdapter
|
|
|
|
|
import android.widget.ListView
|
|
|
|
|
import android.widget.TextView
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
|
import com.example.mathseduc.controllers.ControllerLobby
|
|
|
|
|
import com.example.mathseduc.models.Lobby
|
|
|
|
|
|
|
|
|
|
class MultiActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
@ -12,17 +21,99 @@ class MultiActivity : AppCompatActivity() {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
setContentView(R.layout.activity_multi)
|
|
|
|
|
|
|
|
|
|
val serverList = arrayOf("Serveur 1", "Serveur 2", "Serveur 3")
|
|
|
|
|
val serverList = ControllerLobby.getLobbies()
|
|
|
|
|
|
|
|
|
|
val listView = findViewById<ListView>(R.id.listView)
|
|
|
|
|
if (serverList != null) {
|
|
|
|
|
|
|
|
|
|
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, serverList)
|
|
|
|
|
listView.adapter = adapter
|
|
|
|
|
val listView = findViewById<ListView>(R.id.listView)
|
|
|
|
|
|
|
|
|
|
listView.setOnItemClickListener { _, _, position, _ ->
|
|
|
|
|
val intent = Intent(this, ServerDetailsActivity::class.java)
|
|
|
|
|
intent.putExtra("serverName", serverList[position])
|
|
|
|
|
startActivity(intent)
|
|
|
|
|
val adapter = LobbyAdapter(this, serverList)
|
|
|
|
|
listView.adapter = adapter
|
|
|
|
|
|
|
|
|
|
listView.setOnItemClickListener { _, _, position, _ ->
|
|
|
|
|
val intent = Intent(this, ServerDetailsActivity::class.java)
|
|
|
|
|
intent.putExtra("serverName", serverList[position].name)
|
|
|
|
|
startActivity(intent)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.e("MultiActivity", "Error fetching server list")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class LobbyAdapter(context: Context, lobbies: ArrayList<Lobby>): ArrayAdapter<Lobby>(context, 0, lobbies), View.OnClickListener {
|
|
|
|
|
|
|
|
|
|
private val mContext: Context
|
|
|
|
|
private val mLobbies: ArrayList<Lobby>
|
|
|
|
|
|
|
|
|
|
private var selectedItem = -1;
|
|
|
|
|
|
|
|
|
|
// Get Access to Context and Data Array
|
|
|
|
|
init {
|
|
|
|
|
mContext = context
|
|
|
|
|
mLobbies = lobbies
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getCount(): Int {
|
|
|
|
|
return mLobbies.size
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getItemId(position: Int): Long {
|
|
|
|
|
return mLobbies[position].id.toLong()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getItem(position: Int): Lobby {
|
|
|
|
|
return mLobbies[position]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
|
|
|
|
//return super.getView(position, convertView, parent)
|
|
|
|
|
|
|
|
|
|
var currentLobbyView = convertView
|
|
|
|
|
if (currentLobbyView == null) {
|
|
|
|
|
currentLobbyView =
|
|
|
|
|
LayoutInflater.from(context).inflate(R.layout.list_view_lobby, parent, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val name = currentLobbyView!!.findViewById<TextView>(R.id.name)
|
|
|
|
|
val nbplayers = currentLobbyView!!.findViewById<TextView>(R.id.nbplayers)
|
|
|
|
|
val idchapter = currentLobbyView!!.findViewById<TextView>(R.id.idchapter)
|
|
|
|
|
val difficulty = currentLobbyView!!.findViewById<TextView>(R.id.difficulty)
|
|
|
|
|
|
|
|
|
|
name.text = mLobbies[position].name
|
|
|
|
|
nbplayers.text = mLobbies[position].nbplayers.toString()
|
|
|
|
|
idchapter.text = mLobbies[position].idchapter.toString()
|
|
|
|
|
difficulty.text = mLobbies[position].difficulty.toString()
|
|
|
|
|
|
|
|
|
|
// Visual Feedback for Selection
|
|
|
|
|
/*
|
|
|
|
|
if (selectedItem == position)
|
|
|
|
|
currentLobbyView.setBackgroundColor(Color.rgb(255, 255, 128))
|
|
|
|
|
else
|
|
|
|
|
currentLobbyView.setBackgroundColor(Color.rgb(255, 255, 192))
|
|
|
|
|
|
|
|
|
|
if (mProducts[position].prixht != null)
|
|
|
|
|
pxht.text = "%.2f".format(mLobbies[position].prixht.toFloat()) + "€ HT"
|
|
|
|
|
else
|
|
|
|
|
pxht.text = "Gratuit !"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return currentLobbyView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun setSelectedItem(position: Int) {
|
|
|
|
|
selectedItem = position
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun getSelectedItem(): Lobby? {
|
|
|
|
|
|
|
|
|
|
if (selectedItem != -1)
|
|
|
|
|
return mLobbies[selectedItem]
|
|
|
|
|
else
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onClick(p0: View?) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|