Skip to content

Commit

Permalink
Fixes and Deck Import
Browse files Browse the repository at this point in the history
  • Loading branch information
edipo2s committed Feb 24, 2017
1 parent 4f1fdb5 commit c1a27b4
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 67 deletions.
6 changes: 0 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ android {
println(e.message)
}
}
release {
storeFile file('debug.keystore')
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
}
}
buildTypes {
debug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ enum class DeckClass(val attr1: CardAttribute, val attr2: CardAttribute = CardAt

companion object {

fun getClass(attr1: CardAttribute, attr2: CardAttribute): DeckClass {
return getClasses(listOf(attr1, attr2)).first()
}

fun getClasses(attr: List<CardAttribute>): List<DeckClass> {
return values().filter { attr.contains(it.attr1) && attr.contains(it.attr2) }
}
Expand All @@ -43,8 +47,16 @@ enum class DeckType {
COMBO,
CONTROL,
MIDRANGE,
OTHER
OTHER;

companion object {

fun of(value: String): DeckType {
val name = value.toUpperCase()
return OTHER.takeUnless { values().map { it.name }.contains(name) } ?: valueOf(name)
}

}
}

data class DeckUpdate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ data class Patch(
val uuidDate: String,
val date: LocalDate,
val desc: String,
val legendsDeck: String,
val type: PatchType,
val changes: List<PatchChange>

Expand All @@ -86,13 +87,14 @@ data class Patch(
}

constructor(source: Parcel) : this(source.readString(), LocalDate.ofEpochDay(source.readLong()),
source.readString(), PatchType.values()[source.readInt()],
source.readString(), source.readString(), PatchType.values()[source.readInt()],
mutableListOf<PatchChange>().apply { source.readList(this, PatchChange::class.java.classLoader) })

override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeString(uuidDate)
dest?.writeLong(date.toEpochDay())
dest?.writeString(desc)
dest?.writeString(legendsDeck)
dest?.writeInt(type.ordinal)
dest?.writeList(changes)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ abstract class FirebaseParsers {

val changes: Map<String, Map<String, Any>> = mapOf()
val desc: String = ""
val legendsDeck: String = ""
val type: String = ""

@Suppress("UNCHECKED_CAST")
Expand All @@ -174,7 +175,7 @@ abstract class FirebaseParsers {
val change = it.value[KEY_PATCH_CHANGE].toString()
PatchChange(attr, set, it.key, change)
}
return Patch(uuidDate, date, desc, PatchType.of(type), patchCardChanges)
return Patch(uuidDate, date, desc, legendsDeck, PatchType.of(type), patchCardChanges)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data class CmdUpdateTitle(@IntegerRes val title: Int)

data class CmdShowCardsByAttr(val attr: CardAttribute)

data class CmdShowDecksByClasses(val classes: List<DeckClass>)
data class CmdShowDecksByClasses(val classes: List<DeckClass>?)

data class CmdUpdateRarityMagikaFiltersPosition(val high: Boolean)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ediposouza.teslesgendstracker.ui.cards
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.support.design.widget.BottomSheetBehavior
import android.support.v4.app.ActivityCompat
Expand All @@ -12,6 +13,7 @@ import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.LinearSnapHelper
import android.support.v7.widget.RecyclerView
import android.text.format.DateUtils
import android.transition.Transition
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
Expand Down Expand Up @@ -82,9 +84,38 @@ class CardActivity : BaseActivity() {

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
card_ads_view.load()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.sharedElementEnterTransition?.apply {
addListener(object : Transition.TransitionListener {
override fun onTransitionEnd(transition: Transition?) {
removeListener(this)
configQtdAndFavoriteInfo()
}

override fun onTransitionResume(transition: Transition?) {
}

override fun onTransitionPause(transition: Transition?) {
}

override fun onTransitionCancel(transition: Transition?) {
removeListener(this)
}

override fun onTransitionStart(transition: Transition?) {
}

})
}
} else {
configQtdAndFavoriteInfo()
}
MetricsManager.trackScreen(MetricScreen.SCREEN_CARD_DETAILS())
MetricsManager.trackCardView(card)
card_ads_view.load()
}

private fun configQtdAndFavoriteInfo() {
if (App.hasUserLogged()) {
showUserCardQtd()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import kotlinx.android.synthetic.main.itemlist_card_collection.view.*
import kotlinx.android.synthetic.main.itemlist_card_imported.view.*
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.find
import org.jetbrains.anko.runOnUiThread
import org.jetbrains.anko.toast
import org.jetbrains.anko.uiThread
import org.jsoup.Jsoup
import timber.log.Timber
import java.util.*
Expand Down Expand Up @@ -172,7 +172,7 @@ class CardsCollectionFragment : CardsAllFragment() {
loadUrl("javascript:HtmlViewer.showHTML" +
"('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');")
}
if (url == getString(R.string.dialog_import_legends_deck_login_done_link)) {
if (url == getString(R.string.dialog_import_legends_deck_main_link)) {
loadUrl(getString(R.string.dialog_import_legends_deck_link))
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ class CardsCollectionFragment : CardsAllFragment() {
val cardName = it.select(".td_title_card_collection").text()
val cardQtd = it.select(".td_total_card_collection").text().toInt()
val cardShortName = cardName.replace(" ", "").replace("-", "")
.replace("'", "").replace(",", "").toLowerCase().toLowerCase()
.replace("'", "").replace(",", "").toLowerCase()
cardShortName to cardQtd
}?.filter { it.second > 0 }?.toMap() ?: mapOf()
if (legendsSlots.isNotEmpty()) {
Expand All @@ -249,38 +249,40 @@ class CardsCollectionFragment : CardsAllFragment() {
}

private fun importLegendDecksCards(legendsSlots: Map<String, Int>) {
PublicInteractor.getCards(null) { allCards ->
val legendsDecksCards = allCards.filter { legendsSlots.keys.contains(it.shortName) }.toMutableList()
PrivateInteractor.getUserCollection(null) { userSlots ->
val userCards = allCards.filter { userSlots.keys.contains(it.shortName) }.toMutableList()
val onlyInLegendsDecks = legendsDecksCards.filter { !userSlots.keys.contains(it.shortName) }
val onlyInUserCollection = userCards.filter { !legendsSlots.keys.contains(it.shortName) }
val cardsInCommon = userCards.filter { legendsSlots.keys.contains(it.shortName) }
val userQtdGreater = cardsInCommon.filter {
userSlots[it.shortName] ?: 0 > legendsSlots[it.shortName] ?: 0
}
val legendsQtdGreater = cardsInCommon.filter {
legendsSlots[it.shortName] ?: 0 > userSlots[it.shortName] ?: 0
}
onlyInLegendsDecks.forEach {
val qtd = legendsSlots[it.shortName] ?: 0
PrivateInteractor.setUserCardQtd(it, qtd) {
Timber.d("$qtd ${it.name} card added")
doAsync {
PublicInteractor.getCards(null) { allCards ->
val legendsDecksCards = allCards.filter { legendsSlots.keys.contains(it.shortName) }.toMutableList()
PrivateInteractor.getUserCollection(null) { userSlots ->
val userCards = allCards.filter { userSlots.keys.contains(it.shortName) }.toMutableList()
val onlyInLegendsDecks = legendsDecksCards.filter { !userSlots.keys.contains(it.shortName) }
val onlyInUserCollection = userCards.filter { !legendsSlots.keys.contains(it.shortName) }
val cardsInCommon = userCards.filter { legendsSlots.keys.contains(it.shortName) }
val userQtdGreater = cardsInCommon.filter {
userSlots[it.shortName] ?: 0 > legendsSlots[it.shortName] ?: 0
}
}
legendsQtdGreater.forEach {
val qtd = legendsSlots[it.shortName] ?: 0
PrivateInteractor.setUserCardQtd(it, qtd) {
Timber.d("${it.name} qtd updated to $qtd")
val legendsQtdGreater = cardsInCommon.filter {
legendsSlots[it.shortName] ?: 0 > userSlots[it.shortName] ?: 0
}
onlyInLegendsDecks.forEach {
val qtd = legendsSlots[it.shortName] ?: 0
PrivateInteractor.setUserCardQtd(it, qtd) {
Timber.d("$qtd ${it.name} card added")
}
}
legendsQtdGreater.forEach {
val qtd = legendsSlots[it.shortName] ?: 0
PrivateInteractor.setUserCardQtd(it, qtd) {
Timber.d("${it.name} qtd updated to $qtd")
}
}
showImportSummary(onlyInLegendsDecks, onlyInUserCollection, legendsQtdGreater,
userQtdGreater, legendsSlots, userSlots)
}
showImportSummary(onlyInLegendsDecks, onlyInUserCollection, legendsQtdGreater,
userQtdGreater, legendsSlots, userSlots)
}
}
context.runOnUiThread {
context.toast("Collection imported!")
importDialog?.dismiss()
uiThread {
context.toast("Collection imported!")
importDialog?.dismiss()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,10 @@ class DeckActivity : BaseActivity() {

fun calculateMissingSoul(deck: Deck) {
with(deck_details_soul_missing) {
visibility = View.INVISIBLE
deck_details_soul_missing_loading.visibility = View.VISIBLE
runOnUiThread {
visibility = View.INVISIBLE
deck_details_soul_missing_loading.visibility = View.VISIBLE
}
PrivateInteractor.getDeckMissingCards(deck, { deck_details_soul_missing_loading.visibility = View.VISIBLE }) {
deck_details_soul_missing_loading.visibility = View.GONE
val missingSoul = it.map { it.qtd * it.rarity.soulCost }.sum()
Expand Down
Loading

0 comments on commit c1a27b4

Please sign in to comment.