From 82efa60a367de49dcdfbb8e805146fed4a6f5437 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 12 Dec 2018 20:56:20 -0600 Subject: [PATCH] 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. --- app/build.gradle | 5 ++ app/src/main/AndroidManifest.xml | 1 + .../activities/MainActivity.kt | 65 +------------------ app/src/main/res/layout/activity_main.xml | 37 +++++------ .../main/res/navigation/mobile_navigation.xml | 15 +++++ 5 files changed, 39 insertions(+), 84 deletions(-) create mode 100644 app/src/main/res/navigation/mobile_navigation.xml diff --git a/app/build.gradle b/app/build.gradle index 2cc55f6..b01f760 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,7 @@ android { dependencies { def lifecycle_version = "2.0.0" def room_version = "2.1.0-alpha03" + def nav_version = "1.0.0-alpha08" implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':graphenejlib:graphenej') @@ -48,6 +49,10 @@ dependencies { kapt "androidx.room:room-compiler:$room_version" 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 'org.bitcoinj:bitcoinj-core:0.14.3' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 74048ff..914a868 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,6 +28,7 @@ - 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?) { super.onCreate(savedInstanceState) 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<*>) { @@ -80,11 +22,6 @@ class MainActivity : ConnectedActivity() { * @param connectionStatusUpdate Connection status update. */ 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 -> { } - } + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c2bbe0d..9411d90 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,30 +1,27 @@ - - + - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml new file mode 100644 index 0000000..c362807 --- /dev/null +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file