Skip to content

Commit

Permalink
#30: Add 60+ & 20+ Stats & Handling single player view
Browse files Browse the repository at this point in the history
  • Loading branch information
Entreco committed Apr 15, 2018
1 parent 38f8688 commit 7517b58
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MatchStatAdapter @Inject constructor(private val navigator: Play01Navigato
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val binding = DataBindingUtil.inflate<WidgetListStatsBinding>(LayoutInflater.from(container.context), R.layout.widget_list_stats, container, false)
binding.team0 = items[position]
binding.team1 = items[(position + 1) % items.size]
binding.team1 = if(items.size >= 2) items[(position + 1) % items.size] else null
binding.navigator = navigator
binding.root.tag = position
binding.executePendingBindings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.entreco.dartsscorecard.play.stats

import android.databinding.BindingAdapter
import android.support.v4.view.ViewPager
import android.view.View
import nl.entreco.dartsscorecard.R

/**
Expand All @@ -18,5 +19,12 @@ class MatchStatBinding {
view.adapter = adapter
view.setCurrentItem(0, true)
}

@JvmStatic
@BindingAdapter("hideIfOneTeam")
fun hideIfOnlyOneTeam(view: View, hide: Boolean) {
view.visibility = if(hide) View.GONE else View.VISIBLE
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ class MatchStatPageAnimator(private val size: Float) {

val statFactor = page.width - size
val animator = MatchStatPageAnimatorHandler(binding.player1, binding.player2, binding.name1, binding.name2, binding.score,
binding.stat1, binding.stat2, binding.stat3, binding.stat4, binding.stat5, binding.stat6, binding.stat7, statFactor)
binding.stat1, binding.stat2, binding.stat3, binding.stat4, binding.stat5, binding.stat6, binding.stat7,
binding.stat8, binding.stat9, statFactor)
animator.transform(page, position)
}

internal class MatchStatPageAnimatorHandler(private val player1: View, private val player2: View,
private val name1: View, private val name2: View, private val score: View,
private val stat1: View, private val stat2: View, private val stat3: View,
private val stat4: View, private val stat5: View, private val stat6: View,
private val stat7: View, private val statFactor: Float) {
private val stat7: View, private val stat8: View, private val stat9: View,
private val statFactor: Float) {

// [-1. 1] range of position
fun transform(page: View, position: Float) {
Expand All @@ -47,6 +49,8 @@ class MatchStatPageAnimator(private val size: Float) {
animateStat(stat5, position, statFactor)
animateStat(stat6, position, statFactor)
animateStat(stat7, position, statFactor)
animateStat(stat8, position, statFactor)
animateStat(stat9, position, statFactor)
}

private fun stayPut(view: View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class MatchStatSlideAnimator(private val view: View, private val left: View?, pr
private val binding by lazy { DataBindingUtil.getBinding<WidgetListStatsBinding>(view)!! }
private val animator by lazy {
MatchStatSlideAnimatorHandler(binding.player1, binding.player2, binding.name1, binding.name2, binding.score,
binding.stat1, binding.stat2, binding.stat3, binding.stat4, binding.stat5, binding.stat6, binding.stat7)
binding.stat1, binding.stat2, binding.stat3, binding.stat4, binding.stat5, binding.stat6, binding.stat7,
binding.stat8, binding.stat9)
}

fun onSlide(slideOffset: Float) {
Expand All @@ -28,7 +29,7 @@ class MatchStatSlideAnimator(private val view: View, private val left: View?, pr
private val name1: View, private val name2: View, private val score: View,
private val stat1: View, private val stat2: View, private val stat3: View,
private val stat4: View, private val stat5: View, private val stat6: View,
private val stat7: View) {
private val stat7: View, private val stat8: View, private val stat9: View) {
fun slide(slideOffset: Float) {
// Fly In Players
player1.animate().translationX(slideOffset * -player1.width / 3).setDuration(0).start()
Expand All @@ -45,6 +46,8 @@ class MatchStatSlideAnimator(private val view: View, private val left: View?, pr
animateState(stat5.animate(), 5, slideOffset)
animateState(stat6.animate(), 6, slideOffset)
animateState(stat7.animate(), 7, slideOffset)
animateState(stat8.animate(), 8, slideOffset)
animateState(stat9.animate(), 9, slideOffset)
}

private fun animateState(anim: ViewPropertyAnimator, index: Int, slideOffset: Float) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TeamStatModel(val team: Team, private val stats: MutableList<Stat> = mutab
val n180 = ObservableField<String>(empty)
val n140 = ObservableField<String>(empty)
val n100 = ObservableField<String>(empty)
val n60 = ObservableField<String>(empty)
val n20 = ObservableField<String>(empty)
val hCo = ObservableField<String>(empty)
val co = ObservableField<String>(empty)
val breaks = ObservableField<String>(empty)
Expand All @@ -41,6 +43,8 @@ class TeamStatModel(val team: Team, private val stats: MutableList<Stat> = mutab
update180s()
update140s()
update100s()
update60s()
update20s()
updateHighestCheckout()
updateDoublePercentage()
updateBreaksMade()
Expand Down Expand Up @@ -72,6 +76,15 @@ class TeamStatModel(val team: Team, private val stats: MutableList<Stat> = mutab
}
}

private fun update20s() {
val value = stats.sumBy { it.n20 }
n20.set("$value")
}
private fun update60s() {
val value = stats.sumBy { it.n60 }
n60.set("$value")
}

private fun update100s() {
val value = stats.sumBy { it.n100 }
n100.set("$value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
android:layout_below="@id/description"
android:drawableEnd="@drawable/ic_play_video"
android:layout_centerHorizontal="true"
android:drawableTint="@color/gray"
android:drawableTint="@color/colorAccent"
android:drawablePadding="@dimen/small"
android:onClick="@{(v) -> viewModel.launchVideo(v)}"
app:textWithTags="@{@string/beta_video}"
Expand Down
104 changes: 86 additions & 18 deletions android/DartsScorecard/app/src/main/res/layout/widget_list_stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="team0"
type="nl.entreco.dartsscorecard.play.stats.TeamStatModel" />

<variable
name="team1"
type="nl.entreco.dartsscorecard.play.stats.TeamStatModel" />

<variable
name="navigator"
type="nl.entreco.dartsscorecard.play.Play01Navigator" />
Expand Down Expand Up @@ -44,8 +47,8 @@
android:background="@drawable/profile_bg"
android:contentDescription="@null"
android:onClick="@{(view) -> navigator.gotoTeamProfile(view, team0.team)}"
app:profileImage="@{team0.image}"
android:transitionName="profile" />
android:transitionName="profile"
app:profileImage="@{team0.image}" />

<android.support.v4.widget.Space
android:layout_width="0dp"
Expand All @@ -59,13 +62,15 @@
android:background="@drawable/profile_bg"
android:contentDescription="@null"
android:onClick="@{(view) -> navigator.gotoTeamProfile(view, team1.team)}"
app:profileImage="@{team1.image}"
android:transitionName="profile" />
android:transitionName="profile"
app:hideIfOneTeam="@{team1 == null}"
app:profileImage="@{team1.image}" />

<android.support.v4.widget.Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
android:layout_weight="1"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<!-- Results -->
Expand Down Expand Up @@ -100,12 +105,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/vs"
app:hideIfOneTeam="@{team1 == null}"
tools:text="VS" />

<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
android:layout_weight="1"
app:hideIfOneTeam="@{team1 == null}">

<TextView
android:id="@+id/name2"
Expand Down Expand Up @@ -146,7 +153,8 @@
style="@style/Main.Value"
android:layout_width="@dimen/match_stat_width"
android:layout_height="wrap_content"
android:text="@{team1.avg.toString()}" />
android:text="@{team1.avg.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
Expand All @@ -155,6 +163,60 @@
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team0.n20.toString()}" />

<TextView
style="@style/Main.Stat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/live_20s" />

<TextView
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.n20.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
android:id="@+id/stat3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team0.n60.toString()}" />

<TextView
style="@style/Main.Stat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/live_60s" />

<TextView
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.n60.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
android:id="@+id/stat4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/Main.Value"
android:layout_width="68dp"
Expand All @@ -172,11 +234,12 @@
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.n100.toString()}" />
android:text="@{team1.n100.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
android:id="@+id/stat3"
android:id="@+id/stat5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Expand All @@ -198,11 +261,12 @@
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.n140.toString()}" />
android:text="@{team1.n140.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
android:id="@+id/stat4"
android:id="@+id/stat6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Expand All @@ -225,11 +289,12 @@
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.n180.toString()}" />
android:text="@{team1.n180.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
android:id="@+id/stat5"
android:id="@+id/stat7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Expand All @@ -251,11 +316,12 @@
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.hCo.toString()}" />
android:text="@{team1.hCo.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
android:id="@+id/stat6"
android:id="@+id/stat8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Expand All @@ -277,11 +343,12 @@
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.co.toString()}" />
android:text="@{team1.co.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>

<LinearLayout
android:id="@+id/stat7"
android:id="@+id/stat9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Expand All @@ -303,7 +370,8 @@
style="@style/Main.Value"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@{team1.breaks.toString()}" />
android:text="@{team1.breaks.toString()}"
app:hideIfOneTeam="@{team1 == null}" />
</LinearLayout>


Expand Down
2 changes: 2 additions & 0 deletions android/DartsScorecard/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
<string name="live_180s">180\'s</string>
<string name="live_140s">140+</string>
<string name="live_100s">100+</string>
<string name="live_60s">60+</string>
<string name="live_20s">20+</string>
<string name="live_average">average</string>

<!-- Specific -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nl.entreco.dartsscorecard.play.stats
import android.content.Context
import android.content.res.Resources
import android.support.v4.view.ViewPager
import android.view.View
import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockito_kotlin.whenever
Expand All @@ -17,6 +18,7 @@ import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class MatchStatBindingTest {

@Mock private lateinit var mockView: View
@Mock private lateinit var mockResources: Resources
@Mock private lateinit var mockContext: Context
@Mock private lateinit var mockPager: ViewPager
Expand All @@ -30,4 +32,15 @@ class MatchStatBindingTest {
verify(mockPager).setPageTransformer(any(), any())
}

@Test
fun `it should set Visibility to GONE if hide(true)`() {
MatchStatBinding.hideIfOnlyOneTeam(mockView, true)
verify(mockView).visibility = View.GONE
}

@Test
fun `it should set Visibility to VISIBLE if hide(false)`() {
MatchStatBinding.hideIfOnlyOneTeam(mockView, false)
verify(mockView).visibility = View.VISIBLE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MatchStatPageAnimatorHandlerTest {
}

private fun givenSubject() {
subject = MatchStatPageAnimator.MatchStatPageAnimatorHandler(mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, 100F)
subject = MatchStatPageAnimator.MatchStatPageAnimatorHandler(mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView, mockView,100F)
}

private fun whenTransforming() {
Expand Down
Loading

0 comments on commit 7517b58

Please sign in to comment.