Navigation done ♻️

fragment_navigation
Emre KARTAL 2 years ago
parent ae34b24cb5
commit 8f9a094aef

@ -33,10 +33,14 @@ android {
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
// Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'

@ -247,56 +247,76 @@ class StubData : DataManager() {
)
private val random = java.util.Random()
val matchList = listOf(
Match(
1,
1,
2,
Calendar.getInstance().apply { set(2022, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(1, 1, "DRAW")
),
Match(
2,
3,
1,
Calendar.getInstance().apply { set(2022, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(2, 0, "HOME_TEAM")
),
Match(
3,
2,
3,
Calendar.getInstance().apply { set(2022, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(0, 4, "AWAY_TEAM")
),
Match(
4,
1,
3,
Calendar.getInstance().apply { set(2023, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(0, 1, "AWAY_TEAM")
),
Match(
5,
2,
1,
Calendar.getInstance().apply { set(2023, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(0, 0, "DRAW")
),
Match(
6,
3,
2,
Calendar.getInstance().apply { set(2023, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(2, 0, "HOME_TEAM")
val matchList: MutableList<Match> = mutableListOf()
fun initMatches() {
matchList.add(
Match(
1,
teamList[0],
teamList[1],
Calendar.getInstance()
.apply { set(2022, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(1, 1, "DRAW")
)
)
)
matchList.add(
Match(
2,
teamList[2],
teamList[0],
Calendar.getInstance()
.apply { set(2022, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(2, 0, "HOME_TEAM")
)
)
matchList.add(
Match(
3,
teamList[1],
teamList[2],
Calendar.getInstance()
.apply { set(2022, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(0, 4, "AWAY_TEAM")
)
)
matchList.add(
Match(
4,
teamList[0],
teamList[2],
Calendar.getInstance()
.apply { set(2023, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(0, 1, "AWAY_TEAM")
)
)
matchList.add(
Match(
5,
teamList[1],
teamList[0],
Calendar.getInstance()
.apply { set(2023, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(0, 0, "DRAW")
)
)
matchList.add(
Match(
6,
teamList[2],
teamList[1],
Calendar.getInstance()
.apply { set(2023, random.nextInt(12), random.nextInt(28) + 1) },
"FINISHED",
Score(2, 0, "HOME_TEAM")
)
)
}
val teamList: MutableList<Team> = mutableListOf()
@ -313,8 +333,8 @@ class StubData : DataManager() {
"Navy / Red",
areaList[0],
"Parc des Princes",
peopleList[0] as Coach,
listOf(peopleList[2] as Staff),
peopleList[13] as Coach,
listOf(peopleList[15] as Staff),
listOf(peopleList[0] as Player, peopleList[3] as Player, peopleList[11] as Player)
)
)
@ -330,9 +350,9 @@ class StubData : DataManager() {
"Blue / Red",
areaList[3],
"Camp Nou",
peopleList[0] as Coach,
listOf(peopleList[2] as Staff),
listOf(peopleList[0] as Player, peopleList[5] as Player, peopleList[9] as Player)
peopleList[14] as Coach,
listOf(peopleList[16] as Staff),
listOf(peopleList[2] as Player, peopleList[5] as Player, peopleList[9] as Player)
)
)
teamList.add(
@ -347,8 +367,8 @@ class StubData : DataManager() {
"Red",
areaList[2],
"Anfield",
peopleList[1] as Coach,
listOf(peopleList[3] as Staff),
peopleList[14] as Coach,
listOf(peopleList[15] as Staff),
listOf(peopleList[7] as Player, peopleList[8] as Player, peopleList[10] as Player)
)
)
@ -375,8 +395,6 @@ class StubData : DataManager() {
}
class StubMatchesManager(private val parent: StubData) : MatchesManager {
override fun getItemsByName(substring: String) =
throw java.lang.Exception("Don't call this function")
override fun getItems(): List<Match> = parent.matchList

@ -45,9 +45,6 @@ class ApiManager : DataManager() {
}
class ApiMatchesManager : MatchesManager {
override fun getItemsByName(substring: String): List<Match> {
TODO("Not yet implemented")
}
override fun getItems(): List<Match> {
TODO("Not yet implemented")

@ -9,12 +9,21 @@ abstract class DataManager {
}
interface AreaManager : GenericDataManager<Area>
interface AreaManager : GenericDataManager<Area> {
fun getItemsByName(substring: String): List<Area>
}
interface PeopleManager : GenericDataManager<Personne>
interface PeopleManager : GenericDataManager<Personne> {
fun getItemsByName(substring: String): List<Personne>
}
interface MatchesManager : GenericDataManager<Match>
interface CompetitionsManager : GenericDataManager<Competition>
interface CompetitionsManager : GenericDataManager<Competition> {
fun getItemsByName(substring: String): List<Competition>
}
interface TeamsManager : GenericDataManager<Team> {
fun getItemsByName(substring: String): List<Team>
interface TeamsManager : GenericDataManager<Team>
}

@ -1,7 +1,6 @@
package uca.iut.clermont.model
interface GenericDataManager<T> {
fun getItemsByName(substring: String): List<T>
fun getItems(): List<T>
fun getItemById(id: Int): T?
}

@ -4,8 +4,8 @@ import java.util.Calendar
class Match(
val id: Int,
val idHomeTeam: Int,
val idAwayTeam: Int,
val homeTeam: Team,
val awayTeam: Team,
val date: Calendar,
val status: String,
val score: Score

@ -5,7 +5,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import uca.iut.clermont.R
import uca.iut.clermont.model.Match
import uca.iut.clermont.view.adapter.MatchesAdapter
class HomeFragment : Fragment() {
@ -15,14 +19,23 @@ class HomeFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
/*val adapterMatches = findViewById<RecyclerView>(R.id.ListRecentsMatches)
val view = inflater.inflate(R.layout.fragment_home, container, false)
val matches = (activity as MainActivity).manager.matchesMgr.getItems()
with(adapterMatches) {
adapter = MatchesAdapter(manager.matchesMgr.getItems().toList().toTypedArray())
}
initRecyclerView(view, matches)
return view
}
adapterMatches.layoutManager = LinearLayoutManager(this)*/
private fun initRecyclerView(view: View, matches: List<Match>) {
val recyclerViewMatches = view.findViewById<RecyclerView>(R.id.ListRecentsMatches)
with(recyclerViewMatches) {
layoutManager = LinearLayoutManager(view.context)
adapter = MatchesAdapter(matches.toList().toTypedArray())
}
return inflater.inflate(R.layout.fragment_home, container, false)
}
}

@ -1,26 +1,54 @@
package uca.iut.clermont.view
import android.app.Activity
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import uca.iut.clermont.R
import uca.iut.clermont.data.StubData
class MainActivity : Activity() {
private var manager = StubData()
class MainActivity : AppCompatActivity() {
var manager = StubData()
private lateinit var navController: NavController
@RequiresApi(Build.VERSION_CODES.R)
private fun hideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(
window,
window.decorView.findViewById(android.R.id.content)
).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
@RequiresApi(Build.VERSION_CODES.R)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
hideSystemUI()
setContentView(R.layout.activity_main)
supportActionBar?.hide()
manager.initTeams()
manager.initMatches()
val navHostFragment = findNavController(R.id.fragment) as NavHostFragment
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fragment) as NavHostFragment
navController = navHostFragment.navController
val navController = navHostFragment.navController
//val imageFirstTeam = findViewById<ImageView>(R.id.ImageFirstTeam)
/*Glide.with(this)
@ -29,4 +57,6 @@ class MainActivity : Activity() {
.into(imageFirstTeam)*/
}
}

@ -7,13 +7,18 @@ import uca.iut.clermont.R
import uca.iut.clermont.model.Match
import uca.iut.clermont.view.viewHolder.MatchHolder
class MatchesAdapter(val recentMatches: Array<Match>) : RecyclerView.Adapter<MatchHolder>() {
class MatchesAdapter(private val recentMatches: Array<Match>) : RecyclerView.Adapter<MatchHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MatchHolder {
return MatchHolder(LayoutInflater.from(parent.context).inflate(R.layout.cellule_match, parent, false))
return MatchHolder(
LayoutInflater.from(parent.context).inflate(R.layout.cellule_match, parent, false)
)
}
override fun onBindViewHolder(holder: MatchHolder, position: Int) {
holder.textView.text = recentMatches[position].id.toString()
holder.titleFirstTeam.text = recentMatches[position].homeTeam.name
holder.titleSecondTeam.text = recentMatches[position].awayTeam.name
holder.scoreHomeTeam.text = recentMatches[position].score.home.toString()
holder.scoreAwayTeam.text = recentMatches[position].score.away.toString()
}
override fun getItemCount() = recentMatches.size

@ -6,11 +6,18 @@ import androidx.recyclerview.widget.RecyclerView
import uca.iut.clermont.R
class MatchHolder(view: View) : RecyclerView.ViewHolder(view) {
val textView: TextView
val titleFirstTeam: TextView
val titleSecondTeam: TextView
val scoreHomeTeam: TextView
val scoreAwayTeam: TextView
init {
// Define click listener for the ViewHolder's View
textView = view.findViewById(R.id.TitleFirstTeam)
titleFirstTeam = view.findViewById(R.id.TitleFirstTeam)
titleSecondTeam = view.findViewById(R.id.TitleSecondTeam)
scoreHomeTeam = view.findViewById(R.id.ScoreHomeTeam)
scoreAwayTeam = view.findViewById(R.id.ScoreAwayTeam)
}

@ -6,15 +6,19 @@
android:layout_height="match_parent"
tools:context=".view.MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:defaultNavHost="true"
app:navGraph="@navigation/my_nav"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="parent"/>
app:navGraph="@navigation/my_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="350dp"

@ -25,7 +25,7 @@
android:maxLines="1"
android:text="Champions League - Groupe Stage: Matchay"
android:textColor="@color/title"
android:textSize="14dp"
android:textSize="14sp"
android:textStyle="bold" />
<LinearLayout
@ -52,34 +52,56 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textSize="16dp" />
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:layout_weight="0.4"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/mulish_black"
android:text="2-1"
android:textColor="@color/title"
android:textSize="43dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="@+id/ScoreHomeTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/mulish_black"
android:textColor="@color/title"
android:textSize="37sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/mulish_black"
android:text="-"
android:textColor="@color/title"
android:textSize="37sp" />
<TextView
android:id="@+id/ScoreAwayTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/mulish_black"
android:textColor="@color/title"
android:textSize="37sp" />
</LinearLayout>
<TextView
android:id="@+id/Duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@font/mulish_extrabold"
android:maxLines="2"
android:text="Full-time"
android:textColor="@color/title"
android:textSize="18dp" />
android:textSize="18sp" />
</LinearLayout>
@ -96,11 +118,12 @@
android:layout_height="60dp" />
<TextView
android:id="@+id/TitleSecondTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textSize="16dp" />
android:textSize="16sp" />
</LinearLayout>

@ -46,5 +46,4 @@
app:layout_constraintTop_toBottomOf="@+id/exitContainer" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save