Skip to content

Commit e422e34

Browse files
committed
Add CardAttribute UNKNOWN value
1 parent dd453cd commit e422e34

File tree

8 files changed

+24
-12
lines changed

8 files changed

+24
-12
lines changed

app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ enum class CardAttribute(@DrawableRes val imageRes: Int, val isBasic: Boolean =
6262
AGILITY(R.drawable.attr_agility),
6363
ENDURANCE(R.drawable.attr_endurance),
6464
NEUTRAL(R.drawable.attr_neutral, false),
65-
DUAL(R.drawable.attr_dual, false)
65+
DUAL(R.drawable.attr_dual, false),
66+
UNKNOWN(R.drawable.attr_neutral, false);
67+
68+
companion object {
69+
70+
fun of(value: String): CardAttribute {
71+
val name = value.trim().toUpperCase().replace(" ", "_")
72+
return if (values().map { it.name }.contains(name)) valueOf(name) else UNKNOWN
73+
}
74+
75+
}
76+
6677

6778
}
6879

app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/FirebaseParsers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ abstract class FirebaseParsers {
4444
var clsAttr1 = attr
4545
var clsAttr2 = attr
4646
if (attr == CardAttribute.DUAL) {
47-
clsAttr1 = CardAttribute.valueOf(attr1.trim().toUpperCase())
48-
clsAttr2 = CardAttribute.valueOf(attr2.trim().toUpperCase())
47+
clsAttr1 = CardAttribute.of(attr1.trim().toUpperCase())
48+
clsAttr2 = CardAttribute.of(attr2.trim().toUpperCase())
4949
}
5050
return Card(name, shortName, set, attr, clsAttr1, clsAttr2, CardRarity.of(rarity), unique,
5151
cost.toIntSafely(), attack.toIntSafely(), health.toIntSafely(),

app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object PublicInteractor : BaseInteractor() {
5151

5252
override fun onDataChange(ds: DataSnapshot) {
5353
val cards = ds.children.map {
54-
val attr = CardAttribute.valueOf(it.key.toUpperCase())
54+
val attr = CardAttribute.of(it.key.toUpperCase())
5555
it.children.map {
5656
it.getValue(FirebaseParsers.CardParser::class.java)?.toCard(it.key, set, attr)
5757
}.filterNotNull()
@@ -141,7 +141,7 @@ object PublicInteractor : BaseInteractor() {
141141

142142
override fun onDataChange(ds: DataSnapshot) {
143143
val cards = ds.children.map {
144-
val attr = CardAttribute.valueOf(it.key.toUpperCase())
144+
val attr = CardAttribute.of(it.key.toUpperCase())
145145
it.children.map {
146146
it.getValue(FirebaseParsers.CardParser::class.java)?.toCard(it.key, set, attr)
147147
}.filterNotNull()
@@ -244,7 +244,7 @@ object PublicInteractor : BaseInteractor() {
244244
unknownSetTitle = spoilerTitle
245245
}
246246
val cards = ds.children.map {
247-
val attr = CardAttribute.valueOf(it.key.toUpperCase())
247+
val attr = CardAttribute.of(it.key.toUpperCase())
248248
it.children.map {
249249
it.getValue(FirebaseParsers.CardParser::class.java)?.toCard(it.key, set, attr)
250250
}.filterNotNull()

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/arena/widget/ArenaDraftCards.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ class ArenaDraftCards(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) :
209209
CardArenaTierPlusType.COST -> getExtraPointsForIntValue(arenaTierPlus, draftedCard.cost)
210210
CardArenaTierPlusType.HEALTH -> getExtraPointsForIntValue(arenaTierPlus, draftedCard.health)
211211
CardArenaTierPlusType.ATTR -> extraPoints.takeIf {
212-
!reverseCalc && (draftedCard.attr == CardAttribute.valueOf(arenaTierPlus.value.toUpperCase()) ||
213-
draftedCard.dualAttr1 == CardAttribute.valueOf(arenaTierPlus.value.toUpperCase()) ||
214-
draftedCard.dualAttr2 == CardAttribute.valueOf(arenaTierPlus.value.toUpperCase()))
212+
!reverseCalc && (draftedCard.attr == CardAttribute.of(arenaTierPlus.value.toUpperCase()) ||
213+
draftedCard.dualAttr1 == CardAttribute.of(arenaTierPlus.value.toUpperCase()) ||
214+
draftedCard.dualAttr2 == CardAttribute.of(arenaTierPlus.value.toUpperCase()))
215215
} ?: 0
216216
CardArenaTierPlusType.KEYWORD -> extraPoints.takeIf {
217217
draftedCard.keywords.filter { it.name == arenaTierPlus.value.toUpperCase() }.isNotEmpty()

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/widget/CollectionStatistics.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class CollectionStatistics(ctx: Context?, attrs: AttributeSet?, defStyleAttr: In
118118
CardAttribute.ENDURANCE -> rootView.rarity_statistics_endurance
119119
CardAttribute.NEUTRAL -> rootView.rarity_statistics_neutral
120120
CardAttribute.DUAL -> rootView.rarity_statistics_dual
121+
CardAttribute.UNKNOWN -> rootView.rarity_statistics_neutral
121122
}
122123

123124
}

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/DecksFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class DecksFragment : BaseFragment(), SearchView.OnQueryTextListener {
312312
val deckCls = it.select(".deck_head_image_attributes").map {
313313
val cardCls1 = it.child(0).attr("alt").toUpperCase()
314314
val cardCls2 = it.child(1).attr("alt").toUpperCase()
315-
DeckClass.getClass(CardAttribute.valueOf(cardCls1), CardAttribute.valueOf(cardCls2))
315+
DeckClass.getClass(CardAttribute.of(cardCls1), CardAttribute.of(cardCls2))
316316
}.first()
317317
val deckType = DeckType.of(with(it.select(".panel-body .center").first().text()) {
318318
substring(indexOfLast { it == ' ' } + 1).replace("-", "")

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/seasons/PatchActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class PatchActivity : BaseActivity() {
180180
patch_card_old_image.loadFromPatch(patchChange, patchUuid, false)
181181
patch_card_new_image.loadFromPatch(patchChange, nextPatchUuid, true)
182182
val set = CardSet.of(patchChange.set)
183-
val attr = CardAttribute.valueOf(patchChange.attr.toUpperCase())
183+
val attr = CardAttribute.of(patchChange.attr.toUpperCase())
184184
PublicInteractor.getCard(set, attr, patchChange.shortName) { card ->
185185
patch_card_old_image.setOnClickListener { itemClick(patch_card_old_image, card) }
186186
patch_card_new_image.setOnClickListener { itemClick(patch_card_new_image, card) }

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/seasons/SeasonsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class SeasonsFragment : BaseFragment() {
134134
season_patches_recycler_view.adapter = PatchAdapter(seasonPatches, onPatchClick)
135135
doAsync {
136136
if (season.rewardCardShortname != null) {
137-
val rewardAttr = CardAttribute.valueOf(season.rewardCardAttr.toUpperCase())
137+
val rewardAttr = CardAttribute.of(season.rewardCardAttr.toUpperCase())
138138
PublicInteractor.getCard(CardSet.CORE, rewardAttr, season.rewardCardShortname) { card ->
139139
context.runOnUiThread {
140140
season_card_reward.loadFromCard(card)

0 commit comments

Comments
 (0)