-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from junjange/feature/bottom_navi
- Loading branch information
Showing
13 changed files
with
218 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 60 additions & 14 deletions
74
android/app/src/main/java/com/woowacourse/friendogly/presentation/ui/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,67 @@ | ||
package com.woowacourse.friendogly.presentation.ui | ||
|
||
import android.os.Bundle | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.ViewCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import android.view.View | ||
import androidx.navigation.NavController | ||
import androidx.navigation.fragment.NavHostFragment | ||
import androidx.navigation.ui.setupWithNavController | ||
import com.woowacourse.friendogly.NavigationGraphDirections | ||
import com.woowacourse.friendogly.R | ||
import com.woowacourse.friendogly.databinding.ActivityMainBinding | ||
import com.woowacourse.friendogly.presentation.base.BaseActivity | ||
|
||
class MainActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enableEdgeToEdge() | ||
setContentView(R.layout.activity_main) | ||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> | ||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) | ||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) | ||
insets | ||
class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) { | ||
private lateinit var navHostFragment: NavHostFragment | ||
private lateinit var navController: NavController | ||
private var waitTime = 0L | ||
|
||
override fun initCreateView() { | ||
initNavController() | ||
} | ||
|
||
private fun initNavController() { | ||
navHostFragment = | ||
supportFragmentManager.findFragmentById(R.id.nav_host_fragment_container) as NavHostFragment | ||
navController = navHostFragment.navController | ||
|
||
navController.addOnDestinationChangedListener { _, destination, _ -> | ||
when (destination.id) { | ||
R.id.homeFragment, R.id.woofFragment, R.id.chatFragment, R.id.myPageFragment -> showBottomNav() | ||
else -> hideBottomNav() | ||
} | ||
} | ||
binding.bottomNavi.setupWithNavController(navController) | ||
binding.bottomNavi.setOnItemReselectedListener {} | ||
} | ||
|
||
private fun showBottomNav() { | ||
binding.bottomNavi.visibility = View.VISIBLE | ||
} | ||
|
||
private fun hideBottomNav() { | ||
binding.bottomNavi.visibility = View.GONE | ||
} | ||
|
||
override fun onBackPressed() { | ||
try { | ||
if (onBackPressedDispatcher.hasEnabledCallbacks()) { | ||
super.onBackPressed() | ||
} else { | ||
when (navController.currentDestination?.id) { | ||
R.id.homeFragment -> { | ||
if (System.currentTimeMillis() - waitTime >= 1500) { | ||
waitTime = System.currentTimeMillis() | ||
showToastMessage(getString(R.string.on_back_pressed_Message)) | ||
} else { | ||
finishAffinity() | ||
} | ||
} | ||
|
||
null -> super.onBackPressed() | ||
else -> navController.navigate(NavigationGraphDirections.actionHomeFragment()) | ||
} | ||
} | ||
} catch (e: Exception) { | ||
showToastMessage(e.message.toString()) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...oid/app/src/main/java/com/woowacourse/friendogly/presentation/ui/mypage/MyPageFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.woowacourse.friendogly.presentation.ui.mypage | ||
|
||
import com.woowacourse.friendogly.R | ||
import com.woowacourse.friendogly.databinding.FragmentMyPageBinding | ||
import com.woowacourse.friendogly.presentation.base.BaseFragment | ||
|
||
class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_page) { | ||
override fun initViewCreated() {} | ||
} |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/res/drawable/sel_main_icon_color_bnv_menu.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:color="@color/gray05" android:state_checked="false" /> | ||
<item android:color="@color/black" android:state_checked="true" /> | ||
</selector> |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/res/drawable/sel_main_text_color_bnv_menu.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:color="@color/gray05" android:state_checked="false" /> | ||
<item android:color="@color/black" android:state_checked="true" /> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<layout 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/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presentation.ui.MainActivity"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:id="@+id/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presentation.ui.MainActivity"> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/nav_host_fragment_container" | ||
android:name="androidx.navigation.fragment.NavHostFragment" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:defaultNavHost="true" | ||
app:layout_constraintBottom_toTopOf="@+id/line_bottom_navigation" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:navGraph="@navigation/navigation_main" /> | ||
|
||
<View | ||
android:id="@+id/line_bottom_navigation" | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:background="@color/black" | ||
app:layout_constraintBottom_toTopOf="@id/bottom_navi" | ||
app:layout_constraintTop_toBottomOf="@id/nav_host_fragment_container" /> | ||
|
||
<com.google.android.material.bottomnavigation.BottomNavigationView | ||
android:id="@+id/bottom_navi" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:clipChildren="false" | ||
app:elevation="0dp" | ||
app:itemActiveIndicatorStyle="@android:color/transparent" | ||
app:itemIconTint="@drawable/sel_main_icon_color_bnv_menu" | ||
app:itemTextColor="@drawable/sel_main_text_color_bnv_menu" | ||
app:labelVisibilityMode="labeled" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.0" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:menu="@menu/menu_main_bottom" /> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</layout> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout 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"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<item | ||
android:id="@+id/homeFragment" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_home" | ||
android:title="@string/bottom_home" /> | ||
|
||
<item | ||
android:id="@+id/woofFragment" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_dog" | ||
android:title="@string/bottom_woof" /> | ||
|
||
<item | ||
android:id="@+id/chatFragment" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_chat" | ||
android:title="@string/bottom_chat" /> | ||
|
||
<item | ||
android:id="@+id/myPageFragment" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_my" | ||
android:title="@string/bottom_my_page" /> | ||
|
||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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/navigation_graph" | ||
app:startDestination="@id/myPageFragment"> | ||
|
||
<action | ||
android:id="@+id/action_home_fragment" | ||
app:destination="@id/myPageFragment" | ||
app:enterAnim="@anim/nav_default_enter_anim" | ||
app:exitAnim="@anim/nav_default_exit_anim" | ||
app:popEnterAnim="@anim/nav_default_enter_anim" | ||
app:popExitAnim="@anim/nav_default_pop_exit_anim" | ||
app:popUpTo="@id/navigation_graph" | ||
app:popUpToInclusive="true" /> | ||
|
||
<fragment | ||
android:id="@+id/myPageFragment" | ||
android:name="com.woowacourse.friendogly.presentation.ui.mypage.MyPageFragment" | ||
android:label="MyPageFragment" | ||
tools:layout="@layout/fragment_my_page"> | ||
|
||
</fragment> | ||
|
||
</navigation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
<resources> | ||
<string name="app_name">friendogly</string> | ||
</resources> | ||
|
||
<!--홈화면--> | ||
<string name="on_back_pressed_Message">뒤로가기 버튼을\n한번 더 누르면 종료됩니다.</string> | ||
|
||
<!--내비게이션 메뉴--> | ||
<string name="bottom_home">홈</string> | ||
<string name="bottom_woof">멍멍짖기</string> | ||
<string name="bottom_chat">채팅</string> | ||
<string name="bottom_my_page">나의 댕댕이</string> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters