Merge pull request 'fragment_navigation' (#4) from fragment_navigation into master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #4Gyroscope
commit
6a449a5c13
File diff suppressed because one or more lines are too long
@ -1,4 +0,0 @@
|
||||
<changelist name="Uncommitted_changes_before_Update_at_21_03_2023_09_05_[Changes]" date="1679385937643" recycled="true" deleted="true">
|
||||
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Update_at_21_03_2023_09_05_[Changes]/shelved.patch" />
|
||||
<option name="DESCRIPTION" value="Uncommitted changes before Update at 21/03/2023 09:05 [Changes]" />
|
||||
</changelist>
|
@ -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?
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package uca.iut.clermont.model
|
||||
|
||||
import java.util.Date
|
||||
import java.util.Calendar
|
||||
|
||||
class Season(
|
||||
val id: Int,
|
||||
val startDate: Date,
|
||||
val endDate: Date,
|
||||
val startDate: Calendar,
|
||||
val endDate: Calendar,
|
||||
val currentMatchday: Int,
|
||||
val winner: Int
|
||||
val winner: Int?
|
||||
)
|
@ -1,12 +0,0 @@
|
||||
package uca.iut.clermont.view
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import uca.iut.clermont.R
|
||||
|
||||
class FavoriteActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_favorite)
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package uca.iut.clermont.view
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ImageButton
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import uca.iut.clermont.R
|
||||
import uca.iut.clermont.model.Competition
|
||||
import uca.iut.clermont.model.Match
|
||||
import uca.iut.clermont.view.adapter.FavoritesAdapter
|
||||
import uca.iut.clermont.view.adapter.MatchesAdapter
|
||||
|
||||
class FavoriteFragment: Fragment() {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_favorite, container, false)
|
||||
|
||||
val competitions = (activity as MainActivity).manager.competitionsMgr.getItems()
|
||||
var buttonHome = view.findViewById<ImageButton>(R.id.buttonHome)
|
||||
val buttonTextFavorite = view.findViewById<Button>(R.id.buttonTextHome)
|
||||
|
||||
buttonHome.setOnClickListener {
|
||||
navigate()
|
||||
}
|
||||
|
||||
buttonTextFavorite.setOnClickListener {
|
||||
navigate()
|
||||
}
|
||||
|
||||
initRecyclerView(view, competitions)
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
fun navigate() {
|
||||
findNavController().navigate(R.id.homeFragment)
|
||||
}
|
||||
|
||||
private fun initRecyclerView(view: View, favorites: List<Competition>) {
|
||||
val recyclerViewFavorites = view.findViewById<RecyclerView>(R.id.listFavorites)
|
||||
with(recyclerViewFavorites) {
|
||||
layoutManager = LinearLayoutManager(view.context)
|
||||
adapter = FavoritesAdapter(favorites.toList().toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package uca.iut.clermont.view
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import uca.iut.clermont.R
|
||||
import uca.iut.clermont.data.StubData
|
||||
import uca.iut.clermont.view.adapter.MatchesAdapter
|
||||
|
||||
class HomeActivity : Activity() {
|
||||
|
||||
private var manager = StubData()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_home)
|
||||
//val imageFirstTeam = findViewById<ImageView>(R.id.ImageFirstTeam)
|
||||
|
||||
val adapterMatches = findViewById<RecyclerView>(R.id.ListRecentsMatches)
|
||||
|
||||
with(adapterMatches) {
|
||||
adapter = MatchesAdapter(manager.matchesMgr.getItems().toList().toTypedArray())
|
||||
}
|
||||
|
||||
adapterMatches.layoutManager = LinearLayoutManager(this)
|
||||
|
||||
adapterMatches
|
||||
|
||||
/*Glide.with(this)
|
||||
.load("https://crests.football-data.org/1765.svg")
|
||||
.error(R.drawable.imagenotfound)
|
||||
.into(imageFirstTeam)*/
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package uca.iut.clermont.view
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageButton
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
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() {
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
|
||||
val view = inflater.inflate(R.layout.fragment_home, container, false)
|
||||
val matches = (activity as MainActivity).manager.matchesMgr.getItems()
|
||||
|
||||
val buttonFavorite = view.findViewById<ImageButton>(R.id.buttonFavorite)
|
||||
|
||||
buttonFavorite.setOnClickListener {
|
||||
findNavController().navigate(R.id.favoriteFragment)
|
||||
}
|
||||
|
||||
initRecyclerView(view, matches)
|
||||
return view
|
||||
}
|
||||
|
||||
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())
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package uca.iut.clermont.view
|
||||
|
||||
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.fragment.NavHostFragment
|
||||
import uca.iut.clermont.R
|
||||
import uca.iut.clermont.data.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()
|
||||
manager.initCompetitions()
|
||||
|
||||
val navHostFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.fragment) as NavHostFragment
|
||||
|
||||
val navController = navHostFragment.navController
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package uca.iut.clermont.view
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.hardware.Sensor
|
||||
import android.hardware.SensorEvent
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.fragment.app.Fragment
|
||||
import uca.iut.clermont.R
|
||||
|
||||
|
||||
class StartFragment : Fragment(), SensorEventListener {
|
||||
|
||||
private lateinit var ball: ImageView
|
||||
private lateinit var sensorManager: SensorManager
|
||||
private lateinit var accelerometer: Sensor
|
||||
private var lastX = 0f
|
||||
private var lastY = 0f
|
||||
private var lastZ = 0f
|
||||
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
|
||||
val view = inflater.inflate(R.layout.fragment_start, container, false)
|
||||
|
||||
ball = view.findViewById(R.id.ball)
|
||||
|
||||
sensorManager = activity?.getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
|
||||
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL)
|
||||
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
|
||||
override fun onSensorChanged(event: SensorEvent) {
|
||||
val x = event.values[0]
|
||||
val y = event.values[1]
|
||||
val z = event.values[2]
|
||||
|
||||
val angleX = x / 9.81f
|
||||
val angleY = y / 9.81f
|
||||
|
||||
if (Math.abs(angleX) > 0.1) {
|
||||
// Déplacer la balle à droite ou à gauche en fonction de la direction du mouvement
|
||||
val deltaX = angleX * 20f // La vitesse de déplacement est de 20 pixels par seconde
|
||||
ObjectAnimator.ofFloat(ball, View.TRANSLATION_X, ball.x + deltaX).start()
|
||||
|
||||
// Faire tourner la balle pendant qu'elle se déplace
|
||||
ObjectAnimator.ofFloat(ball, View.ROTATION, -angleX * 70f).start()
|
||||
}
|
||||
|
||||
lastX = x
|
||||
lastY = y
|
||||
lastZ = z
|
||||
}
|
||||
|
||||
override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
sensorManager.unregisterListener(this)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package uca.iut.clermont.view.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import uca.iut.clermont.R
|
||||
import uca.iut.clermont.model.Competition
|
||||
import uca.iut.clermont.view.viewHolder.FavoriteHolder
|
||||
|
||||
class FavoritesAdapter(private val favoriteCompetition: Array<Competition> ) : RecyclerView.Adapter<FavoriteHolder>() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FavoriteHolder {
|
||||
return FavoriteHolder(
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.cellule_favorite, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: FavoriteHolder, position: Int) {
|
||||
holder.textFavorites.text = favoriteCompetition[position].name
|
||||
|
||||
Glide.with(holder.itemView.context)
|
||||
.load(favoriteCompetition[position].emblem)
|
||||
.error(R.drawable.imagenotfound)
|
||||
.into(holder.imageFavorites)
|
||||
}
|
||||
|
||||
override fun getItemCount() = favoriteCompetition.size
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package uca.iut.clermont.view.viewHolder
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import uca.iut.clermont.R
|
||||
|
||||
class FavoriteHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val imageFavorites: ImageView
|
||||
val textFavorites: TextView
|
||||
|
||||
init {
|
||||
imageFavorites = view.findViewById(R.id.imageFavorites)
|
||||
textFavorites = view.findViewById(R.id.textFavorites)
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.8 KiB |
@ -0,0 +1,23 @@
|
||||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
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="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" />
|
||||
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ball"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ball"
|
||||
android:layout_centerInParent="true"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/my_nav"
|
||||
app:startDestination="@id/startFragment">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/startFragment"
|
||||
android:name="uca.iut.clermont.view.StartFragment"
|
||||
android:label="StartFragment" >
|
||||
<action
|
||||
android:id="@+id/action_startFragment_to_homeFragment2"
|
||||
app:destination="@id/homeFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/homeFragment"
|
||||
android:name="uca.iut.clermont.view.HomeFragment"
|
||||
android:label="HomeFragment">
|
||||
<action
|
||||
android:id="@+id/action_homeFragment_to_favoriteFragment"
|
||||
app:destination="@id/favoriteFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/favoriteFragment"
|
||||
android:name="uca.iut.clermont.view.FavoriteFragment"
|
||||
android:label="FavoriteFragment">
|
||||
<action
|
||||
android:id="@+id/action_favoriteFragment_to_homeFragment"
|
||||
app:destination="@id/homeFragment" />
|
||||
</fragment>
|
||||
|
||||
</navigation>
|
Loading…
Reference in new issue