-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AN/USER] feat: 메인 화면을 프래그먼트, 바텀네비게이션 구현(#92) #104
Changes from 5 commits
a8b124e
d54495b
c4f3ff7
49778c9
8f95575
71398e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.festago.festago.presentation.ui.home | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import com.festago.festago.R | ||
import com.festago.festago.databinding.ActivityHomeBinding | ||
import com.festago.festago.presentation.ui.home.festivallist.FestivalListFragment | ||
import com.festago.festago.presentation.ui.home.mypage.MyPageFragment | ||
import com.festago.festago.presentation.ui.home.ticketlist.TicketListFragment | ||
|
||
class HomeActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val binding = ActivityHomeBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.bnvHome.setOnItemSelectedListener { | ||
when (getItemType(it.itemId)) { | ||
HomeItemType.FESTIVAL_LIST -> changeFragment<FestivalListFragment>() | ||
HomeItemType.TICKET_LIST -> changeFragment<TicketListFragment>() | ||
HomeItemType.MY_PAGE -> changeFragment<MyPageFragment>() | ||
} | ||
true | ||
} | ||
|
||
changeFragment<FestivalListFragment>() | ||
} | ||
|
||
private fun getItemType(menuItemId: Int): HomeItemType { | ||
return when (menuItemId) { | ||
R.id.item_festival -> HomeItemType.FESTIVAL_LIST | ||
R.id.item_mypage -> HomeItemType.MY_PAGE | ||
R.id.item_ticket -> HomeItemType.TICKET_LIST | ||
else -> throw IllegalArgumentException("menu item id not found") | ||
} | ||
} | ||
|
||
private inline fun <reified T : Fragment> changeFragment() { | ||
val tag = T::class.java.name | ||
val fragmentTransaction = supportFragmentManager.beginTransaction() | ||
|
||
supportFragmentManager.fragments.forEach { fragment -> | ||
fragmentTransaction.hide(fragment) | ||
} | ||
|
||
var targetFragment = supportFragmentManager.findFragmentByTag(tag) | ||
|
||
if (targetFragment == null) { | ||
targetFragment = T::class.java.newInstance() | ||
fragmentTransaction.add(R.id.fcv_home_container, targetFragment, tag) | ||
} else { | ||
fragmentTransaction.show(targetFragment) | ||
} | ||
|
||
fragmentTransaction.commit() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.festago.festago.presentation.ui.home | ||
|
||
enum class HomeItemType { | ||
FESTIVAL_LIST, | ||
TICKET_LIST, | ||
MY_PAGE, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.festago.festago.presentation.ui.home.festivallist | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.festago.festago.R | ||
import com.festago.festago.databinding.FragmentFestivalListBinding | ||
|
||
class FestivalListFragment : Fragment(R.layout.fragment_festival_list) { | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
val binding = FragmentFestivalListBinding.inflate(inflater) | ||
return binding.root | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.festago.festago.presentation.ui.home.mypage | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.festago.festago.R | ||
import com.festago.festago.databinding.FragmentMyPageBinding | ||
|
||
class MyPageFragment : Fragment(R.layout.fragment_my_page) { | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
val binding = FragmentMyPageBinding.inflate(inflater) | ||
return binding.root | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragment LifeCycle 과 ViewLifeCycle 이 달라서 binding 을 놓아주는 과정이 필요할 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반영했습니다 👍 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.festago.festago.presentation.ui.home.ticketlist | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.festago.festago.R | ||
import com.festago.festago.databinding.FragmentTicketListBinding | ||
|
||
class TicketListFragment : Fragment(R.layout.fragment_ticket_list) { | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
val binding = FragmentTicketListBinding.inflate(inflater) | ||
return binding.root | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#FFFFFF" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M13,5.7l0,-1.7l3,0l-1,-1.49l1,-1.51l-5,0l0,4.7l-9,6.3l0,10l7,0l0,-5l3.03,-2l2.97,2l0,5l7,0l0,-10z"/> | ||
</vector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#FFFFFF" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/> | ||
</vector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presentation.ui.home.HomeActivity"> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/fcv_home_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toTopOf="@id/bnv_home" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.google.android.material.bottomnavigation.BottomNavigationView | ||
android:id="@+id/bnv_home" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:labelVisibilityMode="unlabeled" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:menu="@menu/menu_bottom_navigation" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout> | ||
|
||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presentation.ui.home.festivallist.FestivalListFragment"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:text="Festival List Fragment" /> | ||
|
||
</FrameLayout> | ||
</layout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout> | ||
|
||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presentation.ui.home.mypage.MyPageFragment"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:text="My Page Fragment" /> | ||
|
||
</FrameLayout> | ||
</layout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout> | ||
|
||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presentation.ui.home.ticketlist.TicketListFragment"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:text="Ticket List Fragment" /> | ||
|
||
</FrameLayout> | ||
</layout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:id="@+id/item_festival" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_bottom_navigation_festival" | ||
android:iconTint="@color/md_theme_light_secondary" | ||
android:title="@string/home_bottom_navigation_festival" /> | ||
<item | ||
android:id="@+id/item_ticket" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_festago_logo_foreground" | ||
android:iconTint="@color/md_theme_light_secondary" | ||
android:title="@string/home_bottom_navigation_ticket" /> | ||
<item | ||
android:id="@+id/item_mypage" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_bottom_navigation_user" | ||
android:iconTint="@color/md_theme_light_secondary" | ||
android:title="@string/home_bottom_navigation_user" /> | ||
</menu> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,9 @@ | |
<string name="ticket_entry_tv_before_entry">입장 전</string> | ||
<string name="ticket_entry_tv_after_entry">입장 완료</string> | ||
<string name="ticket_entry_tv_away">외출중</string> | ||
|
||
<!-- Strings related to home --> | ||
<string name="home_bottom_navigation_festival">축제 목록</string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<string name="home_bottom_navigation_ticket">티켓 목록</string> | ||
<string name="home_bottom_navigation_user">마이페이지</string> | ||
</resources> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이슈와 관련된 수정사항만 커밋해주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
예.