Skip to content

Commit 9d13b6b

Browse files
committed
Add login validation for Save/Favorite/Like/Comment deck. Fix snackBar padding bottom
1 parent 26f0d26 commit 9d13b6b

File tree

11 files changed

+66
-36
lines changed

11 files changed

+66
-36
lines changed

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/CardActivity.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import com.ediposouza.teslesgendstracker.R
1212
import com.ediposouza.teslesgendstracker.data.Card
1313
import com.ediposouza.teslesgendstracker.interactor.PrivateInteractor
1414
import com.ediposouza.teslesgendstracker.ui.base.BaseActivity
15-
import com.ediposouza.teslesgendstracker.ui.base.CmdShowLogin
16-
import com.ediposouza.teslesgendstracker.ui.base.CmdShowSnackbarMsg
1715
import com.ediposouza.teslesgendstracker.util.*
1816
import kotlinx.android.synthetic.main.activity_card.*
1917
import org.jetbrains.anko.intentFor
@@ -38,6 +36,7 @@ class CardActivity : BaseActivity() {
3836
override fun onCreate(savedInstanceState: Bundle?) {
3937
super.onCreate(savedInstanceState)
4038
setContentView(R.layout.activity_card)
39+
snackbarNeedMargin = false
4140

4241
favorite = intent.getBooleanExtra(EXTRA_FAVORITE, false)
4342
card_all_image.setOnClickListener {
@@ -104,8 +103,7 @@ class CardActivity : BaseActivity() {
104103
setResult(Activity.RESULT_OK, Intent())
105104
}
106105
} else {
107-
eventBus.post(CmdShowSnackbarMsg(CmdShowSnackbarMsg.TYPE_ERROR, R.string.error_auth)
108-
.withAction(R.string.action_login, { eventBus.post(CmdShowLogin()) }))
106+
showErrorUserNotLogged()
109107
}
110108
}
111109

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DashActivity : BaseFilterActivity(),
4444
override fun onCreate(savedInstanceState: Bundle?) {
4545
super.onCreate(savedInstanceState)
4646
setContentView(R.layout.activity_dash)
47+
snackbarNeedMargin = false
4748
decks_fab_add.hide()
4849
filter_rarity.filterClick = { eventBus.post(CmdFilterRarity(it)) }
4950
filter_magika.filterClick = { eventBus.post(CmdFilterMagika(it)) }

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.ediposouza.teslesgendstracker.data.DeckComment
2828
import com.ediposouza.teslesgendstracker.interactor.PrivateInteractor
2929
import com.ediposouza.teslesgendstracker.interactor.PublicInteractor
3030
import com.ediposouza.teslesgendstracker.ui.base.BaseActivity
31+
import com.ediposouza.teslesgendstracker.ui.base.CmdShowSnackbarMsg
3132
import com.ediposouza.teslesgendstracker.ui.util.CircleTransform
3233
import com.ediposouza.teslesgendstracker.util.MetricScreen
3334
import com.ediposouza.teslesgendstracker.util.MetricsManager
@@ -87,9 +88,13 @@ class DeckActivity : BaseActivity() {
8788
favorite = intent.getBooleanExtra(EXTRA_FAVORITE, false)
8889
like = intent.getBooleanExtra(EXTRA_LIKE, false)
8990
deck_fab_favorite.setOnClickListener {
90-
privateInteractor.setUserDeckFavorite(deck, !favorite) {
91-
favorite = !favorite
92-
updateFavoriteItem()
91+
if (App.hasUserLogged()) {
92+
privateInteractor.setUserDeckFavorite(deck, !favorite) {
93+
favorite = !favorite
94+
updateFavoriteItem()
95+
}
96+
} else {
97+
showErrorUserNotLogged()
9398
}
9499
}
95100
deck_bottom_sheet.setOnClickListener { commentsSheetBehavior.toggleExpanded() }
@@ -101,16 +106,18 @@ class DeckActivity : BaseActivity() {
101106
super.onPostCreate(savedInstanceState)
102107
supportActionBar?.setDisplayHomeAsUpEnabled(true)
103108
deck_comment_send?.setOnClickListener {
104-
if (deck_comment_new.text.toString().length < 4) {
105-
alert(getString(R.string.deck_comment_size_error)) {
106-
okButton { }
107-
setTheme(R.style.AppDialog)
108-
}.show()
109-
} else {
110-
PrivateInteractor().addDeckComment(deck, deck_comment_new.text.toString()) {
111-
deck_comment_new.setText("")
112-
addComment(it)
109+
if (App.hasUserLogged()) {
110+
if (deck_comment_new.text.toString().length < 4) {
111+
eventBus.post(CmdShowSnackbarMsg(CmdShowSnackbarMsg.TYPE_ERROR, R.string.deck_comment_size_error)
112+
.withAction(android.R.string.ok, {}))
113+
} else {
114+
PrivateInteractor().addDeckComment(deck, deck_comment_new.text.toString()) {
115+
deck_comment_new.setText("")
116+
addComment(it)
117+
}
113118
}
119+
} else {
120+
showErrorUserNotLogged()
114121
}
115122
}
116123
onKeyboardVisibilityChange = {
@@ -153,6 +160,10 @@ class DeckActivity : BaseActivity() {
153160
return true
154161
}
155162
R.id.menu_like -> {
163+
if (!App.hasUserLogged()) {
164+
showErrorUserNotLogged()
165+
return false
166+
}
156167
privateInteractor.setUserDeckLike(deck, !like) {
157168
like = !like
158169
updateLikeItem()

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import android.net.Uri
66
import android.os.Bundle
77
import android.os.Handler
88
import android.support.annotation.StringRes
9+
import android.support.design.widget.CoordinatorLayout
910
import android.support.design.widget.Snackbar
1011
import android.support.v7.app.AlertDialog
1112
import android.support.v7.app.AppCompatActivity
1213
import android.support.v7.widget.Toolbar
1314
import android.text.format.DateUtils
15+
import android.view.View
1416
import android.widget.ProgressBar
1517
import com.ediposouza.teslesgendstracker.App
1618
import com.ediposouza.teslesgendstracker.R
@@ -30,6 +32,7 @@ import org.greenrobot.eventbus.EventBus
3032
import org.greenrobot.eventbus.Subscribe
3133
import org.jetbrains.anko.alert
3234
import org.jetbrains.anko.contentView
35+
import org.jetbrains.anko.find
3336
import org.jetbrains.anko.toast
3437
import timber.log.Timber
3538

@@ -45,10 +48,11 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile
4548
private var googleApiClient: GoogleApiClient? = null
4649
private val firebaseAuth by lazy { FirebaseAuth.getInstance() }
4750

48-
protected var canExit: Boolean = false
49-
protected val handler = Handler()
51+
protected var canExit = false
5052
protected var keyboardVisible = false
53+
protected var snackbarNeedMargin = true
5154
protected var onKeyboardVisibilityChange: (() -> Unit)? = null
55+
protected val handler = Handler()
5256
protected val eventBus: EventBus by lazy { EventBus.getDefault() }
5357

5458
val keyboardChangeListener = {
@@ -149,6 +153,11 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile
149153
toast(exitMsg)
150154
}
151155

156+
protected fun showErrorUserNotLogged() {
157+
eventBus.post(CmdShowSnackbarMsg(CmdShowSnackbarMsg.TYPE_ERROR, R.string.error_auth)
158+
.withAction(R.string.action_login, { eventBus.post(CmdShowLogin()) }))
159+
}
160+
152161
private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount?) {
153162
Timber.d("firebaseAuthWithGoogle:" + acct?.id)
154163
showLoading()
@@ -195,12 +204,17 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile
195204
snackbar?.dismiss()
196205
val msgRes = cmdShowSnackbarMsg.msgRes
197206
val msg = if (msgRes > 0) getString(msgRes) else cmdShowSnackbarMsg.msg
198-
snackbar = Snackbar.make(findViewById(R.id.coordinatorLayout), msg, cmdShowSnackbarMsg.duration)
207+
snackbar = Snackbar.make(find<View>(R.id.coordinatorLayout), msg, cmdShowSnackbarMsg.duration)
199208
if (cmdShowSnackbarMsg.action != null) {
200209
val actionTextRes = cmdShowSnackbarMsg.actionTextRes
201210
val actionText = if (actionTextRes > 0) getString(actionTextRes) else cmdShowSnackbarMsg.actionText
202211
snackbar?.setAction(actionText, { cmdShowSnackbarMsg.action?.invoke() })
203212
}
213+
if (snackbarNeedMargin) {
214+
val snackbarLP = snackbar?.view?.layoutParams as CoordinatorLayout.LayoutParams
215+
snackbarLP.bottomMargin = resources.getDimensionPixelSize(R.dimen.navigation_bar_height)
216+
snackbar?.view?.layoutParams = snackbarLP
217+
}
204218
snackbar?.show()
205219
}
206220

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import android.view.Menu
1010
import android.view.MenuItem
1111
import android.view.View
1212
import android.widget.ArrayAdapter
13+
import com.ediposouza.teslesgendstracker.App
1314
import com.ediposouza.teslesgendstracker.R
1415
import com.ediposouza.teslesgendstracker.data.*
1516
import com.ediposouza.teslesgendstracker.interactor.PrivateInteractor
1617
import com.ediposouza.teslesgendstracker.interactor.PublicInteractor
1718
import com.ediposouza.teslesgendstracker.ui.base.BaseFilterActivity
1819
import com.ediposouza.teslesgendstracker.ui.base.CmdShowCardsByAttr
20+
import com.ediposouza.teslesgendstracker.ui.base.CmdShowSnackbarMsg
1921
import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterClass
2022
import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterMagika
2123
import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterRarity
@@ -129,13 +131,15 @@ class NewDeckActivity : BaseFilterActivity() {
129131
return true
130132
}
131133
R.id.menu_done -> {
132-
if (new_deck_cardlist.getCards().sumBy { it.qtd.toInt() } >= DECK_MIN_CARDS_QTD) {
134+
if (!App.hasUserLogged()) {
135+
showErrorUserNotLogged()
136+
return false
137+
}
138+
if (new_deck_cardlist.getCards().sumBy { it.qtd } >= DECK_MIN_CARDS_QTD) {
133139
showSaveDialog()
134140
} else {
135-
alert("Please complete your deck before save it") {
136-
okButton { }
137-
setTheme(R.style.AppDialog)
138-
}.show()
141+
eventBus.post(CmdShowSnackbarMsg(CmdShowSnackbarMsg.TYPE_ERROR, R.string.new_deck_save_error_incomplete)
142+
.withAction(android.R.string.ok, {}))
139143
}
140144
return true
141145
}

app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/InsetFrameLayout.kt renamed to app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/InsetFrameCoordinatorLayout.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package com.ediposouza.teslesgendstracker.ui.widget
33
import android.content.Context
44
import android.os.Build.VERSION
55
import android.os.Build.VERSION_CODES
6+
import android.support.design.widget.CoordinatorLayout
67
import android.util.AttributeSet
78
import android.view.WindowInsets
8-
import android.widget.FrameLayout
99

1010
/**
1111
* Created by EdipoSouza on 12/28/16.
1212
*/
13-
class InsetFrameLayout(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) :
14-
FrameLayout(ctx, attrs, defStyleAttr) {
13+
class InsetFrameCoordinatorLayout(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) :
14+
CoordinatorLayout(ctx, attrs, defStyleAttr) {
1515

1616
private val mInsets = IntArray(4)
1717

app/src/main/res/layout/activity_card.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
android:id="@+id/coordinatorLayout"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8+
android:animateLayoutChanges="true"
89
tools:context="com.ediposouza.teslesgendstracker.ui.CardActivity">
910

1011
<android.support.design.widget.CoordinatorLayout

app/src/main/res/layout/activity_deck.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<com.ediposouza.teslesgendstracker.ui.widget.InsetFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<com.ediposouza.teslesgendstracker.ui.widget.InsetFrameCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/coordinatorLayout"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8-
android:fitsSystemWindows="true"
8+
android:animateLayoutChanges="true"
99
tools:context="com.ediposouza.teslesgendstracker.ui.DeckActivity">
1010

1111
<android.support.design.widget.CoordinatorLayout
1212
android:layout_width="match_parent"
1313
android:layout_height="match_parent"
14-
tools:paddingBottom="@dimen/navigation_bar_height">
14+
android:paddingBottom="@dimen/navigation_bar_height">
1515

1616
<android.support.design.widget.AppBarLayout
1717
android:layout_width="match_parent"
@@ -142,7 +142,7 @@
142142
android:layout_width="match_parent"
143143
android:layout_height="wrap_content"
144144
android:layout_margin="@dimen/default_margin"
145-
tools:paddingBottom="@dimen/card_bottom_sheet_margin_bottom">
145+
android:paddingBottom="@dimen/card_bottom_sheet_margin_bottom">
146146

147147
<TextView
148148
android:layout_width="wrap_content"
@@ -224,4 +224,4 @@
224224

225225
</android.support.design.widget.CoordinatorLayout>
226226

227-
</com.ediposouza.teslesgendstracker.ui.widget.InsetFrameLayout>
227+
</com.ediposouza.teslesgendstracker.ui.widget.InsetFrameCoordinatorLayout>

app/src/main/res/layout/activity_new_deck.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/coordinatorLayout"
@@ -104,4 +104,4 @@
104104

105105
</android.support.design.widget.CoordinatorLayout>
106106

107-
</FrameLayout>
107+
</android.support.design.widget.CoordinatorLayout>

app/src/main/res/values/dimens.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<dimen name="deck_header_height">140dp</dimen>
5858
<dimen name="deck_header_attr_icon_height">32dp</dimen>
59-
<dimen name="deck_comment_bottom_sheet_peek_height">40dp</dimen>
59+
<dimen name="deck_comment_bottom_sheet_peek_height">88dp</dimen>
6060
<dimen name="deck_list_comment_name_width">56dp</dimen>
6161
<dimen name="deck_list_slot_height">32dp</dimen>
6262
<dimen name="deck_list_slot_half_height">16dp</dimen>

0 commit comments

Comments
 (0)