Skip to content

Commit

Permalink
#30: Moved Donate Explanation to seperate layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Entreco committed May 21, 2018
1 parent 28dca04 commit 6253b06
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.entreco.dartsscorecard.beta.donate

import android.databinding.BindingAdapter
import android.databinding.DataBindingUtil
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
Expand Down Expand Up @@ -35,9 +36,7 @@ class DonateBindings {
}

internal fun clearPreviousViewsIfEmpty(viewGroup: ViewGroup) {
val count = (0 until viewGroup.childCount).count { viewGroup.getChildAt(it) is TextView }
if (count == 0) (0 until viewGroup.childCount).forEach { viewGroup.removeViewAt(it) }
else (1 until viewGroup.childCount).forEach { viewGroup.removeViewAt(it) }
viewGroup.removeAllViews()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import nl.entreco.domain.beta.vote.SubmitVoteRequest
import nl.entreco.domain.beta.vote.SubmitVoteResponse
import nl.entreco.domain.beta.vote.SubmitVoteUsecase
import javax.inject.Inject
import kotlin.math.min

/**
* Created by entreco on 07/02/2018.
Expand Down Expand Up @@ -58,7 +59,7 @@ class VoteViewModel @Inject constructor(private val submitVoteUsecase: SubmitVot
val betaModel = feature.get()!!
val currentFeature = betaModel.feature
if (allowedToVote(betaModel, currentFeature)) {
feature.set(BetaModel(currentFeature.copy(votes = currentFeature.votes + amount)))
feature.set(BetaModel(currentFeature.copy(votes = min(currentFeature.required ,currentFeature.votes + amount))))
votes.add(currentFeature.ref)
analytics.trackViewFeature(currentFeature)
submitVoteUsecase.exec(SubmitVoteRequest(betaModel.feature.ref, amount), onVoteSuccess(currentFeature), onVoteFailed(currentFeature))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
type="nl.entreco.dartsscorecard.beta.donate.DonateViewModel" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
style="@style/Beta.Explain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textWithTags="@{@string/votes_explained(total)}"
tools:text="@string/votes_explained" />

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -24,13 +35,6 @@
app:donations="@{viewModel.donations}"
app:viewModel="@{viewModel}">

<TextView
style="@style/Beta.Explain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textWithTags="@{@string/votes_explained(total)}"
tools:text="@string/votes_explained" />

<TextView
style="@style/Beta.Description"
android:layout_width="match_parent"
Expand All @@ -39,4 +43,6 @@
android:text="@string/err_unable_to_donate" />

</LinearLayout>

</LinearLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,8 @@ class DonateBindingsTest {
@Mock private lateinit var mockViewGroup: ViewGroup

@Test
fun `it should clear previous views when list is NOT empty`() {
whenever(mockViewGroup.childCount).thenReturn(5)
fun `it should clear previous views`() {
DonateBindings.clearPreviousViewsIfEmpty(mockViewGroup)
verify(mockViewGroup).removeViewAt(1)
verify(mockViewGroup).removeViewAt(2)
verify(mockViewGroup).removeViewAt(3)
verify(mockViewGroup).removeViewAt(4)
}

@Test
fun `it should remove empty View when list is empty`() {
whenever(mockViewGroup.childCount).thenReturn(0)
DonateBindings.clearPreviousViewsIfEmpty(mockViewGroup)
verify(mockViewGroup, never()).removeViewAt(0)
}

@Test
fun `it should remove empty View when list has 1 item`() {
whenever(mockViewGroup.childCount).thenReturn(2)
DonateBindings.clearPreviousViewsIfEmpty(mockViewGroup)
verify(mockViewGroup).removeViewAt(1)
verify(mockViewGroup).removeAllViews()
}
}

0 comments on commit 6253b06

Please sign in to comment.