Merge branch 'master' of https://codefirst.iut.uca.fr/git/jade.van_brabandt/3.01-QCM_MuscuMaths
continuous-integration/drone/push Build is passing Details

master
Maxence GUITARD 1 year ago
commit e5c118d88b

@ -10,7 +10,7 @@ android {
defaultConfig {
applicationId "com.example.mathseduc"
minSdk 21
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"
@ -41,4 +41,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.google.code.gson:gson:2.10.1")
}

@ -1,46 +0,0 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "com.example.mathseduc"
compileSdk = 34
defaultConfig {
applicationId = "com.example.mathseduc"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"

@ -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?) {
}
}
}

@ -1,6 +1,7 @@
package com.example.mathseduc
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
class ServerDetailsActivity : AppCompatActivity() {
@ -8,5 +9,12 @@ class ServerDetailsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_server_details)
val serverName = intent.getStringExtra("serverName")
// Now you can use the data as needed, for example, display it in a TextView
val serverNameTextView = findViewById<TextView>(R.id.titleServerDetails)
serverNameTextView.text = serverName
}
}

@ -0,0 +1,40 @@
package com.example.mathseduc.controllers
import android.os.StrictMode
import com.example.mathseduc.models.Lobby
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.IOException
class ControllerLobby {
companion object {
fun getLobbies(): ArrayList<Lobby>? {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access
val request = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/all/lobbies/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO/1")
.build()
// API Response
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
// Gson deserialization
val gson = Gson()
val typeTokenProduct = object : TypeToken<ArrayList<Lobby>>() {}.type
return gson.fromJson(response.body!!.string(), typeTokenProduct)
}
return null
}
}
}

@ -0,0 +1,11 @@
package com.example.mathseduc.models
data class Lobby(
val id: String,
val name: String,
val password: String,
val nbplayers: Int,
val idplayercreator: String,
val idchapter: Int,
val difficulty: Int
)

@ -6,7 +6,7 @@
tools:context=".ServerDetailsActivity">
<TextView
android:id="@+id/txtServerDetails"
android:id="@+id/titleServerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="4dp">
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="left|center_vertical"
android:text="Name"
android:textSize="16dp" />
<TextView
android:id="@+id/nbplayers"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:gravity="center|bottom"
android:textSize="10dp"
android:text="NbPlayers"/>
<TextView
android:id="@+id/difficulty"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:gravity="center|bottom"
android:textSize="10dp"
android:text="Difficulty"/>
<TextView
android:id="@+id/idchapter"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:gravity="center|center_vertical"
android:textSize="10dp"
android:text="idChapter"/>
</LinearLayout>
</FrameLayout>

@ -1,5 +0,0 @@
// 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
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
}
Loading…
Cancel
Save