Skip to content

Commit

Permalink
Close #87 - Added support for RC based ban list
Browse files Browse the repository at this point in the history
  • Loading branch information
r0adkll committed Sep 11, 2019
1 parent dc03984 commit d28f51f
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'io.fabric'
def GIT_SHA = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def GIT_TAG = 'git describe --tags'.execute([], project.rootDir).text.trim()

def VERSION_NAME = "1.9.1"
def VERSION_NAME = "1.9.2"


ext.gitVersioner = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import com.r0adkll.deckbuilder.arch.domain.features.cards.model.PokemonCard
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Rule
import io.pokemontcg.model.SuperType


class BasicRule : Rule {


override fun check(cards: List<PokemonCard>): Int? {
val basicCard = cards.find {
it.supertype == SuperType.POKEMON && it.evolvesFrom == null
Expand All @@ -20,4 +18,4 @@ class BasicRule : Rule {
R.string.validation_rule_basic
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.r0adkll.deckbuilder.arch.data.features.validation.model


import com.r0adkll.deckbuilder.R
import com.r0adkll.deckbuilder.arch.domain.features.cards.model.PokemonCard
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Rule
import io.pokemontcg.model.SubType
import io.pokemontcg.model.SuperType


class DuplicateRule : Rule {

override fun check(cards: List<PokemonCard>): Int? {
Expand All @@ -22,8 +20,7 @@ class DuplicateRule : Rule {
}
}


companion object {
private const val MAX_COUNT = 4
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.r0adkll.deckbuilder.arch.data.features.validation.model


import com.r0adkll.deckbuilder.R
import com.r0adkll.deckbuilder.arch.domain.features.cards.model.PokemonCard
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Rule


class PrismStarRule : Rule {

override fun check(cards: List<PokemonCard>): Int? {
Expand All @@ -19,8 +17,7 @@ class PrismStarRule : Rule {
}
}


companion object {
private const val MAX_COUNT = 1
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.r0adkll.deckbuilder.arch.data.features.validation.model


import com.r0adkll.deckbuilder.R
import com.r0adkll.deckbuilder.arch.domain.features.cards.model.PokemonCard
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Rule


class SizeRule : Rule {

private val maxSize = 60
Expand All @@ -17,4 +15,4 @@ class SizeRule : Rule {
R.string.validation_rule_max_size
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.r0adkll.deckbuilder.arch.data.features.validation.repository


import android.annotation.SuppressLint
import com.r0adkll.deckbuilder.arch.domain.features.remote.Remote
import com.r0adkll.deckbuilder.arch.domain.features.cards.model.PokemonCard
import com.r0adkll.deckbuilder.arch.domain.features.cards.repository.CardRepository
import com.r0adkll.deckbuilder.arch.domain.features.decks.repository.DeckRepository
import com.r0adkll.deckbuilder.arch.domain.features.editing.repository.EditRepository
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.BanList
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Rule
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Validation
import com.r0adkll.deckbuilder.arch.domain.features.validation.repository.DeckValidator
Expand Down Expand Up @@ -36,11 +38,13 @@ class DefaultDeckValidator @Inject constructor(
}


@SuppressLint("DefaultLocale")
override fun validate(cards: List<PokemonCard>): Observable<Validation> {
return cardRepository.getExpansions()
.onErrorReturnItem(emptyList())
.map { expansions ->
val reprints = remote.reprints
val banList = remote.banList ?: BanList()

// Validate for standard format
val standardLegal = cards.isNotEmpty() && cards.all { card ->
Expand All @@ -54,7 +58,7 @@ class DefaultDeckValidator @Inject constructor(
reprints.standardHashes.contains(hash)
}
else -> false
}
} && !banList.standard.contains(card.id.toLowerCase())
}
}

Expand All @@ -69,7 +73,7 @@ class DefaultDeckValidator @Inject constructor(
reprints.expandedHashes.contains(hash)
}
else -> false
}
} && !banList.expanded.contains(card.id.toLowerCase())
}
}

Expand All @@ -88,4 +92,4 @@ class DefaultDeckValidator @Inject constructor(
return (this.name.hashCode().toLong() * 31L) +
(this.text?.hashCode()?.toLong() ?: 0L * 31L)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
package com.r0adkll.deckbuilder.arch.data.remote


import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
import com.r0adkll.deckbuilder.BuildConfig
import com.r0adkll.deckbuilder.R
import com.r0adkll.deckbuilder.arch.data.remote.plugin.RemotePlugin
import com.r0adkll.deckbuilder.arch.domain.features.remote.Remote
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.ExpansionPreview
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.ExpansionVersion
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.Reprints
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.SearchProxies
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.*
import com.r0adkll.deckbuilder.util.extensions.FirebaseRemotePreferences
import com.r0adkll.deckbuilder.util.extensions.FirebaseRemotePreferences.RemoteObject
import timber.log.Timber
import javax.inject.Inject


/**
* Wrapper around Firebase Remote Configuration SDK
*/
class FirebaseRemote @Inject constructor(
val plugins: Set<@JvmSuppressWildcards RemotePlugin>
): Remote, FirebaseRemotePreferences {


/**
* Property to access the Firebase Remote Config instance
*/
Expand All @@ -40,64 +34,60 @@ class FirebaseRemote @Inject constructor(
*/
override val expansionVersion by RemoteObject(KEY_EXPANSION_VERSION, ExpansionVersion::class)


/**
* This is the spec for an expansion preview card that appears on the deck list screen to tell
* users about a new expansion that has been added and other information about it. It also attempts
* to direct them to browse the expansion
*/
override val expansionPreview by RemoteObject(KEY_EXPANSION_PREVIEW, ExpansionPreview::class)


/**
* This is a list of search proxy/aliases that better improve the search experience for the user
*/
override val searchProxies by RemoteObject(KEY_SEARCH_PROXIES, SearchProxies::class)


/**
* This is a list of hashes for cards that are not in standard or expanded formats but have been
* reprinted in format valid sets since.
*/
override val reprints by RemoteObject(KEY_REPRINTS, Reprints::class)

/**
* This is the list of banned cards organized by format that should be used by the validator
* to validate card's legality
*/
override val banList by RemoteObject(KEY_BAN_LIST, BanList::class)

/**
* Check for update remote config values and update them if needed. Also set
* remote configuration settings if needed
*/
override fun check() {
Timber.d("Checking remote config values...")

// Configure
val settings = FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(BuildConfig.DEBUG)
.setMinimumFetchIntervalInSeconds(CACHE_EXPIRATION)
.build()
remote.setConfigSettings(settings)
remote.setConfigSettingsAsync(settings)
remote.setDefaults(R.xml.remote_config_defaults)


// Fetch
val cacheExpiration = if (remote.info.configSettings.isDeveloperModeEnabled) 0L else CACHE_EXPIRATION
remote.fetch(cacheExpiration)
remote.fetchAndActivate()
.addOnCompleteListener { _ ->
Timber.i("Remote Config values fetched. Activating!")
Timber.i("> Expansion Version: $expansionVersion")
Timber.i("> Search Proxies: $searchProxies")
Timber.i("> Preview: (version: ${expansionPreview?.version}, code: ${expansionPreview?.code})")
Timber.i("> Reprints: Standard(${reprints?.standardHashes?.size}), Expanded(${reprints?.expandedHashes?.size})")
remote.activateFetched()
Timber.i("> BanList: $banList")
plugins.forEach { it.onFetchActivated(this@FirebaseRemote) }
}
}


companion object {
private const val KEY_EXPANSION_VERSION = "expansion_version"
private const val KEY_EXPANSION_PREVIEW = "expansion_preview_v2"
private const val KEY_SEARCH_PROXIES = "search_proxies"
private const val KEY_REPRINTS = "reprints"

private const val KEY_BAN_LIST = "ban_list"
private const val CACHE_EXPIRATION = 3600L
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.r0adkll.deckbuilder.arch.domain.features.remote


import com.r0adkll.deckbuilder.arch.domain.features.remote.model.ExpansionPreview
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.ExpansionVersion
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.Reprints
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.SearchProxies
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.*


/**
Expand All @@ -21,31 +18,32 @@ interface Remote {
*/
val expansionVersion: ExpansionVersion?


/**
* This is the spec for an expansion preview card that appears on the deck list screen to tell
* users about a new expansion that has been added and other information about it. It also attempts
* to direct them to browse the expansion
*/
val expansionPreview: ExpansionPreview?


/**
* This is a list of search proxy/aliases that better improve the search experience for the user
*/
val searchProxies: SearchProxies?


/**
* This is a list of hashes for cards that are not in standard or expanded formats but have been
* reprinted in format valid sets since.
*/
val reprints: Reprints?

/**
* This is a list of all the banned cards by format, specified as a list of card ids to check
*/
val banList: BanList?

/**
* Check for update remote config values and update them if needed. Also set
* remote configuration settings if needed
*/
fun check()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.r0adkll.deckbuilder.arch.domain.features.remote.model

data class BanList(
val standard: List<String> = emptyList(),
val expanded: List<String> = emptyList(),
val unlimited: List<String> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.graphics.Shader
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize


@Parcelize
data class ExpansionPreview(
val version: Int,
Expand Down Expand Up @@ -63,7 +62,6 @@ data class ExpansionPreview(
}
}


@Parcelize
data class Margins(
val start: Int?,
Expand All @@ -72,4 +70,4 @@ data class ExpansionPreview(
val bottom: Int?
) : Parcelable
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.r0adkll.deckbuilder.arch.domain.features.remote.model



data class ExpansionVersion(
val version: Int,
val expansionCode: String
)
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.r0adkll.deckbuilder.arch.domain.features.remote.model


data class Reprints(
val standardHashes: Set<Long>,
val expandedHashes: Set<Long>
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.r0adkll.deckbuilder.arch.domain.features.remote.model
import com.r0adkll.deckbuilder.internal.analytics.Analytics
import com.r0adkll.deckbuilder.internal.analytics.Event


data class SearchProxies(private val proxies: List<Proxy>) {

fun apply(query: String): String {
Expand All @@ -26,4 +25,4 @@ data class SearchProxies(private val proxies: List<Proxy>) {
val regex: String,
val replacement: String
)
}
}
Loading

0 comments on commit d28f51f

Please sign in to comment.