- Add Navigation's SafeArgs plugin to the project, this plugin enables to pass arguments between fragments in a safe way.
- Use the Navigation AAC to create the navigation from the Balances to the Send and Receive fragments, using Navigation's SafeArgs to activate the camera in SendTransactionFragment in the case the user tapped on the camera button instead ofjust the send button in the Balances.
This commit is contained in:
parent
6e25dd7589
commit
22666021f1
6 changed files with 57 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: "androidx.navigation.safeargs"
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
@ -52,7 +53,6 @@ dependencies {
|
|||
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
|
||||
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
|
||||
|
||||
|
||||
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
|
||||
|
||||
implementation 'org.bitcoinj:bitcoinj-core:0.14.3'
|
||||
|
|
|
@ -6,19 +6,17 @@ import android.preference.PreferenceManager
|
|||
import android.view.*
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.navigation.Navigation
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
|
||||
import cy.agorise.bitsybitshareswallet.R
|
||||
import cy.agorise.bitsybitshareswallet.adapters.BalancesAdapter
|
||||
import cy.agorise.bitsybitshareswallet.adapters.TransfersDetailsAdapter
|
||||
import cy.agorise.bitsybitshareswallet.database.entities.UserAccount
|
||||
import cy.agorise.bitsybitshareswallet.database.joins.BalanceDetail
|
||||
import cy.agorise.bitsybitshareswallet.database.joins.TransferDetail
|
||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||
import cy.agorise.bitsybitshareswallet.viewmodels.BalanceDetailViewModel
|
||||
import cy.agorise.bitsybitshareswallet.viewmodels.TransferDetailViewModel
|
||||
import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
|
||||
import kotlinx.android.synthetic.main.fragment_balances.*
|
||||
|
||||
|
@ -60,6 +58,23 @@ class BalancesFragment : Fragment() {
|
|||
mBalanceDetailViewModel.getAll().observe(this, Observer<List<BalanceDetail>> { balancesDetails ->
|
||||
balancesAdapter.replaceAll(balancesDetails)
|
||||
})
|
||||
|
||||
// Navigate to the Receive Transaction Fragment
|
||||
fabReceiveTransaction.setOnClickListener (
|
||||
Navigation.createNavigateOnClickListener(R.id.receive_action)
|
||||
)
|
||||
|
||||
// Navigate to the Send Transaction Fragment without activating the camera
|
||||
fabSendTransaction.setOnClickListener(
|
||||
Navigation.createNavigateOnClickListener(R.id.send_action)
|
||||
)
|
||||
|
||||
// Navigate to the Send Transaction Fragment using Navigation's SafeArgs to activate the camera
|
||||
fabSendTransactionCamera.setOnClickListener {
|
||||
val action = BalancesFragmentDirections.sendActionCamera()
|
||||
action.setOpenCamera(true)
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
|
|
|
@ -122,7 +122,10 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
|
|||
if (userId != "")
|
||||
mUserAccount = UserAccount(userId)
|
||||
|
||||
verifyCameraPermission()
|
||||
// Use Navigation SafeArgs to decide if we should activate or not the camera feed
|
||||
val safeArgs = SendTransactionFragmentArgs.fromBundle(arguments)
|
||||
if (safeArgs.openCamera)
|
||||
verifyCameraPermission()
|
||||
|
||||
fabOpenCamera.setOnClickListener { if (isCameraPreviewVisible) stopCameraPreview() else verifyCameraPermission() }
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:fabSize="mini"
|
||||
app:maxImageSize="18dp"
|
||||
android:src="@drawable/ic_camera"
|
||||
android:backgroundTint="@color/colorSend"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
|
|
@ -11,6 +11,19 @@
|
|||
android:name="cy.agorise.bitsybitshareswallet.fragments.BalancesFragment"
|
||||
android:label="@string/app_name"
|
||||
tools:layout="@layout/fragment_balances">
|
||||
|
||||
<action
|
||||
android:id="@+id/receive_action"
|
||||
app:destination="@+id/receive_dest"/>
|
||||
|
||||
<action
|
||||
android:id="@+id/send_action"
|
||||
app:destination="@id/send_dest"/>
|
||||
|
||||
<action
|
||||
android:id="@+id/send_action_camera"
|
||||
app:destination="@id/send_dest" >
|
||||
</action>
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
|
@ -24,4 +37,23 @@
|
|||
android:name="cy.agorise.bitsybitshareswallet.fragments.TransactionsFragment"
|
||||
android:label="@string/title_transactions"
|
||||
tools:layout="@layout/fragment_transactions"/>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/receive_dest"
|
||||
android:name="cy.agorise.bitsybitshareswallet.fragments.ReceiveTransactionFragment"
|
||||
android:label="@string/title_receive"
|
||||
tools:layout="@layout/fragment_receive_transaction"/>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/send_dest"
|
||||
android:name="cy.agorise.bitsybitshareswallet.fragments.SendTransactionFragment"
|
||||
android:label="@string/title_send"
|
||||
tools:layout="@layout/fragment_send_transaction">
|
||||
|
||||
<argument
|
||||
android:name="openCamera"
|
||||
app:argType="boolean"
|
||||
android:defaultValue="false" />
|
||||
</fragment>
|
||||
|
||||
</navigation>
|
|
@ -9,6 +9,7 @@ buildscript {
|
|||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha08"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
|
Loading…
Reference in a new issue