Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Entreco committed Jan 30, 2018
2 parents 347794f + 1e556e3 commit 92c8d3c
Show file tree
Hide file tree
Showing 53 changed files with 621 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ class Styler @Inject constructor(private val prefs: SharedPreferences, private v

enum class Style(@StyleRes val style: Int) {
PDC_2018(R.style.Pdc_2018),
BDO_2018(R.style.Bdo_2018),
BDO(R.style.Bdo),
PDC(R.style.Pdc);
}

fun get(): Int {
return prefs.getInt("curStyle", Style.PDC.style)
return prefs.getInt("curStyle", Style.PDC_2018.style)
}

fun switch() {
val curStyle = prefs.getInt("curStyle", Style.PDC.style)
val curStyle = prefs.getInt("curStyle", Style.PDC_2018.style)
prefs.edit().putInt("curStyle", swap(curStyle)).apply()
activity.recreate()
}

private fun swap(style: Int): Int {
return when (style) {
R.style.Pdc_2018 -> Style.BDO.style
R.style.Pdc_2018 -> Style.BDO_2018.style
R.style.Bdo_2018 -> Style.BDO.style
R.style.Bdo -> Style.PDC.style
else -> Style.PDC_2018.style
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class Play01Activity : ViewModelActivity() {

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_play_settings -> swapStyle()
R.id.menu_play_settings -> {
swapStyle()
viewModel.loading.set(true)
}
}
return super.onOptionsItemSelected(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nl.entreco.dartsscorecard.play.input
import android.databinding.BindingAdapter
import android.support.design.widget.FloatingActionButton
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.TextView
import nl.entreco.dartsscorecard.R
import nl.entreco.domain.play.listeners.events.BustEvent
Expand Down Expand Up @@ -55,6 +56,15 @@ abstract class InputBindings {
}


@JvmStatic
@BindingAdapter("ask4finish")
fun showAsk4Finish(view: View, shouldAsk: Boolean) {
view.visibility = if (shouldAsk) View.VISIBLE else View.GONE
view.pivotY = if (shouldAsk) 0F else view.height.toFloat()
view.animate().setInterpolator(AccelerateDecelerateInterpolator()).setDuration(DEFAULT_ANIMATION_TIME).scaleY(if (shouldAsk) 1F else 0F).start()
}


@JvmStatic
@BindingAdapter("special")
fun showSpecialEvents(view: TextView, event: SpecialEvent?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class InputViewModel @Inject constructor(private val analytics: Analytics, priva
val hintProvider = ObservableField<HintKeyProvider>(HintKeyProvider(toggle.get()))
val special = ObservableField<SpecialEvent?>()
val required = ObservableField<Score>()
val finalTurn = ObservableField<Turn?>()
val dartsLeft = ObservableInt()
val resumeDescription = ObservableInt(R.string.game_on)

Expand Down Expand Up @@ -64,7 +65,7 @@ class InputViewModel @Inject constructor(private val analytics: Analytics, priva
scoredTxt.set(scoredTxt.get().dropLast(1))
}

fun clear() : Boolean {
fun clear(): Boolean {
scoredTxt.set("")
return true
}
Expand All @@ -91,7 +92,7 @@ class InputViewModel @Inject constructor(private val analytics: Analytics, priva
submit(scored, listener)
}

fun onUndoPressed(listener: InputListener){
fun onUndoPressed(listener: InputListener) {
listener.onUndo()
clearScoreInput()
}
Expand Down Expand Up @@ -136,10 +137,27 @@ class InputViewModel @Inject constructor(private val analytics: Analytics, priva
}

private fun submitScore(turn: Turn, listener: InputListener) {
listener.onTurnSubmitted(turn.copy(), nextUp?.player!!)
askForDartsAtFinish(turn, required.get(), listener)
}

private fun askForDartsAtFinish(turn: Turn, score: Score?, listener: InputListener) {
if (turn.total() == score?.score && turn.hasZeros()) {
finalTurn.set(turn)
} else {
done(turn, listener)
}
}

fun onFinishWith(dartsUsed: Int, listener: InputListener) {
val turn = finalTurn.get()?.setDartsUsedForFinish(dartsUsed)!!
done(turn, listener)
}

private fun done(turn: Turn, listener: InputListener) {
listener.onTurnSubmitted(turn.copy(), nextUp?.player!!)
this.scoredTxt.set(turn.total().toString())
this.analytics.trackAchievement("scored: $turn")
clearScoreInput()
}

private fun clearScoreInput() {
Expand All @@ -156,6 +174,7 @@ class InputViewModel @Inject constructor(private val analytics: Analytics, priva
nextDescription.set(descriptionFromNext(next))
resumeDescription.set(resumeDescriptionFromNext(next))
current.set(next.player)
finalTurn.set(null)
turn = Turn()
dartsLeft.set(turn.dartsLeft())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TeamScoreViewModel(val team: Team, startScore: Score,

fun threw(turn: Turn, player: Player) {
if (team.contains(player)) {
scored.set(turn.total())
scored.set(this.score.get().score - turn.total())
calculateFinish(this.score.get(), player, turn)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package nl.entreco.dartsscorecard.play.stats

import android.databinding.ObservableArrayList
import android.databinding.ObservableArrayMap
import android.databinding.ObservableField
import android.databinding.ObservableInt
import android.widget.AdapterView
import nl.entreco.dartsscorecard.base.BaseViewModel
import nl.entreco.dartsscorecard.play.score.GameLoadedNotifier
import nl.entreco.dartsscorecard.play.score.UiCallback
Expand All @@ -15,15 +19,32 @@ import javax.inject.Inject
/**
* Created by entreco on 11/01/2018.
*/
class MatchStatViewModel @Inject constructor(
private val fetchGameStatsUsecase: FetchGameStatsUsecase,
private val fetchGameStatUsecase: FetchGameStatUsecase,
private val logger: Logger
) : BaseViewModel(), GameLoadedNotifier<Play01Response>, StatListener {
class MatchStatViewModel @Inject constructor(private val fetchGameStatsUsecase: FetchGameStatsUsecase, private val fetchGameStatUsecase: FetchGameStatUsecase, private val logger: Logger) : BaseViewModel(), GameLoadedNotifier<Play01Response>, StatListener {

val team0 = ObservableField<TeamStatModel>()
val team1 = ObservableField<TeamStatModel>()
val teamEntries = ObservableArrayList<String>()
val teamStats = ObservableArrayMap<Int, TeamStatModel>()

val team0Index = ObservableInt()
val team1Index = ObservableInt()

private lateinit var teams: Array<Team>

fun onTeamStat0Selected(adapter: AdapterView<*>, index: Int){
val resolved = adapter.getItemAtPosition(index).toString()
val selected = teams.indexOfFirst { it.toString().toLowerCase() == resolved.toLowerCase() }
team0.set(teamStats[selected])
team0Index.set(selected)
}

fun onTeamStat1Selected(adapter: AdapterView<*>, index: Int){
val resolved = adapter.getItemAtPosition(index).toString()
val selected = teams.indexOfFirst { it.toString().toLowerCase() == resolved.toLowerCase() }
team1.set(teamStats[selected])
team1Index.set(selected)
}

override fun onLoaded(teams: Array<Team>, scores: Array<Score>, info: Play01Response, uiCallback: UiCallback?) {
initializeStats(teams)
fetchGameStatsUsecase.exec(FetchGameStatsRequest(info.game.id, info.teamIds),
Expand All @@ -33,10 +54,16 @@ class MatchStatViewModel @Inject constructor(

private fun initializeStats(teams: Array<Team>) {
this.teamStats.clear()
this.teamEntries.clear()
this.teams = teams

teams.forEachIndexed { index, team ->
teamStats[index] = TeamStatModel(team)
}

teamEntries.addAll(teams.map { it.toString().capitalize() })
team0Index.set(0)
team1Index.set(if(teams.size > 1) 1 else 0)
}

private fun onStatsFetched(teams: Array<Team>): (FetchGameStatsResponse) -> Unit {
Expand Down
2 changes: 1 addition & 1 deletion android/DartsScorecard/app/src/main/res/drawable/score.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_stop"
android:startColor="?attr/grad_score_start" />
</shape>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="#ffffff"
android:startColor="#eeeeee" />
</shape>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<item>
<shape>
<gradient
android:angle="-90"
android:endColor="?attr/grad_score_header_stop"
android:startColor="?attr/grad_score_header_start" />
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_footer_stop"
android:startColor="?attr/grad_score_footer_start" />
<corners android:bottomLeftRadius="@dimen/def" android:bottomRightRadius="@dimen/def" />
</shape>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_header_stop"
android:startColor="?attr/grad_score_header_start" />
<corners android:topLeftRadius="@dimen/def" android:topRightRadius="@dimen/def" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_header_stop"
android:startColor="?attr/grad_score_header_start" />
</shape>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_name_stop"
android:startColor="?attr/grad_score_name_start" />
</shape>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_pts_stop"
android:startColor="?attr/grad_score_pts_start" />
</shape>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_pts_stop"
android:startColor="?attr/grad_score_pts_start" />
</shape>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_name_stop"
android:startColor="?attr/grad_score_name_start" />

<stroke android:color="?attr/statBorderColor" android:width="1px"/>
</shape>
</item>
<item
android:drawable="@drawable/ic_spinner"
android:gravity="bottom|end" />
<item android:drawable="@drawable/highlight" />
</layer-list>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_name_stop"
android:startColor="?attr/grad_score_name_start" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_hint_start"
android:startColor="?attr/grad_score_hint_stop" />
<corners
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<item>
<shape>
<gradient
android:angle="-90"
android:angle="?attr/gradient_angle"
android:endColor="?attr/grad_score_header_start"
android:startColor="?attr/grad_score_header_stop" />
<corners android:radius="16dp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
android:layout_height="match_parent"
android:orientation="horizontal">


<View
android:layout_width="0dp"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<TextView
style="@style/Setup.Entry.Txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:gravity="start"
android:text="@string/start_score" />

Expand Down
Loading

0 comments on commit 92c8d3c

Please sign in to comment.