@@ -52,7 +52,6 @@ import dev.ricknout.rugbyranker.ranking.ui.WomensRankingViewModel
52
52
53
53
@AndroidEntryPoint
54
54
class SportFragment : Fragment () {
55
-
56
55
private val args: SportFragmentArgs by navArgs()
57
56
58
57
private val sport: Sport by lazy { args.sport }
@@ -99,11 +98,12 @@ class SportFragment : Fragment() {
99
98
resources.getInteger(android.R .integer.config_mediumAnimTime).toLong()
100
99
}
101
100
102
- private val onBackPressedCallback = object : OnBackPressedCallback (false ) {
103
- override fun handleOnBackPressed () {
104
- binding.viewPager.currentItem = POSITION_RANKINGS
101
+ private val onBackPressedCallback =
102
+ object : OnBackPressedCallback (false ) {
103
+ override fun handleOnBackPressed () {
104
+ binding.viewPager.currentItem = POSITION_RANKINGS
105
+ }
105
106
}
106
- }
107
107
108
108
override fun onCreate (savedInstanceState : Bundle ? ) {
109
109
super .onCreate(savedInstanceState)
@@ -120,7 +120,10 @@ class SportFragment : Fragment() {
120
120
return binding.root
121
121
}
122
122
123
- override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
123
+ override fun onViewCreated (
124
+ view : View ,
125
+ savedInstanceState : Bundle ? ,
126
+ ) {
124
127
super .onViewCreated(view, savedInstanceState)
125
128
postponeEnterTransition()
126
129
view.doOnPreDraw { startPostponedEnterTransition() }
@@ -144,20 +147,22 @@ class SportFragment : Fragment() {
144
147
rankingViewModel.setPredictions(predictions)
145
148
val currentPredictions = binding.predictionBar.getPredictions()
146
149
binding.predictionBar.setPredictions(predictions)
147
- val shouldTransition = when {
148
- currentPredictions.isEmpty() && ! predictions.isNullOrEmpty() -> true
149
- currentPredictions.isNotEmpty() && predictions.isNullOrEmpty() -> true
150
- else -> false
151
- }
150
+ val shouldTransition =
151
+ when {
152
+ currentPredictions.isEmpty() && ! predictions.isNullOrEmpty() -> true
153
+ currentPredictions.isNotEmpty() && predictions.isNullOrEmpty() -> true
154
+ else -> false
155
+ }
152
156
val shouldShowRankings = currentPredictions != predictions
153
157
if (shouldShowRankings) binding.viewPager.currentItem = POSITION_RANKINGS
154
158
if (! shouldTransition) return @observe
155
- val transition = MaterialContainerTransform ().apply {
156
- duration = transitionDuration
157
- interpolator = FastOutSlowInInterpolator ()
158
- scrimColor = Color .TRANSPARENT
159
- fadeMode = MaterialContainerTransform .FADE_MODE_OUT
160
- }
159
+ val transition =
160
+ MaterialContainerTransform ().apply {
161
+ duration = transitionDuration
162
+ interpolator = FastOutSlowInInterpolator ()
163
+ scrimColor = Color .TRANSPARENT
164
+ fadeMode = MaterialContainerTransform .FADE_MODE_OUT
165
+ }
161
166
transition.addTarget(binding.fab)
162
167
if (predictions.isNullOrEmpty()) {
163
168
transition.startView = binding.predictionBar
@@ -233,7 +238,6 @@ class SportFragment : Fragment() {
233
238
}.attach()
234
239
binding.appBar.tabLayout.addOnTabSelectedListener(
235
240
object : TabLayout .OnTabSelectedListener {
236
-
237
241
override fun onTabSelected (tab : TabLayout .Tab ? ) {
238
242
onBackPressedCallback.isEnabled = tab?.position != POSITION_RANKINGS
239
243
}
@@ -262,20 +266,20 @@ class SportFragment : Fragment() {
262
266
}
263
267
264
268
private fun setupPredictionBar () {
265
- binding.predictionBar.listener = object : PredictionBar . PredictionBarListener {
266
-
267
- override fun onAddPredictionClick () {
268
- findNavController().navigate(SportFragmentDirections .sportToPrediction(sport))
269
- }
269
+ binding.predictionBar.listener =
270
+ object : PredictionBar . PredictionBarListener {
271
+ override fun onAddPredictionClick () {
272
+ findNavController().navigate(SportFragmentDirections .sportToPrediction(sport))
273
+ }
270
274
271
- override fun onPredictionClick (prediction : Prediction ) {
272
- findNavController().navigate(SportFragmentDirections .sportToPrediction(sport, prediction, edit = true ))
273
- }
275
+ override fun onPredictionClick (prediction : Prediction ) {
276
+ findNavController().navigate(SportFragmentDirections .sportToPrediction(sport, prediction, edit = true ))
277
+ }
274
278
275
- override fun onRemovePredictionClick (prediction : Prediction ) {
276
- predictionViewModel.removePrediction(prediction)
279
+ override fun onRemovePredictionClick (prediction : Prediction ) {
280
+ predictionViewModel.removePrediction(prediction)
281
+ }
277
282
}
278
- }
279
283
}
280
284
281
285
private fun toggleLiveMatchTabIcon (show : Boolean ) {
@@ -312,14 +316,14 @@ class SportFragment : Fragment() {
312
316
}
313
317
314
318
inner class SportAdapter (fragment : Fragment ) : FragmentStateAdapter(fragment) {
315
-
316
- override fun createFragment ( position : Int ) = when (position) {
317
- POSITION_RANKINGS -> RankingFragment .newInstance(sport)
318
- POSITION_MATCHES_UNPLAYED -> MatchFragment .newInstance(sport, Status .UNPLAYED )
319
- POSITION_MATCHES_COMPLETE -> MatchFragment .newInstance(sport, Status .COMPLETE )
320
- POSITION_MATCHES_LIVE -> LiveMatchFragment .newInstance(sport)
321
- else -> throw IllegalArgumentException (" Position $position exceeds SportAdapter count" )
322
- }
319
+ override fun createFragment ( position : Int ) =
320
+ when (position) {
321
+ POSITION_RANKINGS -> RankingFragment .newInstance(sport)
322
+ POSITION_MATCHES_UNPLAYED -> MatchFragment .newInstance(sport, Status .UNPLAYED )
323
+ POSITION_MATCHES_COMPLETE -> MatchFragment .newInstance(sport, Status .COMPLETE )
324
+ POSITION_MATCHES_LIVE -> LiveMatchFragment .newInstance(sport)
325
+ else -> throw IllegalArgumentException (" Position $position exceeds SportAdapter count" )
326
+ }
323
327
324
328
override fun getItemCount () = 4
325
329
}
0 commit comments