Skip to content

Commit

Permalink
Merge pull request #22 from Entreco/develop
Browse files Browse the repository at this point in the history
Setup players merge to develop
  • Loading branch information
Entreco authored Jan 2, 2018
2 parents 075a9ee + d21ff7f commit 00b8d2a
Show file tree
Hide file tree
Showing 138 changed files with 4,081 additions and 220 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ before_install:
- openssl aes-256-cbc -K $encrypted_c5c67234e863_key -iv $encrypted_c5c67234e863_iv
-in android/DartsScorecard/scripts/dsc_keystore.enc -out android/DartsScorecard/scripts/dsc_keystore
-d
- openssl aes-256-cbc -K $encrypted_6f32c5c6093a_key -iv $encrypted_6f32c5c6093a_iv -in android/DartsScorecard/app/google-services.json.enc -out android/DartsScorecard/app/google-services.json -d
- openssl aes-256-cbc -K $encrypted_cba7e26bfac2_key -iv $encrypted_cba7e26bfac2_iv -in android/DartsScorecard/app/google-services.json.enc -out android/DartsScorecard/app/google-services.json -d

- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
Expand Down
2 changes: 2 additions & 0 deletions android/DartsScorecard/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ dependencies {
implementation "com.android.support:design:$support"
implementation "com.android.support.constraint:constraint-layout:$constraint"
implementation "com.google.firebase:firebase-core:$firebase"
implementation "com.google.android.gms:play-services-ads:$firebase"
implementation "android.arch.lifecycle:extensions:$architectureComponents"
implementation "android.arch.persistence.room:runtime:$architectureComponents"

// Test
testImplementation "junit:junit:$junit"
testImplementation "org.mockito:mockito-core:$mockito"
testImplementation "com.nhaarman:mockito-kotlin-kt1.1:$mockitoKotlin"
testImplementation "com.github.dpreussler:android-tdd-utils:$tddUtils"

// AndroidTest
androidTestImplementation "com.android.support.test:runner:$espressoRunner"
Expand Down
Binary file modified android/DartsScorecard/app/google-services.json.enc
Binary file not shown.
5 changes: 5 additions & 0 deletions android/DartsScorecard/app/src/debug/res/values/keys.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- AdMob -->
<string name="setup_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
</resources>
3 changes: 2 additions & 1 deletion android/DartsScorecard/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
</intent-filter>
</activity>
<activity android:name=".launch.LaunchActivity" />
<activity android:name=".setup.Setup01Activity" android:noHistory="true" />
<activity android:name=".setup.Setup01Activity" />
<activity android:name=".setup.edit.EditPlayerActivity" />
<activity android:name=".play.Play01Activity" />

</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nl.entreco.dartsscorecard

import android.app.Application
import com.google.android.gms.ads.MobileAds
import nl.entreco.dartsscorecard.di.application.AppComponent
import nl.entreco.dartsscorecard.di.application.AppModule
import nl.entreco.dartsscorecard.di.application.DaggerAppComponent
Expand All @@ -15,5 +16,10 @@ class App : Application() {
override fun onCreate() {
super.onCreate()
appComponent.inject(this)
initAdMob()
}

private fun initAdMob() {
MobileAds.initialize(this, "ca-app-pub-3793327349392749~1846337901")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import javax.inject.Inject
class Styler @Inject constructor(private val prefs: SharedPreferences, private val activity: Activity) {

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

fun get(): Int {
Expand All @@ -27,7 +28,10 @@ class Styler @Inject constructor(private val prefs: SharedPreferences, private v
}

private fun swap(style: Int): Int {
return if (style == R.style.Pdc) Style.BDO.style
else Style.PDC.style
return when (style) {
R.style.Pdc_2018 -> Style.BDO.style
R.style.Bdo -> Style.PDC.style
else -> Style.PDC_2018.style
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package nl.entreco.dartsscorecard.base

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater

/**
* Created by Entreco on 31/12/2017.
*/
abstract class TestableAdapter<T : RecyclerView.ViewHolder?> : RecyclerView.Adapter<T>() {

protected class LazyInflater(context: Context) {
val inflater: LayoutInflater by lazy { LayoutInflater.from(context) }
}

protected fun tryNotifyItemInserted(position: Int) {
try {
notifyItemInserted(position)
} catch (ignore: NullPointerException) {
}
}

protected fun tryNotifyItemChanged(position: Int) {
try {
notifyItemChanged(position)
} catch (ignore: NullPointerException) {
}
}

protected fun tryNotifyItemRangeRemoved(position: Int, count: Int) {
try {
notifyItemRangeRemoved(position, count)
} catch (ignore: NullPointerException) {
}
}

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)
} catch (ignore: NullPointerException) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package nl.entreco.dartsscorecard.di.setup

import dagger.Subcomponent
import nl.entreco.dartsscorecard.setup.edit.EditPlayerViewModel

/**
* Created by Entreco on 02/01/2018.
*/
@EditPlayerScope
@Subcomponent(modules = [(EditPlayerModule::class)])
interface EditPlayerComponent {
fun viewModel(): EditPlayerViewModel
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nl.entreco.dartsscorecard.di.setup

import dagger.Module
import dagger.Provides
import javax.inject.Named

/**
* Created by Entreco on 02/01/2018.
*/
@Module
class EditPlayerModule(private val suggestedName: String) {

@Provides
@Named("suggestion")
@EditPlayerScope
fun provideSuggestedName(): String {
return suggestedName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nl.entreco.dartsscorecard.di.setup

import javax.inject.Scope

/**
* Created by Entreco on 02/01/2018.
*/
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class EditPlayerScope
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package nl.entreco.dartsscorecard.di.setup

import dagger.Subcomponent
import nl.entreco.dartsscorecard.setup.Setup01ViewModel
import nl.entreco.dartsscorecard.setup.ad.AdViewModel
import nl.entreco.dartsscorecard.setup.players.PlayersViewModel
import nl.entreco.dartsscorecard.setup.settings.SettingsViewModel

/**
* Created by Entreco on 20/12/2017.
Expand All @@ -10,4 +13,7 @@ import nl.entreco.dartsscorecard.setup.Setup01ViewModel
@Subcomponent(modules = [(Setup01Module::class)])
interface Setup01Component {
fun viewModel(): Setup01ViewModel
fun players(): PlayersViewModel
fun ads(): AdViewModel
fun settings(): SettingsViewModel
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package nl.entreco.dartsscorecard.di.setup

import dagger.Module
import dagger.Provides
import nl.entreco.dartsscorecard.setup.Setup01Activity
import nl.entreco.dartsscorecard.setup.Setup01Navigator

/**
* Created by Entreco on 20/12/2017.
*/
@Module
class Setup01Module
class Setup01Module(private val activity: Setup01Activity) {
@Provides
@Setup01Scope
fun provideNavigator(): Setup01Navigator {
return Setup01Navigator(activity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ import nl.entreco.dartsscorecard.di.launch.LaunchComponent
import nl.entreco.dartsscorecard.di.launch.LaunchModule
import nl.entreco.dartsscorecard.di.play.Play01Component
import nl.entreco.dartsscorecard.di.play.Play01Module
import nl.entreco.dartsscorecard.di.setup.EditPlayerComponent
import nl.entreco.dartsscorecard.di.setup.EditPlayerModule
import nl.entreco.dartsscorecard.di.setup.Setup01Component
import nl.entreco.dartsscorecard.di.setup.Setup01Module
import nl.entreco.dartsscorecard.di.viewmodel.db.GameDbModule
import nl.entreco.dartsscorecard.di.viewmodel.db.PlayerDbModule
import nl.entreco.dartsscorecard.di.viewmodel.db.TurnDbModule
import nl.entreco.dartsscorecard.di.viewmodel.threading.ThreadingModule

/**
* Created by Entreco on 14/11/2017.
*/
@ActivityScope
@Subcomponent(modules = [(ViewModelModule::class), (ThreadingModule::class), (GameDbModule::class), (PlayerDbModule::class)])
@Subcomponent(modules = [(ViewModelModule::class), (ThreadingModule::class), (GameDbModule::class), (PlayerDbModule::class), (TurnDbModule::class)])
interface ViewModelComponent {
fun inject(activity: Activity)

// Where can this be used
fun plus(module: LaunchModule): LaunchComponent
fun plus(module: Setup01Module): Setup01Component
fun plus(module: EditPlayerModule): EditPlayerComponent
fun plus(module: Play01Module): Play01Component
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package nl.entreco.dartsscorecard.di.viewmodel.db

import dagger.Module
import dagger.Provides
import nl.entreco.dartsscorecard.di.viewmodel.ActivityScope
import nl.entreco.data.DscDatabase
import nl.entreco.data.db.turn.TurnMapper
import nl.entreco.data.play.repository.LocalTurnRepository
import nl.entreco.domain.repository.TurnRepository

/**
* Created by Entreco on 23/12/2017.
*/
@Module
class TurnDbModule {

@Provides
@ActivityScope
fun provideTurnMapper(): TurnMapper {
return TurnMapper()
}

@Provides
@ActivityScope
fun provideTurnRepository(db: DscDatabase, mapper: TurnMapper): TurnRepository {
return LocalTurnRepository(db, mapper)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import nl.entreco.domain.repository.RetrieveGameRequest
/**
* Created by Entreco on 19/12/2017.
*/
class LaunchBindings {
abstract class LaunchBindings {

companion object {
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Play01Animator(binding: ActivityPlay01Binding) {

private val fab = binding.includeInput?.fab!!
private val inputSheet = binding.includeInput?.inputSheet!!
private val inputResume = binding.includeInput?.inputResume!!
private val mainSheet = binding.includeMain?.mainSheet!!
private val behaviour = BottomSheetBehavior.from(inputSheet)
private val stat1 = binding.includeMain?.stat1!!
Expand Down Expand Up @@ -53,10 +54,25 @@ class Play01Animator(binding: ActivityPlay01Binding) {

// Also, Fly In Version
animateState(version.animate(), 8, slideOffset)

// Show Resume
inputResume.animate().alpha(1 - slideOffset).translationX(slideOffset * -inputResume.width).setDuration(0).start()
}

override fun onStateChanged(bottomSheet: View, newState: Int) {}
override fun onStateChanged(bottomSheet: View, newState: Int) {
when (newState) {
BottomSheetBehavior.STATE_COLLAPSED -> {
inputResume.setOnClickListener { expand() }
}
else -> inputResume.setOnClickListener(null)
}
}
})

expand()
}

private fun expand() {
behaviour.state = BottomSheetBehavior.STATE_EXPANDED
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import nl.entreco.dartsscorecard.base.BaseViewModel
import nl.entreco.dartsscorecard.play.score.GameLoadable
import nl.entreco.dartsscorecard.play.score.UiCallback
import nl.entreco.domain.Logger
import nl.entreco.domain.play.listeners.InputListener
import nl.entreco.domain.play.listeners.PlayerListener
import nl.entreco.domain.play.listeners.ScoreListener
import nl.entreco.domain.play.listeners.SpecialEventListener
import nl.entreco.domain.model.Game
import nl.entreco.domain.model.Next
import nl.entreco.domain.model.Score
import nl.entreco.domain.model.Turn
import nl.entreco.domain.model.players.Player
import nl.entreco.domain.play.listeners.InputListener
import nl.entreco.domain.play.listeners.PlayerListener
import nl.entreco.domain.play.listeners.ScoreListener
import nl.entreco.domain.play.listeners.SpecialEventListener
import nl.entreco.domain.play.usecase.Play01Usecase
import nl.entreco.domain.repository.RetrieveGameRequest
import nl.entreco.domain.repository.StoreTurnRequest
import javax.inject.Inject

/**
Expand All @@ -32,7 +33,7 @@ class Play01ViewModel @Inject constructor(private val playGameUsecase: Play01Use
playGameUsecase.loadGameAndStart(request,
{ game, teams ->
this.game = game
load.startWith(teams, request.create, this)
load.startWith(teams, game.scores, request.create, this)
},
{ err -> logger.e("err: $err") })
}
Expand All @@ -48,6 +49,11 @@ class Play01ViewModel @Inject constructor(private val playGameUsecase: Play01Use

override fun onTurnSubmitted(turn: Turn, by: Player) {
handleTurn(turn, by)
storeTurn(turn)
}

private fun storeTurn(turn: Turn) {
playGameUsecase.storeTurn(StoreTurnRequest(game.id, turn))
}

private fun handleTurn(turn: Turn, by: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import nl.entreco.domain.play.listeners.events.ThrownEvent
/**
* Created by Entreco on 02/12/2017.
*/
class InputBindings {
abstract class InputBindings {


companion object {
Expand Down
Loading

0 comments on commit 00b8d2a

Please sign in to comment.