Fixed the horizontal layout of the home page and realized the search bar 🔍
continuous-integration/drone/push Build is passing Details

For_Me_Teams_Search
Emre KARTAL 2 years ago
parent 177758cfdd
commit 2905584410

@ -38,7 +38,6 @@ class DetailFragment : Fragment() {
val id = arguments?.getInt("idItem")!! val id = arguments?.getInt("idItem")!!
viewModel.competition.observe(viewLifecycleOwner, Observer { comp -> viewModel.competition.observe(viewLifecycleOwner, Observer { comp ->
comp?.let { comp?.let {
competition = comp competition = comp
@ -73,12 +72,15 @@ class DetailFragment : Fragment() {
val buttonExit = view.findViewById<ImageButton>(R.id.buttonExit) val buttonExit = view.findViewById<ImageButton>(R.id.buttonExit)
val imageHeader = view.findViewById<ImageView>(R.id.imageDetail) val imageHeader = view.findViewById<ImageView>(R.id.imageDetail)
val titleHeader = view.findViewById<TextView>(R.id.title) val titleHeader = view.findViewById<TextView>(R.id.title)
val nbMatches = view.findViewById<TextView>(R.id.nbMatches)
val dateEnd = view.findViewById<TextView>(R.id.dateEnd) val dateEnd = view.findViewById<TextView>(R.id.dateEnd)
val dateStart = view.findViewById<TextView>(R.id.dateStart) val dateStart = view.findViewById<TextView>(R.id.dateStart)
val fragmentId = arguments?.getInt("fragmentId")
buttonExit.setOnClickListener { buttonExit.setOnClickListener {
findNavController().navigate(R.id.favoriteFragment) fragmentId?.let {
findNavController().navigate(fragmentId)
}
} }
button.setOnClickListener { button.setOnClickListener {

@ -15,10 +15,10 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import uca.iut.clermont.R import uca.iut.clermont.R
import uca.iut.clermont.model.Competition import uca.iut.clermont.model.Competition
import uca.iut.clermont.view.adapter.FavoritesAdapter import uca.iut.clermont.view.adapter.CompetitionsAdapter
import uca.iut.clermont.view.viewModel.FavoriteViewModel import uca.iut.clermont.view.viewModel.FavoriteViewModel
class FavoriteFragment : Fragment(), FavoritesAdapter.OnItemClickListener { class FavoriteFragment : Fragment(), CompetitionsAdapter.OnItemClickListener {
private val viewModel: FavoriteViewModel by viewModels() private val viewModel: FavoriteViewModel by viewModels()
@ -61,18 +61,21 @@ class FavoriteFragment : Fragment(), FavoritesAdapter.OnItemClickListener {
private fun initRecyclerView( private fun initRecyclerView(
view: View, view: View,
favorites: List<Competition>, favorites: List<Competition>,
listener: FavoritesAdapter.OnItemClickListener listener: CompetitionsAdapter.OnItemClickListener
) { ) {
val recyclerViewFavorites = view.findViewById<RecyclerView>(R.id.listFavorites) val recyclerViewFavorites = view.findViewById<RecyclerView>(R.id.listFavorites)
with(recyclerViewFavorites) { with(recyclerViewFavorites) {
layoutManager = LinearLayoutManager(view.context) layoutManager = LinearLayoutManager(view.context)
adapter = FavoritesAdapter(favorites.toList().toTypedArray(), listener) adapter = CompetitionsAdapter(favorites.toList().toTypedArray(), listener)
} }
} }
override fun onItemClick(position: Int) { override fun onItemClick(position: Int) {
val competitions = viewModel.competitions.value!! val competitions = viewModel.competitions.value!!
val bundle = bundleOf("idItem" to competitions[position].id) val bundle = bundleOf(
"idItem" to competitions[position].id,
"fragmentId" to R.id.favoriteFragment
)
findNavController().navigate(R.id.action_favoriteFragment_to_detailFragment, bundle) findNavController().navigate(R.id.action_favoriteFragment_to_detailFragment, bundle)
} }
} }

@ -1,11 +1,15 @@
package uca.iut.clermont.view package uca.iut.clermont.view
import android.os.Bundle import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.EditText
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.TextView import android.widget.TextView
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
@ -13,13 +17,17 @@ import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import uca.iut.clermont.R import uca.iut.clermont.R
import uca.iut.clermont.model.Competition
import uca.iut.clermont.model.Match import uca.iut.clermont.model.Match
import uca.iut.clermont.view.adapter.CompetitionsAdapter
import uca.iut.clermont.view.adapter.MatchesAdapter import uca.iut.clermont.view.adapter.MatchesAdapter
import uca.iut.clermont.view.viewModel.HomeViewModel import uca.iut.clermont.view.viewModel.HomeViewModel
class HomeFragment : Fragment() { class HomeFragment : Fragment(), CompetitionsAdapter.OnItemClickListener {
val viewModel: HomeViewModel by viewModels() private val viewModel: HomeViewModel by viewModels()
private lateinit var searchBar: EditText
private lateinit var searchAdapter: RecyclerView
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -31,19 +39,26 @@ class HomeFragment : Fragment() {
val buttonFavorite = view.findViewById<ImageButton>(R.id.buttonFavorite) val buttonFavorite = view.findViewById<ImageButton>(R.id.buttonFavorite)
val restartMatches = view.findViewById<ImageButton>(R.id.restartMatches) val restartMatches = view.findViewById<ImageButton>(R.id.restartMatches)
searchAdapter = view.findViewById(R.id.listSearch)
searchBar = view.findViewById(R.id.searchBar);
searchBar.addTextChangedListener(textWatcher);
val text = view.findViewById<TextView>(R.id.textEmpty) val text = view.findViewById<TextView>(R.id.textEmpty)
viewModel.matches.observe(viewLifecycleOwner, Observer { matches -> viewModel.matches.observe(viewLifecycleOwner, Observer { matches ->
matches?.let { matches?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
initRecyclerView(view, it) initRecyclerView(view, it, this)
} else { } else {
text.setText(R.string.noMatches) text.setText(R.string.noMatches)
} }
} }
}) })
searchAdapter.layoutManager = LinearLayoutManager(view.context)
displayMatches() displayMatches()
viewModel.loadCompetitions()
buttonFavorite.setOnClickListener { buttonFavorite.setOnClickListener {
findNavController().navigate(R.id.favoriteFragment) findNavController().navigate(R.id.favoriteFragment)
@ -56,17 +71,70 @@ class HomeFragment : Fragment() {
return view return view
} }
private fun initRecyclerView(view: View, matches: List<Match>) { private val textWatcher = object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
searchNames(s.toString())
}
override fun afterTextChanged(s: Editable?) {
}
}
private fun searchNames(query: String) {
val filteredCompetition = mutableListOf<Competition>()
if (query.isNotEmpty()) {
for (competition in viewModel.competitions.value!!) {
if (competition.name.lowercase()
.contains(query.lowercase()) && filteredCompetition.size < 3
) {
filteredCompetition.add(competition)
}
}
}
searchList(filteredCompetition, this)
}
private fun initRecyclerView(
view: View,
matches: List<Match>,
listener: CompetitionsAdapter.OnItemClickListener
) {
val recyclerViewMatches = view.findViewById<RecyclerView>(R.id.listRecentsMatches) val recyclerViewMatches = view.findViewById<RecyclerView>(R.id.listRecentsMatches)
with(recyclerViewMatches) { with(recyclerViewMatches) {
layoutManager = LinearLayoutManager(view.context) layoutManager = LinearLayoutManager(view.context)
adapter = MatchesAdapter(matches.toList().toTypedArray()) adapter = MatchesAdapter(matches.toList().toTypedArray())
} }
}
private fun searchList(
competitons: List<Competition>,
listener: CompetitionsAdapter.OnItemClickListener
) {
searchAdapter.adapter = CompetitionsAdapter(competitons.toTypedArray(), listener)
} }
private fun displayMatches() { private fun displayMatches() {
viewModel.loadMatches() viewModel.loadMatches()
} }
override fun onPause() {
super.onPause()
searchBar.removeTextChangedListener(textWatcher)
}
override fun onItemClick(position: Int) {
val competitions = viewModel.competitions.value!!
val bundle = bundleOf(
"idItem" to competitions[position].id,
"fragmentId" to R.id.homeFragment
)
findNavController().navigate(R.id.action_homeFragment_to_detailFragment, bundle)
}
} }

@ -10,11 +10,11 @@ import com.bumptech.glide.Glide
import uca.iut.clermont.R import uca.iut.clermont.R
import uca.iut.clermont.model.Competition import uca.iut.clermont.model.Competition
class FavoritesAdapter( class CompetitionsAdapter(
private val favoriteCompetition: Array<Competition>, private val favoriteCompetition: Array<Competition>,
private val listener: OnItemClickListener, private val listener: OnItemClickListener,
) : ) :
RecyclerView.Adapter<FavoritesAdapter.FavoriteHolder>() { RecyclerView.Adapter<CompetitionsAdapter.FavoriteHolder>() {
inner class FavoriteHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener { inner class FavoriteHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {

@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import uca.iut.clermont.api.ApiManager import uca.iut.clermont.api.ApiManager
import uca.iut.clermont.model.Competition
import uca.iut.clermont.model.Match import uca.iut.clermont.model.Match
import java.util.* import java.util.*
@ -12,6 +13,7 @@ class HomeViewModel : ViewModel() {
val manager = ApiManager() val manager = ApiManager()
val matches = MutableLiveData<List<Match>?>() val matches = MutableLiveData<List<Match>?>()
val competitions = MutableLiveData<List<Competition>>()
fun loadMatches() = viewModelScope.launch { fun loadMatches() = viewModelScope.launch {
val matchResults = manager.matchesMgr.getItems() val matchResults = manager.matchesMgr.getItems()
@ -21,4 +23,9 @@ class HomeViewModel : ViewModel() {
.sortedByDescending { it.date } .sortedByDescending { it.date }
} }
fun loadCompetitions() = viewModelScope.launch {
val result = manager.competitionsMgr.getItems()
competitions.value = result
}
} }

@ -50,7 +50,7 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/listFavorites" android:id="@+id/listFavorites"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:paddingHorizontal="30dp"> android:paddingHorizontal="30dp">
<FrameLayout <FrameLayout
@ -30,9 +30,9 @@
android:layout_height="34dp" android:layout_height="34dp"
android:layout_gravity="end" android:layout_gravity="end"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:contentDescription="@string/imageNotFound"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/icon_like" android:src="@drawable/icon_like" />
android:contentDescription="@string/imageNotFound" />
</FrameLayout> </FrameLayout>
@ -91,33 +91,56 @@
</LinearLayout> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="40dp" android:layout_marginLeft="40dp"
android:orientation="vertical"> android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/textViewRecentMatches" android:id="@+id/textViewRecentMatches"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Recent Matches" android:text="Recent Matches"
android:textColor="@color/title" android:textColor="@color/title"
android:textSize="30dp" android:textSize="30dp"
android:textStyle="bold" android:textStyle="bold" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchBarContainer" /> <ImageButton
android:id="@+id/restartMatches"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right"
android:layout_marginTop="20dp"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/restart" />
</FrameLayout>
<TextView
android:id="@+id/textEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/title"
android:textSize="20dp" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/listRecentsMatches" android:id="@+id/listRecentsMatches"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewRecentMatches"
tools:itemCount="10" /> tools:itemCount="10" />
</LinearLayout> </LinearLayout>

@ -52,7 +52,7 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/listFavorites" android:id="@+id/listFavorites"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

@ -84,6 +84,14 @@
</LinearLayout> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchBarContainer" />
<TextView <TextView
android:id="@+id/textViewRecentMatches" android:id="@+id/textViewRecentMatches"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -94,7 +102,7 @@
android:textSize="20dp" android:textSize="20dp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchBarContainer" /> app:layout_constraintTop_toBottomOf="@+id/listSearch" />
<ImageButton <ImageButton
android:id="@+id/restartMatches" android:id="@+id/restartMatches"
@ -105,7 +113,7 @@
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/restart" android:src="@drawable/restart"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/searchBarContainer" /> app:layout_constraintTop_toBottomOf="@id/listSearch" />
<TextView <TextView
android:id="@+id/textEmpty" android:id="@+id/textEmpty"

@ -20,6 +20,9 @@
<action <action
android:id="@+id/action_homeFragment_to_favoriteFragment" android:id="@+id/action_homeFragment_to_favoriteFragment"
app:destination="@id/favoriteFragment" /> app:destination="@id/favoriteFragment" />
<action
android:id="@+id/action_homeFragment_to_detailFragment"
app:destination="@id/detailFragment" />
</fragment> </fragment>
<fragment <fragment

Loading…
Cancel
Save