Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Entreco committed Jan 6, 2018
2 parents 9a8b524 + 5154bbf commit 1557399
Show file tree
Hide file tree
Showing 36 changed files with 449 additions and 174 deletions.
13 changes: 10 additions & 3 deletions android/DartsScorecard/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@
</intent-filter>
</activity>
<activity android:name=".launch.LaunchActivity" />
<activity android:name=".setup.Setup01Activity" />
<activity android:name=".setup.edit.EditPlayerActivity" />
<activity android:name=".play.Play01Activity" />
<activity
android:name=".setup.Setup01Activity"
android:parentActivityName=".launch.LaunchActivity" />
<activity
android:name=".setup.edit.EditPlayerActivity"
android:parentActivityName=".setup.Setup01Activity"
android:windowSoftInputMode="adjustResize"/>
<activity
android:name=".play.Play01Activity"
android:parentActivityName=".launch.LaunchActivity" />

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ abstract class TestableAdapter<T : RecyclerView.ViewHolder?> : RecyclerView.Adap
}
}

protected fun tryNotifyItemRangeInserted(position: Int, count: Int) {
try {
notifyItemRangeInserted(position, count)
} catch (ignore: NullPointerException) {
}
}

protected fun tryNotifyItemRangeChanged(position: Int, count: Int) {
try {
notifyItemRangeChanged(position, count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.annotation.StringRes
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import nl.entreco.dartsscorecard.App
import nl.entreco.dartsscorecard.R
import nl.entreco.dartsscorecard.di.viewmodel.ViewModelComponent
import nl.entreco.dartsscorecard.di.viewmodel.ViewModelModule

Expand Down Expand Up @@ -52,4 +55,10 @@ abstract class ViewModelActivity : AppCompatActivity() {
protected fun swapStyle() {
styler.switch()
}

protected fun initToolbar(toolbar: Toolbar, @StringRes title: Int = R.string.app_name, showHomeEnabled: Boolean = true) {
setSupportActionBar(toolbar)
setTitle(title)
supportActionBar?.setDisplayHomeAsUpEnabled(showHomeEnabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import nl.entreco.dartsscorecard.R
Expand Down Expand Up @@ -39,11 +40,16 @@ class Play01Activity : ViewModelActivity() {
initGame()
}

initToolbar(toolbar(binding))
resumeGame()
}

private fun initGame() {
viewModel.load(retrieveSetup(), scoreViewModel)
viewModel.load(retrieveSetup(intent), scoreViewModel)
}

private fun toolbar(binding: ActivityPlay01Binding): Toolbar {
return binding.includeToolbar?.toolbar!!
}

private fun resumeGame() {
Expand All @@ -65,13 +71,14 @@ class Play01Activity : ViewModelActivity() {
return super.onOptionsItemSelected(item)
}

private fun retrieveSetup(): RetrieveGameRequest {
return RetrieveGameRequest(intent.getLongExtra("gameId", -1),
TeamIdsString(intent.getStringExtra("teamIds")),
intent.getParcelableExtra("exec"))
}

companion object {
@JvmStatic
fun retrieveSetup(intent: Intent): RetrieveGameRequest {
return RetrieveGameRequest(intent.getLongExtra("gameId", -1),
TeamIdsString(intent.getStringExtra("teamIds")),
intent.getParcelableExtra("exec"))
}

@JvmStatic
fun startGame(context: Context, retrieve: RetrieveGameRequest) {
val intent = Intent(context, Play01Activity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import android.support.v4.graphics.ColorUtils
import android.util.Log
import android.util.TypedValue
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.OvershootInterpolator
import android.view.animation.AccelerateInterpolator
import android.view.animation.DecelerateInterpolator
import android.widget.ImageView
import android.widget.TextView
import nl.entreco.dartsscorecard.R
Expand All @@ -35,33 +36,44 @@ abstract class TeamScoreBindings {
val diff = oldScore - score
when (diff) {
180 -> handle180(view)
0 -> {}
else -> { clear(view, 0)}
0 -> { }
else -> {
clear(view)
}
}
}

private fun clear(view: TextView, delay: Long) {
view.animate().cancel()
view.animate().translationX(200F).setStartDelay(delay).withEndAction({
view.setText( R.string.empty )
}).setDuration(DEFAULT_ANIMATION_TIME).start()
private fun clear(view: TextView, delay: Long = 0) {
view.animate().scaleY(0F).setStartDelay(delay)
.setInterpolator(DecelerateInterpolator())
.withStartAction {
view.pivotY = view.height.toFloat()
}
.withEndAction({
view.scaleY = 0F
view.translationY = 0F
view.setText(R.string.empty)
}).setDuration(if (delay == 0L) 0 else DEFAULT_ANIMATION_TIME).start()
}

private fun handle180(view: TextView) {
view.animate().cancel()
view.setText( R.string.score_180 )
view.animate().translationX(0F).setInterpolator(OvershootInterpolator()).setDuration(DEFAULT_ANIMATION_TIME)
view.setText(R.string.score_180)
view.animate().scaleY(1F).setDuration(DEFAULT_ANIMATION_TIME)
.setInterpolator(AccelerateInterpolator())
.withStartAction {
view.scaleY = 0F
view.pivotY = 0F
}
.withEndAction({
val howLong = 1200L
animateColor(view, R.attr.colorOneEighty, R.attr.scoreText, howLong)
clear(view, howLong)
animateColor(view, R.attr.colorOneEighty, R.attr.scoreText, 1200L)
clear(view, 1200L)
}).start()
}

private fun animateColor(view: TextView, attr: Int, attr2: Int, duration: Long) {
view.animate().setDuration(duration / 3)
.setStartDelay(duration / 3)
.withStartAction{ view.setTextColor(fromAttr(view.context, attr)) }
.withStartAction { view.setTextColor(fromAttr(view.context, attr)) }
.withEndAction { view.setTextColor(fromAttr(view.context, attr2)) }
.start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.widget.Toolbar
import nl.entreco.dartsscorecard.R
import nl.entreco.dartsscorecard.base.ViewModelActivity
import nl.entreco.dartsscorecard.databinding.ActivitySetup01Binding
Expand Down Expand Up @@ -35,6 +36,11 @@ class Setup01Activity : ViewModelActivity() {
binding.navigator = navigator

navigator.onAddNewPlayer(0)
initToolbar(toolbar(binding), R.string.title_setup)
}

private fun toolbar(binding: ActivitySetup01Binding): Toolbar {
return binding.includeToolbar?.toolbar!!
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.entreco.dartsscorecard.setup.edit

import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.widget.Toolbar
import nl.entreco.dartsscorecard.R
import nl.entreco.dartsscorecard.base.ViewModelActivity
import nl.entreco.dartsscorecard.databinding.ActivityEditPlayerBinding
Expand All @@ -15,25 +16,24 @@ class EditPlayerActivity : ViewModelActivity() {

private val component: EditPlayerComponent by componentProvider { it.plus(EditPlayerModule(getSuggestedName())) }
private val viewModel: EditPlayerViewModel by viewModelProvider { component.viewModel() }
private val navigator: EditPlayerNavigator by lazy{ EditPlayerNavigator(this)}
private val navigator: EditPlayerNavigator by lazy { EditPlayerNavigator(this) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = DataBindingUtil.setContentView<ActivityEditPlayerBinding>(this, R.layout.activity_edit_player)
binding.viewModel = viewModel
binding.navigator = navigator
initToolbar()
}

private fun initToolbar() {
setTitle(R.string.title_select_player)
supportActionBar?.setDisplayShowHomeEnabled(true)
initToolbar(toolbar(binding), R.string.title_select_player)
}

private fun getSuggestedName(): String {
return intent.getStringExtra("suggestion")
}

private fun toolbar(binding: ActivityEditPlayerBinding): Toolbar {
return binding.includeToolbar?.toolbar!!
}

override fun onBackPressed() {
navigator.onBackPressed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package nl.entreco.dartsscorecard.setup.edit

import android.databinding.ObservableArrayList
import android.databinding.ObservableField
import android.support.design.widget.Snackbar
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import nl.entreco.dartsscorecard.R
import nl.entreco.dartsscorecard.base.BaseViewModel
import nl.entreco.domain.model.players.Player
import nl.entreco.domain.setup.usecase.CreatePlayerRequest
Expand Down Expand Up @@ -80,12 +83,15 @@ class EditPlayerViewModel @Inject constructor(private val createPlayerUsecase: C
}

fun onActionDone(view: TextView, action: Int, navigator: EditPlayerNavigator): Boolean {
if (action == EditorInfo.IME_ACTION_DONE) {
val existing = allPlayers.findLast { it.name.toLowerCase() == view.text.toString() }
if (donePressed(action)) {
val desiredName = view.text.toString().toLowerCase()
val existing = allPlayers.findLast {
it.name.toLowerCase() == desiredName
}
if (existing == null) {
createPlayerUsecase.exec(CreatePlayerRequest(view.text.toString(), 16),
createPlayerUsecase.exec(CreatePlayerRequest(desiredName, 16),
onCreateSuccess(navigator),
onCreateFailed())
onCreateFailed(view.rootView))
} else {
navigator.onSelected(existing)
}
Expand All @@ -94,8 +100,12 @@ class EditPlayerViewModel @Inject constructor(private val createPlayerUsecase: C
return false
}

private fun donePressed(action: Int) = action == EditorInfo.IME_ACTION_DONE

private fun onCreateSuccess(navigator: EditPlayerNavigator): (Player) -> Unit =
{ player -> navigator.onSelected(player) }

private fun onCreateFailed(): (Throwable) -> Unit = { }
private fun onCreateFailed(view : View): (Throwable) -> Unit = {
Snackbar.make(view, R.string.err_unable_to_create_player, Snackbar.LENGTH_SHORT).show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class SettingsViewModel @Inject constructor(fetchPrefs: FetchPreferredSettingsUs
fetchPrefs.exec { preferred.set(it) }
}

private val min = preferred.get().min
val startScoreIndex = ObservableInt(preferred.get().score)
val min = preferred.get().min
val max = preferred.get().max
val startScore = ObservableInt()
val numSets = ObservableInt(preferred.get().sets)
Expand All @@ -46,18 +46,18 @@ class SettingsViewModel @Inject constructor(fetchPrefs: FetchPreferredSettingsUs

fun onSetsProgressChanged(sets: Int) {
if (sets in min..max) {
numSets.set(sets + 1)
numSets.set(sets)
}
}

fun onLegsProgressChanged(legs: Int) {
if (legs in min..max) {
numLegs.set(legs + 1)
numLegs.set(legs)
}
}

fun setupRequest(): CreateGameRequest {
storePrefs.exec(StoreSettingsRequest(numSets.get() - 1, numLegs.get() - 1, min, max, startScoreIndex.get()))
return CreateGameRequest(startScore.get(), 0, numLegs.get(), numSets.get())
storePrefs.exec(StoreSettingsRequest(numSets.get(), numLegs.get(), min, max, startScoreIndex.get()))
return CreateGameRequest(startScore.get(), 0, numLegs.get() + 1, numSets.get() + 1)
}
}
Loading

0 comments on commit 1557399

Please sign in to comment.