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

androidCompose
Maxence GUITARD 1 year ago
commit f416910ed8

@ -34,7 +34,6 @@ android {
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'

@ -23,5 +23,6 @@
<activity android:name=".ServerDetailsActivity" />
<activity android:name=".CreateLobbyActivity" />
<activity android:name=".ConnexionPlayerActivity" />
<activity android:name=".QuizMultiActivity" />
</application>
</manifest>

@ -22,6 +22,8 @@ class MainActivity : AppCompatActivity() {
btnSolo.setOnClickListener {
// Traitement pour le bouton Solo
// Vous pouvez ajouter le code correspondant ici
val intent = Intent(this, QuizMultiActivity::class.java)
startActivity(intent)
}
btnMulti.setOnClickListener {

@ -7,11 +7,9 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.ListView
import android.widget.TextView
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.example.mathseduc.controllers.ControllerChapter
import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerUtiliser
import com.example.mathseduc.models.Lobby
@ -35,17 +33,22 @@ class MultiActivity : AppCompatActivity() {
listView.adapter = adapter
listView.setOnItemClickListener { _, _, position, _ ->
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
formDataBuilder.addFormDataPart("idplayer", MainActivity.idPlayerConnected.toString())
formDataBuilder.addFormDataPart("idlobby", serverList[position].id.toString())
formDataBuilder.addFormDataPart("playertime", "0")
ControllerUtiliser.createUtiliserByIdLobby(formDataBuilder)
val intent = Intent(this, ServerDetailsActivity::class.java)
intent.putExtra("serverName", serverList[position].name)
intent.putExtra("lobbyId", serverList[position].id)
startActivity(intent)
if (ControllerLobby.getNbPlayerInLobby(serverList[position].id) < serverList[position].nbplayers){
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
formDataBuilder.addFormDataPart("idplayer", MainActivity.idPlayerConnected.toString())
formDataBuilder.addFormDataPart("idlobby", serverList[position].id.toString())
formDataBuilder.addFormDataPart("playertime", "0")
ControllerUtiliser.createUtiliserByIdLobby(formDataBuilder)
val intent = Intent(this, ServerDetailsActivity::class.java)
intent.putExtra("serverName", serverList[position].name)
intent.putExtra("lobbyId", serverList[position].id)
startActivity(intent)
} else {
Toast.makeText(this, "Oh nan, le serveur est déja plein ! Réessayer plus tard.", Toast.LENGTH_SHORT).show()
}
}
} else {
Log.e("MultiActivity", "Error fetching server list")
@ -97,10 +100,11 @@ class MultiActivity : AppCompatActivity() {
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()
nbplayers.text = ControllerLobby.getNbPlayerInLobby(mLobbies[position].id).toString() + "/" + mLobbies[position].nbplayers.toString()
idchapter.text = ControllerChapter.getChapterNameById(mLobbies[position].idchapter)
difficulty.text = mLobbies[position].difficulty.toString()
// Visual Feedback for Selection
/*
if (selectedItem == position)

@ -0,0 +1,64 @@
package com.example.mathseduc
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.Button
import android.widget.ProgressBar
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class QuizMultiActivity : AppCompatActivity() {
private lateinit var countDownTimer: CountDownTimer
var progressBarValue : Int = 0
var chronoValue : Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_quiz_multi)
var progressBar1 = findViewById<ProgressBar>(R.id.progressBar1)
var chrono = findViewById<ProgressBar>(R.id.chrono)
progressBar1.max = 100
chrono.max = 30
var incrementeButton = findViewById<Button>(R.id.buttonValider)
// Initialiser le CountDownTimer
countDownTimer = object : CountDownTimer(30*1000, 1000) {
override fun onTick(millisUntilFinished: Long) {
// Incrémenter la valeur de la ProgressBar chaque seconde
chronoValue++
chrono.progress = chronoValue
progressBarValue++
progressBar1.progress = progressBarValue
}
override fun onFinish() {
// Code à exécuter lorsque le timer est terminé
}
}
incrementeButton.setOnClickListener {
progressBarValue += 10
progressBar1.progress = progressBarValue
}
// Démarrer le CountDownTimer
countDownTimer.start()
}
override fun onDestroy() {
super.onDestroy()
// Arrêter le CountDownTimer pour éviter les fuites de mémoire
countDownTimer.cancel()
}
}

@ -1,6 +1,7 @@
package com.example.mathseduc
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -8,16 +9,28 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import com.example.mathseduc.controllers.ControllerLobby
import com.example.mathseduc.controllers.ControllerPlayer
import com.example.mathseduc.controllers.ControllerUtiliser
import com.example.mathseduc.models.Player
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import okhttp3.MultipartBody
class ServerDetailsActivity : AppCompatActivity() {
private var playerList: List<Player> = emptyList()
private val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
MyBackPressed()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
setContentView(R.layout.activity_server_details)
val serverName = intent.getStringExtra("serverName")
@ -27,38 +40,51 @@ class ServerDetailsActivity : AppCompatActivity() {
serverNameTextView.text = serverName
val lobbyId = intent.getIntExtra("lobbyId", -1)
val playerIds = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId)
if (playerIds != null) {
val playerList = playerIds.mapNotNull { playerId ->
ControllerPlayer.getPlayerInfoById(playerId.toString())
if (savedInstanceState != null) {
playerList = savedInstanceState?.getParcelableArrayList("playerList") ?: emptyList() //TODO deprecated c'est pas normal !!!
} else {
// Si l'état d'instance est nul, récupérez la liste des joueurs normalement
val playerId = ControllerPlayer.getPlayersIdFromLobbyId(lobbyId)
if (playerId != null) {
playerList = playerId.mapNotNull { playerId ->
ControllerPlayer.getPlayerInfoById(playerId.toString())
}
}
val listViewPlayers = findViewById<ListView>(R.id.listViewPlayers)
val playerAdapter = PlayerAdapter(this, playerList)
listViewPlayers.adapter = playerAdapter
}
val listViewPlayers = findViewById<ListView>(R.id.listViewPlayers)
val playerAdapter = PlayerAdapter(this, playerList)
listViewPlayers.adapter = playerAdapter
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
// Save the player list to the instance state
outState.putParcelableArrayList("playerList", ArrayList(playerList))
}
override fun onStop() {
super.onStop()
private fun MyBackPressed() {
val lobbyId = intent.getIntExtra("lobbyId", -1)
ControllerUtiliser.DeleteUtiliserForLobby(MainActivity.idPlayerConnected,lobbyId)
ControllerUtiliser.DeleteUtiliserForLobby(MainActivity.idPlayerConnected, lobbyId)
if(ControllerLobby.PlayerCreatorIdPresentInLobby(MainActivity.idPlayerConnected,lobbyId)){
if (ControllerLobby.PlayerCreatorIdPresentInLobby(MainActivity.idPlayerConnected, lobbyId)) {
val idNextPlayerCreator = ControllerUtiliser.getIdNextPlayerInLobby(lobbyId)
if (idNextPlayerCreator == -1){
if (idNextPlayerCreator == -1) {
ControllerLobby.deleteLobby(lobbyId)
} else {
val formDataBuilder = MultipartBody.Builder().setType(MultipartBody.FORM)
formDataBuilder.addFormDataPart("idplayercreator", idNextPlayerCreator.toString())
ControllerLobby.updateLobbyIdCreatorLobby(lobbyId,formDataBuilder)
ControllerLobby.updateLobbyIdCreatorLobby(lobbyId, formDataBuilder)
}
}
finish()
}
class PlayerAdapter(context: Context, players: List<Player>) :

@ -39,5 +39,34 @@ class ControllerChapter {
return null
}
fun getChapterNameById(idchapter : Int): String? {
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/chapters/$idchapter/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
.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<Chapter>>() {}.type
// Parse API response and return the list of chapters
val chapter: ArrayList<Chapter> = gson.fromJson(response.body!!.string(), typeTokenProduct)
return chapter[0].name
}
return null
}
}
}

@ -3,6 +3,7 @@ package com.example.mathseduc.controllers
import android.os.StrictMode
import android.util.Log
import com.example.mathseduc.models.Lobby
import com.example.mathseduc.models.Utiliser
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import okhttp3.MultipartBody
@ -154,5 +155,32 @@ class ControllerLobby {
Log.e("updateLobby", "Error updating lobby", e)
}
}
fun getNbPlayerInLobby(lobbyId: Int): Int {
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/utiliser/$lobbyId/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
.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<Utiliser>>() {}.type
val utiliser: ArrayList<Utiliser> = gson.fromJson(response.body!!.string(), typeTokenProduct)
return utiliser.size
}
return -1
}
}
}

@ -1,7 +1,36 @@
package com.example.mathseduc.models
import android.os.Parcel
import android.os.Parcelable
data class Player(
val id: Int,
val nickname: String,
val password: String
)
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readString() ?: "",
parcel.readString() ?: ""
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(id)
parcel.writeString(nickname)
parcel.writeString(password)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Player> {
override fun createFromParcel(parcel: Parcel): Player {
return Player(parcel)
}
override fun newArray(size: Int): Array<Player?> {
return arrayOfNulls(size)
}
}
}

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="ring"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="@color/black"/>
</shape>
</item>
<item android:id="@+id/chrono">
<shape android:shape="ring"
android:thickness="10dp"
android:useLevel="true">
<solid android:color="@color/white"/>
</shape>
</item>
</layer-list>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- View border color and width -->
<stroke
android:width="1dp"
android:color="@color/white" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>

@ -0,0 +1,204 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_weight="0.05"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/progressBar2"
android:layout_weight="0.05"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/progressBar3"
android:layout_weight="0.05"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/progressBar4"
android:layout_weight="0.05"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/chrono"
android:layout_weight="0.05"
android:paddingHorizontal="10dp"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateOnly="false"
android:rotation="-90"
android:progressDrawable="@drawable/chrono"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingVertical="20dp"
android:orientation="horizontal">
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/question_border"
android:gravity="center"
android:text="Question"
android:layout_weight="5"
android:textColor="@color/white"
android:textSize="20sp" />
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:orientation="horizontal">
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/blue"
android:text="Answer1" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/green"
android:text="Answer2" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/orange"
android:text="Answer3" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/purple_500"
android:text="Answer4" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/buttonPasser"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/red"
android:text="Passer" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<Button
android:id="@+id/buttonValider"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/green"
android:text="Valider" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

@ -18,34 +18,34 @@
android:layout_weight="0.4"
android:gravity="left|center_vertical"
android:text="Name"
android:textSize="16dp" />
android:textSize="18dp" />
<TextView
android:id="@+id/nbplayers"
android:id="@+id/difficulty"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="10dp"
android:text="NbPlayers"/>
android:textSize="14dp"
android:text="Difficulty"/>
<TextView
android:id="@+id/difficulty"
android:id="@+id/idchapter"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="10dp"
android:text="Difficulty"/>
android:textSize="14dp"
android:text="idChapter"/>
<TextView
android:id="@+id/idchapter"
android:id="@+id/nbplayers"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="10dp"
android:text="idChapter"/>
android:textSize="14dp"
android:text="NbPlayers"/>
</LinearLayout>

@ -11,6 +11,7 @@
<color name="orange">#FFA500</color>
<color name="grey">#8C92AC</color>
<color name="blue">#0d6efd</color>
<color name="red">#FF0000</color>
<color name="blackgrey">#5c636a</color>
<color name="cyan">#00FFFF</color>
<color name="turquoise">#40E0D0</color>

Loading…
Cancel
Save