Skip to content
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

Merged
merged 6 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이슈와 관련된 수정사항만 커밋해주세요!

Copy link
Member Author

@EmilyCh0 EmilyCh0 Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예.

}
}

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,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fragment LifeCycle 과 ViewLifeCycle 이 달라서 binding 을 놓아주는 과정이 필요할 것 같아요!

https://developer.android.com/guide/fragments/lifecycle

Copy link
Member Author

Choose a reason for hiding this comment

The 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>
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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!-- Strings related to home --> 넣어주면 좋을 거 같아요!

<string name="home_bottom_navigation_ticket">티켓 목록</string>
<string name="home_bottom_navigation_user">마이페이지</string>
</resources>