Created Kotlin etension functions to add a enabled/disabled functionality to FloatingActionButtons. This is used in the SendTransactionFragment to show the Send button as disabled when the information to send a transaction is not all correct.

This commit is contained in:
Severiano Jaramillo 2019-01-03 09:11:58 -06:00
parent 1b4de3fb1e
commit 8eed991e0e
5 changed files with 24 additions and 7 deletions

View file

@ -29,6 +29,8 @@ import cy.agorise.bitsybitshareswallet.database.joins.BalanceDetail
import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository
import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.utils.CryptoUtils
import cy.agorise.bitsybitshareswallet.utils.disable
import cy.agorise.bitsybitshareswallet.utils.enable
import cy.agorise.bitsybitshareswallet.viewmodels.BalanceDetailViewModel
import cy.agorise.graphenej.*
import cy.agorise.graphenej.api.ConnectionStatusUpdate
@ -160,7 +162,7 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
}
fabSendTransaction.setOnClickListener { startSendTransferOperation() }
fabSendTransaction.hide()
fabSendTransaction.disable(R.color.lightGray)
authorityRepository = AuthorityRepository(context!!)
@ -391,9 +393,9 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
private fun enableDisableSendFAB() {
if (isToAccountCorrect && isAmountCorrect)
fabSendTransaction.show()
fabSendTransaction.enable(R.color.colorSend)
else
fabSendTransaction.hide()
fabSendTransaction.disable(R.color.lightGray)
}
private fun startSendTransferOperation() {

View file

@ -0,0 +1,15 @@
package cy.agorise.bitsybitshareswallet.utils
import android.content.res.ColorStateList
import androidx.core.content.ContextCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
fun FloatingActionButton.enable(colorResource: Int) {
this.isEnabled = true
this.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this.context, colorResource))
}
fun FloatingActionButton.disable(colorResource: Int) {
this.isEnabled = false
this.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this.context, colorResource))
}

View file

@ -186,7 +186,6 @@
app:fabCustomSize="90dp"
app:maxImageSize="70dp"
app:srcCompat="@drawable/ic_arrow_forward"
android:backgroundTint="@color/colorSend"
app:layout_constraintEnd_toEndOf="@id/vSend"
app:layout_constraintTop_toTopOf="@+id/vSend" />

View file

@ -105,7 +105,7 @@
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginTop="12dp"
android:background="@color/lightGray"
android:background="@color/superLightGray"
app:layout_constraintTop_toBottomOf="@id/tvFrom"
app:layout_constraintStart_toEndOf="@id/firstVerticalGuideline"
app:layout_constraintEnd_toStartOf="@id/fourthVerticalGuideline" />
@ -133,7 +133,7 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="12dp"
android:background="@color/lightGray"/>
android:background="@color/superLightGray"/>
</LinearLayout>

View file

@ -10,7 +10,8 @@
<color name="black">#000</color>
<color name="gray">#888</color>
<color name="ppGreen">#139657</color>
<color name="lightGray">#e0e0e0</color>
<color name="lightGray">#aaa</color>
<color name="superLightGray">#e0e0e0</color>
<color name="darkGray">#616161</color>
<color name="colorReceive">#669900</color>
<color name="colorSend">#DC473A</color>