Skip to content

Commit 30066a3

Browse files
author
SangEun
committed
add sample project
1 parent a310a97 commit 30066a3

File tree

15 files changed

+267
-4
lines changed

15 files changed

+267
-4
lines changed

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ android {
2929
kotlinOptions {
3030
jvmTarget = '1.8'
3131
}
32+
buildFeatures {
33+
dataBinding = true
34+
}
3235
}
3336

3437
dependencies {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.daou.scrollbottomnavigation
2+
3+
import androidx.fragment.app.Fragment
4+
5+
abstract class BaseFragment(val key: String): Fragment() {
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.daou.scrollbottomnavigation
2+
3+
import com.daou.lib.model.HOME
4+
5+
class HomeFragment: BaseFragment(HOME.typeString) {
6+
}

app/src/main/java/com/daou/scrollbottomnavigation/MainActivity.kt

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,138 @@ package com.daou.scrollbottomnavigation
22

33
import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
5+
import androidx.constraintlayout.widget.ConstraintLayout
56
import androidx.databinding.DataBindingUtil
67
import androidx.fragment.app.Fragment
8+
import com.daou.lib.hide
9+
import com.daou.lib.model.*
10+
import com.daou.lib.show
711
import com.daou.scrollbottomnavigation.databinding.ActivityMainBinding
12+
import com.google.android.material.bottomsheet.BottomSheetBehavior
813

914
class MainActivity : AppCompatActivity() {
1015
private lateinit var binding: ActivityMainBinding
11-
private val fragmentList = listOf<Fragment>()
16+
private val fragmentList = listOf<BaseFragment>(HomeFragment())
17+
private val sheetBehavior: BottomSheetBehavior<ConstraintLayout> by lazy {
18+
BottomSheetBehavior.from(binding.clSlideMenuWrap)
19+
}
20+
1221
override fun onCreate(savedInstanceState: Bundle?) {
1322
super.onCreate(savedInstanceState)
1423
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
1524
initBottomNavigationView()
25+
//가로모드에서 메뉴가 올라오는 현상 방지
26+
sheetBehavior.isDraggable = false
27+
setBottomTabItemList()
1628
}
1729

1830
private fun initBottomNavigationView() {
1931
with(binding) {
2032
mainViewPagerAdapter = ViewPagerFragmentAdapter(this@MainActivity, fragmentList)
2133
bottomNav.setOnClickFixedMenu {
22-
34+
invertMenuBehavior()
2335
}
2436
bottomNav.setOnNavigationItemSelectedListener { tabItem ->
37+
val isMenuOpened = sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED
38+
if (isMenuOpened) {
39+
sheetBehavior.hide()
40+
}
41+
when (tabItem.type) {
42+
HOME, NOTIFICATION -> {
43+
val index = fragmentList.indexOfFirst { it.key == tabItem.type.typeString }
44+
if (index != -1) switchTab(index, tabItem)
45+
}
46+
is WEB -> {}
47+
else -> {}
48+
}
2549
}
2650
}
2751
}
52+
53+
private fun switchTab(menuIndex: Int, tabItem: BottomTabItem) {
54+
binding.viewPager.setCurrentItem(menuIndex, false)
55+
changeSlideMenuState(willShowMenu = false)
56+
}
57+
58+
private fun changeSlideMenuState(willShowMenu: Boolean) {
59+
if (willShowMenu) {
60+
sheetBehavior.show()
61+
setFixedMenuIconRes(R.drawable.ic_cancel)
62+
} else {
63+
setFixedMenuIconRes(R.drawable.ic_menu_normal)
64+
sheetBehavior.hide()
65+
}
66+
}
67+
68+
private fun setFixedMenuIconRes(resId: Int) {
69+
binding.bottomNav.setFixedMenuIcon(resId)
70+
}
71+
72+
private fun invertMenuBehavior() {
73+
if (sheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) {
74+
changeSlideMenuState(false)
75+
} else {
76+
changeSlideMenuState(true)
77+
}
78+
}
79+
80+
private fun setBottomTabItemList() {
81+
val menuList = listOf(
82+
BottomTabItem(
83+
appName = "menu1",
84+
text = "menu1",
85+
badgeContent = null,
86+
type = HOME,
87+
iconRes = R.drawable.icon_bottom_menu_heart,
88+
isClicked = false,
89+
isDormant = false
90+
),
91+
BottomTabItem(
92+
appName = "menu2",
93+
text = "menu2",
94+
badgeContent = null,
95+
type = HOME,
96+
iconRes = R.drawable.icon_bottom_menu_heart,
97+
isClicked = false,
98+
isDormant = false
99+
),
100+
BottomTabItem(
101+
appName = "menu3",
102+
text = "menu3",
103+
badgeContent = null,
104+
type = HOME,
105+
iconRes = R.drawable.icon_bottom_menu_heart,
106+
isClicked = false,
107+
isDormant = false
108+
),
109+
BottomTabItem(
110+
appName = "menu4",
111+
text = "menu4",
112+
badgeContent = null,
113+
type = HOME,
114+
iconRes = R.drawable.icon_bottom_menu_heart,
115+
isClicked = false,
116+
isDormant = false
117+
),
118+
BottomTabItem(
119+
appName = "menu5",
120+
text = "menu5",
121+
badgeContent = null,
122+
type = HOME,
123+
iconRes = R.drawable.icon_bottom_menu_heart,
124+
isClicked = false,
125+
isDormant = false
126+
),
127+
BottomTabItem(
128+
appName = "menu6",
129+
text = "menu6",
130+
badgeContent = null,
131+
type = HOME,
132+
iconRes = R.drawable.icon_bottom_menu_heart,
133+
isClicked = false,
134+
isDormant = false
135+
),
136+
)
137+
binding.bottomNav.setBottomTabItemList(menuList)
138+
}
28139
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:pathData="M2.146,2.146c0.196,-0.195 0.512,-0.195 0.708,0L12,11.293 21.146,2.146c0.196,-0.195 0.512,-0.195 0.708,0 0.195,0.196 0.195,0.512 0,0.708L12.707,12l9.147,9.146c0.173,0.174 0.192,0.443 0.057,0.638l-0.057,0.07c-0.196,0.195 -0.512,0.195 -0.708,0L12,12.707 2.854,21.854c-0.196,0.195 -0.512,0.195 -0.708,0 -0.195,-0.196 -0.195,-0.512 0,-0.708L11.293,12 2.146,2.854C1.973,2.68 1.954,2.41 2.09,2.216z"
8+
android:fillColor="#333"
9+
android:fillType="nonZero"/>
10+
<group>
11+
<clip-path
12+
android:pathData="M2.146,2.146c0.196,-0.195 0.512,-0.195 0.708,0L12,11.293 21.146,2.146c0.196,-0.195 0.512,-0.195 0.708,0 0.195,0.196 0.195,0.512 0,0.708L12.707,12l9.147,9.146c0.173,0.174 0.192,0.443 0.057,0.638l-0.057,0.07c-0.196,0.195 -0.512,0.195 -0.708,0L12,12.707 2.854,21.854c-0.196,0.195 -0.512,0.195 -0.708,0 -0.195,-0.196 -0.195,-0.512 0,-0.708L11.293,12 2.146,2.854C1.973,2.68 1.954,2.41 2.09,2.216z"/>
13+
<path
14+
android:pathData="M0,0L24,0L24,24L0,24z"
15+
android:fillColor="#333"
16+
android:fillType="evenOdd"/>
17+
</group>
18+
</vector>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="25dp"
3+
android:height="24dp"
4+
android:viewportWidth="25"
5+
android:viewportHeight="24">
6+
<path
7+
android:pathData="M3.358,5.11c-2.147,2.148 -2.147,5.63 0,7.777l6.834,6.834 0.135,0.125c0.505,0.437 1.158,0.649 1.814,0.601l0.108,-0.012 -0.072,-0.007c0.775,0.112 1.562,-0.142 2.127,-0.707l6.833,-6.834 0.181,-0.19c1.972,-2.174 1.895,-5.511 -0.18,-7.586l-0.2,-0.19 -0.193,-0.167c-2.168,-1.79 -5.37,-1.658 -7.384,0.357L12.248,6.223l-1.113,-1.112c-2.147,-2.148 -5.629,-2.148 -7.776,0zM20.093,5.512l0.165,0.142 0.181,0.172c1.69,1.69 1.752,4.42 0.146,6.191l-0.163,0.172 -6.826,6.825c-0.339,0.34 -0.81,0.491 -1.276,0.424h-0.143c-0.466,0.067 -0.938,-0.085 -1.277,-0.424L4.066,12.18c-1.757,-1.757 -1.757,-4.605 0,-6.362 1.757,-1.757 4.605,-1.757 6.362,0l1.466,1.466c0.196,0.195 0.512,0.195 0.708,0l1.466,-1.466c1.643,-1.643 4.252,-1.755 6.025,-0.306z"
8+
android:fillColor="#333"
9+
android:fillType="nonZero"/>
10+
<group>
11+
<clip-path
12+
android:pathData="M3.358,5.11c-2.147,2.148 -2.147,5.63 0,7.777l6.834,6.834 0.135,0.125c0.505,0.437 1.158,0.649 1.814,0.601l0.108,-0.012 -0.072,-0.007c0.775,0.112 1.562,-0.142 2.127,-0.707l6.833,-6.834 0.181,-0.19c1.972,-2.174 1.895,-5.511 -0.18,-7.586l-0.2,-0.19 -0.193,-0.167c-2.168,-1.79 -5.37,-1.658 -7.384,0.357L12.248,6.223l-1.113,-1.112c-2.147,-2.148 -5.629,-2.148 -7.776,0zM20.093,5.512l0.165,0.142 0.181,0.172c1.69,1.69 1.752,4.42 0.146,6.191l-0.163,0.172 -6.826,6.825c-0.339,0.34 -0.81,0.491 -1.276,0.424h-0.143c-0.466,0.067 -0.938,-0.085 -1.277,-0.424L4.066,12.18c-1.757,-1.757 -1.757,-4.605 0,-6.362 1.757,-1.757 4.605,-1.757 6.362,0l1.466,1.466c0.196,0.195 0.512,0.195 0.708,0l1.466,-1.466c1.643,-1.643 4.252,-1.755 6.025,-0.306z"/>
13+
<path
14+
android:pathData="M0.248,0L24.248,0L24.248,24L0.248,24z"
15+
android:fillColor="#333"
16+
android:fillType="evenOdd"/>
17+
</group>
18+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="25dp"
3+
android:height="24dp"
4+
android:viewportWidth="25"
5+
android:viewportHeight="24">
6+
<path
7+
android:pathData="M3.358,5.11c-2.147,2.148 -2.147,5.63 0,7.777l6.834,6.834 0.135,0.125c0.505,0.437 1.158,0.649 1.814,0.601l0.108,-0.012 -0.072,-0.007c0.775,0.112 1.562,-0.142 2.127,-0.707l6.833,-6.834 0.181,-0.19c1.972,-2.174 1.895,-5.511 -0.18,-7.586l-0.2,-0.19 -0.193,-0.167c-2.168,-1.79 -5.37,-1.658 -7.384,0.357L12.248,6.223l-1.113,-1.112c-2.147,-2.148 -5.629,-2.148 -7.776,0z"
8+
android:fillColor="#333"
9+
android:fillType="nonZero"/>
10+
</vector>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:pathData="M12,17.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM4,17.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM20,17.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM12,18.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM4,18.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM20,18.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM12,9.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM4,9.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM20,9.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM12,10.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM4,10.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM20,10.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM12,1.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM4,1.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5S2.62,1.524 4,1.524zM20,1.5c1.38,0 2.5,1.12 2.5,2.5S21.38,6.5 20,6.5 17.5,5.38 17.5,4 18.62,1.5 20,1.5zM12,2.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM4,2.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM20,2.5c-0.828,0 -1.5,0.672 -1.5,1.5s0.672,1.5 1.5,1.5 1.5,-0.672 1.5,-1.5 -0.672,-1.5 -1.5,-1.5z"
8+
android:fillColor="#333"
9+
android:fillType="nonZero"/>
10+
<group>
11+
<clip-path
12+
android:pathData="M12,17.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM4,17.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM20,17.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM12,18.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM4,18.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM20,18.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM12,9.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM4,9.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM20,9.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM12,10.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM4,10.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM20,10.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM12,1.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5 1.12,-2.5 2.5,-2.5zM4,1.524c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5 -2.5,-1.12 -2.5,-2.5S2.62,1.524 4,1.524zM20,1.5c1.38,0 2.5,1.12 2.5,2.5S21.38,6.5 20,6.5 17.5,5.38 17.5,4 18.62,1.5 20,1.5zM12,2.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM4,2.524c-0.828,0 -1.5,0.672 -1.5,1.5 0,0.829 0.672,1.5 1.5,1.5s1.5,-0.671 1.5,-1.5c0,-0.828 -0.672,-1.5 -1.5,-1.5zM20,2.5c-0.828,0 -1.5,0.672 -1.5,1.5s0.672,1.5 1.5,1.5 1.5,-0.672 1.5,-1.5 -0.672,-1.5 -1.5,-1.5z"/>
13+
<path
14+
android:pathData="M0,0L24,0L24,24L0,24z"
15+
android:fillColor="#333"
16+
android:fillType="evenOdd"/>
17+
</group>
18+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<item android:drawable="@drawable/ic_heart_24" android:state_selected="false" />
5+
6+
<item android:drawable="@drawable/ic_heart_24_active" android:state_selected="true" />
7+
8+
<item android:drawable="@drawable/ic_heart_24" />
9+
10+
</selector>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<solid android:color="#FFFFFF"/>
4+
<corners android:topLeftRadius="40dp" android:topRightRadius="40dp"/>
5+
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
6+
</shape>

0 commit comments

Comments
 (0)