Introduce the new Android Architecture Components' Navigation.
- Remove the old MainActivity layout that included a BottomNavigationView. - Start using the Navigation AAC and make the BalancesFragment the default Fragment so that it is the first to appear.
This commit is contained in:
parent
410d22c5b0
commit
82efa60a36
5 changed files with 39 additions and 84 deletions
|
@ -33,6 +33,7 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
def lifecycle_version = "2.0.0"
|
def lifecycle_version = "2.0.0"
|
||||||
def room_version = "2.1.0-alpha03"
|
def room_version = "2.1.0-alpha03"
|
||||||
|
def nav_version = "1.0.0-alpha08"
|
||||||
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation project(':graphenejlib:graphenej')
|
implementation project(':graphenejlib:graphenej')
|
||||||
|
@ -48,6 +49,10 @@ dependencies {
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
implementation "androidx.room:room-rxjava2:$room_version" // RxJava support for Room
|
implementation "androidx.room:room-rxjava2:$room_version" // RxJava support for Room
|
||||||
|
|
||||||
|
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 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
|
||||||
|
|
||||||
implementation 'org.bitcoinj:bitcoinj-core:0.14.3'
|
implementation 'org.bitcoinj:bitcoinj-core:0.14.3'
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
<activity android:name=".activities.ImportBrainkeyActivity"/>
|
<activity android:name=".activities.ImportBrainkeyActivity"/>
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.MainActivity"
|
android:name=".activities.MainActivity"
|
||||||
|
android:theme="@style/Theme.Bitsy.NoActionBar"
|
||||||
android:windowSoftInputMode="adjustPan"/>
|
android:windowSoftInputMode="adjustPan"/>
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.SettingsActivity"
|
android:name=".activities.SettingsActivity"
|
||||||
|
|
|
@ -1,74 +1,16 @@
|
||||||
package cy.agorise.bitsybitshareswallet.activities
|
package cy.agorise.bitsybitshareswallet.activities
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuItem
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
import cy.agorise.bitsybitshareswallet.fragments.BalancesFragment
|
|
||||||
import cy.agorise.bitsybitshareswallet.fragments.MerchantsFragment
|
|
||||||
import cy.agorise.bitsybitshareswallet.fragments.ReceiveTransactionFragment
|
|
||||||
import cy.agorise.bitsybitshareswallet.fragments.SendTransactionFragment
|
|
||||||
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 val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
|
|
||||||
when (item.itemId) {
|
|
||||||
R.id.navigation_receive -> {
|
|
||||||
loadFragment(ReceiveTransactionFragment())
|
|
||||||
return@OnNavigationItemSelectedListener true
|
|
||||||
}
|
|
||||||
R.id.navigation_balances -> {
|
|
||||||
loadFragment(BalancesFragment())
|
|
||||||
return@OnNavigationItemSelectedListener true
|
|
||||||
}
|
|
||||||
R.id.navigation_merchants -> {
|
|
||||||
loadFragment(MerchantsFragment())
|
|
||||||
return@OnNavigationItemSelectedListener true
|
|
||||||
}
|
|
||||||
R.id.navigation_send -> {
|
|
||||||
loadFragment(SendTransactionFragment())
|
|
||||||
return@OnNavigationItemSelectedListener true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
|
|
||||||
navigation.selectedItemId = R.id.navigation_balances
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadFragment(fragment: Fragment) {
|
|
||||||
val ft = supportFragmentManager.beginTransaction()
|
|
||||||
ft.replace(R.id.fragment_frame, fragment)
|
|
||||||
ft.commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
|
||||||
// Inflates the menu and places it in the toolbar
|
|
||||||
menuInflater.inflate(R.menu.menu_main, menu)
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
|
||||||
return if (item!!.itemId == R.id.menu_settings) {
|
|
||||||
val intent = Intent(this, SettingsActivity::class.java)
|
|
||||||
startActivity(intent)
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleJsonRpcResponse(response: JsonRpcResponse<*>) {
|
override fun handleJsonRpcResponse(response: JsonRpcResponse<*>) {
|
||||||
|
@ -80,11 +22,6 @@ class MainActivity : ConnectedActivity() {
|
||||||
* @param connectionStatusUpdate Connection status update.
|
* @param connectionStatusUpdate Connection status update.
|
||||||
*/
|
*/
|
||||||
override fun handleConnectionStatusUpdate(connectionStatusUpdate: ConnectionStatusUpdate) {
|
override fun handleConnectionStatusUpdate(connectionStatusUpdate: ConnectionStatusUpdate) {
|
||||||
when (connectionStatusUpdate.updateCode) {
|
|
||||||
ConnectionStatusUpdate.CONNECTED -> { /* Do nothing for now */ }
|
|
||||||
ConnectionStatusUpdate.DISCONNECTED -> { /* Do nothing for now */ }
|
|
||||||
ConnectionStatusUpdate.AUTHENTICATED -> {}//updateBalances() }
|
|
||||||
ConnectionStatusUpdate.API_UPDATE -> { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,27 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/container"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
tools:context=".activities.MainActivity">
|
tools:context=".activities.MainActivity">
|
||||||
|
|
||||||
<FrameLayout
|
<androidx.appcompat.widget.Toolbar
|
||||||
android:id="@+id/fragment_frame"
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/colorPrimary"
|
||||||
|
android:theme="@style/ThemeOverlay.AppCompat.Dark" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/my_nav_host_fragment"
|
||||||
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
android:layout_weight="1"
|
||||||
app:layout_constraintBottom_toTopOf="@id/navigation"/>
|
app:defaultNavHost="true"
|
||||||
|
app:navGraph="@navigation/mobile_navigation" />
|
||||||
|
|
||||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
</LinearLayout>
|
||||||
android:id="@+id/navigation"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="0dp"
|
|
||||||
android:layout_marginStart="0dp"
|
|
||||||
android:background="?android:attr/windowBackground"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
|
||||||
app:menu="@menu/navigation"/>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
15
app/src/main/res/navigation/mobile_navigation.xml
Normal file
15
app/src/main/res/navigation/mobile_navigation.xml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<navigation
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/mobile_navigation"
|
||||||
|
app:startDestination="@id/balancesFragment">
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/balancesFragment"
|
||||||
|
android:name="cy.agorise.bitsybitshareswallet.fragments.BalancesFragment"
|
||||||
|
android:label="BalancesFragment"
|
||||||
|
tools:layout="@layout/fragment_balances">
|
||||||
|
</fragment>
|
||||||
|
</navigation>
|
Loading…
Reference in a new issue