Merge branch 'master' into testApp
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
commit
84e5210dd9
@ -1,20 +1,94 @@
|
|||||||
package uca.iutinfo.studentbros.views
|
package uca.iutinfo.studentbros.views
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Adapter
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import uca.iutinfo.studentbros.R
|
||||||
|
import uca.iutinfo.studentbros.activity.LevelChoiceActivity
|
||||||
import uca.iutinfo.studentbros.model.Level
|
import uca.iutinfo.studentbros.model.Level
|
||||||
|
|
||||||
class AdapterLevelChoice(val lesLevels : MutableList<Level>) : androidx.recyclerview.widget.RecyclerView.Adapter<ViewHolderLevelChoice>() {
|
//class AdapterLevelChoice(val lesLevels : MutableList<Level>) : androidx.recyclerview.widget.RecyclerView.Adapter<ViewHolderLevelChoice>() {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderLevelChoice {
|
//
|
||||||
return ViewHolderLevelChoice(TextView(parent.context))
|
//// var single_item_position = -1
|
||||||
|
// override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderLevelChoice {
|
||||||
|
// val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
|
// val view = layoutInflater.inflate(R.layout.item_level,parent,false)
|
||||||
|
// return ViewHolderLevelChoice(view)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun getItemCount(): Int {
|
||||||
|
|
||||||
|
|
||||||
|
// return lesLevels.size
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun onBindViewHolder(holder: ViewHolderLevelChoice, position: Int) {
|
||||||
|
// if (single_item_position == position){
|
||||||
|
// holder.label.setBackgroundColor(Color.BLUE)
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// holder.label.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//https://www.youtube.com/watch?v=huXWWurL1c0
|
||||||
|
class AdapterLevelChoice(context: LevelChoiceActivity, arrayList: ArrayList<Level>) : RecyclerView.Adapter<AdapterLevelChoice.ViewHolder>() {
|
||||||
|
private val context: Context
|
||||||
|
private val arrayList: ArrayList<Level>
|
||||||
|
var single_item_position = -1
|
||||||
|
var levelSelected: Int? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.context = context
|
||||||
|
this.arrayList = arrayList
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
|
val view = layoutInflater.inflate(R.layout.item_level, parent, false)
|
||||||
|
return ViewHolder(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return lesLevels.size
|
return arrayList.size
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
val level = arrayList[position]
|
||||||
|
holder.itemView.findViewById<TextView>(R.id.toto).text = level.name
|
||||||
|
if (single_item_position == position) {
|
||||||
|
holder.itemView.setBackgroundColor(Color.BLUE)
|
||||||
|
levelSelected = level.numero //le numero d'un niveau est unique
|
||||||
|
} else {
|
||||||
|
holder.itemView.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolderLevelChoice, position: Int) {
|
inner class ViewHolder(itemView: View) :
|
||||||
holder.label.text= String.format("%d - %s", lesLevels.get(position).numero,lesLevels.get(position).name)
|
androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView) {
|
||||||
|
init {
|
||||||
|
itemView.setOnClickListener { setSingleSelection(adapterPosition) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fun getLevelSelectedd() : Int? {
|
||||||
|
return levelSelected
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setSingleSelection(adapterPosition: Int) {
|
||||||
|
if (adapterPosition == RecyclerView.NO_POSITION) return
|
||||||
|
notifyItemChanged(single_item_position)
|
||||||
|
single_item_position = adapterPosition
|
||||||
|
notifyItemChanged(single_item_position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package uca.iutinfo.studentbros.views
|
package uca.iutinfo.studentbros.views
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||||
|
|
||||||
class ViewHolderLevelChoice(val label : TextView) : ViewHolder(label) {
|
//https://proandroiddev.com/a-guide-to-recyclerview-selection-3ed9f2381504
|
||||||
|
class ViewHolderLevelChoice(val itemView: View) : ViewHolder(itemView) {
|
||||||
}
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:padding="20dp"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/toto"
|
||||||
|
android:textSize="18dp"/>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in new issue