View Model visible dans le navgraph. Début d’une liste de présence AttendanceListFragment

This commit is contained in:
biloute02 2023-12-19 22:38:08 +01:00
parent a911de59b1
commit a856513920
12 changed files with 40 additions and 96 deletions

View file

@ -16,13 +16,16 @@ import android.widget.EditText
import android.widget.ProgressBar
import android.widget.Toast
import androidx.navigation.fragment.findNavController
import androidx.navigation.navGraphViewModels
import com.example.palto.databinding.FragmentLoginBinding
import com.example.palto.R
class LoginFragment : Fragment() {
private lateinit var loginViewModel: LoginViewModel
private val loginViewModel: LoginViewModel by
navGraphViewModels (R.id.nav_graph) { LoginViewModelFactory() }
private var _binding: FragmentLoginBinding? = null
// This property is only valid between onCreateView and
@ -37,13 +40,10 @@ class LoginFragment : Fragment() {
_binding = FragmentLoginBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
loginViewModel = ViewModelProvider(this, LoginViewModelFactory())
.get(LoginViewModel::class.java)
val hostnameEditText = binding.hostname
val usernameEditText = binding.username
@ -77,7 +77,7 @@ class LoginFragment : Fragment() {
showLoginFailed(it)
}
loginResult.success?.let {
findNavController().navigate(R.id.action_loginFragment_to_itemFragment)
findNavController().navigate(R.id.action_loginFragment_to_attendanceFragment)
//updateUiWithUser(it)
}
})

View file

@ -1,4 +1,4 @@
package com.example.palto
package com.example.palto.ui.session
import android.os.Bundle
import androidx.fragment.app.Fragment
@ -8,12 +8,13 @@ import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.palto.placeholder.PlaceholderContent
import com.example.palto.R
import com.example.palto.ui.session.placeholder.PlaceholderContent
/**
* A fragment representing a list of Items.
*/
class ItemFragment : Fragment() {
class AttendanceListFragment : Fragment() {
private var columnCount = 1
@ -26,10 +27,11 @@ class ItemFragment : Fragment() {
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_item_list, container, false)
val view = inflater.inflate(R.layout.fragment_attendance_list, container, false)
// Set the adapter
if (view is RecyclerView) {
@ -38,7 +40,7 @@ class ItemFragment : Fragment() {
columnCount <= 1 -> LinearLayoutManager(context)
else -> GridLayoutManager(context, columnCount)
}
adapter = MyItemRecyclerViewAdapter(PlaceholderContent.ITEMS)
adapter = MyAttendanceRecyclerViewAdapter(PlaceholderContent.ITEMS)
}
}
return view
@ -52,7 +54,7 @@ class ItemFragment : Fragment() {
// TODO: Customize parameter initialization
@JvmStatic
fun newInstance(columnCount: Int) =
ItemFragment().apply {
AttendanceListFragment().apply {
arguments = Bundle().apply {
putInt(ARG_COLUMN_COUNT, columnCount)
}

View file

@ -1,26 +1,27 @@
package com.example.palto
package com.example.palto.ui.session
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.example.palto.R
import com.example.palto.placeholder.PlaceholderContent.PlaceholderItem
import com.example.palto.databinding.FragmentItemBinding
import com.example.palto.ui.session.placeholder.PlaceholderContent.PlaceholderItem
import com.example.palto.databinding.FragmentAttendanceBinding
/**
* [RecyclerView.Adapter] that can display a [PlaceholderItem].
* TODO: Replace the implementation with code for your data type.
*/
class MyItemRecyclerViewAdapter(
class MyAttendanceRecyclerViewAdapter(
private val values: List<PlaceholderItem>
) : RecyclerView.Adapter<MyItemRecyclerViewAdapter.ViewHolder>() {
) : RecyclerView.Adapter<MyAttendanceRecyclerViewAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
FragmentItemBinding.inflate(
FragmentAttendanceBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
@ -37,7 +38,8 @@ class MyItemRecyclerViewAdapter(
override fun getItemCount(): Int = values.size
inner class ViewHolder(binding: FragmentItemBinding) : RecyclerView.ViewHolder(binding.root) {
inner class ViewHolder(binding: FragmentAttendanceBinding) :
RecyclerView.ViewHolder(binding.root) {
val idView: TextView = binding.itemNumber
val contentView: TextView = binding.content

View file

@ -1,4 +1,4 @@
package com.example.palto.placeholder
package com.example.palto.ui.session.placeholder
import java.util.ArrayList
import java.util.HashMap

View file

@ -1,32 +0,0 @@
package com.example.palto.ui.sheet
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.palto.R
class SheetDetailFragment : Fragment() {
companion object {
fun newInstance() = SheetDetailFragment()
}
private lateinit var viewModel: SheetDetailViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_sheet_detail, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProvider(this).get(SheetDetailViewModel::class.java)
// TODO: Use the ViewModel
}
}

View file

@ -1,7 +0,0 @@
package com.example.palto.ui.sheet
import androidx.lifecycle.ViewModel
class SheetDetailViewModel : ViewModel() {
// TODO: Implement the ViewModel
}

View file

@ -3,11 +3,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:name="com.example.palto.ItemFragment"
android:name="com.example.palto.ui.session.AttendanceFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".ItemFragment"
tools:listitem="@layout/fragment_item" />
tools:context=".ui.session.AttendanceListFragment"
tools:listitem="@layout/fragment_attendance" />

View file

@ -18,7 +18,7 @@
android:layout_marginStart="24dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="24dp"
android:autofillHints="@string/prompt_server"
android:autofillHints="@string/prompt_hostname"
android:hint="@string/prompt_hostname"
android:inputType="text"
android:selectAllOnFocus="true"
@ -56,17 +56,17 @@
android:imeOptions="actionDone"
android:inputType="textPassword"
android:selectAllOnFocus="true"
app:layout_constraintBottom_toTopOf="@+id/helpmsg"
app:layout_constraintBottom_toTopOf="@+id/help_message"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username" />
<TextView
android:id="@+id/helpmsg"
android:id="@+id/help_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Identifiants Invalides"
android:text="@string/help_message"
app:layout_constraintBottom_toTopOf="@+id/login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -87,7 +87,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/helpmsg"
app:layout_constraintTop_toBottomOf="@+id/help_message"
app:layout_constraintVertical_bias="0.2" />
<ProgressBar

View file

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".ui.sheet.SheetDetailFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello" />
</FrameLayout>

View file

@ -7,24 +7,15 @@
<fragment
android:id="@+id/loginFragment"
android:name="com.example.palto.ui.login.LoginFragment"
android:label="fragment_login"
android:label="fragment._login"
tools:layout="@layout/fragment_login" >
<action
android:id="@+id/action_loginFragment_to_itemFragment"
app:destination="@id/itemFragment"
app:enterAnim="@android:anim/slide_in_left"
app:exitAnim="@android:anim/slide_in_left"
app:popEnterAnim="@android:anim/slide_in_left"
app:popExitAnim="@android:anim/slide_in_left" />
android:id="@+id/action_loginFragment_to_attendanceFragment"
app:destination="@id/attendanceFragment" />
</fragment>
<fragment
android:id="@+id/itemFragment"
android:name="com.example.palto.ItemFragment"
android:label="fragment_item_list"
tools:layout="@layout/fragment_item_list" />
<fragment
android:id="@+id/sheetDetailFragment"
android:name="com.example.palto.ui.sheet.SheetDetailFragment"
android:label="fragment_sheet_detail"
tools:layout="@layout/fragment_sheet_detail" />
android:id="@+id/attendanceFragment"
android:name="com.example.palto.ui.session.AttendanceListFragment"
android:label="fragment_attendance_list"
tools:layout="@layout/fragment_attendance_list" />
</navigation>

View file

@ -11,4 +11,5 @@
<string name="invalid_username">Nom dutilisateur non valide</string>
<string name="invalid_password">Mot de passe invalide</string>
<string name="login_failed">"Erreur de connexion !"</string>
<string name="help_message">Identifiants Invalides</string>
</resources>