Skip to content

Commit

Permalink
[BUD-50] feat : buddy 추가 부분 뒤로 가기 버튼 기능 추가(#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
KDW03 committed Apr 9, 2023
1 parent cc2e596 commit 65dfdc8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.nocapstone.buddyvet.buddy.ui

import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.nocapstone.buddyvet.buddy.databinding.FragmentCompleteRegistrationBinding
import com.nocapstone.common.util.LoginUtil
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -35,6 +37,8 @@ class CompleteRegistrationFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initMenu()

binding.apply {
this.viewModel = buddyViewModel
this.lifecycleOwner = viewLifecycleOwner
Expand All @@ -47,6 +51,25 @@ class CompleteRegistrationFragment : Fragment() {
}
}

private fun initMenu() {
val menuHost: MenuHost = requireActivity()

menuHost.addMenuProvider(object : MenuProvider {

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
android.R.id.home -> {
findNavController().popBackStack()
}
}
return true
}
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
}


override fun onDestroyView() {
super.onDestroyView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package com.nocapstone.buddyvet.buddy.ui

import android.os.Bundle
import android.util.Log
import android.view.*
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.navigation.fragment.findNavController
import com.nocapstone.buddyvet.buddy.R
import com.nocapstone.buddyvet.buddy.databinding.FragmentInputBuddyInfoBinding
Expand Down Expand Up @@ -38,6 +39,8 @@ class InputBuddyInfoFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initMenu()

val neuteredAdapter = ArrayAdapter(
requireContext(),
list_item,
Expand Down Expand Up @@ -104,5 +107,24 @@ class InputBuddyInfoFragment : Fragment() {
_binding = null
}

private fun initMenu() {
val menuHost: MenuHost = requireActivity()

menuHost.addMenuProvider(object : MenuProvider {

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
android.R.id.home -> {
findNavController().popBackStack()
}
}
return true
}
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
}


}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.nocapstone.buddyvet.buddy.ui

import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.navigation.fragment.findNavController
import com.nocapstone.buddyvet.buddy.R
import com.nocapstone.buddyvet.buddy.databinding.FragmentInputBuddyTypeBinding
Expand All @@ -27,6 +28,7 @@ class InputBuddyTypeFragment : Fragment() {
// Inflate the layout for this fragment
_binding = FragmentInputBuddyTypeBinding.inflate(inflater, container, false)


(activity as MainActivityUtil).run {
setToolbarTitle("버디 추가")
setVisibilityBottomAppbar(View.GONE)
Expand All @@ -39,6 +41,7 @@ class InputBuddyTypeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initMenu()

binding.viewModel = buddyViewModel
binding.lifecycleOwner = viewLifecycleOwner
Expand All @@ -62,4 +65,23 @@ class InputBuddyTypeFragment : Fragment() {
_binding = null
}

private fun initMenu() {
val menuHost: MenuHost = requireActivity()

menuHost.addMenuProvider(object : MenuProvider {

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
android.R.id.home -> {
findNavController().popBackStack()
}
}
return true
}
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
}

}
4 changes: 2 additions & 2 deletions buddy/src/main/res/layout/fragment_input_buddy_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
android:textSize="17sp" />

<TextView
android:id="@+id/adoptDay_tv"
android:id="@+id/birthDay_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="16dp"
Expand Down Expand Up @@ -176,7 +176,7 @@
android:textSize="17sp" />

<TextView
android:id="@+id/birthDay_tv"
android:id="@+id/adoptDay_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="16dp"
Expand Down

0 comments on commit 65dfdc8

Please sign in to comment.