Skip to content

Commit

Permalink
Merge branch 'release/v1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
edipo2s committed Jun 20, 2017
2 parents e5ddf0c + 6fbbf3b commit 6074cc5
Show file tree
Hide file tree
Showing 117 changed files with 1,174 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/ediposouza/teslesgendstracker/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class App : MultiDexApplication() {
val sync = !ConfigManager.isDBUpdating() && !ConfigManager.isVersionUnsupported()
reference.child(BaseInteractor.NODE_BASICS).keepSynced(sync)
reference.child(BaseInteractor.NODE_CARDS).keepSynced(sync)
reference.child(BaseInteractor.NODE_TOKENS).keepSynced(sync)
reference.child(BaseInteractor.NODE_PATCHES).keepSynced(sync)
reference.child(BaseInteractor.NODE_SEASONS).keepSynced(sync)
reference.child(BaseInteractor.NODE_SPOILER).keepSynced(sync)
Expand All @@ -62,4 +63,4 @@ class App : MultiDexApplication() {
}
}

}
}
32 changes: 25 additions & 7 deletions app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ enum class CardRace(val desc: String) {
enum class CardKeyword {

ACTIVATE,
BATTLES,
BREAKTHROUGH,
CHANGE,
CHARGE,
Expand All @@ -185,6 +186,7 @@ enum class CardKeyword {
REGENERATE,
SHACKLE,
SILENCE,
SHOUT,
SLAY,
SUMMON,
WARD,
Expand Down Expand Up @@ -336,7 +338,8 @@ data class CardBasicInfo(

val shortName: String,
val set: String,
val attr: String
val attr: String,
val isToken: Boolean
)

data class CardSlot(
Expand Down Expand Up @@ -387,7 +390,10 @@ data class Card(
val arenaTierPlus: List<CardArenaTierPlus?>,
val evolves: Boolean,
val season: String,
val shout: Int
val shout: Int,
val creators: List<String>,
val generates: List<String>,
val tokens: List<String>

) : Comparable<Card>, Parcelable {

Expand All @@ -400,10 +406,10 @@ data class Card(
val DUMMY = Card("", "", CardSet.CORE, CardAttribute.DUAL, CardAttribute.STRENGTH,
CardAttribute.WILLPOWER, CardRarity.EPIC, false, 0, 0, 0, CardType.ACTION,
CardRace.ARGONIAN, emptyList<CardKeyword>(), "", CardArenaTier.AVERAGE,
listOf(), false, "", 0)
listOf(), false, "", 0, listOf(), listOf(), listOf())

const val ARTS_PATH = "Arts"
const val CARD_PATH = "Cards"
const val ARTS_TOKENS_PATH = "TokensArts"
const val SOUNDS_PATH = "Sounds"
const val SOUND_TYPE_ATTACK = "attack"
const val SOUND_TYPE_PLAY = "enter_play"
Expand All @@ -420,14 +426,17 @@ data class Card(
mutableListOf<CardKeyword>().apply { source.readList(this, CardKeyword::class.java.classLoader) },
source.readString(), CardArenaTier.values()[source.readInt()],
mutableListOf<CardArenaTierPlus>().apply { source.readList(this, CardArenaTierPlus::class.java.classLoader) },
1 == source.readInt(), source.readString(), source.readInt())
1 == source.readInt(), source.readString(), source.readInt(),
mutableListOf<String>().apply { source.readStringList(this) },
mutableListOf<String>().apply { source.readStringList(this) },
mutableListOf<String>().apply { source.readStringList(this) })

override fun describeContents() = 0

fun fullArtPath(): String {
val setName = set.name.toLowerCase().capitalize()
val attrName = attr.name.toLowerCase().capitalize()
val artPath = "$ARTS_PATH/$setName/$attrName/$shortName.webp"
val artPath = "${ARTS_PATH.takeUnless { isToken() } ?: ARTS_TOKENS_PATH}/$setName/$attrName/$shortName.webp"
return artPath
}

Expand Down Expand Up @@ -468,6 +477,12 @@ data class Card(
}
}

fun canGenerateCards(): Boolean = generates.isNotEmpty()

fun canGenerateTokens(): Boolean = tokens.isNotEmpty()

fun isToken(): Boolean = creators.isNotEmpty()

fun hasLocalAttackSound(resources: Resources): Boolean {
return resources.getAssets().list(getLocalCardSoundPath()).contains("${shortName}_$SOUND_TYPE_ATTACK.mp3")
}
Expand Down Expand Up @@ -519,10 +534,13 @@ data class Card(
dest?.writeInt((if (evolves) 1 else 0))
dest?.writeString(season)
dest?.writeInt(shout)
dest?.writeStringList(creators)
dest?.writeStringList(generates)
dest?.writeStringList(tokens)
}

override fun compareTo(other: Card): Int {
val compareCost = cost.compareTo(other.cost)
return if (compareCost != 0) compareCost else name.compareTo(other.name)
return if (compareCost != 0) compareCost else shortName.compareTo(other.shortName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ open class BaseInteractor {

val NODE_BASICS = "basics"
val NODE_CARDS = "cards"
val NODE_TOKENS = "tokens"
val NODE_PATCHES = "patches"
val NODE_SEASONS = "seasons"
val NODE_SPOILER = "spoiler"
Expand Down Expand Up @@ -116,4 +117,4 @@ open class BaseInteractor {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ abstract class FirebaseParsers {
val attr2: String = ""
val season: String = ""
val shout: Int = 0
val creators: String = ""
val generates: String = ""
val tokens: String = ""

fun toCard(shortName: String, set: CardSet, attr: CardAttribute): Card {
var clsAttr1 = attr
Expand All @@ -49,7 +52,9 @@ abstract class FirebaseParsers {
.mapTo(arrayListOf<CardKeyword>()) {
CardKeyword.of(it)
},
text, CardArenaTier.of(arenaTier), getCardArenaTierPlus(), evolves, season, shout)
text, CardArenaTier.of(arenaTier), getCardArenaTierPlus(), evolves, season, shout,
creators.split(", ").filter { it.isNotEmpty() }, generates.split(", ").filter { it.isNotEmpty() },
tokens.split(", ").filter { it.isNotEmpty() })
}

private fun getCardArenaTierPlus(): List<CardArenaTierPlus?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,54 @@ object PublicInteractor : BaseInteractor() {
}
}

fun getTokens(set: CardSet?, onSuccess: (List<Card>) -> Unit) {
getListFromSets(set, onSuccess) { set, onEachSuccess ->
with(database.child(NODE_TOKENS).child(set.db).orderByChild(KEY_CARD_COST)) {
keepSynced()
addListenerForSingleValueEvent(object : ValueEventListener {

override fun onDataChange(ds: DataSnapshot) {
val cards = ds.children.map {
val attr = CardAttribute.valueOf(it.key.toUpperCase())
it.children.map {
it.getValue(FirebaseParsers.CardParser::class.java)?.toCard(it.key, set, attr)
}.filterNotNull()
}.flatMap { it }
onEachSuccess.invoke(cards)
}

override fun onCancelled(de: DatabaseError) {
Timber.d("Fail: " + de.message)
}

})
}
}
}

fun getTokens(set: CardSet?, attr: CardAttribute, onSuccess: (List<Card>) -> Unit) {
val onFinalSuccess: (List<Card>) -> Unit = { onSuccess(it.sorted()) }
getListFromSets(set, attr, onFinalSuccess) { set, attr, onEachSuccess ->
val node_attr = attr.name.toLowerCase()
database.child(NODE_TOKENS).child(set.db).child(node_attr).orderByChild(KEY_CARD_COST)
.addListenerForSingleValueEvent(object : ValueEventListener {

override fun onDataChange(ds: DataSnapshot) {
val cards = ds.children.mapTo(arrayListOf()) {
it.getValue(FirebaseParsers.CardParser::class.java)?.toCard(it.key, set, attr)
}.filterNotNull()
Timber.d(cards.toString())
onEachSuccess.invoke(cards)
}

override fun onCancelled(de: DatabaseError) {
Timber.d("Fail: " + de.message)
}

})
}
}

fun isSpoilerEnable(onSuccess: (Boolean) -> Unit) {
database.child(NODE_SPOILER).child(KEY_SPOILER_ENABLE)
.addListenerForSingleValueEvent(object : ValueEventListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ class DashActivity : BaseFilterActivity(),
card?.let {
val anim = ActivityOptionsCompat.makeSceneTransitionAnimation(ctx, dash_toolbar_title,
getString(R.string.card_transition_name))
ActivityCompat.startActivity(ctx, CardActivity.newIntent(ctx, it), anim.toBundle())
try {
ActivityCompat.startActivity(ctx, CardActivity.newIntent(ctx, card), anim.toBundle())
} catch (e: Exception) {
startActivity(CardActivity.newIntent(ctx, card))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.ediposouza.teslesgendstracker.util.inflate
import kotlinx.android.synthetic.main.fragment_arena_draft.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.jetbrains.anko.toast
import org.threeten.bp.LocalDateTime

/**
Expand Down Expand Up @@ -100,6 +101,7 @@ class NewArenaDraftFragment : BaseFragment() {
arena_draft_cards3.config(activity, selectedClass, cards, cardListOnClick, arena_draft_cardlist)
}
MetricsManager.trackScreen(MetricScreen.SCREEN_NEW_ARENA_DRAFT())
context.toast(R.string.new_arena_warning)
}

@Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ open class BaseFragment : Fragment() {

open fun configLoggedViews() {
signin_buttons.visibility = View.INVISIBLE.takeIf { App.hasUserLogged() } ?: View.VISIBLE
configSignButtons()
}

fun configSignButtons() {
signin_google_button.setOnClickListener { showLogin() }
with(signin_facebook_button) {
setReadPermissions("email")
Expand Down
Loading

0 comments on commit 6074cc5

Please sign in to comment.