Make proper configurations to enable the Navigation component and make use of it to add the navigation to the Merchants fragment and back to the Balances fragment.
This commit is contained in:
parent
82efa60a36
commit
3d6ce645b5
6 changed files with 74 additions and 29 deletions
|
@ -1,16 +1,61 @@
|
||||||
package cy.agorise.bitsybitshareswallet.activities
|
package cy.agorise.bitsybitshareswallet.activities
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.navigation.findNavController
|
||||||
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
|
import androidx.navigation.ui.navigateUp
|
||||||
|
import androidx.navigation.ui.onNavDestinationSelected
|
||||||
|
import androidx.navigation.ui.setupActionBarWithNavController
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
||||||
import cy.agorise.graphenej.models.JsonRpcResponse
|
import cy.agorise.graphenej.models.JsonRpcResponse
|
||||||
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
class MainActivity : ConnectedActivity() {
|
class MainActivity : ConnectedActivity() {
|
||||||
private val TAG = this.javaClass.simpleName
|
private val TAG = this.javaClass.simpleName
|
||||||
|
|
||||||
|
private lateinit var appBarConfiguration : AppBarConfiguration
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
setSupportActionBar(toolbar)
|
||||||
|
|
||||||
|
val host: NavHostFragment = supportFragmentManager
|
||||||
|
.findFragmentById(R.id.navHostFragment) as NavHostFragment? ?: return
|
||||||
|
|
||||||
|
// Set up Action Bar
|
||||||
|
val navController = host.navController
|
||||||
|
|
||||||
|
appBarConfiguration = AppBarConfiguration(navController.graph)
|
||||||
|
|
||||||
|
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
|
|
||||||
|
navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||||
|
val dest: String = try {
|
||||||
|
resources.getResourceName(destination.id)
|
||||||
|
} catch (e: Resources.NotFoundException) {
|
||||||
|
Integer.toString(destination.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
// Have the NavigationUI look for an action or destination matching the menu
|
||||||
|
// item id and navigate there if found.
|
||||||
|
// Otherwise, bubble up to the parent.
|
||||||
|
return item.onNavDestinationSelected(findNavController(R.id.navHostFragment))
|
||||||
|
|| super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
|
// Allows NavigationUI to support proper up navigation or the drawer layout
|
||||||
|
// drawer menu, depending on the situation
|
||||||
|
return findNavController(R.id.navHostFragment).navigateUp(appBarConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleJsonRpcResponse(response: JsonRpcResponse<*>) {
|
override fun handleJsonRpcResponse(response: JsonRpcResponse<*>) {
|
||||||
|
|
|
@ -3,10 +3,8 @@ package cy.agorise.bitsybitshareswallet.fragments
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
|
import android.view.*
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
@ -33,6 +31,8 @@ class BalancesFragment : Fragment() {
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
|
setHasOptionsMenu(true)
|
||||||
|
|
||||||
return inflater.inflate(R.layout.fragment_balances, container, false)
|
return inflater.inflate(R.layout.fragment_balances, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,4 +71,8 @@ class BalancesFragment : Fragment() {
|
||||||
transfersDetailsAdapter.replaceAll(transfersDetails)
|
transfersDetailsAdapter.replaceAll(transfersDetails)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
|
inflater.inflate(R.menu.menu_balances, menu)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark" />
|
android:theme="@style/ThemeOverlay.AppCompat.Dark" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/my_nav_host_fragment"
|
android:id="@+id/navHostFragment"
|
||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
|
17
app/src/main/res/menu/menu_balances.xml
Normal file
17
app/src/main/res/menu/menu_balances.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/merchants_dest"
|
||||||
|
android:icon="@drawable/ic_merchants"
|
||||||
|
android:title="@string/title_merchants"
|
||||||
|
app:showAsAction="always"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_settings"
|
||||||
|
android:icon="@drawable/ic_settings"
|
||||||
|
android:title="@string/title_settings"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
|
</menu>
|
|
@ -1,24 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/navigation_receive"
|
|
||||||
android:icon="@drawable/ic_receive"
|
|
||||||
android:title="@string/title_receive"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/navigation_balances"
|
|
||||||
android:icon="@drawable/ic_balances"
|
|
||||||
android:title="@string/title_balances"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/navigation_merchants"
|
|
||||||
android:icon="@drawable/ic_merchants"
|
|
||||||
android:title="@string/title_merchants"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/navigation_send"
|
|
||||||
android:icon="@drawable/ic_send"
|
|
||||||
android:title="@string/title_send"/>
|
|
||||||
|
|
||||||
</menu>
|
|
|
@ -9,7 +9,10 @@
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/balancesFragment"
|
android:id="@+id/balancesFragment"
|
||||||
android:name="cy.agorise.bitsybitshareswallet.fragments.BalancesFragment"
|
android:name="cy.agorise.bitsybitshareswallet.fragments.BalancesFragment"
|
||||||
android:label="BalancesFragment"
|
android:label="@string/app_name"
|
||||||
tools:layout="@layout/fragment_balances">
|
tools:layout="@layout/fragment_balances">
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment android:id="@+id/merchants_dest"
|
||||||
|
android:name="cy.agorise.bitsybitshareswallet.fragments.MerchantsFragment"
|
||||||
|
android:label="fragment_merchants" tools:layout="@layout/fragment_merchants"/>
|
||||||
</navigation>
|
</navigation>
|
Loading…
Reference in a new issue