Skip to content

Commit

Permalink
[AN/USER] feat: 메인 화면을 프래그먼트, 바텀네비게이션 구현(#92) (#104)
Browse files Browse the repository at this point in the history
* feat: 빈 프래그먼트 추가 (FestivalList, TicketList, MyPage)

* feat: 바텀네비게이션 menu

* feat: HomeActivity 바텀네비게이션 구현

* refactor: 확장함수 제거

* chore: 문자열 리소스 주석 추가

* fix: onDestroyView에서 binding null 처리
  • Loading branch information
EmilyCh0 authored Jul 24, 2023
1 parent 92ed15c commit 96511a4
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 5 deletions.
12 changes: 8 additions & 4 deletions android/festago/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -15,17 +16,20 @@
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".presentation.ui.ticketentry.TicketEntryActivity"
android:exported="true"></activity>
<activity
android:name=".presentation.ui.MainActivity"
android:name=".presentation.ui.home.HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".presentation.ui.ticketentry.TicketEntryActivity"
android:exported="false" />
<activity
android:name=".presentation.ui.MainActivity"
android:exported="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MainViewModel(

fun loadTicket() {
viewModelScope.launch(exceptionHandler) {
_ticket.postValue(ticketRepository.loadTicket(0L).toPresentation())
_ticket.postValue(ticketRepository.loadTicket(9L).toPresentation())
}
}

Expand Down
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,29 @@
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) {

private var _binding: FragmentFestivalListBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
_binding = FragmentFestivalListBinding.inflate(inflater)
return binding.root
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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) {

private var _binding: FragmentMyPageBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
_binding = FragmentMyPageBinding.inflate(inflater)
return binding.root
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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) {

private var _binding: FragmentTicketListBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
_binding = FragmentTicketListBinding.inflate(inflater)
return binding.root
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
}
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>
27 changes: 27 additions & 0 deletions android/festago/app/src/main/res/layout/activity_home.xml
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>
16 changes: 16 additions & 0 deletions android/festago/app/src/main/res/layout/fragment_festival_list.xml
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>
16 changes: 16 additions & 0 deletions android/festago/app/src/main/res/layout/fragment_my_page.xml
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>
16 changes: 16 additions & 0 deletions android/festago/app/src/main/res/layout/fragment_ticket_list.xml
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>
21 changes: 21 additions & 0 deletions android/festago/app/src/main/res/menu/menu_bottom_navigation.xml
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>
5 changes: 5 additions & 0 deletions android/festago/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
<string name="home_bottom_navigation_ticket">티켓 목록</string>
<string name="home_bottom_navigation_user">마이페이지</string>
</resources>

0 comments on commit 96511a4

Please sign in to comment.