Skip to content

Commit

Permalink
Merge branch 'release/v0.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
edipo2s committed Dec 31, 2016
2 parents 89b4797 + b16db24 commit 7f8a2b5
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 84 deletions.
Binary file modified app/libs/clansFAB.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ class CardActivity : BaseActivity() {
if (App.hasUserLogged()) {
PrivateInteractor().setUserCardFavorite(card, !favorite) {
favorite = !favorite
MetricsManager.trackAction(if (favorite) MetricAction.ACTION_CARD_DETAILS_FAVORITE()
else MetricAction.ACTION_CARD_DETAILS_UNFAVORITE())
val stringRes = if (favorite) R.string.card_favorited else R.string.card_unfavorited
toast(getString(stringRes, card.name))
loadCardInfo()
setResult(Activity.RESULT_OK, Intent())
MetricsManager.trackAction(if (favorite)
MetricAction.ACTION_CARD_DETAILS_FAVORITE() else MetricAction.ACTION_CARD_DETAILS_UNFAVORITE())
}
} else {
showErrorUserNotLogged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import com.bumptech.glide.Glide
import com.ediposouza.teslesgendstracker.App
import com.ediposouza.teslesgendstracker.R
Expand All @@ -30,20 +31,15 @@ import com.ediposouza.teslesgendstracker.interactor.PublicInteractor
import com.ediposouza.teslesgendstracker.ui.base.BaseActivity
import com.ediposouza.teslesgendstracker.ui.base.CmdShowSnackbarMsg
import com.ediposouza.teslesgendstracker.ui.util.CircleTransform
import com.ediposouza.teslesgendstracker.util.MetricScreen
import com.ediposouza.teslesgendstracker.util.MetricsManager
import com.ediposouza.teslesgendstracker.util.inflate
import com.ediposouza.teslesgendstracker.util.toggleExpanded
import com.ediposouza.teslesgendstracker.ui.util.KeyboardUtil
import com.ediposouza.teslesgendstracker.util.*
import com.google.firebase.auth.FirebaseAuth
import io.fabric.sdk.android.services.common.CommonUtils
import jp.wasabeef.recyclerview.animators.SlideInLeftAnimator
import kotlinx.android.synthetic.main.activity_deck.*
import kotlinx.android.synthetic.main.include_deck_info.*
import kotlinx.android.synthetic.main.itemlist_deck_comment.view.*
import org.jetbrains.anko.alert
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.intentFor
import org.jetbrains.anko.toast
import org.jetbrains.anko.*
import org.threeten.bp.format.DateTimeFormatter
import timber.log.Timber
import java.text.NumberFormat
Expand All @@ -67,6 +63,7 @@ class DeckActivity : BaseActivity() {

private val publicInteractor by lazy { PublicInteractor() }
private val privateInteractor by lazy { PrivateInteractor() }
private val keyboardUtil by lazy { KeyboardUtil(this, contentView) }
private val deckOwned by lazy { intent.getBooleanExtra(EXTRA_OWNED, false) }
private val deck: Deck by lazy { intent.getParcelableExtra<Deck>(EXTRA_DECK) }
private val numberInstance: NumberFormat by lazy { NumberFormat.getNumberInstance() }
Expand All @@ -79,32 +76,53 @@ class DeckActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_deck)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val statusBarHeight = resources.getDimensionPixelSize(R.dimen.status_bar_height)
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
val coverLP = deck_class_cover.layoutParams as RelativeLayout.LayoutParams
coverLP.height = coverLP.height - statusBarHeight
deck_class_cover.layoutParams = coverLP
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
val layoutParams = toolbar.layoutParams as CollapsingToolbarLayout.LayoutParams
layoutParams.topMargin = resources.getDimensionPixelSize(R.dimen.status_bar_height)
layoutParams.topMargin = statusBarHeight
toolbar.layoutParams = layoutParams
}

favorite = intent.getBooleanExtra(EXTRA_FAVORITE, false)
like = intent.getBooleanExtra(EXTRA_LIKE, false)
configViews()
updateFavoriteItem()
loadDeckInfo()
}

private fun configViews() {
deck_fab_favorite.setOnClickListener {
if (App.hasUserLogged()) {
privateInteractor.setUserDeckFavorite(deck, !favorite) {
favorite = !favorite
updateFavoriteItem()
MetricsManager.trackAction(if (favorite)
MetricAction.ACTION_DECK_DETAILS_FAVORITE() else MetricAction.ACTION_DECK_DETAILS_UNFAVORITE())
}
} else {
showErrorUserNotLogged()
}
}
deck_bottom_sheet.setOnClickListener { commentsSheetBehavior.toggleExpanded() }
updateFavoriteItem()
loadDeckInfo()
}
commentsSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, slideOffset: Float) {
}

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
override fun onStateChanged(bottomSheet: View, newState: Int) {
when (newState) {
BottomSheetBehavior.STATE_EXPANDED ->
MetricsManager.trackAction(MetricAction.ACTION_DECK_COMMENTS_EXPAND())
BottomSheetBehavior.STATE_COLLAPSED ->
MetricsManager.trackAction(MetricAction.ACTION_DECK_COMMENTS_COLLAPSE())
}
}

})
deck_bottom_sheet.setOnClickListener { commentsSheetBehavior.toggleExpanded() }
deck_comment_send?.setOnClickListener {
if (App.hasUserLogged()) {
if (deck_comment_new.text.toString().length < 4) {
Expand All @@ -114,12 +132,18 @@ class DeckActivity : BaseActivity() {
PrivateInteractor().addDeckComment(deck, deck_comment_new.text.toString()) {
deck_comment_new.setText("")
addComment(it)
MetricsManager.trackAction(MetricAction.ACTION_DECK_COMMENTS_SEND())
}
}
} else {
showErrorUserNotLogged()
}
}
}

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
onKeyboardVisibilityChange = {
deck_comment_recycle_view.requestLayout()
}
Expand All @@ -146,6 +170,16 @@ class DeckActivity : BaseActivity() {
}
}

override fun onStart() {
super.onStart()
keyboardUtil.enable()
}

override fun onStop() {
super.onStop()
keyboardUtil.disable()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(if (deckOwned) R.menu.menu_deck_owner else R.menu.menu_deck, menu)
menuLike = menu?.findItem(R.id.menu_like)
Expand All @@ -169,6 +203,8 @@ class DeckActivity : BaseActivity() {
updateLikeItem()
val deckLikes = Integer.parseInt(deck_details_likes.text.toString())
deck_details_likes.text = numberInstance.format(deckLikes + if (like) 1 else -1)
MetricsManager.trackAction(if (like)
MetricAction.ACTION_DECK_DETAILS_LIKE() else MetricAction.ACTION_DECK_DETAILS_UNLIKE())
}
return true
}
Expand All @@ -179,6 +215,7 @@ class DeckActivity : BaseActivity() {
privateInteractor.deleteDeck(deck, deck.private) {
toast(R.string.deck_deleted)
ActivityCompat.finishAfterTransition(this@DeckActivity)
MetricsManager.trackAction(MetricAction.ACTION_DECK_DETAILS_DELETE())
}
})
setTheme(R.style.AppDialog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ open class CardsAllFragment : BaseFragment() {
fun onCmdShowCardsByAttr(showCardsByAttr: CmdShowCardsByAttr) {
loadCardsByAttr(showCardsByAttr.attr)
if (isFragmentSelected) {
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_ATTR(), showCardsByAttr.attr.name)
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_ATTR(showCardsByAttr.attr))
}
}

Expand All @@ -145,8 +145,7 @@ open class CardsAllFragment : BaseFragment() {
classFilter = filterClass.cls
showCards()
if (isFragmentSelected) {
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_SET(),
setFilter?.name ?: MetricAction.ACTION_CARD_FILTER_SET.VALUE_CLEAR)
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_SET(setFilter))
}
}

Expand All @@ -161,8 +160,7 @@ open class CardsAllFragment : BaseFragment() {
rarityFilter = filterRarity.rarity
showCards()
if (isFragmentSelected) {
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_RARITY(),
rarityFilter?.name ?: MetricAction.ACTION_CARD_FILTER_RARITY.VALUE_CLEAR)
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_RARITY(rarityFilter))
}
}

Expand All @@ -171,8 +169,7 @@ open class CardsAllFragment : BaseFragment() {
magikaFilter = filterMagika.magika
showCards()
if (isFragmentSelected) {
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_MAGIKA(), if (magikaFilter >= 0)
magikaFilter.toString() else MetricAction.ACTION_CARD_FILTER_MAGIKA.VALUE_CLEAR)
MetricsManager.trackAction(MetricAction.ACTION_CARD_FILTER_MAGIKA(magikaFilter))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CardsCollectionFragment : CardsAllFragment() {
cards_recycler_view?.itemAnimator = null
cardsCollectionAdapter.updateSlot(cardSlot, finalQtd)
view_statistics.updateStatistics(currentAttr)
MetricsManager.trackAction(MetricAction.ACTION_COLLECTION_CARD_QTD_CHANGE(), finalQtd.toString())
MetricsManager.trackAction(MetricAction.ACTION_COLLECTION_CARD_QTD_CHANGE(finalQtd))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterMagika
import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterRarity
import com.ediposouza.teslesgendstracker.ui.decks.CmdAddCard
import com.ediposouza.teslesgendstracker.ui.decks.CmdRemAttr
import com.ediposouza.teslesgendstracker.util.MetricAction
import com.ediposouza.teslesgendstracker.util.MetricScreen
import com.ediposouza.teslesgendstracker.util.MetricsManager
import kotlinx.android.synthetic.main.activity_new_deck.*
Expand Down Expand Up @@ -182,6 +183,7 @@ class NewDeckActivity : BaseFilterActivity() {
val data = intentFor<NewDeckActivity>(DECK_PRIVATE_EXTRA to deckPrivate)
setResult(Activity.RESULT_OK, data)
ActivityCompat.finishAfterTransition(this)
MetricsManager.trackAction(MetricAction.ACTION_NEW_DECK_SAVE(deckTypeText, deckPatchDesc, deckPrivate))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class MagikaCosts(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) :
constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0)

fun updateCosts(cards: List<CardSlot>) {
magikaCost0Qtd = cards.filter { it.card.cost == 0 }.sumBy { it.qtd.toInt() }
magikaCost1Qtd = cards.filter { it.card.cost == 1 }.sumBy { it.qtd.toInt() }
magikaCost2Qtd = cards.filter { it.card.cost == 2 }.sumBy { it.qtd.toInt() }
magikaCost3Qtd = cards.filter { it.card.cost == 3 }.sumBy { it.qtd.toInt() }
magikaCost4Qtd = cards.filter { it.card.cost == 4 }.sumBy { it.qtd.toInt() }
magikaCost5Qtd = cards.filter { it.card.cost == 5 }.sumBy { it.qtd.toInt() }
magikaCost6Qtd = cards.filter { it.card.cost == 6 }.sumBy { it.qtd.toInt() }
magikaCost7PlusQtd = cards.filter { it.card.cost >= 7 }.sumBy { it.qtd.toInt() }
magikaCost0Qtd = cards.filter { it.card.cost == 0 }.sumBy { it.qtd }
magikaCost1Qtd = cards.filter { it.card.cost == 1 }.sumBy { it.qtd }
magikaCost2Qtd = cards.filter { it.card.cost == 2 }.sumBy { it.qtd }
magikaCost3Qtd = cards.filter { it.card.cost == 3 }.sumBy { it.qtd }
magikaCost4Qtd = cards.filter { it.card.cost == 4 }.sumBy { it.qtd }
magikaCost5Qtd = cards.filter { it.card.cost == 5 }.sumBy { it.qtd }
magikaCost6Qtd = cards.filter { it.card.cost == 6 }.sumBy { it.qtd }
magikaCost7PlusQtd = cards.filter { it.card.cost >= 7 }.sumBy { it.qtd }
}

private fun updateMagikaCostBars() {
Expand All @@ -108,7 +108,8 @@ class MagikaCosts(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) :
val zeroMargin = resources.getDimensionPixelSize(R.dimen.deck_new_magika_costs_bar_min_height)
val magikaCostViewLP = magikaCostView?.layoutParams as RelativeLayout.LayoutParams
val factor: Float = if (maxMagikaCostQtd == 0) 0f else magikaCostQtd / maxMagikaCostQtd.toFloat()
magikaCostViewLP.topMargin = (zeroMargin - zeroMargin * factor).toInt()
val topMargin = (zeroMargin - zeroMargin * factor).toInt()
magikaCostViewLP.topMargin = if (topMargin == zeroMargin) topMargin - 5 else topMargin
magikaCostView?.layoutParams = magikaCostViewLP
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.ediposouza.teslesgendstracker.ui.util

import android.app.Activity
import android.graphics.Rect
import android.os.Build
import android.view.View
import android.view.ViewTreeObserver


/**
* Created by EdipoSouza on 12/31/16.
*/
/**
* Created by mikepenz on 14.03.15.
* This class implements a hack to change the layout padding on bottom if the keyboard is shown
* to allow long lists with editTextViews
* Basic idea for this solution found here: http://stackoverflow.com/a/9108219/325479
*/
class KeyboardUtil(act: Activity, private val contentView: View?) {

//a small helper to allow showing the editText focus
private var onGlobalLayoutListener: ViewTreeObserver.OnGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener {
val r = Rect()
//r will be populated with the coordinates of your view that area still visible.
decorView.getWindowVisibleDisplayFrame(r)

//get screen height and calculate the difference with the useable area from the r
val height = decorView.context.resources.displayMetrics.heightPixels
val diff = height - r.bottom

//if it could be a keyboard add the padding to the view
if (diff != 0) {
// if the use-able screen height differs from the total screen height we assume that it shows a keyboard now
//check if the padding is 0 (if yes set the padding for the keyboard)
if (contentView?.paddingBottom !== diff) {
//set the padding of the contentView for the keyboard
contentView?.setPadding(0, 0, 0, diff)
}
} else {
//check if the padding is != 0 (if yes reset the padding)
if (contentView?.paddingBottom !== 0) {
//reset the padding of the contentView
contentView?.setPadding(0, 0, 0, 0)
}
}
}

private val decorView: View

init {
this.decorView = act.window.decorView

//only required on newer android versions. it was working on API level 19 (Build.VERSION_CODES.KITKAT)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
decorView.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener)
}
}

fun enable() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
decorView.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener)
}
}

fun disable() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
decorView.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class CollectionStatistics(ctx: Context?, attrs: AttributeSet?, defStyleAttr: In
constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0)

override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return true
val statisticPeekHeight = resources.getDimensionPixelSize(R.dimen.statistics_bottom_peek_height)
val clickYPos = ev?.y ?: 0f
return clickYPos < statisticPeekHeight || super.onInterceptTouchEvent(ev)
}

fun scrollToTop() {
Expand Down
Loading

0 comments on commit 7f8a2b5

Please sign in to comment.