Skip to content

Commit 6cc5d27

Browse files
committed
✨ 바텀 네비게이션 연결 구현
1 parent ebd0852 commit 6cc5d27

File tree

9 files changed

+61
-50
lines changed

9 files changed

+61
-50
lines changed

presentation/src/main/java/com/whyranoid/presentation/MainActivity.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@ package com.whyranoid.presentation
33
import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
55
import androidx.navigation.fragment.NavHostFragment
6+
import androidx.navigation.ui.NavigationUI
7+
import com.whyranoid.presentation.databinding.ActivityMainBinding
68
import dagger.hilt.android.AndroidEntryPoint
79

810
@AndroidEntryPoint
911
class MainActivity : AppCompatActivity() {
12+
13+
private lateinit var binding: ActivityMainBinding
14+
1015
override fun onCreate(savedInstanceState: Bundle?) {
1116
super.onCreate(savedInstanceState)
12-
setContentView(R.layout.activity_main)
17+
18+
binding = ActivityMainBinding.inflate(layoutInflater)
19+
setContentView(binding.root)
1320

1421
val navHostFragment =
1522
supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
1623
val navController = navHostFragment.navController
24+
25+
NavigationUI.setupWithNavController(binding.bottomNavigation, navController)
1726
}
1827
}

presentation/src/main/java/com/whyranoid/presentation/myrun/MyRunFragment.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.view.View
55
import android.widget.EditText
66
import androidx.appcompat.app.AlertDialog
77
import androidx.fragment.app.viewModels
8+
import androidx.navigation.fragment.findNavController
89
import com.whyranoid.presentation.R
910
import com.whyranoid.presentation.base.BaseFragment
1011
import com.whyranoid.presentation.databinding.FragmentMyRunBinding
@@ -38,6 +39,14 @@ internal class MyRunFragment : BaseFragment<FragmentMyRunBinding>(R.layout.fragm
3839
}
3940

4041
binding.rvMyRunningHistory.adapter = runningHistoryAdapter
42+
43+
binding.topAppBar.setOnMenuItemClickListener { menuItem ->
44+
when (menuItem.itemId) {
45+
R.id.my_run_setting ->
46+
findNavController().navigate(R.id.action_myRunFragment_to_settingFragment)
47+
}
48+
true
49+
}
4150
}
4251

4352
private fun observeInfo() {
Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
tools:context=".MainActivity">
4+
xmlns:tools="http://schemas.android.com/tools">
85

9-
<androidx.fragment.app.FragmentContainerView
10-
android:id="@+id/fragment_container"
11-
android:name="androidx.navigation.fragment.NavHostFragment"
12-
android:layout_width="0dp"
13-
android:layout_height="0dp"
14-
app:defaultNavHost="true"
15-
app:layout_constraintBottom_toBottomOf="parent"
16-
app:layout_constraintEnd_toEndOf="parent"
17-
app:layout_constraintStart_toStartOf="parent"
18-
app:layout_constraintTop_toTopOf="parent"
19-
app:navGraph="@navigation/navigation_graph" />
6+
<data>
207

21-
</androidx.constraintlayout.widget.ConstraintLayout>
8+
</data>
9+
10+
<androidx.constraintlayout.widget.ConstraintLayout
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
tools:context=".MainActivity">
14+
15+
<androidx.fragment.app.FragmentContainerView
16+
android:id="@+id/fragment_container"
17+
android:name="androidx.navigation.fragment.NavHostFragment"
18+
android:layout_width="0dp"
19+
android:layout_height="0dp"
20+
app:defaultNavHost="true"
21+
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
22+
app:layout_constraintEnd_toEndOf="parent"
23+
app:layout_constraintStart_toStartOf="parent"
24+
app:layout_constraintTop_toTopOf="parent"
25+
app:navGraph="@navigation/navigation_graph" />
26+
27+
<com.google.android.material.bottomnavigation.BottomNavigationView
28+
android:id="@+id/bottom_navigation"
29+
style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
30+
android:layout_width="0dp"
31+
android:layout_height="wrap_content"
32+
app:layout_constraintBottom_toBottomOf="parent"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintEnd_toEndOf="parent"
35+
app:menu="@menu/bottom_navigation_menu" />
36+
37+
</androidx.constraintlayout.widget.ConstraintLayout>
38+
</layout>

presentation/src/main/res/layout/bottom_navigation_bar.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

presentation/src/main/res/layout/fragment_my_run.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
android:layout_width="match_parent"
3636
android:layout_height="0dp"
3737
app:layout_constraintTop_toBottomOf="@id/tool_bar"
38-
app:layout_constraintBottom_toTopOf="@id/bottom_navigation">
38+
app:layout_constraintBottom_toBottomOf="parent">
3939

4040
<androidx.core.widget.NestedScrollView
4141
android:layout_width="match_parent"
@@ -120,11 +120,9 @@
120120
</androidx.constraintlayout.widget.ConstraintLayout>
121121

122122
</androidx.core.widget.NestedScrollView>
123+
123124
</androidx.constraintlayout.widget.ConstraintLayout>
124125

125-
<include
126-
android:id="@+id/bottom_navigation"
127-
layout="@layout/bottom_navigation_bar" />
128126

129127
</androidx.constraintlayout.widget.ConstraintLayout>
130128
</layout>

presentation/src/main/res/layout/fragment_running_start.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
android:layout_width="match_parent"
1515
android:layout_height="match_parent">
1616

17-
<include
18-
android:id="@+id/bottom_navigation"
19-
layout="@layout/bottom_navigation_bar" />
20-
2117
<include
2218
android:id="@+id/tv_network_connection"
2319
layout="@layout/network_conntection_alert"
@@ -108,7 +104,7 @@
108104
android:onClick="@{() -> vm.onStartButtonClicked()}"
109105
app:cardBackgroundColor="@color/mogakrun_primary_light"
110106
app:cardCornerRadius="999dp"
111-
app:layout_constraintBottom_toBottomOf="@id/bottom_navigation"
107+
app:layout_constraintBottom_toBottomOf="parent"
112108
app:layout_constraintDimensionRatio="1:1"
113109
app:layout_constraintEnd_toEndOf="@id/width_end"
114110
app:layout_constraintStart_toStartOf="@id/width_start"

presentation/src/main/res/layout/fragment_setting.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
android:layout_height="?attr/actionBarSize"
2525
app:titleCentered="true"
2626
app:title="@string/my_run_tool_bar_menu_setting"
27-
app:navigationIcon="@drawable/navigation_back_button"
2827
/>
2928

3029
</com.google.android.material.appbar.AppBarLayout>

presentation/src/main/res/menu/bottom_navigation_menu.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android">
33
<item
4-
android:id="@+id/page_community"
4+
android:id="@+id/communityFragment"
55
android:enabled="true"
66
android:icon="@drawable/bottom_navigation_community"
77
android:title="@string/bottom_navigation_menu_community"/>
88
<item
9-
android:id="@+id/page_running"
9+
android:id="@+id/runningStartFragment"
1010
android:enabled="true"
1111
android:icon="@drawable/bottom_navigation_running"
1212
android:title="@string/bottom_navigation_menu_running"/>
1313
<item
14-
android:id="@+id/page_my_run"
14+
android:id="@+id/myRunFragment"
1515
android:enabled="true"
1616
android:icon="@drawable/bottom_navigation_my_run"
1717
android:title="@string/bottom_navigation_menu_my_run"

presentation/src/main/res/navigation/navigation_graph.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/navigation_graph.xml"
6-
app:startDestination="@id/myRunFragment">
6+
app:startDestination="@id/runningStartFragment">
77

88
<fragment
99
android:id="@+id/myRunFragment"
@@ -23,11 +23,7 @@
2323
android:id="@+id/runningStartFragment"
2424
android:name="com.whyranoid.presentation.runningstart.RunningStartFragment"
2525
android:label="RunningStartFragment"
26-
tools:layout="@layout/fragment_running_start">
27-
<action
28-
android:id="@+id/action_runningStartFragment_to_myRunFragment"
29-
app:destination="@id/myRunFragment" />
30-
</fragment>
26+
tools:layout="@layout/fragment_running_start"/>
3127
<fragment
3228
android:id="@+id/communityFragment"
3329
android:name="com.whyranoid.presentation.community.CommunityFragment"

0 commit comments

Comments
 (0)