Ajout de bouttons pour créer des éléments dans les listes Menu et Session
This commit is contained in:
parent
bff62daaec
commit
a79b591e90
10 changed files with 76 additions and 63 deletions
|
@ -15,19 +15,6 @@ import com.example.palto.domain.Session
|
|||
class MenuAdapter :
|
||||
ListAdapter<Session, MenuAdapter.ViewHolder>(SessionDiffCallback) {
|
||||
|
||||
/*
|
||||
class ViewHolder(binding: FragmentSessionItemBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
val idView: TextView = binding.itemNumber
|
||||
val contentView: TextView = binding.content
|
||||
|
||||
override fun toString(): String {
|
||||
return super.toString() + " '" + contentView.text + "'"
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
FragmentMenuItemBinding.inflate(
|
||||
|
@ -40,22 +27,20 @@ class MenuAdapter :
|
|||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.idView.text = position.toString()
|
||||
holder.contentView.text = item.id
|
||||
holder.sessionId.text = item.id
|
||||
}
|
||||
|
||||
//override fun getItemCount(): Int = values.size
|
||||
|
||||
inner class ViewHolder(
|
||||
binding: FragmentMenuItemBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
val idView: TextView = binding.itemNumber
|
||||
val contentView: TextView = binding.content
|
||||
val sessionId: TextView = binding.sessionId
|
||||
override fun toString(): String {
|
||||
return super.toString() + " '" + idView.text + contentView.text + "'"
|
||||
return super.toString() + " '" + sessionId.text + "'"
|
||||
}
|
||||
}
|
||||
|
||||
//override fun getItemCount(): Int = values.size
|
||||
}
|
||||
|
||||
object SessionDiffCallback : DiffUtil.ItemCallback<Session>() {
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package com.example.palto.ui.menu
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.navGraphViewModels
|
||||
import com.example.palto.R
|
||||
import com.example.palto.databinding.FragmentMenuListBinding
|
||||
import com.example.palto.databinding.FragmentSessionListBinding
|
||||
|
||||
/**
|
||||
* A fragment representing a list of Sessions.
|
||||
*/
|
||||
class MenuFragment : Fragment() {
|
||||
|
||||
private val menuViewModel: MenuViewModel by viewModels()
|
||||
private val menuViewModel: MenuViewModel by
|
||||
navGraphViewModels(R.id.nav_graph)
|
||||
|
||||
private var _binding: FragmentMenuListBinding? = null
|
||||
// This property is only valid between onCreateView and onDestroyView
|
||||
|
@ -29,17 +30,16 @@ class MenuFragment : Fragment() {
|
|||
_binding = FragmentMenuListBinding.inflate(inflater, container, false)
|
||||
|
||||
val adapter = MenuAdapter()
|
||||
binding.menuList.adapter = MenuAdapter()
|
||||
binding.menuList.adapter = adapter
|
||||
menuViewModel.sessions.observe(viewLifecycleOwner) {
|
||||
Log.d("PALTO", "A session has been created")
|
||||
adapter.submitList(it)
|
||||
}
|
||||
|
||||
binding.createSession.setOnClickListener {
|
||||
menuViewModel.createSession()
|
||||
findNavController().navigate(R.id.action_menuFragment_to_sessionFragment)
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
menuViewModel.createSession()
|
||||
}
|
||||
}
|
|
@ -4,18 +4,18 @@ import android.util.Log
|
|||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.example.palto.data.repository.LoginRepository
|
||||
import com.example.palto.domain.Session
|
||||
|
||||
class MenuViewModel() : ViewModel() {
|
||||
|
||||
private var _sessions = MutableLiveData<List<Session>>(emptyList())
|
||||
val sessions: LiveData<List<Session>> = _sessions
|
||||
val sessions = _sessions as LiveData<List<Session>>
|
||||
|
||||
fun createSession() {
|
||||
val session = Session(
|
||||
id = "aahh"
|
||||
)
|
||||
_sessions.value = (_sessions.value ?: emptyList()) + session
|
||||
Log.d("PALTO", "MenuViewModel: a session has been added into the list.")
|
||||
}
|
||||
}
|
|
@ -29,7 +29,6 @@ class SessionAdapter :
|
|||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.cardId.text = item.uid.toHexString()
|
||||
//holder.contentView.text = item.content
|
||||
}
|
||||
|
||||
inner class ViewHolder(
|
||||
|
|
|
@ -41,16 +41,19 @@ class SessionFragment : Fragment() {
|
|||
val adapter = SessionAdapter()
|
||||
binding.sessionList.adapter = adapter
|
||||
sessionViewModel.cards.observe(viewLifecycleOwner) {
|
||||
Log.d("NFC", "A card has been had to the list")
|
||||
adapter.submitList(it)
|
||||
}
|
||||
|
||||
// Set the listener for a new NFC tag.
|
||||
nfcViewModel.tag.observe(viewLifecycleOwner) {
|
||||
Log.d("NFC", "tag observer has been notified")
|
||||
Log.d("NFC", "The tag observers has been notified.")
|
||||
sessionViewModel.insertCard(it)
|
||||
}
|
||||
|
||||
binding.createCard.setOnClickListener {
|
||||
//sessionViewModel.
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ class SessionViewModel(
|
|||
private val attendanceRepository: AttendanceRepository
|
||||
) : ViewModel() {
|
||||
|
||||
private val _cards: MutableLiveData<List<Card>> = MutableLiveData(emptyList())
|
||||
private val _cards = MutableLiveData<List<Card>>(emptyList())
|
||||
val cards = _cards as LiveData<List<Card>>
|
||||
|
||||
fun insertCard(tag: Tag) {
|
||||
|
@ -27,7 +27,7 @@ class SessionViewModel(
|
|||
"tmp"
|
||||
)
|
||||
_cards.value = (_cards.value ?: emptyList()) + card
|
||||
Log.d("NFC", "view model: A card has been had to the list")
|
||||
Log.d("PALTO", "SessionViewModel: a card has been added into the list.")
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,16 +5,10 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_number"
|
||||
android:id="@+id/session_id"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
</LinearLayout>
|
|
@ -1,13 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout 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:id="@+id/menu_list"
|
||||
android:name="com.example.palto.ui.menu.menuFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context=".ui.menu.MenuFragment"
|
||||
tools:listitem="@layout/fragment_menu_item" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/menu_list"
|
||||
android:name="com.example.palto.ui.menu.menuFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context=".ui.menu.MenuFragment"
|
||||
tools:listitem="@layout/fragment_menu_item" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/create_session"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/create_session"
|
||||
app:srcCompat="@android:drawable/ic_input_add" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -1,13 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout 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:id="@+id/session_list"
|
||||
android:name="com.example.palto.ui.session.sessionFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context=".ui.session.SessionFragment"
|
||||
tools:listitem="@layout/fragment_session_item" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/session_list"
|
||||
android:name="com.example.palto.ui.session.sessionFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context=".ui.session.SessionFragment"
|
||||
tools:listitem="@layout/fragment_session_item" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/create_card"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/create_card"
|
||||
app:srcCompat="@android:drawable/ic_input_add" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -12,4 +12,6 @@
|
|||
<string name="invalid_password">Mot de passe invalide</string>
|
||||
<string name="login_failed">"Erreur de connexion !"</string>
|
||||
<string name="help_message">Identifiants Invalides</string>
|
||||
<string name="create_session">Créer une session</string>
|
||||
<string name="create_card">Créer une présence</string>
|
||||
</resources>
|
Loading…
Reference in a new issue