diff --git a/app/src/main/java/pbd/tubes/exe_android/MainActivity.kt b/app/src/main/java/pbd/tubes/exe_android/MainActivity.kt index 2cb7135bbc08fe28ac32cbe99cc3919df3c48d64..30aaff87413000b0338261b7c07daa024c3d7b1a 100644 --- a/app/src/main/java/pbd/tubes/exe_android/MainActivity.kt +++ b/app/src/main/java/pbd/tubes/exe_android/MainActivity.kt @@ -22,9 +22,12 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) - actionBar?.let { binding.container.setPadding(0, it.height, 0, 0) } + actionBar?.let { + binding.container.setPadding(0, it.height, 0, 0) + Log.d("MyApp", "Padded action bar set") + } setContentView(binding.root) - val navView: BottomNavigationView = binding.navView + val navView: BottomNavigationView? = binding.navView val navController = findNavController(R.id.nav_host_fragment_activity_main) // Passing each menu ID as a set of Ids because each @@ -35,78 +38,12 @@ class MainActivity : AppCompatActivity() { ) ) setupActionBarWithNavController(navController, appBarConfiguration) - navView.setupWithNavController(navController) + navView!!.setupWithNavController(navController) binding.addFab.setOnClickListener { navController.navigate(R.id.navigation_add_transaction) } } - - override fun onConfigurationChanged(newConfig: Configuration) { - super.onConfigurationChanged(newConfig) - if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { - updateConstraintsForLandscape() - } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { - updateConstraintsForPortrait() - } - val navController = findNavController(R.id.nav_host_fragment_activity_main) - val appBarConfiguration = AppBarConfiguration( - setOf( - R.id.navigation_transactions, R.id.navigation_scan, R.id.navigation_chart, R.id.navigation_settings - ) - ) - setupActionBarWithNavController(navController, appBarConfiguration) - binding.navView.setupWithNavController(navController) - } - - private fun updateConstraintsForLandscape() { - //TODO(update for landscape = bottomnavview -> railnavview) - binding.container.removeView(binding.navView) - - val navigationRailView = NavigationRailView(this) - navigationRailView.id = R.id.bottom_nav_menu - - val inflater = MenuInflater(this) - inflater.inflate(R.menu.bottom_nav_menu, navigationRailView.menu) - - // Get the existing layout parameters of the view - val layoutParams = binding.navView.layoutParams as ConstraintLayout.LayoutParams - actionBar?.let { binding.container.setPadding(0, it.height, 0, 0) } - - layoutParams.startToStart = ConstraintLayout.LayoutParams.PARENT_ID - layoutParams.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID - layoutParams.endToEnd = ConstraintLayout.LayoutParams.UNSET - layoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID - layoutParams.width = ConstraintLayout.LayoutParams.WRAP_CONTENT - layoutParams.height = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT - binding.container.addView(navigationRailView) - binding.navView.layoutParams = layoutParams - Log.d("Orientation Changed", "Device is now landscape") - } - private fun updateConstraintsForPortrait() { - //TODO(update for portrait = bottomnavview <- railnavview) - binding.container.removeView(binding.navView) - - val navigationBottomView = BottomNavigationView(this) - navigationBottomView.id = R.id.bottom_nav_menu - - val inflater = MenuInflater(this) - inflater.inflate(R.menu.bottom_nav_menu, navigationBottomView.menu) - - // Get the existing layout parameters of the view - val layoutParams = binding.navView.layoutParams as ConstraintLayout.LayoutParams - actionBar?.let { binding.container.setPadding(0, it.height, 0, 0) } - - layoutParams.startToStart = ConstraintLayout.LayoutParams.PARENT_ID - layoutParams.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID - layoutParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID - layoutParams.topToTop = ConstraintLayout.LayoutParams.UNSET - layoutParams.height = ConstraintLayout.LayoutParams.WRAP_CONTENT - layoutParams.width = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT - binding.container.addView(navigationBottomView) - binding.navView.layoutParams = layoutParams - Log.d("Orientation Changed", "Device is now portrait") - } // private fun fabShow(){ // binding.addFab.show() // binding.mainFabText.visibility = View.VISIBLE diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c3f3f22d34fecab03c4887a4d6e5fcafe1b5fd11 --- /dev/null +++ b/app/src/main/res/layout-land/activity_main.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/container" + android:layout_width="match_parent" + android:layout_height="match_parent" + > + + <com.google.android.material.navigationrail.NavigationRailView + android:id="@+id/nav_view_rail" + android:layout_width="wrap_content" + android:layout_height="0dp" + android:layout_marginStart="0dp" + android:layout_marginEnd="0dp" + android:background="?android:attr/windowBackground" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:menu="@menu/bottom_nav_menu" + /> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/add_fab" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/ic_add_24" + android:layout_marginBottom="16dp" + android:layout_marginEnd="16dp" + android:contentDescription="@string/transaction_operations_fab_text" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + android:layout_gravity="bottom|end" + /> + + <fragment + android:id="@+id/nav_host_fragment_activity_main" + android:name="androidx.navigation.fragment.NavHostFragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:defaultNavHost="true" + app:layout_constraintBottom_toTopOf="parent" + app:layout_constraintLeft_toRightOf="@id/nav_view_rail" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:navGraph="@navigation/mobile_navigation" /> + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ba65725b6c4fed27ccf2484900471dd94908dc6a..91f87866406bfc14cccd6803a9172c6727739191 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,19 +6,6 @@ android:layout_height="match_parent" > -<!-- <com.google.android.material.navigationrail.NavigationRailView--> -<!-- android:id="@+id/nav_view_rail"--> -<!-- android:layout_width="wrap_content"--> -<!-- android:layout_height="0dp"--> -<!-- android:layout_marginStart="0dp"--> -<!-- android:layout_marginEnd="0dp"--> -<!-- android:background="?android:attr/windowBackground"--> -<!-- app:layout_constraintBottom_toBottomOf="parent"--> -<!-- app:layout_constraintLeft_toLeftOf="parent"--> -<!-- app:layout_constraintTop_toTopOf="parent"--> -<!-- app:menu="@menu/bottom_nav_menu"--> -<!-- />--> - <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/nav_view" android:layout_width="0dp" @@ -34,11 +21,11 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_add_24" - android:layout_marginBottom="64dp" + android:layout_marginBottom="16dp" android:layout_marginEnd="16dp" android:contentDescription="@string/transaction_operations_fab_text" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@id/nav_view" android:layout_gravity="bottom|end" />